akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,0);
  for(i=0;i<d;i++){
    cost+=s[i][ans[i]];
    x[ans[i]]=i;
    for(j=0;j<26;j++){
      cost-=c[i]*(d-x[i]);
    }
  }
  return cost;
}
void solve(){
  int i;
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
  }
  if(score<keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
    ans[i]=ans1[i];
  }
  score=keisan();
  while(clock()-ti<195.4*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
#coding=utf-8

def solve(ss, ts):
    u_ss = list(set(ss))
    u_ts = list(set(ts))
    ss_dict = {}
    ts_dict = {}
    for u in u_ss:
        ss_dict[u] = ss.count(u)
    for u in u_ts:
        ts_dict[u] = ts.count(u)
    ans_dict = {}
    for u in list(ss_dict.keys()) + list(ts_dict.keys()):
        ss_dict[u] = ss_dict[u] if u in list(ss_dict.keys()) else 0
        ts_dict[u] = ts_dict[u] if u in list(ts_dict.keys()) else 0

        ans_dict[u] = ss_dict[u] - ts_dict[u]
    ans = max(list(ans_dict.values()))
    if ans < 0:
        ans = 0
    return ans

if __name__ == '__main__':
    N = int(input())
    ss = []
    ts = []
    for _ in range(N):
       ss = ss + [input()] 
    M = int(input())
    for _ in range(M):
       ts = ts + [input()] 

    print(solve(ss, ts))


Measured memory_bytes: 3064
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
vector<pair<long long, long long>> vertex[200000];
long long dp[200000] = {};
int main() {
	int n;
	cin >> n;
	REP(i, n-1) {
		long long a, b, c;
		cin >> a >> b >> c;
		vertex[a].push_back(make_pair(b, c));
		vertex[b].push_back(make_pair(a, c));
	}
	long long q, k;
	cin >> q >> k;
	REP(i, n + 1) {
		dp[i] = LONG_INF;
	}
	dp[k] = 0;
	queue<int> wow;
	wow.push(k);
	while (wow.empty() == false) {
		int hoge = wow.front();wow.pop();
		for (int i = 0;i < vertex[hoge].size();++i) {
			if (dp[vertex[hoge][i].first] > dp[hoge] + vertex[hoge][i].second) {
				dp[vertex[hoge][i].first] = dp[hoge] + vertex[hoge][i].second;
				wow.push(vertex[hoge][i].first);
			}
		}
	}
	REP(i, q) {
		long long a, b;
		cin >> a >> b;
		cout << dp[a] + dp[b] << endl;
	}
	return 0;
}

Measured memory_bytes: 13056
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,A,B;cin>>N>>A>>B;
  if(B==A){
    print(1);
    re 0;
  }
  if(N==1){
    print(0);
    re 0;
  }
  if(B<A){
    print(0);
    re 0;
  }
  int min_=(N-1)*A+B,max_=A+(N-1)*B;
  print(max_-min_+1);

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

long long power(long long x, long long n, long long mod = 1000000007) {
    if (n == 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

void solve() {
    int n;
    cin >> n;
    VI dp(n+1);
    dp[0] = 0;
    dp[1] = 1;
    // int ans = n;
    REP(i,2,n+1) {
        dp[i] = dp[i-1] + 1;
        REP(p,1,7) {
            if (i - power(6,p) < 0) continue;
            dp[i] = min(dp[i], dp[i - power(6,p)] + 1);
        }
        REP(p,1,6) {
            if (i - power(9,p) < 0) continue;
            dp[i] = min(dp[i], dp[i - power(9,p)] + 1);
        }
    }
    cout << dp[n] << endl;
}

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

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

using i64 = long long;

const int N = 55;

bool mx[N][N];

set<int> nums;
vector<int> a, b;
int n;


static bool roy_floyd() {
	for (int i = 0; i < N; ++i)
		mx[i][i] = 1;

	for (int p = 0; p < N; ++p)
	for (int i = 0; i < N; ++i)
	for (int j = 0; j < N; ++j)
		mx[i][j]|= mx[i][p] && mx[p][j]; }

static bool check() {
	memset(mx, 0x00, sizeof mx);
	for (auto div: nums)
		for (int num = 0; num < N; ++num)
			mx[num][num % div] = 1;

	roy_floyd();

	for (int i = 0; i < n; ++i)
		if (!mx[a[i]][b[i]])
			return false;
	return true; }


int main() {
#ifdef HOME
	freopen("agc22c.in", "r", stdin);
	freopen("agc22c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 ant;

	cin >> n;
	a.resize(n);
	for (auto &i: a)
		cin >> i;
	b.resize(n);
	for (auto &i: b)
		cin >> i;

	for (int i = 1; i < N; ++i)
		nums.insert(i);

	if (!check()) {
		cout << "-1\n";
		return 0; }

	for (int i = N - 1; i >= 1; --i) {
		nums.erase(i);
		if (!check())
			nums.insert(i);	}

	ant = 0;
	for (auto i: nums)
		ant|= 1LL << i;

	cout << ant << endl;

	return 0; }



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

int main(){
  ll a;
  double b;
  cin>>a>>b;
  ll ib=b*100+0.1;
  a*=ib;
  a/=100;
  printf("%lld\n", a);
}

Measured memory_bytes: 3772
#include <bits/stdc++.h> 
#define LL long long int
using namespace std; 
 
int main() 
{ 
    int n;
    string s;
    cin>>n>>s;
    if(n%2!=0) {
        cout<<"No"<<endl;
        return 0;
    }

    // cout<<s.substr(0, n/2)<<" "<<s.substr(n/2)<<endl;
    if(s.substr(0, n/2) == s.substr(n/2)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll h,ans=0,p = 1;cin>>h;
    while(h)
    {
        h/=2;
        ans+=p;
        p*=2;
    }
    cout<<ans;
    return 0;
}


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    cin >> a[0];
    ll min = a[0],ans=0;
    rep(i,n-1){
        cin >> a[i+1];
        if(a[i+1]<min) ans+=min-a[i+1];
        if(a[i+1]>min) min = a[i+1];
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 4760
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	int p[1010];
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p, p + N);
	int sum = 0;
	for (int i = 0; i < K; i++) {
		sum += p[i];
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3608
MOD = 10**9+7
n,m = map(int,input().split())

f = [1,1]
for i in range(2, n+1):
    f.append(f[i-2]+f[i-1])

cur = 0
ans = 1
for i in range(m):
    a = int(input())
    if a==cur:
        print(0)
        break
    ans *= f[a-cur-1]
    ans %= MOD
    cur = a+1
else:
    ans *= f[n-cur]
    ans %= MOD
    print(ans)


Measured memory_bytes: 460020
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

if N == 1 and M == 0:
  print(0)
  exit()

sc = [LIST() for _ in range(M)]

ans = [-1]*N
for s, c in sc:	
  if N >= 2 and s == 1 and c == 0:
    print(-1)
    exit()
  if ans[s-1] != -1 and ans[s-1] != c: #既に値が入ってる
    print(-1)
    exit()
  ans[s-1] = c
    
if ans[0] == -1:
  ans[0] = 1

for i in range(N):
  if ans[i] == -1:
    ans[i] = 0
    
for n in ans:
  print(n, end="")
print()

Measured memory_bytes: 5168
n = int(input())
s = input()

ans = 0
for i in range(1,n):
    set_l = set(s[0:i])
    set_r = set(s[i::])
    set_both = set_l & set_r
    if ans < len(set_both):
        ans = len(set_both)
print (ans)


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

int main()
{
	int a,b,c,i;
	cin>>a>>b>>c;
	bool flag=false;
	if(a%b==c)
	{
		cout<<"YES";
	}
	for(i=2;i<=b;i++)
	{
		if((a*i)%b==c)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int t = sc.nextInt();
		for (int tc = 0; tc < t; tc++) {
			if (tc != 0) {
				System.out.println();
			}
			int h = sc.nextInt() + 2;
			int w = sc.nextInt() + 2;

			String ext = "###########";
			ext = ext + ext + ext + ext + ext;

			char map[][] = new char[h][w];

			int dirc = -1;
			int x = -1;
			int y = -1;

			for (int i = 0; i < h; i++) {
				String buffer = "";
				if (i == 0 || i == h - 1) {
					buffer = ext;
				} else {
					buffer = "#" + sc.next() + "#";
				}
				for (int j = 0; j < w; j++) {
					map[i][j] = buffer.charAt(j);
					if ("^v<>".indexOf(map[i][j]) != -1) {
						dirc = "^v<>".indexOf(map[i][j]);
						x = i;
						y = j;
						map[i][j] = '.';
					}
				}
			}

			int sn = sc.nextInt();
			String sec = sc.next();
			int dx[] = { -1, 1, 0, 0 };
			int dy[] = { 0, 0, -1, 1 };

			String move = "UDLR";
			for (int i = 0; i < sn; i++) {
				char com = sec.charAt(i);
				if (move.indexOf(com) != -1) {
					dirc = move.indexOf(com);
					if (map[x + dx[dirc]][y + dy[dirc]] == '.') {
						x += dx[dirc];
						y += dy[dirc];
					}
				} else {
					int nx = x;
					int ny = y;
					String kabe = "#*";
					for (; kabe.indexOf(map[nx][ny]) == -1;) { // dangan
						nx += dx[dirc];
						ny += dy[dirc];
					}
					if (kabe.indexOf(map[nx][ny]) == 1) {
						map[nx][ny] = '.';
					}
				}
			}

			map[x][y] = "^v<>".toCharArray()[dirc];

			for (int i = 1; i < h - 1; i++) {
				for (int j = 1; j < w - 1; j++) {
					System.out.print(map[i][j]);
				}
				System.out.println();
			}
		}
	}

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

Measured memory_bytes: 12000
#include<iostream>

using namespace std;

int main()
{

    int n;
    cin>>n;

    int k;
    cin>>k;

    int T=0;

    for(int i=0;i<k;i++)
    {
        int x;
        cin>>x;

        T|=(1<<x);
    }

    for(int i=0;i<(1<<n);i++)
    {
        if((i&~T)) continue;
        cout<<i<<":";
        for(int j=0;j<n;j++)
        {
            if((i>>j)&1) cout<<" "<<j;
        }
        cout<<endl;
    }

    return 0;
}




Measured memory_bytes: 3124
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int h = scan.nextInt();
        int a = scan.nextInt();
        int out;
        if(h % a == 0){
            out = h / a;
            System.out.println(out);
        }else{
            out = h / a + 1;
            System.out.println(out);
        }
    }
}

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

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    vector<ll>vec;
    for (ll i = 10; i <= 1e18; i *= 5) {
        vec.push_back(i);
    }
    if (N % 2 == 0) {
        //ans = N / 10 + N / 50;
        for (ll i: vec) {
            ans += N / i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import static java.lang.System.*;

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 a = 1; a <= h; a++) {
				for(int b = 1; b <= w; b++) {
					out.print("#");
				}
				out.println();
			}
			out.println();
		}
	}
}


Measured memory_bytes: 35164
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
const int maxn = 1e6 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
vector<int> v;
int N;
ll sum = 0;
int main(){
    FAST_IO
    int N;
    cin>>N;
    for(int i = 1; i <= N; i++){
        int tmp;
        cin>>tmp;
        v.emplace_back(tmp - i);
    }
    sort(v.begin(),v.end());
    int b = 0;
    if(v.size() % 2 == 1) b = v[v.size() / 2];
    else b = (v[v.size() / 2] + v[v.size() / 2 - 1]) / 2;
    for(int i = 0; i < v.size(); i++) sum += abs(v[i] - b);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <queue>
#include <set>

#define MAX_V 200010
using namespace std;

vector<int> G[MAX_V];
queue <int> que;
int a[MAX_V],p[MAX_V],n;

//サイクルを一周して最後に矛盾がないかどうか
bool cycle(int x, int y){
	int i = p[x];
	int pre = y;
	while(i!=x){
		set<int> s;
		s.insert(pre);
		for(int j=0;j<G[i].size();j++){
			s.insert(a[G[i][j]]);
		}
		int z = 0;
		while(s.count(z)){
			z++;
		}
		a[i] = z;
		pre = a[i];
		i = p[i];
	}
	set<int> st;
	st.insert(pre);
	for(int j=0;j<G[x].size();j++){
		st.insert(a[G[x][j]]);
	}
	int z = 0;
	while(st.count(z)){
		z++;
	}
	return y==z;
}

int main(){
	int i,j,z;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> p[i];
		p[i]--;
		G[p[i]].push_back(i);
	}

	for(i=0;i<n;i++){
		if(G[i].size()==0){
			que.push(i);
		}
		a[i]  = -1;
	}

	while(!que.empty()){
		set<int> s;
		int x = que.front();
		que.pop();
		if(a[x]>=0) continue;
		for(j=0;j<G[x].size();j++){
			if(a[G[x][j]]<0){
				z = 1;
			}
			s.insert(a[G[x][j]]);
		}
		if(z){
			z = 0;
			continue;
		}
		int y = 0;
		while(s.count(y)){
			y++;
		}
		a[x] = y;
		que.push(p[x]);
	}

	for(i=0;i<n;i++){
		if(a[i]<0){
			z = i;
			break;
		}
	}
	
	set<int> st;
	for(i=0;i<G[z].size();i++){
		st.insert(a[G[z][i]]);
	}
	j = 0;
	while(st.count(j)){
		j++;
	}
	int k = j;
	j++;
	while(st.count(j)){
		j++;
	}
	int l = j;
	if(cycle(z,k)||cycle(z,l)){
		cout << "POSSIBLE" << endl;
		return 0;
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
vector<int>a;
int main(){
	a.resize(4);
	scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
	sort(a.begin(),a.end());puts(a==vector<int>{1,4,7,9}?"YES":"NO");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, m, a[], b[];
		int count[];
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		count = new int[n];
		
		for(int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			count[a[i] - 1]++;
			count[b[i] - 1]++;
		}
		
		sc.close();
		
		for(int i:count)System.out.println(i);
	}

}


Measured memory_bytes: 22996
N, M = map(int, input().split())
A_list = [list(map(int, input().split())) for i in range(N)]

x_set = set(A_list[0][1:])
for i in range(1, N):
  x_set = x_set & set(A_list[i][1:])
print(len(x_set))
  

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  int search = 0;
  int count = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        search = i;
        for (int l = 0; l < N; l++) {
          if (S[l] == search + '0') {
            if (count == 0) {
              search = j;
              count++;
              continue;
            } else if (count == 1) {
              search = k;
              count++;
              continue;
            } else {
              ans++;
              count = 0;
              break;
            }
          }
        }
        count = 0;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int arr[n+2];
for(int i=0;i<n;i++){
    cin>>arr[i];
}
vector<int>v;
int cnt=0;
for(int i=1;i<n-1;i++){
        v.clear();
    v={arr[i],arr[i-1],arr[i+1]};
sort(v.begin(),v.end());
if(v[1]==arr[i]){
    cnt++;
}
}
cout<<cnt<<endl;


}


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

namespace ConsoleApplication59
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (a[0] * a[1] > a[2] * a[3])
                Console.WriteLine(a[0] * a[1]);
            else Console.WriteLine(a[2] * a[3]);
        }
    }
}


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

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

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

    vector<ll> c(9);
    for(auto &e: c) cin >> e;

    vector<ll> a(3);
    for(a[0]=0; a[0]<=100; a[0]++)
    for(a[1]=0; a[1]<=100; a[1]++)
    for(a[2]=0; a[2]<=100; a[2]++) {
        ll b[] = {c[0]-a[0], c[1]-a[0], c[2]-a[0]};

        bool ok = true;
        for(ll i=0; i<3; i++)
        for(ll j=0; j<3; j++)
            ok &= c[i*3+j] == a[i] + b[j];
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0;i < N;i++) {
    int a;
    cin >> a;
    a--;
    vec.at(i) = a;
}
int j = 0;
for (int i = 1;i < N+2;i++) {
    if (vec.at(j) == 1) {
        cout << i << endl;
        return 0;
    }
    j = vec.at(j);
}
cout << -1 << endl;


