akhauriyash/Code-Regression huggingface dataset:
import copy
N=int(input())

A=[]
for i in range(N):
    a=list(map(int,input().split()))
    A.append(a)
B=[[1 for i in range(N)]for i in range(N)]
#print(B)
C=copy.deepcopy(A)
for c in range(N):
    for a in range(N):
        for b in range(N):
            if a!=b and a!=c and b!=c:
                if C[a][b]==(C[a][c]+C[c][b]):
                    B[a][b]=0
                    B[b][a]=0
                A[a][b]=min(A[a][b],A[a][c]+A[c][b])
if C==A:
    ans=0
    for i in range(N):
        for j in range(N):
            if B[i][j]==1:
                ans+=A[i][j]
    print(ans//2)
else:
    print(-1)
#print(A)
#print(B)

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

int main()
{
    int n ,m;
    cin>>n>>m;
    int ans=0;
    if(n>1)
        ans+=(n*(n-1))/2;
    if(m>1)
        ans+=(m*(m-1))/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
	val (n, k) = readLine()!!.split(" ")
	val N : Int = n.toInt()
	val K : Int = k.toInt()
	var list : MutableList<Long> = mutableListOf()
	var calc : Long
	var result : Long = 0
	for (i in 0..N - 1) {
		val h = readLine()
		list.add(h!!.toLong())
	}
	list.sort()
	for (i in 0..N - K) {
		calc = list[i + (K - 1)] - list[i]
		if (i == 0) {
			result = calc
		}
		if (result > calc) {
			result = calc
		}
	}
	println("${result}")
}

Measured memory_bytes: 46276
#include <bits/stdc++.h>
#define int long long
using namespace std;
// by hjnan
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
int T, a, b, c, d;
map<int, int> mp;
main(void) {
  for(read(T); T --;) {
    read(a); read(b); read(c); read(d);
    mp.clear();
    if(b > d || a < b) puts("No");
    else {
      int p = __gcd(d, b);
      int ta = (a - c) % p + c;
      if(ta == c) ta += p;
      if(ta < b) puts("No");
      else puts("Yes");
    }
  }
}

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

using namespace std;

int main(){

	string s;
	cin >> s;

	cout << 700 + ((s[0] == 'o' ? 1 : 0) + (s[1] == 'o' ? 1 : 0) + (s[2] == 'o' ? 1 : 0)) * 100 << endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll sb = 0;
    multiset<int> smaller, bigger;
    int q;
    cin >> q;
    ll sum_smaller = 0, sum_bigger = 0;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int a, b;
            cin >> a >> b;
            if(smaller.empty() or a > *smaller.rbegin()) {
                bigger.insert(a);
                sum_bigger += a;    
                if(bigger.size() > smaller.size()) {
                    sum_bigger -= *bigger.begin();
                    sum_smaller += *bigger.begin();
                    smaller.insert(*bigger.begin());
                    bigger.erase(bigger.begin());
                }
            } else {
                smaller.insert(a);
                sum_smaller += a;
                if(smaller.size() > bigger.size() + 1) {
                    sum_smaller -= *smaller.rbegin();
                    sum_bigger += *smaller.rbegin();
                    bigger.insert(*smaller.rbegin());
                    smaller.erase(--smaller.end());
                }
            }
            sb += b;
        } else {
            cout << *smaller.rbegin() << " " << (sum_bigger - *smaller.rbegin() * ll(bigger.size())) + (*smaller.rbegin() * ll(smaller.size()) - sum_smaller) + sb << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
int main() {
	int r,g,b;
	std::cin >> r >> g >> b;
	if((g*10+b*1)%4==0) {
		std::cout << "YES" << std::endl;
	}
		else{ 
			std::cout << "NO" << std::endl;
		
	}
	return 0;
}
			

Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b, x;
  scanf("%d%d%d", &a, &b, &x);
  if (x>=a && x<=a+b) printf("YES\n");
  else printf("NO\n");
  return 0;
}


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

int main()
{
	boost;
	int n, i;
	cin >> n;
	
	ll ans = 0;
	for(int i = 1; i < n; i++) {
		if(n % i == 0) ans += (n / i) - 1;
		else ans += n / i;
	}
	cout << ans;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int K;
int d[100100];
int main(){
	cin >> K;
	for(int i=0;i<K;i++)d[i]=INF;
	int s = 1;
	d[s]=0;
	deque<int> deq;
	deq.push_back(1);
	while(!deq.empty()){
		int prev = deq.back();
		deq.pop_back();
		int nxt = (prev+1)%K;
		if(d[nxt]>d[prev]+1){
			d[nxt]=d[prev]+1;
			deq.push_front(nxt);
		}
		nxt = (prev*10)%K;
		if(d[nxt]>d[prev]){
			d[nxt]=d[prev];
			deq.push_back(nxt);
		}
	}
	cout << d[0]+1 << endl;
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
typedef long long int ll;
using namespace std;
#define INF 1234567890
#define LIMIT 10005

int a[LIMIT], b[LIMIT];
ll sum_a, sum_b;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum_a += a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		sum_b += b[i];
	}
	if (sum_a > sum_b) {
		cout << "No";
		return 0;
	}
	sum_b -= sum_a;
	for (int i = 1; i <= n; i++) {
		sum_b -= max((b[i] - a[i] + 1) / 2, 0);
	}
	if (sum_b >= 0)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}



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

using namespace std;

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

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

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

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll r,d,x;
    cin>>r>>d>>x;

    REP(i,10){
        x = r*x-d;
        cout << x <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2e5+5;
int n,m,len,du,dr,dl,dd,sd[4],td[4];
char s[maxn],t[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	#endif
	n=rd(); m=rd();
	len=rd();
	int x,y;
	x=rd(); y=rd();
	scanf("%s",s+1); scanf("%s",t+1);
	dl=y; du=x; dr=m-y+1; dd=n-x+1;
	/*for(rg int i=len;i>=1;i--){
		if(s[i] == 'L') sd[0]++; if(s[i] == 'U') sd[1]++;
		if(s[i] == 'R') sd[2]++; if(s[i] == 'D') sd[3]++;
		if(t[i] == 'L') td[0]++; if(t[i] == 'U') td[1]++;
		if(t[i] == 'R') td[2]++; if(t[i] == 'D') td[3]++;
	}*/
	int fl=0;
	go(i,len+1,1){
		if(s[i] == 'L') dl--;
		if(dl == 0){ fl=1; break; }
		if(t[i] == 'R' && dl < m) dl++;
	}
	go(i,len+1,1){
		if(s[i] == 'R') dr--;
		if(dr == 0){ fl=1; break; }
		if(t[i] == 'L' && dr < m) dr++;
	}
	go(i,len+1,1){
		if(s[i] == 'U') du--;
		if(du == 0){ fl=1; break; }
		if(t[i] == 'D' && du < n) du++;
	}
	go(i,len+1,1){
		if(s[i] == 'D') dd--;
		if(dd == 0){ fl=1; break; }
		if(t[i] == 'U' && dd < n) dd++;
	}
	if(fl) puts("NO");
	else puts("YES");
	return 0;
}//Faze


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

int main() {
	int a;
	cin >> a;
    string s;
    cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }

}


Measured memory_bytes: 256
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    while(true){
      val in = StdIn.readLine().split(" ").map(_.toInt)
      if(in(0) == -1 && in(1) == -1 && in(2) == -1){return}
      println(getGrade(in(0),in(1),in(2)))
    }
  }

  def getGrade(m:Int,f:Int,r:Int): String = (m,f,r) match {
    case (m,f,_) if m == -1 || f == -1 || m + f < 30 => "F"
    case (m,f,_) if m + f >= 80 => "A"
    case (m,f,_) if m + f >= 65 && m + f < 80 => "B"
    case (m,f,r) if (m + f >= 50 && m + f < 65) || (m + f >= 30 && m + f < 50 && r >= 50) => "C"
    case (m,f,_) if m + f >= 30 && m + f < 50 => "D"
  }
}

