akhauriyash/Code-Regression huggingface dataset:
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
H=n1()

dp=[float("inf")]*n
dp[0]=0
for i in range(0,n):
    for j in range(1,k+1):
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))

print(dp[n-1])

Measured memory_bytes: 55556
#include<cstdio>
#define MAX(a,b) (a>(b)?a:(b))
int n,m,a[100010];
signed main()
{
	scanf("%d%d",&n,&m);int mn(0),cnt(0),ans(0);
	for(register int i(1);i<=n;i++)
		scanf("%d",&a[i]);
	for(register int i(n);i;i--)
		cnt=MAX(cnt,(mn=MAX(a[i],mn))-a[i]);
	mn=0;
	for(register int i(n);i;i--)
		ans+=((mn=MAX(mn,a[i]))==cnt+a[i]);
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;

ll n;
ll a[100001];
ll ans = 0;

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

    //連想配列
    //添字を基準にしてそれぞれが何個あるか知る時に便利
    map<ll,ll> mp;
    for(ll i=0;i<n;i++) mp[a[i]]++;

    for(auto p: mp){
        ll x=p.first;
        ll y=p.second;
        if(y<x) ans += y;
        else ans += y-x;
    }

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


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

int main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<int> a;

	a.emplace_back(0);
	if (s[0] == '0')
		a.emplace_back(0);

	for (int i = 1; i < n; i++)
		if (s[i - 1] != s[i])
			a.emplace_back(i);

	a.emplace_back(n);
	if (s[n - 1] == '0')
		a.emplace_back(n);

	if (k * 2 >= (int) a.size()) {
		cout << *(a.end() - 1);
		return 0;
	}

	int max = 0;
	for (int i = 0; i + k * 2 + 1 < (int) a.size(); i += 2) {
		if (a[i + k * 2 + 1] - a[i] > max)
			max = a[i + k * 2 + 1] - a[i];
	}
	cout << max << endl;
}


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

