akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
H = list(map(int, input().split()))
dp = [float("inf") for _ in range(n)]  # 最小化問題なのでinfで初期化
dp[0] = 0  # 初期条件

for i in range(n - 1):  # 配るDP
    for j in range(1, min(k+1, n-i)):
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[n - 1])

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

int a[510][510];

void calc(int m, int d, int n, int val) {
    if (d > n) return;
    vector<int> u;
    for (int i = 0; i < n; i++) {
        if (i % d == m) u.emplace_back(i);
    }
    if (u.empty()) return;
    for (int i = 0; i < u.size(); i++) {
        for (int j = 0; j < u.size(); j++) {
            if (i % 2 != j % 2) a[u[i]][u[j]] = val;
        }
    }
    calc(m, d*2, n, val+1);
    calc(m+d, d*2, n, val+1);
}

int main() {
    int n; cin >> n;
    calc(0, 1, n, 1);
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            if (j != i+1) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

//int a[200000];
int tmp_a[200000];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> tmp_a[i];
    }

    int M = 0;
    vector <int> ans;
    for(int i = N - 1; i >= 0; i--){
        if(tmp_a[i] == 1){
            M ++;
            ans.push_back(i + 1);
        }
        int tmp = tmp_a[i];
        for(int j = 1; j <= int(floor(sqrt(i + 1))); j++){
            //cout << i + 1 << " " << j << endl;
            if((i + 1) % j == 0){
                tmp_a[j - 1] ^= tmp;
                if(j - 1 != (i + 1) / j - 1){
                    tmp_a[(i + 1) / j - 1] ^= tmp;
                }
            }
        }
        /* 
        for(int j = 0; j < N; j++){
            cout << tmp_a[j] << " ";
        }
        cout << endl;
        */
    }
    cout << M << endl;
    if(ans.size() == 0){
        //do nothing
    } else {
        for(int i = 0; i < ans.size(); i++){
            if(i != ans.size() - 1){
                cout << ans[i] << " ";
            } else {
                cout << ans[i] << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2424
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
ABC = zip(m,m,m)

x,y,z = 0,0,0 # 最後の活動 -> 幸福度のmax
for a,b,c in ABC:
    x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c

answer = max(x,y,z)
print(answer)

Measured memory_bytes: 20192
import java.util.Scanner;
public class Main{
	int o,h,s,e;
	double q,w,a;
	String  i,l,k;
	Scanner scan=new Scanner(System.in);
	public void output() {
String[] date=new String[2];
for(o=0;o<2;o++) {
	date[o]=scan.next();
}
int len = date[1].length();
if(len-1==0) {
	i = date[1].substring(1);
}else {
 i = date[1].substring(len-1);
}
l=date[0]+i;
 if(l.equals(date[1])) {
	 System.out.println("Yes");
 }else {
	 System.out.println("No");
 }
// System.out.println(date[0]);
 //System.out.println(i);
 //System.out.println(l);
	}
	public static void main(String[] args) {
		Main p=new Main();
		p.output();
	}
}

Measured memory_bytes: 39132
from collections import Counter
n = int(input())
l = []
for i in range(n):
  s = input()
  l.append(s)
#print(l)
c = Counter(l)
max_n = c.most_common()[0][1]
#print(c, max_n)
out = []
for key, val in c.items():
  if val == max_n:
    out.append(key)
for o in sorted(out):
  print(o)

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5, mod = 1e9+7;

ll ans = 1;

inline void gun(ll x) {
   ans = ans * x % mod;
}

int main()
{
   int n, k;
   cin >> n >> k;
   bool zer = 0;
   vector <ll> pos, neg;
   for(int i=0; i<n; i++) {
      ll x;
      scanf("%lld", &x);
      if(x > 0) pos.push_back(x);
      else if(x < 0) neg.push_back(-x);
      else zer = 1;
   }

   int np = pos.size(), nn = neg.size();

   int exng = (nn >> 1) * 2;
   if(k & 1) exng = min(k - 1, exng);
   if(np + exng >= k) {
      // positive ans possible
      priority_queue <ll> ppq, npq;
      for(ll x : pos) ppq.push(-x);
      for(ll x : neg) npq.push(x);

      while(np < k && k > 1) {
         gun(npq.top()); npq.pop();
         gun(npq.top()); npq.pop();
         k -= 2;
      }
//cout << np << " " << k << endl;

      while(!ppq.empty() && ppq.size() > k) ppq.pop();
      while(min(ppq.size(), npq.size()) > 1) {
         ll x = ppq.top(); ppq.pop();
         x *= ppq.top(); ppq.pop();
         ll y = npq.top(); npq.pop();
         y *= npq.top(); npq.pop();
//         cout << x << " " << y << " " << ans << endl;
         gun(max(x, y) % mod);
      }
//      cout << ans << endl;

      while(!ppq.empty()) gun(-ppq.top()), ppq.pop();
   }
   else if(!zer) {
      // gotta make negative
      for(ll x : pos) neg.push_back(x);
      sort(neg.begin(), neg.end());
      for(int i=0; i<k; i++) gun(neg[i]);
      gun(-1);
   }
   else ans = 0;

   if(ans < 0) ans += mod;
   cout << ans << endl;
}


Measured memory_bytes: 8060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  string s; cin >> s;
  int ans = 0, ans2 = 0;
  for(int i = 0; i < s.length(); i++){
    if(i % 2 == 0){
      if(s[i] != '0') ans++;
      else ans2++;
    }
    else{
      if(s[i] != '1') ans++;
      else ans2++;
    }
  }


  cout << min(ans, ans2) << endl;
  return;
}

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


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    map<char, int> cnt;
    REP(i, 4) {
        char tmp;
        cin >> tmp;
        cnt[tmp]++;
    }
    if(cnt.size() == 2) {
        for(auto& c : cnt) {
            if(c.second != 2) {
                printf("No\n");
                return 0;
            }
        }
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }


int main(void){
  int n;cin >> n;
  vint a(n);
  int cnt_neg=0,min=INF+2;
  rep(i,n){
    cin >> a[i];
    if(a[i]<0)
      cnt_neg++;
    chmin(min,abs(a[i]));
  }
  
  ll ans=0;
  rep(i,n){
    if(a[i]<0)ans-=a[i];
    else ans+=a[i];
  }
  if(cnt_neg%2==1) ans-=min*2;
  
  cout << ans << endl;
  



  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define double long double
using namespace std;
typedef pair<int, int>P;
void pyes() { cout << "Yay!" << endl; }
void pno() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
signed main() {
	double n, m, d;
	cin >> n >> m >> d;
	if (d == 0)cout << setprecision(10) << (m - 1) / n << endl;
	else cout << setprecision(10) << (n - d) * 2 / (n * n) * (m - 1) << endl;
	ggr
}





Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.nextInt();
		sc.nextInt();
		sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		System.out.println(e - a > k ? ":(" : "Yay!");

	}

}

Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	char s[201],t[101],p[101];
	scanf("%s %s",s,p);
	strcpy(t,s);
	strcat(s,t);
	if(strstr(s,p) == NULL) printf("No\n");
	else printf("Yes\n");
	
  return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 2e5+5;
int n, pre[maxn], suf[maxn];
char s[maxn];

int main(){
	scanf("%d\n%s", &n, s+1);
	for(int i = 1; i<=n; i++) pre[i] = pre[i-1] + (s[i] == '#'); 
	for(int i = n; i>=1; i--) suf[i] = suf[i+1] + (s[i] == '.'); 
	int ans = n;
	for(int i = 0; i<=n; i++) ans = min(ans, pre[i]+suf[i+1]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int tmp;
vector<int> vec;

int main(){
    for (int i=0; i<10; i++) {
        scanf("%d",&tmp);
        vec.push_back(tmp);
        make_heap(vec.begin(),vec.end());
    }
    for (int i=0; i<3; i++) {
        printf("%d\n",vec.front());
        pop_heap(vec.begin(),vec.end());
        vec.pop_back();
    }
}

Measured memory_bytes: 2784
from heapq import heapify, heappop, heappush
N = int(input())
A = list(map(int, input().split()))
heapify(A)
for i in range(1, N + 1):
    curr_cnt = 0
    if len(A) > 0:
        temp = heappop(A)
        if i == temp:
            while i == temp and (len(A) > 0):
                curr_cnt += 1
                temp = heappop(A)
            if i == temp:
                curr_cnt += 1
            else:
                heappush(A, temp)
        else:
            heappush(A, temp)
    print(curr_cnt)

Measured memory_bytes: 33584
import sys
# メタデータ入力
n, m = map(int,input().split())

if n >= m:
  print(0)
  sys.exit()
# 座標入力
pos = list(map(int,input().split()))
# ソート
pos.sort()

# 差分計算
distances = []
for i, x in enumerate(pos):
  if i == 0:
    continue
  distances.append(abs(pos[i] - pos[i-1]))

distances.sort()
for i in range(n-1):
	distances.pop()
print(sum(distances))

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
const int N=110,T=72010,p=1e9+7;
int add(int x,int y){return(x+y)%p;}
int mul(int x,int y){return 1ll*x*y%p;}
int n,k;
int f[N][T],siz[T];
vector<int>s;
#define mp(x) (lower_bound(s.begin(),s.end(),x)-s.begin()+1)
int main(){
//	freopen("1.in","r",stdin);
    cin>>n>>k;
    for(int i=1,l=1,r;l<=n;l=r+1,++i){
        r=n/(n/l);
        f[1][i]=r-l+1;
        siz[i]=r-l+1;
	    s.push_back(n/l);
	}
	sort(s.begin(),s.end());
	int len=s.size();
	for(int i=2;i<=k;++i){
		for(int j=1;j<=len;++j)f[i-1][j]=add(f[i-1][j],f[i-1][j-1]);
	    for(int j=1;j<=len;++j){
	        f[i][j]=mul(f[i-1][mp(n/s[j-1])],siz[j]);
		}
	}
	int ans=0;
	for(int i=1;i<=len;++i)ans=add(ans,f[k][i]);
	cout<<ans<<endl;
//	cout<<s.size()<<endl;
//	for(vector<int>::iterator it=s.begin();it!=s.end();++it)cout<<(*it)<<' ';puts("");
}

Measured memory_bytes: 28796
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const lli cbr = (lli)(2500);

lli n, ar[N], p[N], ans;
vector<lli> pr;
map<map<lli, lli>, lli> mpx;
map<map<lli, lli>, bool> mark;

void primes() {
	for(lli i = 2; i < cbr; i++) {
		bool fl = false;
		for(lli j = 2; j * j <= i; j++)
			if(i % j == 0) {
				fl = true;
				break;
			}
		if(!fl)
			pr.pb(i);
	}
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	primes();
	
	cin >> n;
	for(lli i = 1; i <= n; i++)
		cin >> ar[i];

	bool fl = false;
	for(lli i = 1; i <= n; i++) {
		map<lli, lli> m;
		lli t = ar[i];
		for(auto p : pr) {
			lli cnt = 0;
			while(t % p == 0)
				t /= p, cnt++;
			if(cnt % 3 != 0)
				m[p] = cnt % 3;
		}
		lli sq = sqrt(t);
		if(sq != 1 && sq * sq == t)
			m[sq] = 2;
		else if(sq != 1)
			m[t] = 1;
		if(m.size() == 0)
			fl = true;
		else
			mpx[m]++;
	}

	if(fl)
		ans++;

	for(auto i : mpx) {
		map<lli, lli> m;
		for(auto j : i.fi) {
			lli ot = (3 - j.se) % 3;
			if(ot != 0)
				m[j.fi] = ot;
		}
		if(mark[i.fi])
			continue;
		ans += max(i.se, mpx[m]);
		mark[i.fi] = true;
		mark[m] = true;
	}
	cout << ans;
}

Measured memory_bytes: 120832
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD #出力の制限
N = 5*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K = MI()
ans = cmb(2*N-1,N-1,MOD)
if K<N-1:
    for i in range(K+1,N):
        ans -= cmb(N,i,MOD)*cmb(N-1,i,MOD)
print(ans%MOD)


Measured memory_bytes: 64472
# include <cstdio>
# include <algorithm>
# include <cstring>
# include <cmath>
# include <climits>
# include <iostream>
# include <string>
# include <queue>
# include <vector>
# include <set>
# include <map>
# include <cstdlib>
# include <stack>
# include <ctime>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=2e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
	x*=f;
}

int n;
struct node{
	int t,id;
	bool operator < (const node &cmp)const{
		return t<cmp.t;
	}
}a[N];

int main()
{
	read(n);
	Rep(i,1,n)read(a[i].t),a[i].id=i;
	sort(a+1,a+n+1);
	Rep(i,1,n)printf("%d ",a[i].id);
	puts("");
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
  int j,a,b;
  scanf("%d%d",&a,&b);
  while(1)
    {
      j = a % b;
      if(j == 0) break;
      else 
	{
	  a = b;
	  b = j;
	}
    }
  printf("%d\n",b);

  return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vector<tuple<string, ll, ll>> restaurants(n);
  rep(i, n) {
    cin >> get<0>(restaurants[i]) >> get<1>(restaurants[i]);
    get<2>(restaurants[i]) = i + 1;
  }

  sort(all(restaurants), [](tuple<string, ll, ll> const& l, tuple<string, ll, ll> const& r) {
    if (get<0>(l) < get<0>(r))
      return true;
    if (get<0>(l) == get<0>(r) && get<1>(l) > get<1>(r))
      return true;
    return false;
  });

  FORm(it, restaurants) {
    cout << get<2>(*it) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rsort(x) sort(x.rbegin(), x.rend())
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define fio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define znit(x) memset(x, 0, sizeof(x))
#define mnit(x) memset(x, -1, sizeof(x))
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db EPS = 1e-7;

const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 9;
ll mypow(ll x, ll y, ll p){ll ret = 1;while(y){if(y & 1) ret = (ret * x) % p;x = (x * x) % p; y /= 2;}return ret;}
ll inv(ll x, ll p){return mypow(x, p - 2, p);}
ll gcd(ll x, ll y){return y ? gcd(y, x % y) : x;}
const int MAX = 2e5 + 3;

ll T, A, B, C, D;

int main(){
	scanf("%lld", &T);
	while(T--){
		scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
		ll g = __gcd(B, D);
		bool f = true;
		if(A - B < 0 || D - B < 0){
			puts("No");
			continue;
		}
		if(A - C > A - B){
			ll x = (A - B) / g;
			ll y = (A - C) / g;
			x++;
			if((A - C) % g == 0)	y--;
			if(x <= y)	f = 0;
		}
		if(f)	puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

int N, L;

signed main()
{
	cin >> N >> L;
	vi apples(N);

	int sum = 0;
	rep(i, N) {
		apples[i] = L + i;
		sum += apples[i];
	}

	int diff_mn = inf, ans = 0;

	rep(i, N) {
		if (chmin(diff_mn, abs(apples[i]))) {
			ans = sum - apples[i];
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, s1, s2, s3, s4;
  cin >> N ;
  
  s1 = N / 1000;
  s2 = (N % 1000) / 100;
  s3 = (N % 100) / 10;
  s4 = N % 10;
  
  if(((s1 == s2) && (s2 == s3)) || ((s2 == s3) && (s3 == s4))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
}

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

long long gcd(long long A, long long B) {
    if (B == 0) return A;
    return gcd(B, A % B);
}

int main() 
{
    int A, B;
    cin >> A >> B;
    long long ans = A / gcd(A, B) * B;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int A,B;
    cin>>A>>B;
    int a=A+B;
    int b=A-B;
    int c=A*B;
    int m=max(a,b);
    m=max(m,c);
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl
#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#else
#define DBPRT(a) do{}while(0)
#define DBSTART if(0){
#define DBEND }
#endif
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

string s;

int main(){
	cin >> s;
	ll sz = s.size();
	ll res = 0;
	REP(i,sz/2){
		if(s[i]!=s[sz-i-1]) res ++;
	}
	PRT(res);

	return 0;
}









Measured memory_bytes: 256
import sys


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a * b // g


fin = sys.stdin.readline
N = int(fin())
T_list = tuple(int(fin()) for _ in range(N))
l = T_list[0]
for T in T_list[1:]:
    l = lcm(l, T)
print(l)


Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
int main(){
    int pasta,minpasta=2001,drink,mindrink=2001;
    for(int i=0;i<3;i++){
        scanf("%d",&pasta);
        if(pasta<minpasta)
            minpasta=pasta;
    }
    for(int i=0;i<2;i++){
        scanf("%d",&drink);
        if(drink<mindrink)
            mindrink=drink;
    }
    printf("%d\n",minpasta+mindrink-50);
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	int ans = 0;
	for(int i = 0 ; i < N ; i++) cin >> A[i];
	for(int i = 1 ; i <= N ; i++){
		if( N % i == 0 ){
			int f = 0;
			for(int j = 0 ; j < N ; j++){
				if( A[j%i] != A[j] ) f = 1; 
			}
			if(!f) {
				ans = max(ans,N/i);
			}
		}
	}
	cout << ans << endl;
}	

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n;
  cin >> n;
  map<char,ll> mp;
  mp['m'] = 1000;
  mp['c'] = 100;
  mp['x'] = 10;
  mp['i'] = 1;

  rep(z,n){
    string s1,s2;
    cin >> s1 >> s2;
    ll a=0,b=0;
    rep(i,s1.size()){
      if(s1[i] >= '0' && s1[i] <= '9'){
        a += (ll)(s1[i]-'0')*mp[s1[i+1]];
        i++;
      }else{
        a += mp[s1[i]];
      }
    }
    rep(i,s2.size()){
      if(s2[i] >= '0' && s2[i] <= '9'){
        a += (ll)(s2[i]-'0')*mp[s2[i+1]];
        i++;
      }else{
        a += mp[s2[i]];
      }
    }
    //decode
    ll sum = a+b;
    string ans = "";
    if(sum%10 >= 2) {
      ans = ans + toString(sum%10) + "i";
    }else if(sum % 10 == 1){
      ans = ans + "i";
    }
    sum/= 10;
    if(sum%10 >= 2) ans = toString(sum%10) + "x" + ans;
    else if(sum % 10 == 1){
      ans = "x" + ans;
    }
    sum/= 10;
    if(sum%10 >= 2) ans = toString(sum%10) + "c" + ans;
    else if(sum % 10 == 1){
      ans = "c" + ans ;
    }
    sum/= 10;
    if(sum%10 >= 2) ans = toString(sum%10) + "m" + ans;
    else if(sum % 10 == 1){
      ans = "m" + ans;
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3208
let max_m = 2000

let make_dp a n =
  let dp = Array.make_matrix (n + 1) (max_m + 1) false in
  let rec duduwa i j =
    if j > max_m then doit (i + 1)
    else begin
      if dp.(i - 1).(j) then dp.(i).(j) <- true
      else if j > a.(i - 1) && dp.(i - 1).(j - a.(i - 1)) then dp.(i).(j) <- true;
      duduwa i (j + 1)
    end
  and doit i =
    if i > n then dp
    else (dp.(i).(a.(i - 1)) <- true; duduwa i 1)
  in
  doit 1

let () =
  let read_ns () = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
  let n = read_int () in
  let a = Array.of_list (read_ns ()) in
  let _ = read_int () in
  let dp = make_dp a n in
  let m = read_ns () in
  List.iter (fun e -> print_endline (if dp.(n).(e) then "yes" else "no")) m

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

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

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

const int MAX = 5 * 1e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N;
string S;

int dp[MAX][MAX];

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

    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            if (S[i] != S[j]) {
                dp[i + 1][j + 1] = 0;
            } else {
                if (j - dp[i][j] <= i) dp[i + 1][j + 1] = dp[i][j];
                else dp[i + 1][j + 1] = dp[i][j] + 1;
            }
        }
    }

    int ans = 0;
    rep(i, N + 1){
        rep(j, N + 1){
            ans = max(ans, dp[i][j]);
        }
    }

    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
 
  map<string,int> c;
  rep(i,n){
    string s;
    cin >> s;
    if(c.count(s)){
      c[s]++;
    }else{
      c[s] = 1;
    }
  }
  
  int smax = 0;
  for(auto s : c){
    smax = max(smax,s.second);
  }
  for(auto s : c){
    if(s.second == smax) cout << s.first << endl; 
  }
}



Measured memory_bytes: 25216
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    if (N >= 3 && M >= 3) printf("%lld\n", (LL)(N - 2) * (M - 2));
    else {
       if (N == 1) {
          if (M == 1) puts("1");
          else printf("%d\n", (M - 2));
       } else if (N == 2) puts("0");
       else {
          LL cnt = (N - 2);
          if (M == 1) printf("%lld\n", cnt);
          else printf("%lld\n", cnt * (M - 2));
       }
    }
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
    p = [0]*n
    p[0] = 1
    for x in range(n):
        for y in v[x]:
            p[y] += p[x]/len(v[x])
    e = [0]*n
    e_ = [0]*n
    for x in range(n)[::-1]:
        s = 0
        for y in v[x]:
            s += e[y]
        if v[x]:
            e[x] = e_[x] = 1+s/len(v[x])
        if len(v[x]) > 1:
            e_[x] = 1+(s-max([e[y] for y in v[x]]))/(len(v[x])-1)
    ans = e[0]
    print(ans+min(list(map(lambda x:x[0]*(x[2]-x[1]), zip(p,e,e_)))))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 53468
#include<bits/stdc++.h>   //万能头
using namespace std;
int main(){
    long long n,min,l=0;     //十位数要开long long
    cin>>n;
    min=n;      //长度最小的
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){min=n/i;}}//N=A*B故要整除,因为A*B中我们枚举的是A，然而A是不可能超过B，即A的长度不可能超过B，故取B的值
    while(min!=0){min/=10;l++;}            //长度
    cout<<l<<endl;
    return 0;//结束程序，结果发现其实就是三年级的长方形与正方形累的奥数题 ：同周长求最小面积 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
using namespace std;
typedef long long ll;
pair<ll,ll> rl[101010];


ll dp[101][101010]={};

int main(){
	int n,w;
	cin>>n>>w;
	pair<int,ll> p[101];//w,v

	rep(i,n){
		cin>>p[i].first>>p[i].second;
	}
	repr(i,n){
		rep(j,w+1){
			if(j<p[i].first){
				dp[i][j]=dp[i+1][j];
			}else{
				dp[i][j]=max(p[i].second+dp[i+1][j-p[i].first],dp[i+1][j]);
			}
		}
	}
	cout<<dp[0][w]<<endl;
	return 0;
}


Measured memory_bytes: 80128
n,m=map(int,input().split())
A=[int(i)//2 for i in input().split()]

def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

def div2(x):
  ret=0
  while x%2==0:
    ret+=1
    x//=2
  return ret

s=div2(A[0])
chk=True

mul=A[0]
for i in range(1,n):
  if s!=div2(A[i]) or mul>m:
    chk=False
  else:
    mul=mul*A[i]//gcd(mul,A[i])
if not chk:
  print(0)
else:
  print(m//mul-m//(mul*2))

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll a,b,c,d,k;cin>>a>>b>>c>>d>>k;
  cout<<60*(c-a)+d-b-k<<endl;
  return 0;
}

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

int letters1[26]={0}, letters2[26]={0};
int main()
{
    int i=0;
    string S,T;

    cin>>S>>T;
    for(i=0;i<S.length();i++)
    {
        letters1[int(S[i]-'a')]++;
    }
    for(i=0;i<T.length();i++)
    {
        letters2[int(T[i]-'a')]++;
    }

    for(i=0;i<T.length();i++)
    {
        if(letters1[int(S[i]-'a')] != letters2[int(T[i]-'a')])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}



Measured memory_bytes: 776
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b;
	cin >> a >> b;
	co(6-a-b);

	return 0;
}


Measured memory_bytes: 764
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M ,K = map(int, input().split())
UF = UnionFind(N)
ans = [0]*N
for i in range(M):
    a, b = map(int, input().split())
    UF.union(a-1, b-1)
    ans[a-1] -= 1
    ans[b-1] -= 1  
for i in range(K):
    a, b = map(int, input().split())
    if UF.same(a-1, b-1):
        ans[a-1] -= 1
        ans[b-1] -= 1   
for i in range(N):
    ans[i] += UF.size(i)-1
print(*ans)

    


Measured memory_bytes: 94552
#!usr/bin/env python3

def string_three_numbers_spliter():
    a, b, c = [int(i) for i in input().split()]
    return a, b, c


def count_nums_of_factors_of_c_in_a_and_b(a, b, c):
    count = 0
    # XXX Refactor the algorithm below as it is exhaustive and inefficient.
    for i in range(1, c+1):
        if (c % i == 0):
            if i >= a and i <= b:
                count += 1
    return count


def main():
    a, b, c = string_three_numbers_spliter()
    print(count_nums_of_factors_of_c_in_a_and_b(a, b, c))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7760
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func main() {
	const (
		max = 1000000
		min = -1000000
	)
	k, x := nextInt(), nextInt()

	start := x - k + 1
	if start < min {
		start = min
	}
	end := x + k - 1
	if end > max {
		end = max
	}

	for i := start; i < end+1; i++ {
		fmt.Print(i)
		if i != end {
			fmt.Print(" ")
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>

#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n';
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
    #define eprintf(...) 42
#endif

clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll INF = (ll)1e18;
ll MOD;

ll add(ll x, ll y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
ll mul(ll x, ll y) {
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(x, bin_pow(x, p - 1));
    return bin_pow(mul(x, x), p / 2);
}

const int N = 100100;
int n, d = 1, r;
int a[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    startTime = clock();
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a[x]++;
        d = max(d, x);
    }
    int r = (d + 1) / 2;
    bool ok = true;
    for (int i = 1; i < r; ++i) {
        if (a[i] > 0)
            ok = false;
    }
    if (!((a[r] == 1 && d % 2 == 0) || (a[r] == 2 && d % 2 == 1)))
        ok = false;
    for (int i = r + 1; i <= d; ++i) {
        if (a[i] < 2)
            ok = false;
    }
    cout << (ok ? "Possible" : "Impossible") << endl;
    
    return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int k, t;
  cin >> k >> t;
  int max_in = 0;
  REP(i,t) {
    int tmp;
    cin >> tmp;
    max_in = max(max_in, tmp);
  }
  int ans = 2 * max_in - 1 - k;
  if(ans <= 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
/***** MAIN *****/


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

long long N,D,X[200010],Y[200010],ans;

int main() {
    cin >> N >> D;
    ans = 0;
    for (int i; i < N; i++){
        cin >> X[i] >> Y[i];
        if (sqrt(pow(X[i],2) + pow(Y[i],2)) <= D ) {
            ans += 1;
        }
    }
        cout << ans << endl;
}

Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    deque<int> d;
    rep(i, n) {
        int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (p == 0) d.push_front(a[i]);
        else d[p-1] = a[i];
    }
    cout << sz(d) << endl;
}

Measured memory_bytes: 1024
import itertools
import queue


def does_contradict(assumed_honest_men):
    table = {i: None for i in range(1, N+1)}
    table.update({man: 1 for man in assumed_honest_men})
    for honest_man in assumed_honest_men:
        for target, flag in testimonies[honest_man]:
            if table[target] is None and flag == 1:
                return True
            elif table[target] is not None and table[target] != flag:
                return True
    return False


N = int(input())
testimonies = dict()
for witness in range(1, N+1):
    testimonies[witness] = list()
    for _ in range(int(input())):
        target, flag = map(int, input().split(" "))
        testimonies[witness].append((target, flag))

for i in range(N+1, 0, -1):
    for assumption in itertools.combinations(range(1, N+1), i):
        if not does_contradict(assumption):
            print(len(assumption))
            exit(0)
else:
    print(0)

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
int frek[1000001];
bool valid(int);
int main()
{

    int n;cin >> n;
    int arr[n] , ans = 0;
    for (int i = 0 ; i < n ; i++){
        cin >> arr[i];
        frek[arr[i]]++;
    }
    if (frek[1]){
        if (frek[1] == 1)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }
    for (int i = 0 ; i < n ; i++)
        if (valid(arr[i]))++ans;
    cout << ans << endl;
}
bool valid(int x){
    if (frek[x] > 1)
        return 0;
    for (int i = 2 ; i <= sqrt(x) ; i++){
        if (!(x % i) && (frek[x / i] || frek[i]))
            return 0;
    }
    return 1;
}


Measured memory_bytes: 8100
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B&lang=jp
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<int> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

const int V_MAX = 10003;
struct Vertex v[V_MAX];


int main(){
	priority_queue<Vertex>Q;
	int n; // vertex 0-indexed
	SCD(n);
	REP(i,n){ // 0-indexed
		int u,k;
		SCD2(u,k);
		REP(j,k){
			int nv,c; // to edge , its cost
			SCD2(nv,c);
			v[u].edges_to.push_back(nv);
			v[u].edges_cost.push_back(c);
		}
	}
	
	REP(i,n){
		v[i].done = false;
		v[i].cost = -1;
	}
	
	v[0].cost = 0; //start
	Q.push(v[0]);
	
	while (!Q.empty()){
		Vertex nowV = Q.top(); Q.pop();
		nowV.done = true;
		
		REP(i,nowV.edges_to.size()){
			int nto = nowV.edges_to[i];
			int ncost = nowV.cost + nowV.edges_cost[i];
			if (((v[nto].cost) < 0) or (ncost < v[nto].cost)){  //not visited or required refresh
				v[nto].cost = ncost;
				Q.push(v[nto]);
			
			}
			
		}
	}
	
	REP(i,n){ // output
		printf("%d %d\n",i,v[i].cost);
	}
	
	
}







Measured memory_bytes: 3824
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    int ans = 0;
    for(int i = 0; i < n; i++){
      for(int j = n; j >= i;j--){
        if(s.substring(i, j).matches("[ACGT]*")){
          int l = s.substring(i, j).length();
          if(l > ans){
            ans = l;
          }
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
n=int(input())
dic = {}
for i in range(n):
    st=input()
    dic.setdefault(st,0)
    dic[st]+=1
ans=0
answers=[]
for k,v in dic.items():
    if v==ans:
        ans=v
        answers.append(k)
    elif v>ans:
        ans=v
        answers=[k]
answers.sort()
for ans in answers:
    print(ans)

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

int main() {

  	int n, k;
  	cin>>n>>k;
	int d, x;
  	map<int, int> _map;
	for(int i = 0; i < k ; i++){
    	cin>>d;
      	while(d--) {
          	cin>>x;
        	_map[x] += 1;
        }
    }
  	int ans = 0;
	for(int i = 1; i <= n; i++)
      if(_map.count(i) == 0)
        ans++;
  	cout<<ans<<endl;
}
	

Measured memory_bytes: 3632