Measured memory_bytes: 43728
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T = int > T in() {
  T x;
  cin >> x;
  return (x);
}
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec< string > s(N);
  map< string, int > count;
  FORA(e, s) {
    cin >> e;
    sort(ALL(e));
    count[e]++;
    //  print(e);
  }
  int ans = 0;
  for (auto itr = count.begin(); itr != count.end(); itr++) {
    int val = itr->second;
    ans += val * (val - 1) / 2;
    //  print(val);
  }
  print(ans);
}

Measured memory_bytes: 16640
using System;

class MainClass
{
    
    public static void Main(string[] args)
    {


        //long N = long.Parse(Console.ReadLine());
        //long[] a = new long[N];
        //long[] b = new long[N];

        //for (int i = 0; i < N; i++)
        //{
        //    string[] s1 = Console.ReadLine().Split(' ');
        //    a[i] = long.Parse(s1[0]);
        //    b[i] = long.Parse(s1[0]);


        //}

        string[] s1 = Console.ReadLine().Split(' ');
        long x = long.Parse(s1[0]);
        long y = long.Parse(s1[1]);


        if(x == y)
        {
            Console.WriteLine("-1");
        }
        else if(x%y == 0)
        {
            Console.WriteLine("-1");
        }
        else
        {
            Console.WriteLine(x);
        }

        //Console.WriteLine("Yes");
        //Console.WriteLine("No");

    }

}