int main(){
  int A, B;
  int count = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    int temp = i;
    int reversed = 0;
    while (temp > 0) {
      reversed = reversed * 10 + temp % 10;
      temp /= 10;
    }
    if (reversed == i) count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 256
a,b=map(int,input().split())

def calc(x):
      
    a = x%4

    if a == 0:
        return x
    elif a == 1:
        return 1
    elif a == 2:
       return x^1
    else:
        return 0
 
print(calc(b) ^ calc(a-1))


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> city(N, 0);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == b) city[a - 1]++;
    else {
      city[a - 1]++;
      city[b - 1]++;
    }
  }
  for (int i = 0; i < N; ++i) {
    cout << city[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    string s[3];
    REP(i,3){
        cin >> s[i];
    }
    int ans = 0;
    REP(i,n){
        int cnt[26] = {};
        REP(j,3){
            cnt[s[j][i] - 'a']++;
        }
        sort(cnt, cnt + 26);
        reverse(cnt, cnt + 26);
        ans += 3 - cnt[0];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int 
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define do			double
#define all(v)		v.begin(),v.end()	
#define et(v)		for(auto itr:v)
#define mod			1000000007
inline void p(int x[],int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }

void solve()
{  	
	ll N,M,K,i,j,sum=0;
	cin>>N;
	vector<ll> A(N);
	f(i,N)
		cin>>A[i];
	f(i,N-1)
	{
		if(A[i]>A[i+1])
		{	sum+=A[i]-A[i+1];
			A[i+1]=A[i];
		}
	}
	cout<<sum;



}
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{
		

		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<"\n";
		
	}
	return 0;
}


Measured memory_bytes: 4688
#include<iostream>
using namespace std;
#define ll long long

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

int main()
{

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

    ll k;
  cin >> k;
  
 	ll g1, g2, sum=0;
  for(ll i=1; i<=k; i++){
    for(ll j=1; j<=k; j++){
      g1 = GCD(i,j);
      for(ll m=1; m<=k; m++){
        g2 = GCD(g1, m);
        sum += g2;
      }
    }
  }
  cout << sum;
  
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
inline ll min(ll a,ll b){
	return a<b?a:b;
}
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	n%=k;
	printf("%lld\n",min(n,k-n));
	return 0;
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

const int N = 1e5 + 1e3;

char str[N];

int main () {

	scanf ("%s", str + 1);

	int len = strlen(str + 1);
	puts((len - (str[1] == str[len])) & 1 ? "First" : "Second");

    return 0;

}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

        while (in.hasNext()) {
            int a = in.nextInt();
            int b = in.nextInt();
            int k = (int)Math.log10( (double)(a+b) )+1;
            System.out.println(k);
        }
    }
}

Measured memory_bytes: 26524
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1007;

int main(){
	ll n,m;
	cin>>n>>m;
	ll ans;
	ans = min(n,m/2);
	n-=ans;
	m-=ans*2;
	if(m!=0){
		ans+=m/4;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int Square(int x, int y)
{
return x*y;
}
 
int Length(int x, int y)
{
return 2*(x+y);
}
 
int main()
{
int x;
int y;
 
cin>>x>>y;
cout<<Square(x,y) <<" "<<Length(x,y)<<endl;
return 0;
}
 

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

int main(){
	string key[10];
	key[0]="";
	key[1]=".,!? ";
	key[2]="abc";
	key[3]="def";
	key[4]="ghi";
	key[5]="jkl";
	key[6]="mno";
	key[7]="pqrs";
	key[8]="tuv";
	key[9]="wxyz";

	int m;
	cin >> m;
	for(int i=0;i<m;i++){
		string str;
		cin >> str;
		vector<char> res;
		int b=-1,n=-1;
		for(int i=0,a;i<str.length();i++,n++,b=a){
			a=(char)str[i]-'0';
			if(b!=-1&&b!=a){
				if(b!=0)
					res.push_back(key[b][n%key[b].length()]);
				n=-1;
			}
		}
		if(b!=0)
			res.push_back(key[b][n%key[b].length()]);


		string s(res.begin(),res.end());
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
n, m, v, p = map(int, input().split())

a = list(map(int, input().split()))
a.sort(reverse=True)

mv = m*max(0, v-p+1)
b = a[p-1:]

l, r = b[0], b[0]+m
while l < r:
    md = (l+r)//2
    c = 0
    for i in b:
        c += min(m, md-i)
    if mv <= c:
        r = md
    else:
        l = md + 1

result = p
for i in b[1:]:
    if i+m >= r:
        result += 1
    else:
        break
print(result)

Measured memory_bytes: 62576
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    long x, y;
    readlnTo(x, y);
    long ans = long.max;
    if(x <= y) {
        ans = min(ans, y-x);
    }
    if(-x <= y) {
        ans = min(ans, y - (-x) + 1);
    }
    if(x <= -y) {
        ans = min(ans, -y - x + 1);
    }
    if(-x <= -y) {
        ans = min(ans, -y - (-x) + 2);
    }
    writeln(ans);
}



Measured memory_bytes: 256
from itertools import *
from numpy import *
n,k = map(int,input().split())
k = 2*k+1
s = input()
x = [0]*(s[0]=="0")+[len(list(v))for k,v in groupby(s)]+[0]*(s[-1]=="0")
x1 = array(x[k:])
x2 = array(x[:-k])
x3 = sum(x[:k])
y = [x3]+list(x3+cumsum(x1-x2))
print(max(y[::2]))

Measured memory_bytes: 34424
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

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

    if(A <= C && C <= B) cout << "Yes" << endl;
    else if(B <= C && C <= A) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

n,k=map(int,input().split())
a=list(map(int,input().split()))
x=max(a)
for i in range(1,n):
    a[0]=gcd(a[0],a[i])
if k%a[0]==0 and k<=x:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14096
#include<bits/stdc++.h>
using namespace std;
const long long INF = (long long)1 << 60;

struct cake
{
    long long x, y, z;
};


int main() {
    int N, M;
    cin >> N >> M;
    vector<cake> input;
    for (size_t i = 0; i < N; i++)
    {
        cake c;
        cin >> c.x >> c.y >> c.z;
        input.push_back(c);
    }

    long long d[N];
    long long ans = -INF;
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < N; j++)
        {
            d[j] = 0;
            if(i & 1) d[j] += input[j].x;
            else d[j] -= input[j].x;
            if(i & 2) d[j] += input[j].y;
            else d[j] -= input[j].y;
            if(i & 4) d[j] += input[j].z;
            else d[j] -= input[j].z;
        }
        sort(d, d + N);
        long long tmp = 0;
        for (int j = 0; j < M; j++)
        {
            tmp += d[N - 1 - j];
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}

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

int main()
{
  int a[3][3];
  bool c[3][3];
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  rep(i, 3) rep(j, 3) c[i][j] = false;
  int n; cin >> n;
  rep(k, n) {
    int b; cin >> b;
    rep(i, 3) rep(j, 3) {
      if (a[i][j]==b) c[i][j] = true;
    }
  }
  bool flg = false;
  rep(i, 3) {
    if (c[i][0]&&c[i][1]&&c[i][2]) flg = true;
  }
  rep(i, 3) {
    if (c[0][i]&&c[1][i]&&c[2][i]) flg = true;
  }
  if (c[0][0]&&c[1][1]&&c[2][2]) flg = true;
  if (c[2][0]&&c[1][1]&&c[0][2]) flg = true;
  if (flg) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
// AOJ 1590: One-Time Path
// 2017.11.29 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 200000
typedef struct { int t, node; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
//	return 1;
}

void enq(int n, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].node = n, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 1000000010
typedef struct { int to[20]; int c[20]; } TBL;
TBL tbl[100002];
int len[100002];
int dist[100002];

typedef struct { int a, c; } T;
T last[100002]; int sz;

int cmp(T *a, T *b) { return b->c - a->c; }

void dijkstra(int start)
{
	int i, s, e, c, d;

	qsize = 0;
	dist[start] = 0;
	enq(start, 0);
	while (qsize) {
		s = que[0].node; c = que[0].t, deq();
		for (i = 0; i < len[s]; i++) {
			e = tbl[s].to[i];
			if (c <= (d = tbl[s].c[i]) && d < dist[e]) dist[e] = d, enq(e, d);
		}
	}
}

char buf[40], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, n1, m, a, b, c, i;

	fgets(bp=buf, 40, stdin);
	n = getint(), bp++, m = getint();
	n1 = n - 1;

	for (i = 0; i < m; i++) {
		fgets(bp=buf, 40, stdin);
		a = getint()-1, bp++, b = getint()-1, bp++, c = getint();
		tbl[a].to[len[a]] = b, tbl[a].c[len[a]++] = c;
		if (b == n1) last[sz].a = a, last[sz++].c = c;
	}

	memset(dist, 0x77, sizeof(dist));
	dijkstra(0);

	if (dist[n-1] > INF) puts("-1");
	else {
		qsort(last, sz, sizeof(T), cmp);
		for (i = 0; i < sz; i++) {
			a = last[i].a;
			if (dist[a] <= last[i].c) { printf("%d\n", last[i].c); break; }
		}
	}
	return 0;
}

Measured memory_bytes: 18048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int[][] dp = new int[s.length() + 1][t.length() + 1];

		for (int i = 1; i <= s.length(); i++) {
			for (int j = 1; j <= t.length(); j++) {
				if (s.charAt(i-1) != t.charAt(j-1)) {
					dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
				} else {
					dp[i][j] = dp[i-1][j-1] + 1;
				}
			}
		}

		if (dp[s.length()][t.length()] == 0) {
			System.out.println();
			return;
		}

		StringBuilder sb = new StringBuilder();
		int i = s.length(), j = t.length();
		while (i != 0 && j != 0) {
			if (dp[i][j] == dp[i-1][j]) {
				i--;
			} else if (dp[i][j] == dp[i][j-1]) {
				j--;
			} else if (dp[i][j] == dp[i-1][j-1] + 1) {
				sb.append(t.charAt(j-1));
				i--;
				j--;
			}
		}
		sb.reverse();
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 82892
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	sort(ar+1,ar+n+1,greater<ll>());

	ll an=ar[1]; j=2; k=0;
	for(i=2;i<n;i++){
		if(k==2){
			j++; k=0;
		}
		an+=ar[j]; k++;
	}
	cout<<an<<endl;
	return 0;	
}

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

int N,A;

int main()
{
    cin>>N;
    int cnt=30;
    for (int i=0; i<N; i++) {
        cin>>A;
        int cntTemp=0;
        for (int j=0; A%2==0; j++) {
            A/=2;
            cntTemp++;
        }
        if (cnt>cntTemp) cnt=cntTemp;
    }
    cout <<cnt;
    return 0;
}

//Shift ONly


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<int> A(n);

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

    map<int,int> cnts;
    for (auto x : A) {
        ++cnts[x];
    }

    int res = 0;
    for (auto& p : cnts) {
        res = max(res, p.second);

        int x = p.first;

        int ans = p.second;
        for (int i = -1; i < 2; i += 2) {
            int nx = x + i;
            auto it = cnts.find(nx);
            if (it != cnts.end()) {
                ans += it->second;
            }
        }
        res = max(res, ans);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 6456
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        map<string, int> mp;
        int mx = INT_MIN;
        for (int x = 0; x < n; ++x){
            string s; cin >> s;
            mp[s]++;
            mx = max(mx, mp[s]);
        }
        for (auto x : mp){
            if (x.second == mx){
                cout << x.first << endl;
            }
        }
    return 0;
}


Measured memory_bytes: 19228
N = input()
l = map(int, raw_input().split())
i = 1
while i < N:
    l_str = map(str,l)
    print " ".join(l_str)
    tmp = l[i]
    j = i - 1
    while j >= 0 and tmp < l[j]:
        l[j + 1] = l[j]
        j -= 1
    l[j + 1] = tmp
    i += 1
l_str = map(str,l)
print " ".join(l_str)

Measured memory_bytes: 6392
import sys

def solve():
    input = sys.stdin.readline
    W, H, x, y = map(int, input().split())
    if x * 2 == W and y * 2 == H: print(W * H / 2, 1)
    else: print(W * H / 2, 0)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 2940
while True:
  try:
    a = int(input())
  except:break
  if a%39 == 0:
        print("3C39")
  else:
    b = a // 39
    c = a - 39 * b
    if c < 10:
      print("3C0",c,sep='')
    else:
      print("3C",c,sep='')


Measured memory_bytes: 5588
/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <iomanip>

int main(){
  
  // read problem
  long long int N;
  double tmp;
  std::vector<double> p;
  
  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lf", &tmp);
    p.push_back(tmp);
  }
  
  // solve problem
  std::vector<std::vector<double> > dp_table(N+1);
  for(long long int i = 0; i <= N; i++){
    for(long long int j = 0; j <= i; j++){
      dp_table[i].push_back(0.0);
    }
  }
  
  dp_table[0][0] = 1.0;
  for(long long int i = 1; i <= N; i++){
    // the probability that all coins are face.
    dp_table[i][i] = dp_table[i-1][i-1] * p[i-1];
    // the probability that all coins are back
    dp_table[i][0] = dp_table[i-1][0] * (1.0 - p[i-1]);
    
    // other cases
    for(long long int j = 1; j < i; j++){
      dp_table[i][j] = dp_table[i-1][j-1] * p[i-1] + dp_table[i-1][j] * (1-p[i-1]);
    }
  }
  
  double ans = 0.0;
  for(long long int i = (N+1)/2; i <= N; i++){
    ans += dp_table[N][i];
  }
  
  std::cout << std::setprecision(12) << ans << std::endl;
  
  
}



Measured memory_bytes: 43776
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int s = sc.nextInt();
      int m=0,h=0;
      while(s>=60){
        s = s - 60;
        m++;
        while(m>=60){
          m = m - 60;
          h++;
        }
      }
      System.out.println(h+":"+m+":"+s);
    }
}