return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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

int main()
{
    ios::sync_with_stdio(false);
    int L, R;
    cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    L %= 2019;
    R %= 2019;
    if (L > R) {
        cout << 0 << endl;
        return 0;        
    }

    int ans = 2020;
    for (int i = L; i < R; ++i) {
        for (int j = i + 1; j <= R; ++j) {
            int x = (i * j) % 2019;
            ans = min(ans, x);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,s=0,t=0,i;
	for(i=0;i<4;i++)
	{
		scanf("%d",&a);
		s+=a;
	}
	for(i=0;i<4;i++)
	{
		scanf("%d",&b);
		t+=b;		
	}
	if(s>t)
	{
		printf("%d\n",s);
	}
	else if(s<t)
	{
		printf("%d\n",t);
	}
	else{
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n, k;
  cin >> n >> k;
  int a[200000+10];
  int b[200000+10];
  for(int i=0; i<n; i++){
    cin >> a[i+1];
    b[i+1] = -1;
  }
  int x = 1;
  int p = 0;
  int q = 0;
  b[x] = p;
  while(true){
    p += 1;
    x = a[x];
    if (b[x] >= 0){
      q = b[x];
      break;
    } else {
      b[x] = p;
    }
  }
  // cout << x << " " << p << " " << q;
  int z = x;
  x = 1;
  while(k > 0){
    k -= 1;
    x = a[x];
    if(x == z) k = k%(p-q);

  }
  cout << x;

 }

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n;
	cin >> n;
	vector<P> a(n);
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		a[i].second = x - y;
		a[i].first = x + y;
	}
	sort(all(a));

	int ans = 0, t = a[0].second - 10;
	rep(i, n) {
		//cout << a[i].first << " " << a[i].second << endl;
		if(t <= a[i].second) {
			ans++;
			t = a[i].first;
			//cout << t << " ";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	int n, i;

	scanf("%d", &n);
	long f = 1;
	for (i = 2; i <= n; ++i)
		f *= i;

	printf("%ld\n", f);
	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	while (true){
		int n, m, ans = 0, w = 0, e = 0, a[10000][2] = {}, fri[10000] = {}, save[20000] = {};
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		for (int i = 0; i < m; i++){
			for (int r = 0; r < 2; r++){
				cin >> a[i][r];
			}
		}
		for (int i = 0; i < m; i++){
			for (int r = 0; r < 2; r++){
				if (a[i][0] == 1){
					if (a[i][0] != a[i][1]){
						ans++;
							fri[w] = a[i][1];
							a[i][0] = 0;
							a[i][1] = 0;
							w++;
					}
					else break;
				}
			}
		}
		for (int j = 0; j <= w; j++){
			for (int i = 0; i < m; i++){
				for (int r = 0; r < 2; r++){
					if (fri[j] == a[i][r])
						a[i][r] = 0;
				}
			}
		}
		for (int i = 0; i < m; i++){
			for (int r = 0; r < 2; r++){
				if (0 == a[i][r]){
					if (r == 0){
						if (a[i][1] != 0){
							for (int p = 0; p <e+1; p++){
								if (a[i][1] == save[p])
									a[i][1] = 0;
							}
							if (a[i][1] == 0) break;
							save[e] = a[i][1];
							e++;
							ans++;
						}
					}
				
					if (r == 1){
						if (a[i][0] != 0){
							for (int p = 0; p < e + 1; p++){
								if (a[i][0] == save[p])
									a[i][0] = 0;
							}
							if (a[i][0] == 0) break;
							save[e] = a[i][0];
							e++;
							ans++;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1360
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        int sum = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }
        int[] d = new int[N + 1];
        d[0] = Math.abs(A[0]);
        sum += d[0];
        d[N] = Math.abs(A[N - 1]);
        sum += d[N];
        for(int i=1; i<N; i++){
            d[i] = Math.abs(A[i] - A[i - 1]);
            sum += d[i];
        }
        int ans = sum;

        ans -= d[0] + d[1];
        ans += Math.abs(A[1]);
        System.out.println(ans);
        for(int i=1; i<N-1; i++){
            ans = sum;
            ans -= d[i] + d[i + 1];
            ans += Math.abs(A[i + 1] - A[i - 1]);
            System.out.println(ans);
        }
        ans = sum;
        ans -= d[N] + d[N - 1];
        ans += Math.abs(A[N - 2]);
        System.out.println(ans);
    }
}

Measured memory_bytes: 63868
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  int time;
  int id;
  int pcnt;
  P(int time,int id, int pcnt) :time(time),id(id),pcnt(pcnt) {}
};
const bool operator<(const P& a, const P& b) {
  return a.time!=b.time?a.time>b.time : a.id>b.id;
}
int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    vector<int> consume[n], charge[n];
    priority_queue<P> Q;
    REP(i,n) {
      int a;
      int cnt = 0;
      while(cin>>a, a) {
        if (cnt%2)
          charge[i].push_back(a);
        else
          consume[i].push_back(a);
        cnt++;
      }
      Q.push(P(consume[i][0], i, 0));
    }
    int pcnt[n];
    memset(pcnt,0,sizeof(pcnt));
    int res = 0;
    int nowtime = 0;
    for (int now=0; ; ++now) {
      P p = Q.top();
      int time=p.time,id=p.id,pcnt=p.pcnt;
      if (time >= m) break;
      if (now >= time) {
        //cout << now <<" " <<time << " "  << id << " " <<pcnt << endl;
        res += min(now, m)-time;
        now += charge[id][pcnt];
        Q.pop();
        int next = (pcnt+1)%charge[id].size();
        //cout << now+consume[id][next] << endl;
        Q.push(P(now+consume[id][next], id, next));

        now--;
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 0
let id x = x

let lst_to_num lst =
  List.fold_left (fun s v -> s * 10 + v) 0 lst

let differential s =
  let lst = List.map int_of_string (Str.split (Str.regexp "") s) in
  let lstmn = List.sort compare lst in
  let lstmx = List.sort (fun x y -> compare y x) lst in
  (lst_to_num lstmx) - (lst_to_num lstmn)

let _ = 
  let n = Scanf.scanf "%d\n" id in
  for i = 1 to n do
    let x = Scanf.scanf "%s\n" differential in
    Printf.printf "%d\n" x
  done

Measured memory_bytes: 2324
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string b; cin>>b;
    if(b=="A") print("T");
    else if (b=="T") print("A");
    else if (b=="C") print("G");
    else if(b=="G") print("C");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string a, b, c, d = "aaa";
    cin >> a >> b;
    c = a + b;

    for(int i = 2; i < 317; i++) {
        int a = i * i;
        if(stoi(c) == a) d = "bbb";
    }
    
    if(d == "aaa") cout << "No" << endl;
    if(d == "bbb") cout << "Yes" << endl;
}


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

bool dp[100010][2];

int main(){
	int n,k;
	cin>>n>>k;
	vi arr(n+1);
	for(int i=1;i<=n;i++)
		cin>>arr[i];
		
	//dp[i][j] - se j ganha com i pedras
	
	for(int i=1;i<=n;i++){
		dp[arr[i]][0]=1;
	}
	
	for(int d=0;d<=k;d++){
		for(int i=1;i<=n;i++){
			for(int t=0;t<2;t++){
				if(d>=arr[i]){
					dp[d][t]=dp[d][t] ||  (dp[d-arr[i]][!t] == 0);
				}
			}
		}
	}
	
	
	if(dp[k][0]){
		cout<<"First\n";
	}else{
		cout<<"Second\n";
	}
	
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 using namespace std;
#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define aint(a)                  a.begin(), a.end()
#define pb                      push_back
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define asort(c)                sort(aint(c)) 
#define lbpos(x,v)              (int)(lower_bound(aint(v),x)-v.begin())//=v.size()==>No LB 
#define ubpos(x,v)              (int)(upper_bound(aint(v),x)-v.begin())//=v.size()==>No UB
#define PI                      3.14159265358979323846
#define int                     long long
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  long double                 ld;
#define debug(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
clock_t time_p=clock();
void timer()
{
    time_p=clock()-time_p;
    cerr<<"Execution Time: "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";
}


int32_t main()
{
  FIO;
  int n,p;
  cin>>n>>p;
  if(n==1)
  {
    cout<<p; return 0;
  }
  if(p<=n)
  {
    cout<<1; return 0;
  }
  int init=ceil(pow(p, 1.0/n));
 // debug(init);
  init=max(2LL,init+2);
  int ans=1LL;
  rep(i,2,init)
  {
    int cnt=0;
    int num=p;
    while(num%i==0)
    {
      num/=i;
      cnt++;
    }
    if(cnt>=n)
      ans=max(ans,i);
  }
  cout<<ans;
  timer();
  return 0;
}  

Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {
        int n = sc.nextInt();
        List<Pair> ls = new ArrayList<>();
        List<Pair> rs = new ArrayList<>();

        int total = 0;

        for (int i=0; i<n; i++) {
            char[] arr = sc.next().toCharArray();
            int b = 0;
            int h = 0;
            for (int j=0; j<arr.length; j++) {
                if (arr[j] == '(') {
                    h++;
                } else {
                    h--;
                }
                b = Math.min(b, h);
            }
//            System.out.println(b);
//            System.out.println(h);
            if (0 < h) ls.add(new Pair(b, h));
            else rs.add(new Pair(b-h, -h));
            total += h;
        }

        Collections.sort(ls);
        Collections.sort(rs);

        if (check(ls) && check(rs) && total == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }


    boolean check(List<Pair> pairList) {
        int h = 0;
        for (Pair p: pairList) {
            int b = h + p.b;
            if (b < 0) return false;
            h += p.h;
        }
        return true;
    }

    public class Pair implements Comparable<Pair>{
        int b;
        int h;
        public Pair(int b, int h) {
            this.b = b;
            this.h = h;
        }

        public int compareTo(Pair pair) {
            if (this.b < pair.b) return 1;
            if (pair.b < this.b) return -1;
            return 0;
        }

    }
}



Measured memory_bytes: 92460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll I, O, T, J, L, S, Z;
  cin >> I >> O >> T >> J >> L >> S >> Z;

  ll K0 = O, K1 = O;

  K0 += I / 2 * 2 + J / 2 * 2 + L / 2 * 2;
  if (I % 2 == 1 && J / 2 == 1 && L / 2 == 1)
    K0 += 3;

  if (I >= 1 && J >= 1 && L >= 1)
    K1 += 3;
  K1 += max(0LL, I - 1) / 2 * 2 + max(0LL, J - 1) / 2 * 2 + max(0LL, L - 1) / 2 * 2;

  cout << max(K0, K1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

int count_range(i64 lo, i64 hi, vector<i64>& xs)
{
	int l = lower_bound(xs.begin(), xs.end(), lo) - xs.begin();
	int r = lower_bound(xs.begin(), xs.end(), hi) - xs.begin();
	return max(r - l, 0);
}

int main()
{
	int n;
	vector<int> as, bs;

	scanf("%d", &n);
	as.resize(n);
	bs.resize(n);
	for(int i = 0; i < n; ++i)
		scanf("%d", &as[i]);
	for(int i = 0; i < n; ++i)
		scanf("%d", &bs[i]);

	int ans = 0;

	vector<i64> als, bls;

	for(int bit = 0; bit < 31; ++bit) {

		als.clear();
		bls.clear();

		const i64 mask = (1LL << (bit + 1)) - 1;
		const i64 h_bit = (1LL << bit);
		const i64 hh_bit = (1LL << (bit + 1));

		for(int i = 0; i < n; ++i)
			als.push_back(as[i] & mask);
		for(int i = 0; i < n; ++i)
			bls.push_back(bs[i] & mask);
		sort(bls.begin(), bls.end());

		i64 count = 0;

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

			i64 x = als[i];
			int c = 0;

			if(x & (1LL << bit)) {

				c += count_range(0, hh_bit - x, bls);
				c += count_range(hh_bit + h_bit - x, hh_bit, bls);

			} else {

				c += count_range(h_bit - x, hh_bit - x, bls);
			}

			count += c;
		}

		if(count & 1)
			ans = ans | (1 << bit);
	}

	printf("%d\n", ans);

	return 0;
}

/* waffle */


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

using namespace std;
#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e6+10;
//int a[maxn],sum;
//int d[maxn];
//int c;
//int dfs(int v,int k)
//{
//    if(k==s)
//    {
//
//    }
//    for(int i=v+1;i<sum;i++)
//    {
//        if(a[v]+c<a[i])
//        {
//            b[i]=1;
//            dfs(a[i],k+1);
//            b[i]=0;
//        }
//
//    }
//}
int a[maxn];
int main()
{
    int n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        sint(a[i]);
        sum+=a[i];
    }
    int isok=1;
    int ans=0;
    for(int i=0; i<n; i++)
        if(4*m*a[i]>=sum)
        {
            ans++;
        }
    if(ans>=m)
        printf("Yes");
    else
        printf("No");
    return 0;

}


Measured memory_bytes: 256
N = gets.to_i
ws = gets.split.map(&:to_i)

sum1 = 0
sum2 = ws.inject(:+)
ans = 100 * 1000

N.times do |i|
  s = ws[i]
  sum1 += s
  sum2 -= s
  ans = (sum1 - sum2).abs if (sum1 - sum2).abs < ans
end

puts ans

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 1000000007;

struct Simple {
  int n;
  vector<int> fac, ifac, inv;

  void build(int n) {
    this->n = n;
    fac.resize(n + 1);
    ifac.resize(n + 1);
    inv.resize(n + 1);
    fac[0] = 1;
    for (int x = 1; x <= n; ++x)
      fac[x] = fac[x - 1] * (ll)x % P;
    inv[1] = 1;
    for (int x = 2; x <= n; ++x)
      inv[x] = -(P / x) * (ll)inv[P % x] % P + P;
    ifac[0] = 1;
    for (int x = 1; x <= n; ++x)
      ifac[x] = ifac[x - 1] * (ll)inv[x] % P;
  }

  Simple() {
    build(1);
  }

  void check(int k) {
    int nn = n;
    if (k > nn) {
      while (k > nn)
        nn <<= 1;
      build(nn);
    }
  }

  int gfac(int k) {
    check(k);
    return fac[k];
  }

  int gifac(int k) {
    check(k);
    return ifac[k];
  }

  int ginv(int k) {
    check(k);
    return inv[k];
  }

  int binom(int n, int m) {
    if (m < 0 || m > n)
      return 0;
    return gfac(n) * (ll)gifac(m) % P * gifac(n - m) % P;
  }
} simp;

int norm(int x) { return x >= P ? x - P : x; }

void add(int& x, int y) {
  (x += y) >= P ? (x -= P) : 0;
}

void sub(int& x, int y) {
  (x -= y) < 0 ? (x += P) : 0;
}

int mpow(int x, int k, int p = P) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % p;
    x = x * (ll)x % p;
    k >>= 1;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vi dp(3);
  dp[0] = 1;
  int ans = 0;
  function<int(int, int)> f = [&](int n, int k) {
    return simp.ginv(k) * (ll)simp.gifac(n) % P;
  };
  for (int i = 1; i <= n; ++i) {
    vi newDp(3);
    int tot = norm(norm(dp[0] + dp[1]) + dp[2]);
    for (int j = 0; j < 3; ++j)
      newDp[j] = norm(tot + P - dp[j]);
    dp = newDp;
    ans = (ans + dp[1] * (ll)simp.binom(n, i) % P * f(n, i)) % P;
  }
  ans = ans * (ll)simp.gfac(n - 1) % P;
  ans = ans * (ll)mpow(3, P - 1 - n) % P;
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 12544
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main(void){
for(int i=1;i<10;i++){
for(int j=1;j<10;j++){
printf("%dx%d=%d\n",i,j,i*j);
}
}
return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <cstdlib>
#include <list>
using namespace std;

int main() {
	list<int>L; int n, x; char s[15];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'i')cin >> x,  L.push_front(x);
		else if (s[6] == 'F')L.pop_front();
		else if (s[6] == 'L')L.pop_back();
		else {
			cin >> x;
			for (list<int>::iterator it = L.begin(); it != L.end(); it++)
				if (*it == x) {
					L.erase(it); break;
				}
		}
		
	}
	n = 0;
	for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
		if (n++)cout << " ";
		cout << *it;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 34352
#include <bits/stdc++.h>
using namespace std;
int n,cnt;
vector<int>num[11];
vector<string>ans;
vector<int>v[11];
char c[11];
void dfs(int x){
	if (x==n+1){
		string s="";
		for (int i=1;i<=cnt;i++) for (int j=0;j<v[i].size();j++) c[v[i][j]]=i-1+'a';
		for (int i=1;i<=n;i++) s+=c[i];
		ans.push_back(s); 
		return;
	}
	for (int i=1;i<=cnt;i++){
		v[i].push_back(x);
		dfs(x+1);
		v[i].pop_back();
	}
	cnt++;
	v[cnt].clear(),v[cnt].push_back(x);
	dfs(x+1); 
	cnt--;
}
int main(){
	cin>>n;
	dfs(1);
	sort (ans.begin(),ans.end());
	for (int i=0;i<ans.size();i++)
		cout<<ans[i]<<"\n";
}

Measured memory_bytes: 9588
N = int(input())
h = list(map(int,input().split()))

dp = [0] * N
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    two_step = dp[i-2] + abs(h[i] - h[i-2])
    one_step = dp[i-1] + abs(h[i] - h[i-1])
    dp[i] = min(one_step, two_step)

print(dp[N-1])

Measured memory_bytes: 13980
#include<stdio.h>
int main(){
  int n, S[10000], q, T[500], i, j, cnt = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);

  scanf("%d", &q);
  for(j = 0; j < q; j++)
    scanf("%d", &T[j]);



  for(i = 0; i < q; i++)
    for(j = 0; j < n; j++)
      if(T[i] == S[j])   {
    cnt++;
    break;
      }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const int DX[4] = {+1, -1, 0, 0};
const int DY[4] = {0, 0, +1, -1};
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    vector<vector<int>> A(H + 2, vector<int>(W + 2, 1));
    for (int i = 0; i < H; i++) {
        string s; cin >> s;
        for (int j = 0; j < W; j++) {
            if (s[j] == '.') A[i + 1][j + 1] = 0;
        }
    }
    auto f = [&](int i, int j) {
        vector<vector<int>> visited(H + 2, vector<int>(W + 2));
        int ans = 0;
        queue<tuple<int, int, int>> S;
        S.emplace(i, j, 0);
        while (!S.empty()) {
            int ai, aj, ad; tie(ai, aj, ad) = S.front(); S.pop();
            if (visited[ai][aj]) continue;
            if (A[ai][aj] != 0) continue;
            visited[ai][aj] = 1;
            ans = max(ans, ad);
            for (int k = 0; k < 4; k++) {
                int bi = ai + DX[k];
                int bj = aj + DY[k];
                int bd = ad + 1;
                S.emplace(bi, bj, bd);
            }
        }
        return ans;
    };
    int ans = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            ans = max(ans, f(i, j));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int dfs(int index, int total, int op, int* A)
{
	int ret = op;
	if (index == 4)
	{
		if (total == 7)
		{
			ret = op & 0x7;
		}
	}
	else
	{
		ret = dfs(index + 1, total + A[index], op | (0x1 << (index - 1)), A);
		if (static_cast<bool>(ret & 0x8))
		{
			ret = dfs(index + 1, total - A[index], op, A);
		}
	}
	return ret;
}

int main()
{
	int D[4] = { 1000, 100, 10, 1 };
	int A[4];
	char C[2] = { '-', '+' };
	int N;
	std::cin >> N;
	for (int i = 0; i < 4; ++i)
	{
		A[i] = N / D[i];
		N %= D[i];
	}

	char ANS[8];
	int ret = dfs(1, A[0], 0x8, A);
	ANS[0] = '0' + A[0];
	for (int i = 0; i < 3; ++i)
	{
		int opi = (ret >> i) & 0x1;
		ANS[i * 2 + 1] = C[opi];
		ANS[i * 2 + 2] = '0' + A[i + 1];
	}

	ANS[7] = 0;

	std::cout << ANS << "=7" << std::endl;

	return 0;
}


Measured memory_bytes: 3636