Measured memory_bytes: 11092
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,i,j,temp;
    cin>>n;
    long long p[n+1],a[n+1],b[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    for(i=1,j=n;i<=n;i++,j--)
    {
        a[i]=i;
        b[i]=j;
    }
    for(i=1;i<=n;i++)
    {
        a[p[i]]=a[p[i]]+i;
        for(j=p[i];j<=n;j++)
        {
            a[j]=a[j]+n;
            b[j]=b[j]-n;
        }
    }
    temp=1-b[n];
    for(i=1;i<=n;i++)
    {
        a[i]=a[i]+temp;
        b[i]=b[i]+temp;
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(i=1;i<=n;i++)
    {
        cout<<b[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 4112
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    a = LI()
    dic = collections.Counter(a)
    dlst = sorted(dic.items(),key=lambda x: x[1])
    cnt = len(dic)-k
    ans = 0

    for i in range(cnt):
        ans += dlst[i][1]
    print(ans)
        
main()            


Measured memory_bytes: 131184
def meet(faster, slower):
  if slower[0] - faster[0] < 0:
    print(0)
  else:
    count = (slower[0] - faster[0]) // (sum(faster) - sum(slower))
    if (slower[0] - faster[0]) % (sum(faster) - sum(slower)) == 0:
      print(count * 2)
    else:
      print(count * 2 + 1)

t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

at1 = a1 * t1
at2 = a2 * t2
bt1 = b1 * t1
bt2 = b2 * t2

if at1 + at2 < bt1 + bt2:
  faster = [bt1, bt2]
  slower = [at1, at2]
  meet(faster, slower)
elif at1 + at2 > bt1 + bt2:
  faster = [at1, at2]
  slower = [bt1, bt2]
  meet(faster, slower)
else:
  print('infinity')

Measured memory_bytes: 3064
n,c,k = map(int, input().split())
a = []
bus = 1
for i in range(n):
  a.append(int(input()))
a.sort()

j = 0
count = 1
while j + count in range(n):
  if a[j + count] <= a[j] + k and count < c:
    count = count + 1
  else:
    bus = bus + 1
    j = j + count
    count = 1
print(bus)

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

int main(){

    while (1){
        string x;
	    cin >> x;
        if (x == "0") break;
        int sum = 0;
        for (int i=0;i<(int)x.size();i++){
            sum += x[i] - '0';
        }
        cout << sum <<endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int cal[110];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n;

    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            cal[i*j]++;

    if(cal[n])cout<<"Yes\n"<<"\n";
    else cout<<"No\n";

    return 0;
}


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

#define Pb push_back
/*
 5 3
 1 2 1 10
 1 3 2 20
 2 4 4 30
 5 2 1 40
 1 100 1 4
 1 100 1 5
 3 1000 3 4
 */
const int maxn =3e5+10;
struct Edge{
    int to,corlor,w;
};
vector<Edge> G[maxn];

int depth[maxn],vs[maxn],ID[maxn],dis[maxn];
int n;
int f[maxn][20];
void dfs(int node,int fa,int d,int &k){
    ID[node] = k;
    vs[k] = node;
    depth[k++] = d;
    // dis[node] = distance;
    for(int i = 0;i < G[node].size(); ++i){
        Edge &t = G[node][i];
        if(t.to == fa) continue;
        dis[t.to] = dis[node]+t.w;
        dfs(t.to,node,d+1,k);
        vs[k] = node;
        depth[k++] = d;
    }
}


void init_rmq(int n){
    for(int i = 1;i <= n ; ++i) f[i][0] = i;
    for(int j = 1;(1<<j) <= n; ++j){
        for(int i = 1;i + (1<<j)-1 <= n; ++i){
            if(depth[f[i][j-1]]< depth[f[i+(1<<(j-1))][j-1]])
                f[i][j] = f[i][j-1];
            else
                f[i][j] = f[i+(1<<(j-1))][j-1];
            
        }
    }
}
int rmq_query(int l,int r){
    int x = 0;
    while((1<<(x+1)) <= r-l+1) x++;
    if(depth[f[l][x]] < depth[f[r-(1<<x)+1][x]])
        return f[l][x];
    else
        return f[r-(1<<x)+1][x];
}
void init_lca(){
    int k = 1;
    dfs(1,-1,0,k);
    init_rmq(2*n-1);
}
int lca(int u,int v){
    // cout<<rmq_query(ID[u],ID[v])<<endl;
    return vs[rmq_query(min(ID[u],ID[v]),max(ID[u],ID[v]))];
}
struct que{
    int corlor,w,coe,id;
};
vector<que> Query[maxn];
int ans[maxn],num[maxn],value[maxn];// num[i] 个数，value 值
void dfs(int u,int fa){
    for(auto qu:Query[u]){
        // cout<<dis[u]<<endl;
        ans[qu.id] +=(dis[u]+num[qu.corlor]*qu.w-value[qu.corlor])*qu.coe;
    }
    for(auto p: G[u]){
        int to = p.to;
        if(to == fa) continue;
        num[p.corlor]++;
        value[p.corlor] += p.w;
        dfs(to,u);
        num[p.corlor]--;
        value[p.corlor] -= p.w;
    }
}
int main(void)
{
    //cout<<"abc177F Colorful Tree\n";
    int q;
    cin>>n>>q;
    for(int i = 1;i < n;++i){
        int u,v,c,w;
        scanf("%d%d%d%d",&u,&v,&c,&w);
        G[u].Pb(Edge{v,c,w});
        G[v].Pb(Edge{u,c,w});
    }
    init_lca();
    for(int i = 1;i <= q; ++i){
        int x,y,u,v;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        int fa = lca(u,v);
        
        Query[u].Pb(que{x,y,1,i});
        Query[v].Pb(que{x,y,1,i});
        Query[fa].Pb(que{x,y,-2,i});
    }
    dfs(1,-1);
    for(int i  = 1;i <= q; ++i){
        printf("%d\n",ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 51580
#include <stdio.h>
 
int A[25], n;
 
int solve(int p, int t){
     
    if (p == n){
        if (t == 0){
            return (1);
        }
        else {
            return (0);
        }
    }
     
    if (solve(p + 1, t - A[p]) == 1){
        return (1);
    }
    if (solve(p + 1, t) == 1){
        return (1);
    }
    return (0);
}
 
int main(void)
{
     
    int M, q, i;
     
    scanf("%d", &n);
     
    for (i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
     
    for (i = 0; i < q; i++){
        scanf("%d", &M);
         
         
         
        if (solve(0, M) == 1){
            puts("yes");
        }
        else {
            puts("no");
        }
    }
    return (0);
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using douv = vector<double>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
    void YN (bool b){
        if(b){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin2(n,k);
    int kp = k-1;
    rap(n-1,i){
        k*=kp;
    }
    cout<<k<<endl;
    return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  char a[H][W];
  bool ans=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<H && ans;i++){
    for(int j=0;j<W && ans;j++){
      if(a[i][j]=='#'){
        if(a[i-1][j]!='#' && a[i+1][j]!='#' && a[i][j-1]!='#' && a[i][j+1]!='#'){
          ans=false;
        }
      }
    }
  }
  if(ans)cout << "Yes";
  else cout << "No";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int INF = 100000;
string a[]={"Sunny","Cloudy","Rainy"};
char ch[100005];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s;
    cin>>s;
    bool ok=false;
    int k=1;
    for(auto x: s){
       ch[k++]=x;
    }
    for(int i=1;i<=k;i++){
        if(ch[i]=='R'){
            int x=i;
            if(x%2==0){
                ok=true;
                break;
            }
        }
        if(ch[i]=='L'){
            int x=i;
            if(x%2){
                ok=true;
                break;
            }
        }
    }
    if(ok){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}


 
int main(void){
    int bingo[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d",&bingo[i][j]);
        }
    }
    int N;
    
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[i]==bingo[j][k]){
                    bingo[j][k]=0;
                }
            }
        }
    }
    for(int i=0;i<3;i++){
        int temp=0;
        for(int j=0;j<3;j++){
            temp+=bingo[i][j];
        }
        if(temp==0){
            printf("Yes");
            return 0;
        }
    }
    for(int i=0;i<3;i++){
        int temp=0;
        for(int j=0;j<3;j++){
            temp+=bingo[j][i];
        }
        if(temp==0){
            printf("Yes");
            return 0;
        }
    }
    int sum1=0,sum2=0;
    for(int i=0;i<3;i++){
        sum1+=bingo[i][i];
        sum2+=bingo[i][2-i];
    }
    if(sum1==0||sum2==0){
        printf("Yes");
        return 0;
    }
    printf("No");
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>

#define maxn 100010
char s[maxn], t[maxn];
int gcd(int a, int b)
{
	return !b ? a : gcd(b, a % b);
}
typedef long long ll;
int main()
{
	int n, m; scanf("%d%d", &n, &m);
	scanf("%s%s", s, t);
	bool flag = 1;
	ll ans = 1ll * n * m / gcd(n, m);
	for (int i = 0; i < n; ++i)
		if (i * (ans / n) % (ans / m) == 0)
			flag &= s[i] == t[i * (ans / n) / (ans / m)];
	if (flag)
		printf("%lld\n", ans);
	else puts("-1");
	return 0;
}
/*
6 3
abbcca
abc
*/

Measured memory_bytes: 384
from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)
 
 
listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)
listn=listn-q
s=Counter(a)
for i in s.keys():
  listn[i-1]+=s[i]
 
#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')

Measured memory_bytes: 37164
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var a, b, c, d int

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, d = nextInt(), nextInt(), nextInt(), nextInt()
	iTaka := 0
	iAoki := 0
	for c > 0 {
		c -= b
		iTaka += 1
	}

	for a > 0 {
		a -= d
		iAoki += 1
	}

	//fmt.Println(iTaka, iAoki)

	if iTaka <= iAoki {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cout << v[i] << ' ';
	}
	cout << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

int main(){
	int n; cin >> n;
	string s; cin >> s;
	int q; cin >> q;
	vector<set<int>> m(26, set<int>());
	rep(i,n){
		m[s[i]-'a'].insert(i);
	}
	Rep(q){
		int a;
		cin >>a;
		if(a == 1){
			int b; char c; cin >> b >> c;
			--b;
			if(s[b] == c) continue;
			m[s[b]-'a'].erase(b);
			s[b]=c;
			m[c-'a'].insert(b);
		}else{
			int b,c; cin >> b >> c;
			--b; --c;
			int ans = 0;
			rep(i,26){
				if(m[i].lower_bound(b) != m[i].end() && *(m[i].lower_bound(b)) <= c){
					ans++;
				}
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 24196
#include<stdio.h>
int main()
{
	int i,a,b,C,N,temp,j,p,k;
	int D[101] = {0},m[101] = {0};
	scanf("%d",&N);
	scanf("%d %d",&a,&b);
	scanf("%d",&C);
	for(i = 0; i < N; i++){
		scanf("%d",&D[i]);
	}
	
	for(i = 0; i < N; i++){
		for(j = N; j > i; j--){
			if(D[i] < D[j]){
				temp = D[i];
				D[i] = D[j];
				D[j] = temp;
			}
		}
	}
	
	p = a;
	k = C;
	
	for(i = 0; i < N; i++){
		p = p + b;
		k = k + D[i];
		m[i] = k/p;
	}
	
		for(i = 0; i < N; i++){
		for(j = N; j > i; j--){
			if(m[i] < m[j]){
				temp = m[i];
				m[i] = m[j];
				m[j] = temp;
			}
		}
	}
	
	printf("%d\n",m[0]);
	
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;
		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				for (int k = 0; k <= C; k++) {
					if (i * 500 + j * 100 + k * 50 == X)
						ans++;
				}
			}
		}
		System.out.println(ans);
	}

}

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

int main(){
	vector<int> number(2);
	
	for(int i=0;i<2;i++){
		cin >> number.at(i);
	}
	
	sort(number.begin(), number.end());
	
	int answer;
	
	if(number.at(1)-number.at(0)>=2){
		answer=number.at(1)*2-1;
	}	
	else{
		answer=number.at(1)+number.at(0);
	}
	
	cout << answer <<endl;
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n,k,q;
  cin >> n >> k >> q;
  V v(q);
  VIN(v);
  V an(n);
  REP(i,n){
    an.at(i) = 0;
  }
  REP(i,q){
    an.at(v.at(i)-1) += 1;
  }
  REP(i,n){
    if (k - (q-an.at(i)) <= 0){
      No;
    }else{
      Yes;
    }
  }
  return 0;
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define fora(i,a,b) for(int i = a ; i<b ;i++)
typedef long long ll;
typedef int i;
typedef vector<i>vi;
typedef pair<i,i>pi;

ll v[100010];
ll dp[100010];
ll f(int i){
	if(i == 0) return 0;
	if(i < 0) return 1e12;
	ll &r = dp[i];
	if(r!=-1) return r;
	r = 1e12;
	r = min(r,f(i-1)+abs(v[i]-v[i-1]));
	r = min(r,f(i-2)+abs(v[i]-v[i-2]));
	return r;
}
int main(){
	//freopen("in.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	while(cin>>n){
		fora(i,0,n)cin>>v[i];
		memset(dp,-1 , sizeof dp);
		cout<<f(n-1)<<"\n";
	}

	return 0;
}

Measured memory_bytes: 9856
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+20;
const int MAX=10000007;
inline int read() {
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}

inline void out(int x) {   
	if(x>9) out(x/10);   
	putchar(x%10+'0'); 
} 
char s[20];
double p=acos(-1);
int main(){
	int n,m;
	cin>>n>>m;
	int a[10005];
	int sum=0;
	rep(i,1,m){
		a[i]=read();
		sum+=a[i];
	}
	if(n-sum>=0)out(n-sum);
	else printf("-1");

	return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

vector<pll> to[100100];

ll dist[100100];

void dfs(ll v,ll d,ll p=-1){
    dist[v]=d;
    for(auto x:to[v]){
        if(x.fi==p) continue;
        dfs(x.fi,x.se+d,v);
    }
    return ;
}

int main(){
    ll n;
    cin >> n;
    rep(i,n-1){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        to[a].push_back(make_pair(b,c));
        to[b].push_back(make_pair(a,c));
    }
    ll q,k;
    cin >> q >> k;
    k--;
    dfs(k,0LL);
    rep(i,q){
        ll x,y;
        cin >> x >> y;
        x--; y--;
        cout << dist[x]+dist[y] << endl;
    }
    return 0;
} 


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

using namespace std;

string S;
int K;
int N;
int dp[110][5][2];

int main()
{
	cin>>S>>K;
	
	N = S.length();
	dp[0][0][1] = 1;
	
	for(int i = 0; i < N; i ++)
	{
		for(int j = 0; j <= K; j ++)
		{
			int Num = S[i] - '0';
			
			if(Num == 0)
			{
				dp[i + 1][j][0] += dp[i][j][0];
				dp[i + 1][j][1] += dp[i][j][1];
				dp[i + 1][j + 1][0] += (dp[i][j][0] * 9);
			}
			else
			{
				dp[i + 1][j][0] += (dp[i][j][0] + dp[i][j][1]);
				dp[i + 1][j + 1][0] += (dp[i][j][0] * 9);
				dp[i + 1][j + 1][0] += (dp[i][j][1] * (Num - 1));
				dp[i + 1][j + 1][1] += dp[i][j][1];
			}
		}
	}
	
	cout<<dp[N][K][0] + dp[N][K][1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int mtr, sv;
     scanf("%d %d", &mtr, &sv);
     
     int bb= mtr%sv == 0;
     int aa= mtr/sv;
   
     bb ? printf("%d\n", aa) : printf("%d\n", aa+1);


    return 0;
}

Measured memory_bytes: 1696
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> cnt(N);
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        cnt[a]++;
    }
    //ll ans = 1 << (N/2);
    ll ans = 1;
    for(int i = 0;i < N/2;i++){
        ans = (ans * 2) % MOD;
    }
    //奇数なら0が1つ　偶数なら0なし
    if(N & 1 ? cnt[0] != 1 : cnt[0] != 0){
        ans = 0;
    }
    //奇数なら偶数が2つ 偶数なら奇数が2つ
    for(int i = 1;i < N;i++){
        if(N & 1){   if(i & 1 ? cnt[i] != 0 : cnt[i] != 2)ans = 0;}
        else{        if(i & 1 ? cnt[i] != 2 : cnt[i] != 0)ans = 0;}
    }
    cout << ans << endl; 
}

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

int gcd(int x, int y);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int n, m, q;
vector<int> a(0);
vector<int> b(0);
vector<int> c(0);
vector<int> d(0);
int ans = 0;

void dfs(vector<int> a_array) {
    if (a_array.size() == n) {
        int num = 0;
        rep(i, q) {
            if (a_array[b[i] - 1] - a_array[a[i] - 1] == c[i])
                num += d[i];
        }
        ans = max(num, ans);
    }
    else {
        int num = 1;
        if (a_array.size() != 0)
            num = a_array[a_array.size() - 1];
        for (int i = num; i <= m; i++) {
            a_array.emplace_back(i);
            dfs(a_array);
            a_array.erase(a_array.begin() + a_array.size ()- 1);
        }
    }

}

int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        int ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        a.emplace_back(ai);
        b.emplace_back(bi);
        c.emplace_back(ci);
        d.emplace_back(di);
    }
    vector<int> a_array(0, 0);
    dfs(a_array);

    cout << ans << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


Measured memory_bytes: 3612
import sys
input=sys.stdin.readline

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])
 
    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])
 
    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        res = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                res = self.segfunc(res, self.seg[r])
            if l & 1:
                res = self.segfunc(res, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        return res
 
def func(x, y):
    return max(x,y)

seg=SegTree([0]*300001,0,func)

n,k=map(int,input().split())
a=[int(input()) for i in range(n)]

for i in a:
    l=max(0,i-k)
    r=min(300000,i+k)

    pin=seg.query(l,r+1)+1
    seg.update(i,pin)


print(seg.query(0,300001))

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

using namespace std;

int h, w;
long long x[200005 * 4], y[200005 * 4];

void go(int l, int r, int i) {
	y[i] = r == 1 ? LLONG_MAX / 2 : 1;
	if (l + 1 == r) {
		x[i] = l ? 1 : LLONG_MAX / 2;
		return;
	}
	int mi = (l + r) / 2;
	go(l, mi, i * 2);
	go(mi, r, i * 2 + 1);
}

long long get(int a, int l, int r, int i) {
	if (x[i])
		return x[i] + a - l;
	int mi = (l + r) / 2;
	if (a < mi)
		return get(a, l, mi, i * 2);
	return get(a, mi, r, i * 2 + 1);
}

void f(int a, int b, long long c, int l, int r, int i) {
	if (a == l && b == r) {
		x[i] = y[i] = c;
		return;
	}
	int mi = (l + r) / 2;
	if (x[i]) {
		x[i * 2] = y[i * 2] = x[i];
		x[i * 2 + 1] = y[i * 2 + 1] = x[i] + mi - l;
		x[i] = 0;
	}
	if (a < mi)
		f(a, min(mi, b), c, l, mi, i * 2);
	if (mi < b)
		f(max(a, mi), b, c + max(a, mi) - a, mi, r, i * 2 + 1);
	y[i] = min(y[i * 2], y[i * 2 + 1]);
}

int main() {
	scanf("%d%d", &h, &w);
	go(0, w + 1, 1);
	for (int j = 0; j < h; j++) {
		for (int i = w + 1; i <= w; i++) {
			long long tmp = get(i, 0, w + 1, 1);
			if (tmp >= LLONG_MAX / 2)
				tmp = -1;
			printf("%lld%c", tmp, " \n"[i == w]);
		}
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		long long tc = get(ta - 1, 0, w + 1, 1);
		f(ta, tb + 1, tc + 1, 0, w + 1, 1);
		printf("%lld\n", y[1] >= LLONG_MAX / 2 ? -1 : y[1] + j);
	}
	for (int i = w + 1; i <= w; i++) {
		long long tmp = get(i, 0, w + 1, 1);
		if (tmp >= LLONG_MAX / 2)
			tmp = -1;
		printf("%lld%c", tmp, " \n"[i == w]);
	}
}

Measured memory_bytes: 11996
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    double c,d,k=0,e;
    for(int z=0;z<a;z++){
        cin>>c>>d;
        e=c*c+d*d;
        e=sqrt(e);
        //cout<<e<<endl;
        if(e<=b){
            k++;
        }
    }
    cout<<k<<endl;
}


Measured memory_bytes: 3872
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;

public class Hello
{
    public static int[,] a;
    public static int aL;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        aL = int.Parse(line[2]);
        a = new int[aL, 4];
        for (int i = 0; i < aL; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < 4; j++)
                a[i, j] = int.Parse(line[j]);
        }
        getAns(n, m);
    }
    static int calc(string s)
    {
        var res = 0;
        for (int i = 0; i < aL; i++)
        {
            var wb = s[a[i, 1] - 1];
            var wa = s[a[i, 0] - 1];
            if (wb - wa == a[i, 2]) res += a[i, 3];
        }
        return res;
    }
    static void getAns(int n, int m)
    {
        var ans = 0;
        var q = new Queue<string>();
        for (int i = 0; i < m; i++) q.Enqueue(i.ToString());
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.Length == n) ans = Max(ans, calc(w));
            else
            {
                var wr = w[w.Length - 1] - '0';
                for (int i = wr; i < m; i++) q.Enqueue(w + i.ToString());
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 32288
#include<stdio.h>
#define Max_N 101
int N,M;
int map[Max_N][Max_N];
int result = 0;

int row[4] = {-1,1,0,0};//上下左右
int column[4] = {0,0,-1,1};//上下左右

void dfs(int r,int c,char target){
  int i;
  int pointer_r,pointer_c;
  for(i=0;i<4;i++){
    pointer_r = r+row[i];
    pointer_c = c+column[i];
    if(pointer_r>=0&&pointer_r<N&&pointer_c>=0&&pointer_c<M){
      if(map[pointer_r][pointer_c]-target==0){
        map[pointer_r][pointer_c]='.';
        dfs(pointer_r,pointer_c,target);
      }
    }
  }
}

int main(){
  while(1){
    scanf("%d%d",&N,&M);
    if(N==0&&M==0){
      break;
    }
    else{
      int i,j;
      result = 0;
      for(i=0;i<N;i++){
        char keeper[Max_N];
        scanf("%s",keeper);
        for(j=0;j<M;j++){
          map[i][j]=keeper[j];
        }
      }

      //printf("\n");
      for(i=0;i<N;i++){
        for(j=0;j<M;j++){
          //printf("%c",map[i][j]);
          if(map[i][j]!='.'){
            result++;
            char target = map[i][j];
            map[i][j]='.';
            //printf("we are here\n");
            dfs(i,j,target);
          }
        }
        //printf("\n");
      }
    }
    printf("%d\n",result);
  }
  return 0;
}



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

string make(int a, int times) {
    string s;
    rep(i, times) {
        s += to_string(a);
    }
    return s;
}

int main() {
    int a, b;
    while (cin >> a >> b) {
        string ans = min(make(a, b), make(b, a));
        cout << ans << endl;
    }
}


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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

ll power(ll a, ll b) {
  if(b==0) return 1;
  ll res = power(a, b/2);
  res *= res;
  res %= mod;
  if(b&1) {
    res *= a;
    res %= mod;
  }
  return res;
}
void add_self(ll& a, ll b) {
  a += b;
  if(a >= mod) {
    a -= mod;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll s;
  cin >> s;
  if(s < 3) {
    cout << "0\n";
    return 0;
  }
  vector<int> dp(s + 1, 1);
  dp[0] = dp[1] = dp[2] = 0;
  for(int i = 4; i <= s; i++) {
    for(int sub = 3; sub <= i; sub++) {
      dp[i] += dp[i-sub];
      if(dp[i] >= mod) {
        dp[i] -= mod;
      }
    }
  }  
  cout << dp[s] << '\n';
  return 0;
}


Measured memory_bytes: 3660
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 78296
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int h=sc.nextInt();
            int w=sc.nextInt();
            if(h==0&&w==0) break;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(i==0||i==h-1) System.out.printf("#");
                    else{
                        if(j==0||j==w-1) System.out.printf("#");
                        else System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
        
    }
}


Measured memory_bytes: 60564
N = int(input())
nums = input()
print(nums)
A = list(map(int, nums.split()))

for i in range(1,N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(" ".join(map(str, A)))


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

char cnt[30], countocc[10];

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  for (int i = 0; i < 4; ++i) cnt[getchar() - 'A']++;
  for (int i = 0; i < 26; ++i) countocc[cnt[i]]++;
  cout << (countocc[2] == 2 ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256