Measured memory_bytes: 26224
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int main() {
	int N;
	ll x, ans=0;
	cin >> N >> x;
	vector<ll> a(N), mn(N);
	for(int i=0; i<N; ++i){
	    cin >> a[i];
	    mn[i]=a[i];
	    ans += a[i];
	}
	for(int i=1; i<N; ++i){
	    ll now=0;
	    for(int j=0; j<N; ++j){
	        mn[j]=min(mn[j], a[(j+N-i)%N]);
	        now += mn[j];
	    }
	    ans=min(ans, now+x*i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

ll Pow(ll n, ll p) {
	if (p == 0)return 1;
	if (p == 1)return n;
	ll t = Pow(n, p / 2);
	if (p & 1) return (t * t % MOD) * n % MOD;
	else return t * t % MOD;
}

int main() {
	ll n, k; cin >> n >> k;

	ll ans = 0;
	if (!(k & 1)) {//k is even
		ll cnt = 0;
		repe(i, 1, n) {
			if (i % k == k / 2)cnt++;
		}
		//ans = Pow(cnt, 3);
		ans += cnt * cnt*cnt;
	}

	ll cnt = 0;
	repe(i, 1, n) {
		if (i % k == 0)cnt++;
	}
	ll t = n / k;
	ans += t * t*t;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.file.Paths;

class DoublyLinkedList implements Iterable<Integer> {  

	private Node virtualNode;

	class Node {
		int value;
		Node prev;
		Node next;

		Node(int x) {
			value = x;
			prev = null;
			next = null;
		}
	}

	public DoublyLinkedList() {
		virtualNode = new Node(0);
		virtualNode.next = virtualNode;
		virtualNode.prev = virtualNode;
	}

	// insert to the front
	public void insert(int x) {
		Node node = new Node(x);
		node.next = virtualNode.next;
		virtualNode.next.prev = node;
		virtualNode.next = node;
		node.prev = virtualNode;
	}

	private Node linearSearch(int x) {
		Node currentNode = virtualNode.next;
		// there is no element
		if (currentNode == virtualNode)
			return null;
		while (currentNode != virtualNode) {
			if (currentNode.value != x)
				currentNode = currentNode.next;
			else 
				return currentNode;
		}

	// nothing matched found
		return null;
	}

	
	public void delete(int x) throws Exception {
		Node nodeDeleted = linearSearch(x);
		if (nodeDeleted == null) {
			return;
		}else {
			delete(nodeDeleted);
		}
	}

	private void delete(Node nodeDeleted) throws Exception {

		if (!isEmpty()){
			Node prevNode = nodeDeleted.prev;
			Node nextNode = nodeDeleted.next;
			prevNode.next = nextNode;
			nextNode.prev = prevNode;
		}else {
			throw new Exception("List is empty");
		}
		
	}

	public void deleteFirst() throws Exception {
		delete(virtualNode.next);
	}

	public void deleteLast() throws Exception {
		delete(virtualNode.prev);
	}

	public int pop() throws Exception {
		int v = virtualNode.next.value;
		deleteFirst();
		return v;			
	}

	private boolean isEmpty() {
		return virtualNode.next == virtualNode;
	}

	public Iterator<Integer> iterator() {
		return new Iterator<Integer>() {
			private Node currentNode = virtualNode.next;

			public boolean hasNext() {
				return currentNode != virtualNode;
			}

			public Integer next() {
				int v = currentNode.value;
				currentNode = currentNode.next;
				return v;
			}
		};
	}
}


public class Main
{
	public static void main(String[] args) {

		DoublyLinkedList list = new DoublyLinkedList();

		// BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
	
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			int n = Integer.parseInt(reader.readLine());


			String line;

			for (int i = 0; i < n; i++) {

				line = reader.readLine();
			
				if (line.charAt(0) == 'i') {
					list.insert(Integer.parseInt(line.substring(7)));
				}else if (line.charAt(6) == ' ') {
					list.delete(Integer.parseInt(line.substring(7)));
				}else if (line.charAt(6) == 'F') {
					list.deleteFirst();
				}else {
					list.deleteLast();
				}

			}

			StringBuilder builder = new StringBuilder();
			builder.append(list.pop());

			for (int i: list) {
				builder.append(" " + i);
			}
			System.out.println(builder.toString());

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 131428
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll white = 0, red = 0;
    rep(i, n){
        if(s[i] == 'W') white++;
        else red++;
    }
    if(white == 0 || red == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    rep(i, n){
        if(i >= red && s[i] == 'R') ans++;
    }
    cout << ans << endl;
    return 0;
}

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

inline int read()
{
	int f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}

int n;
int ans;
bool t;
char c[100005];

int main()
{
	int i;
	scanf("%s",c+1);
	n=strlen(c+1);
	t=0;
	int cnt=0;
	for(i=1;i<=n;i++)
	{
		if(c[i]-'0'!=t) cnt++;
		t^=1;
	}
	t=1;
	for(i=1;i<=n;i++)
	{
		if(c[i]-'0'!=t) ans++;
		t^=1;
	}
	printf("%d",min(ans,cnt));
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n,m,l;
    cin >> n >> m >> l;
    long long arrayA[n][m];
    long long arrayB[m][l];
    long long arrayC[n][l];
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            cin >> arrayA[i][j];
        }
    }
    
    for(int i=0;i<m;i++) {
        for(int j=0;j<l;j++) {
            cin >> arrayB[i][j];
        }
    }
    
    for(int i=0;i<n;i++) {
        for(int j=0;j<l;j++) {
            arrayC[i][j] = 0;
        }
    }
    
    for(int i=0;i<n;i++) {
        for(int j=0;j<l;j++) {
            for(int k=0;k<m;k++) {
                arrayC[i][j] = arrayC[i][j] + arrayA[i][k] * arrayB[k][j];
            }
        }
    }
    
    for(int i=0;i<n;i++) {
        for(int j=0;j<l;j++) {
            cout << arrayC[i][j];
            if(j != l-1)
                cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3276
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val s = read() 
    val n = s.length
    var size = 0
    for(i in 0 until n) {
        for(j in i until n) {
            val slicedS = s.slice(i..j) 
            if(slicedS.all {  listOf('A', 'T', 'G', 'C').contains(it) }) {
                size = Math.max(size, slicedS.length)
            }
        }
    }
    println(size)
    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

using namespace std;

int main(){
    int a,b;
    while(true){
        cin >> a >> b;
        if(a+b == 0){break;}
        if(a>b){cout << b << " " << a << endl;}
        else{cout << a << " " << b << endl;}
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

using namespace std;

int max(int a, int b);
void findLCS(char *X, char *Y, int XLen, int YLen);

int max(int a, int b) {
	return (a > b)? a : b;
}

void findLCS(char *X, char *Y, int XLen, int YLen) {
	int L[XLen + 1][YLen + 1];
	int r, c, i;

	/*
	 * find the length of the LCS
	 */
	for(r = 0; r <= XLen; r++) {

		for(c = 0; c <= YLen; c++) {

			if(r == 0 || c == 0) {

				L[r][c] = 0;

			} else if(X[r - 1] == Y[c - 1]) {

				L[r][c] = L[r - 1][c - 1] + 1;

			} else {

				L[r][c] = max(L[r - 1][c], L[r][c - 1]);
			}
		}
	}

	/*
	 * Print LCS
	 */
	r = XLen;
	c = YLen;
	i = L[r][c];

	char LCS[i+1];

	/*
	 * setting the NULL character at the end of LCS character array.
	 * as we know in C programming language, NULL character is used
	 * to denote the end of a string
	 */
	LCS[i] = '\0';

	while(r > 0 && c > 0) {

		if(X[r - 1] == Y[c - 1]) {

			LCS[i - 1] = X[r - 1];

			i--;
			r--;
			c--;

		} else if(L[r - 1][c] > L[r][c - 1]) {

			r--;

		} else {

			c--;

		}

	}

	//print result
	// printf("Length of the LCS: %d\n", L[XLen][YLen]);
	printf("%s\n", LCS);
}
int main() {
	char X[3030];
	char Y[3030];
	scanf("%s", X);
	scanf("%s", Y);

	//length of the sequences
	int XLen = strlen(X);
	int YLen = strlen(Y);

	findLCS(X, Y, XLen, YLen);

	return 0;
}

Measured memory_bytes: 35456
//#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int ans=0;
    cin >> s;
  
   if(s=="SUN"){
       ans=7;
       }
   if (s == "MON")
   {
       ans = 6;
   }
   if (s == "TUE")
   {
       ans = 5;
   }
   if (s == "WED")
   {
       ans = 4;
   }
   if (s == "THU")
   {
       ans = 3;
   }
   if (s == "FRI")
   {
       ans = 2;
   }
   if (s == "SAT")
   {
       ans = 1;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
    
	ll n, k, s; cin >> n >> k >> s;
	for (int i = 0; i < n; i++) {
		if (i < k) { cout << s;}
		else { 
			if (s == 1000000000) { cout << "999999999"; }
			else { cout << s + 1; }
		}
		if (i != n - 1) { cout << " "; }
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1280
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
A = np.insert(A,0,0)
C = np.cumsum(A)
C %= M
ans = 0
d = defaultdict(int)
for i in range(N+1):
  ans += d[C[i]]
  d[C[i]] += 1
print(ans)

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

void initStrArray(char** p, int n, int len){
    for(int i=0; i<n; i++){
        *(p + i) = (char*)malloc(sizeof(char) * (len + 1));
    }
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int p[m];
    char* w[m];
    initStrArray(w, m, 3);
    rep(i, 0, m){
        scanf("%d %s", &p[i], w[i]);
    }
    int f[n+1],ac[n+1], wa[n+1];
    rep(i, 0, n+1){
        f[i] = 0;
        ac[i] = 0;
        wa[i] = 0;
    }
    rep(i, 0, m){
        if(*(w[i]) == 'A'){
            ac[p[i]]++;
            f[p[i]] = 1;
        }else{
            if(f[p[i]] == 0){
                wa[p[i]]++;
            }
        }
    }
    int ac_sum = 0, wa_sum = 0;
    rep(i, 1, n+1){
        if(ac[i] > 0){
            ac_sum++;
            wa_sum += wa[i];
        }
    }
    printf("%d %d", ac_sum, wa_sum);

    return 0;
}

Measured memory_bytes: 5632
ns=5.times.map{gets.to_i}
ans=0
rests=ns.map{|v| v%10}.select{|v| v>0}.sort
ns.each do |i|
  cur=0
  while cur<i
    cur+=10
  end
  ans+=cur
end
puts rests.size>0 ? ans-10+rests[0]:ans


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

int main(){
    ll a,b,total=0;
    cin >> a >> b;
    vector<ll> vec(b);
    rep(i,b) cin >> vec[i];
    rep(i,b){
        total+=vec[i];
    }
    if(total>=a) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

void sort3(int *a, int *b, int *c) {
    int d;
    if(*a < *b) {
        d = *a;
        *a = *b;
        *b = d;
    }
    if(*b < *c) {
        d = *b;
        *b = *c;
        *c = d;
    }
    if(*a < *b) {
        d = *a;
        *a = *b;
        *b = d;
    }
}

int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;

    sort3(&a, &b, &c);

    int ans = (a - b) + (b - c);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

char s1[10000], s2[10000];
int main()
{
	while(scanf("%s %s", s1, s2) != EOF)
	{
		int len1 = strlen(s1);
		int len2 = strlen(s2);
		//printf("len1 = %d len2 = %d\n", len1, len2);
		if(len1 > len2)
			printf("GREATER\n");
		if(len1 < len2)
			printf("LESS\n");
		if(len1 == len2)
		{
			if(strcmp(s1, s2) == 0)
				printf("EQUAL\n");
			if(strcmp(s1, s2) > 0)
				printf("GREATER\n");
			if(strcmp(s1, s2) < 0)
				printf("LESS\n");
		}
		memset(s1, 0, sizeof(s1));
		memset(s2, 0, sizeof(s2));
	}
}

Measured memory_bytes: 128
N, M = gets.chomp.split.map(&:to_i)
ABS = readlines.map { |l| l.chomp.split.map(&:to_i) }

h = Hash.new { |h, k| h[k] = [] }
ABS.each do |a, b|
  h[a] << b
  h[b] << a
end

def solve(s = 1, g = N, edges)
  q = []
  q += edges[s]
  routes = []
  while !q.empty?
    n = q.pop
    next if routes.include?(n)
    routes << n
    q += edges[n]
  end
  routes.count != N
end

c = 0
ABS.each do |a, b|
  h[a].delete(b)
  h[b].delete(a)
  c += 1 if solve(1, N, h)
  h[a] << b
  h[b] << a
end

p c

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define M 1000000007
#define vll vector<ll>
#define pll pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
ll a[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t, n, i, j, c, k, m, x, y, f, ans;
  cin >> n >> x >> t;
  cout << t*((n + x -1)/x);
  return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct UnionFind {
    vector<int> data;
    int gnum;
    UnionFind(int size) : data(size, -1), gnum(size) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
            gnum--;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
    int getGroupNum() {
        return gnum;
    }
    vector<vector<int>> getGroups() {
        int now = 0;
        map<int, vector<int>> G;
        for (int i = 0; i < data.size(); i++) {
            G[root(i)].push_back(i);
        }
        vector<vector<int>> ret;
        for(auto g : G) {
            ret.push_back(g.second);
        }
        return ret;
    }
};


void solve() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unionSet(a, b);
    }

    vector<vector<int>> g = uf.getGroups();
    int ans = 0;
    for(int i = 0; i < g.size(); i++) {
        ans = max(ans, (int)g[i].size());
    }

    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 36888
#include <iostream>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";
 
ll change(string s){
  ll ret = 0;
  ll alpha[26] = {};
  rep(i, 0, s.length()){
    alpha[s[i] - 'a']++;
  }
  rep(i, 0, 26){
    ret += alpha[i];
    ret *= 10;
  }
  return ret;
}

int main(){
  ll n, ans, now, last=0, count=1;
  string s;
  priority_queue<ll> s_list;
  cin >> n;
  rep(i, 0, n){
    cin >> s;
    s_list.push(change(s));
  }
  
  rep(i, 0, n){
    now = s_list.top();
    s_list.pop();
    if (now == last){
      count++;
    }else{
      if (count > 1) ans += count * (count-1) / 2;
      count = 1;
    }
    last = now;
  }
  if (count > 1) ans += count * (count-1) / 2;
  
  print(ans)
  
  return 0;
}

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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

int main(int, char**) {
	string s1, s2;
	cin >> s1 >> s2;
	reverse(s1.begin(), s1.end());
	if (s1==s2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
L = [3, 5, 7]

cnt = 0


def f(s):
    if s > n:
        return False

    str_s = str(s)
    return sum(f(s*10 + i) for i in L) + ("7" in str_s and "5" in str_s and "3" in str_s)


print(f(0))

Measured memory_bytes: 3060
'''
ITP-1_9-A
 ?????????????´¢
??????????????? W ??¨?????? T ????????????????????????T ??????????????? W ?????°???????????????????????°?????????????????????????????????
?????? T ????????????????????????????????????????????§????????????????????????????????? Ti ??¨???????????????????????? Ti ?????????????????? W ??¨??????????????????????????°??????????????????
???????????§????????¨?°???????????????\???????????????
???Constraints
W????????????????????????10????¶????????????????
T??????????????????????????????????????????1000????¶????????????????
???Input
?????????????????? W ????????????????????????
?¶???????????????°????????????????????£??????????????????????????????END_OF_TEXT ??¨??????????????????????????????????????????????????????
???Output
?????? W ?????°???????????????????????????
'''
# inputData
checkString = input()
lineString = []
while True:
    searchString = input()
    # endCheck
    if searchString == 'END_OF_TEXT':
        break
    searchString = (searchString.lower()).split()
    lineString.extend(searchString)

# outputCheck 
print(lineString.count(checkString))

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

using namespace std;

int main(){
  int N;
  cin >> N;
  double X[N];
  for(int i = 0; i< N; i++){
    cin >> X[i];
  }
  
  double min = X[0];
  double max = X[0];
  for(int i = 1; i < N; i++){
    if(min > X[i]){
      min = X[i];
    }
    if(max < X[i]){
      max = X[i];
    }
  }
  
  double ans = 0;;
  double rep = 99999999;
  for(int i = (int)min; i <= (int)max; i++){
    for(int j = 0; j < N; j++){
      ans = ans + pow(X[j] - i,2);
    }
    if(rep > ans){
      rep = ans;
    }
   ans = 0;
  }
  
  cout << rep << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

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

map<string,int> mp;
inline void out(string f)
{
    cout << f << " x " << mp[f] << "\n";
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("cowland.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    while (n--) {
        cin >> s;
        mp[s]++;
    }
    out("AC"); out("WA"); out("TLE"); out("RE");

    return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> a(N);
  for (size_t i = 0; i < a.size(); i++) {
    cin >> a[i];
  }
  vector<int> a_continuity;
  for (size_t i = 1; i < a.size(); i++) {
    if (a[i - 1] == a[i]) {
      if (a_continuity.empty()) {
        a_continuity.push_back(2);
      } else {
        a_continuity.back()++;
      }
    } else {
      a_continuity.push_back(1);
    }
    //cout << "debug;" << a_continuity[i] << endl;
  }
  int ans = 0;
  for (size_t i = 0; i < a_continuity.size(); i++) {
    ans += a_continuity[i] / 2;
    // cout << a_continuity[i] << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int n;
	ll ans = 1;
	scanf("%d", &n);
	for (int i = 1; i < n + 1; ++i) {
		ans *= i % 1000000007;
		ans = ans % 1000000007;
	}
	printf("%lld\n", ans % 1000000007);

	return 0;
}


Measured memory_bytes: 128