akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    for(int i = 1; 1; i *= 2) {
        if(i > N) {
            cout << i / 2 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> d(10);
	for (int i = 0; i < 10; i++) {
		d[i] = -1;
	}
	for (int i = 0; i < m; i++) {
		int s, c;
		cin >> s >> c;
		if (d[s - 1] == -1 || d[s - 1] == c) {
			d[s - 1] = c;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	if (d[0] == 0) {
		if (n == 1) {
			cout << 0 << endl;
		} else {
			cout << -1 << endl;
			return 0;
		}
	} else {
		for (int i = 0; i < n; i++) {
			if (d[i] == -1 && i == 0 && n > 1) cout << 1;
			else if (d[i] == -1) cout << 0;
			else cout << d[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<int> ans(s.size());

  // RLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

  int next_l = 0;
  int next_r = s.size() - 1;
  REP(i, s.size()) {
    if(s[i] == 'R') {
      int start = i + 1 > next_l ? (i + 1) : next_l;
      for (int j = start; j < s.size(); j++) {
        if(s[j] == 'L') {
          if((j-i) % 2 == 0) {
            ans[j]++;
          } else {
            ans[j-1]++;
          }
          next_l = j;
          break;
        }
      }
      next_r = i;
    } else {
      int start = i - 1 < next_r ? (i - 1) : next_r;
      for (int j = start; j >= 0; j--) {
        if(s[j] == 'R') {
          if((i - j) % 2 == 0) {
            ans[j]++;
          } else {
            ans[j+1]++;
          }
          next_r = j;
          break;
        }
      }
    }
  }

  REP(i, s.size()) {
    cout << ans[i] << " ";
  }

  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int ans = S.size()/2;
    int L = S.size();
    if(L%2==0){
        char num;
        for(int i=0;i+(L/2)<L;i++){
            if(i==0){
                num=S[(L/2)+i];
                if(num!=S[(L/2)-1-i])break;
            }
            else{
                if(num!=S[(L/2)+i]||num!=S[(L/2)-1-i]){
                    break;
                }
            }
            ans++;
        }
    }
    else{
        char num=S[(L/2)];ans++;
        for(int i=1;i+(L/2)<L;i++){
            if(num!=S[(L/2)+i]||num!=S[(L/2)-i]){
                break;
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vi arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    int count = 0;
    for (int i = 1; i < n-1; ++i) {
        if (arr[i-1] < arr[i] && arr[i] < arr[i+1]) count += 1;
        else if (arr[i-1] > arr[i] && arr[i] > arr[i+1]) count += 1;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    import std.math;
    int x, a, b;
    scan(x, a, b);
    writeln(abs(x-a) < abs(x-b) ? "A" : "B");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using namespace std;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<int> vec(n);
    for(int i=0;i<n;++i)
    {
    	cin>>vec[i];
    }

    long long min=9999999999999ll;
    sort(vec.begin(),vec.end());
    for(int i=vec[0];i<=vec[n-1];++i)
    {
    	long long sum=0;
    	for(int j=0;j<n;++j)
    	{
    		sum+=(vec[j]-i)*(vec[j]-i);
    	}
    	if(sum<min)
    	{
    		min=sum;
    	}
    }
    cout<<min<<endl;



}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	4 * MAX5;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll t = 1;
ll n, x, k, q, m, y, r;
string s;

ll day[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

// <------------- Implement Functions Here ----------> //

  


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	ll val = n%100;
	ll turn = val/5 + (val%5 != 0);

	if(n/100 < turn ) cout<<0;
	else cout<<1;
}

int main() {
	fastio; randomINT;
	//cin >> t;
	while (t--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 12996
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >>  n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  cout << a[a.size()/2]-a[SZ(a)/2-1] << endl;
}


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

int main() {
	char a;
	cin >> a;
	if (a == 'A') cout << "T" << endl;
	if (a == 'T') cout << "A" << endl;
	if (a == 'C') cout << "G" << endl;
	if (a == 'G') cout << "C" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,k = 1;
	scanf("%d",&n);
	int a[n];
	for (int i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for (int i = 0;i < n;i++){
	if(a[i] % 2 == 0){
	if ((a[i] % 3 != 0)&&(a[i] % 5 != 0)){
			k = 0;
			break;}
	}
	}
	if(k == 1) printf("APPROVED");
	else printf("DENIED");
}


Measured memory_bytes: 128
n = STDIN.gets.to_i

square = Array.new(2, Array.new(n))
square[0]= STDIN.gets.split(' ').map(&:to_i)
square[1]= STDIN.gets.split(' ').map(&:to_i)

max = 0

0.upto(n-1) do |i|
  up = square[0][0..i].reduce(&:+)
  down = square[1][i..n-1].reduce(&:+)
  if(max < (up + down))
    max = (up + down)
  end
end

puts max

Measured memory_bytes: 1788
n = int(input())
l = []
s = 0
for i in range(1,10**7+1):
  if n>=s:
    s += i
    l.append(i)
  else:
    break
if s-n>0:
  a = s-n
  l.remove(a)
for i in l:
  print(i)

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int r, k;
    cin >> r >> k;
    if(r<10){
        cout << 100*(10-r)+k << endl;
    }else{
        cout << k << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
  A[i].pop(0)

ans = 0
for j in range(1,m+1):
  if all(j in A[i] for i in range(len(A))) == True:
    ans += 1

print(ans)

Measured memory_bytes: 3060
// syakyo http://d.hatena.ne.jp/simezi_tan/20120906/1346880190

#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int n;
double x[100], y[100], v[100];

inline double d(int i, double a, double b){
    return sqrt((x[i] - a)*(x[i] - a) + (y[i] - b)*(y[i] - b));
}

inline double g(double a, double b){
    double res = 0;
    rep(i, n){
        res = max(res, d(i, a, b)/v[i]);
    }
    return res;
}

inline double f(double x){
    double l = 0, r = 100, a, b;
    double ans;
    rep(i, 100){
        a = (l * 2 + r) / 3;
        b = (l + r * 2) / 3;
        if ((ans = g(x, a)) > g(x, b)) l = a;
        else r = b;
    }
    return ans;
}

int main(){
    while (cin >> n, n){
        rep(i, n){
            cin >> x[i] >> y[i] >> v[i];
        }
        double l = 0, r = 100, a, b;
        double ans;
        rep(i, 100){
            a = (l * 2 + r) / 3;
            b = (l + r * 2) / 3;
            if ((ans = f(a)) > f(b)) l = a;
            else r = b;
        }
        cout << fixed << setprecision(20);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1292
import bisect

N = int(input())
if N==1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


l = factorization(N)

a = [i * (i + 1) // 2 for i in range(2 * 10**6)]
ans = 0


for p in l:
    n = bisect.bisect_right(a, p[1]) - 1
    ans += n

print(ans)


Measured memory_bytes: 162340
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    swap(a,b);
    swap(a,c);
    printf("%d %d %d",a,b,c);
    return 0;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void)
{
	char map[101][102];
	int flag[101][102];
	int row, col,i,j,Flag;

	while (1) 
	{
		scanf("%d %d", &row, &col);

		if (row == 0 && col == 0) 
		{
			break;
		}

		for (i = 0; i < 101; i++) 
		{
			for (j = 0; j < 101; j++) 
			{
				flag[i][j] = 0;
			}
		}

		for (i = 0; i < row; i++) 
		{
			scanf("%s", map[i]);
		}

		i = 0;
		j = 0;

		while (1) 
		{
			if (flag[i][j] == 1)
			{
				Flag = 1;
				break;
			}
			else if (map[i][j] == '.') 
			{
				Flag = 2;
				break;
			}

			switch (map[i][j])
			{
			case '^':flag[i][j] = 1; --i; break;
			case 'v':flag[i][j] = 1; ++i; break;
			case '>':flag[i][j] = 1; ++j; break;
			case '<':flag[i][j] = 1; --j; break;
			}
		}

		if (Flag == 1) 
		{
			printf("LOOP\n");
		}

		if (Flag == 2) 
		{
			printf("%d %d\n", j, i);
		}

	}

	return (0);
}


Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,inf=0x3f3f3f;
int col[maxn]={0},num=0;
int head[maxn]={0},flag=1;
struct qw
{
	int nex,to,cos;
}e[maxn<<1];
void add(int u,int v,int c)
{
	e[++num].nex=head[u];
	e[num].to=v;
	e[num].cos=c;
	head[u]=num;
}
void dfs(int u,int fa,int dis)
{
	for(int i=head[u];i;i=e[i].nex)
	{
		int v=e[i].to;
		if(v==fa) continue;
		int qw=(dis+e[i].cos)%2;
		if(qw==0) 
		{
			col[v]=1;
			dfs(v,u,qw);
		}
		else
		{
			col[v]=0;
			dfs(v,u,qw);
		}
	}
}
int main()
{
	int n;
	cin>>n;
	memset(col,inf,sizeof(inf));
	int i,j,root=0;
	for(i=1;i<=n-1;i++)
	{
		int u,v,c;cin>>u>>v>>c;
		if(!root) root=u;
		add(u,v,c);add(v,u,c);
	}
	col[root]=1;dfs(root,0,0);
	for(i=1;i<=n;i++)
	cout<<col[i]<<endl;
}

Measured memory_bytes: 7680
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int k = Integer.parseInt(str[0]);
        int s = Integer.parseInt(str[1]);
        int ans = 0;
        
        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                if (s - x - y >= 0 && s - x - y <= k) ans++;
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21332
import java.util.*;
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
String m = sc.nextLine();
String n = sc.nextLine();
String m1 = m.substring(0,1);
String n1 = n.substring(0,1);
String m2 = m.substring(1,2);
String n2 = n.substring(1,2);
String m3 = m.substring(2);
String n3 = n.substring(2);
int i = 0;


        if (m.equals(n)){
                        System.out.println(3);
}else{
if(m1.equals(n1)) i++;
if(m2.equals(n2)) i++;
if(m3.equals(n3)) i++;
System.out.println(i);
}


        sc.close();
    }
}


Measured memory_bytes: 24916
import math

X = int(input())
 #素数判定はsqrt(X)までで十分

flag_1 = True
flag_2 = True

while flag_1 :
    flag_2 = True
    for i in range(2,math.ceil(math.sqrt(X))) :
        if X % i == 0 :
            flag_2 = False
            X = X + 1
            break
    if flag_2 == True :
        print(X)
        break

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

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

int main() {
    int N;
    cin >> N;
    int count2 = 0;
    int count4 = 0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a%4 == 0){
            count4++;
        }else if(a%2 == 0){
            count2++;
        }
    }
    
    if(count4 * 2 + 1 * (bool)count4 + count2 - 1 * (bool)count2  >= N || count2 == N){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;

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

#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

ll dist(ll a,ll b,ll c,ll d){
	return abs(a-c) + abs(b-d);
}

int main(){
	ll N,M;
	cin >> N >> M;
	ll x[114514];
	ll y[114514];

	//赤の可能性があるなら1以上
	ll out[114514];
	//ボールの個数-1
	ll ball[114514] = {0};
	out[1] = 1;

	long cnt = 0;
	REP(i,M){
		cin >> x[i] >> y[i];
		out[y[i]] += out[x[i]];

		//xのボールの数を減らす
		ball[x[i]] --;

		//球が0になった時には垢の可能性はない
		if(ball[x[i]] == -1){
			out[x[i]] = 0;
		}

		//y側をふやす
		ball[y[i]]++;


	}


	REP(i,N){
		if(out[i+1] > 0) cnt++;
	}


	cout << cnt << endl;
	
}

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

int main(){
  ll A,B,N;
  cin >> A >> B >> N;
  ll x;
  if(N<B-1) x=N;
  else x=B-1;
  ll M = (A*x-(A*x%B))/B-A*((x-x%B)/B);
  cout << M << endl;
}

Measured memory_bytes: 3684
import java.util.*

enum class Color {
    RED, GREEN, NONE
}

fun main() {
    val builder = StringBuilder()

    val (x, y, _, _, _) = readInputLine().split(" ").map { it.toInt() }

    val queue = PriorityQueue<Pair<Long, Color>> { x, y -> y.first.compareTo(x.first) }

    readInputLine().split(" ").forEach {
        queue.add(Pair(it.toLong(), Color.RED))
    }
    readInputLine().split(" ").forEach {
        queue.add(Pair(it.toLong(), Color.GREEN))
    }
    readInputLine().split(" ").forEach {
        queue.add(Pair(it.toLong(), Color.NONE))
    }

    var total = 0
    var red = 0
    var green = 0
    var ans = 0L

    while (total < x + y) {
        val (q, color) = queue.poll()
        when (color) {
            Color.RED -> {
                if (red < x) {
                    red++
                    total++
                    ans += q
                }
            }
            Color.GREEN -> {
                if (green < y) {
                    green++
                    total++
                    ans += q
                }
            }
            Color.NONE -> {
                total++
                ans += q
            }
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 90112
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (ord)
import Data.Int (Int64)
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import qualified Data.Sequence as Seq

buildTable :: BS.ByteString -> V.Vector (Seq.Seq Int)
buildTable s = let s' = V.generate (BS.length s) $ \i -> BS.index s i
               in V.scanr (\(i,c) a -> Seq.update (ord c - ord 'a') i a) (Seq.replicate 26 (-1)) (V.indexed s')

main = do
  s <- BS.getLine
  t <- BS.getLine
  let s_table = buildTable s
  let loop :: Int64 -> Int -> BS.ByteString -> Int64
      loop !i !j t = case BS.uncons t of
                       Nothing -> i
                       Just (c, t') ->
                         let k = (s_table V.! j) `Seq.index` (ord c - ord 'a')
                         in if k == -1
                            then let l = V.head s_table `Seq.index` (ord c - ord 'a')
                                 in if l == -1
                                    then -1
                                    else loop (i + fromIntegral (l + BS.length s - j) + 1) (l+1) t'
                            else loop (i + fromIntegral (k - j) + 1) (k+1) t'
  print $ loop 0 0 t


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

using namespace std;

using ll = long long;

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

    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
from collections import deque
N, Q = map(int, input().split())
lst = [[] for _ in range(N)]
ans = [0] * N
for i in range(N-1):
    a,b = map(int, input().split())
    lst[b-1].append(a-1)
    lst[a-1].append(b-1)
for j in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

q = deque()
q.append(0)
flag = [0] * N
while q:
    y = q.pop()
    flag[y] = 1
    for k in lst[y]:
        if flag[k] == 1:
            continue
        ans[k] += ans[y]
        q.append(k)
print(*ans)



Measured memory_bytes: 56084
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int stoi(string str) {
  int ans = 0;
  for(int i = 0; i < str.length(); i++) {
    ans += (int)(str[i] - '0') * (int)pow(10.0, (int)str.length()-i-1);
  }
  return ans;
}

bool isNum(char c) {
  if(c >= '0' && c <= '9') return true;
  return false;
}

int main() {
  int sum = 0;
  while(1) {
    if(cin.eof()) break;
    string str;
    getline(cin, str);
    string num = "";
    for(int i = 0; i < str.length(); i++) {
      if(isNum(str[i])) num += str[i];
      if(( !isNum(str[i]) || i+1 == str.length() ) && num.length() > 0) {
	sum += stoi(num);
	num = "";
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N;
  int t[N+1]; double v[N]; int sum=0; t[0] = 0;
  rep(i, N){
    cin >> t[i+1]; t[i+1]+=t[i];
  }
  rep(i, N){
    cin >> v[i];
  }
  double K[N+1];
  K[0] = 0; K[N] = 0;
  rep(i, N-1){
    K[i+1] = min(v[i], v[i+1]);
  }
  double tmp[2*sum+1]; double ans = 0;
  rep(i, 2*t[N]+1){
    tmp[i] = inf;
    rep(j, N+1){
      tmp[i] = min(tmp[i], K[j]+abs(t[j]-i*0.5)); 
    }
    rep(j, N){
      if(t[j]<=i*0.5 && i*0.5<=t[j+1]) tmp[i] = min(tmp[i], (double)v[j]);
    }
    if(i>0) ans+=(tmp[i]+tmp[i-1])*0.25;
  }
  printf("%.12lf\n", ans);
 }


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n; str a, b, c; cin >> n >> a >> b >> c;
  ll ans = 0;
  for(ll i = 0;i < n;i++)
  {
    if(a[i] == b[i]&&b[i] == c[i])
    {
      continue;
    }
    else if(a[i] != b[i]&&a[i] != c[i]&&b[i] != c[i])
    {
      ans += 2;
    }
    else
    {
      ans++;
    }
  }
  fin(ans)
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
s = input()
x = s[0] + s[1]
y = s[2] + s[3]
x = int(x)
y = int(y)
if x > 0 and x < 13:
    if y > 0 and y < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif y > 0 and y < 13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
typedef long long ll;
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; }
using namespace std;

int main(){
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	while(s.size()){
		string t5 = s.substr(0,5), t6 = s.substr(0,6), t7 = s.substr(0,7);
		if(t5 == "maerd" || t5 == "esare") s = s.substr(5);
		else if(t6 == "resare") s = s.substr(6);
		else if(t7 == "remaerd") s = s.substr(7);
		else{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,k,x,y;
 
int main(){
  ll ans=0;
  cin >> n ;
  vi a(n+1),b(n+1),c(n+1),d(n+1);
  REP(i,n+1) cin>>a[i];



  if (n==0){
    if (a[0]==1){
      cout<<1<<endl;
      return 0;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  


  if (a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }

 
 

  d[n]=a[n];
  for(ll i=n-1;i>=0;i--){
    d[i]=d[i+1]+a[i];
  }

  ll nown=1;
  b[0]=1;
  c[0]=1;
  for(ll i=1;i<n+1;i++){
    nown=min(min(nown*2,d[i]),llMAX);
    b[i]=nown;
    nown-=a[i];
    if (nown<0){
      cout<<-1<<endl;
      return 0;
    }


    c[i]=nown;
  }

  

 
 
 
  int flag=0;
  for(ll i=0;i<n+1;i++){
    ans+=b[i];
    flag+=(b[i]<=0);
    //flag+=(c[i]<0);
  }
  /*
  if (flag!=0){
    cout<<-1<<endl;
    return 0;
  }
  */
 
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6432
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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() {
  int K;
  cin >> K;
  int temp_num = 7;
  vector<bool> hasAppeared(K+1);
  int ans = 1;
  while(true) {
    if (temp_num % K == 0) break;
    else {
      if (hasAppeared[temp_num]) {
        ans = -1;
        break;
      }
      else {
        hasAppeared[temp_num] = true;
        temp_num *= 10;
        temp_num += 7;
        temp_num %= K;
        ++ans;
      }
    }
  }
  cout << ans << endl; 
  return 0;
}

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

using namespace std;

int main() {
  int d, n;
  cin >> d >> n;
  int a;
  if (n == 100) n++;
  if (d == 0)
    a = 1;
  else if (d == 1)
    a = 100;
  else
    a = 10000;
  cout << a * n << endl;
}

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

#define PI 3.141592653

void funk(int,double,double,double,double);

int main() {
  int x;
  scanf("%d",&x);

  printf("%f %f\n",0.0,0.0);
  funk(x,0.0,0.0,100.0,0.0);
  printf("%f %f\n",100.0,0.0);

  return 0;
}

void funk(int n,double x1,double y1,double x2,double y2) {
  double sx,sy,tx,ty,ux,uy;
   
  if(!n) {
    return;
  }

  sx = (2 * x1 + x2) / 3;
  sy = (2 * y1 + y2) / 3;
  tx = (x1 + 2 * x2) / 3;
  ty = (y1 + 2 * y2) / 3;
  ux = (tx - sx) * cos(PI / 3) - (ty - sy) * sin(PI / 3) + sx;
  uy = (tx - sx) * sin(PI / 3) + (ty - sy) * cos(PI / 3) + sy;

  funk(n - 1,x1,y1,sx,sy);
  printf("%f %f\n",sx,sy);
  funk(n - 1,sx,sy,ux,uy);
  printf("%f %f\n",ux,uy);
  funk(n - 1,ux,uy,tx,ty);
  printf("%f %f\n",tx,ty);
  funk(n - 1,tx,ty,x2,y2);
}
  

  

 

  



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    string s;cin>>s;
    ll ns=siz(s),ans=0;

    ll posf=0,posb=ns-1;

    while(posb-posf>0){
        if(s[posf]==s[posb]){
            posf++;
            posb--;
        }else{
            if(s[posf]=='x'){
                posf++;
            }else if(s[posb]=='x'){
                posb--;
            }else{
                cout<<-1<<endl;
                return 0;
            }
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  long long N;
  string s,t;
  cin >> N >> s >> t;
  
  for (int i=N; i>=1; i--) {
    for (int j=0; j<i; j++) {
      if (s[N-i+j] != t[j]) break;
      if (j == i-1) {
        cout << N*2-i << endl;
        return 0;
      }
    }
  }
  
  cout << N*2 << endl;
}

Measured memory_bytes: 256
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int a,b,m;
	cin >>  a>> b >> m;
	vector<int> x(a),y(b);
	rip(i,a,0) cin >> x[i];
	rip(i,b,0) cin >> y[i];
	int ans = INT_MAX/2;
	rip(i,m,0){
		int t,s,c;
		cin >> t >> s >> c;
		chmin(ans, x[t-1]+y[s-1]-c);
	}
	sort(all(x));
	sort(all(y));
	chmin(ans, x[0]+y[0]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] x = new int[n];
		int result = 0;

		for (int i = 0; i < x.length; i++) {
			x[i] = in.nextInt();
		}

		for (int i = 0; i < x.length; i++) {
			if (x[i] < Math.abs(k-x[i])) {
				result += x[i];
			}
			else {
				result += Math.abs(k-x[i]);
			}
		}

		System.out.println(result*2);
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
pair<pair<string,int>,int> x[n];
string s;
int p;
REP(i,n) {
  cin >> s >> p;
  x[i] = make_pair(make_pair(s,-p),i+1);
}
sort(x,x+n);
REP(i,n) {
  cout << x[i].second << endl;
}

return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int INF = 10000*100000+100;
int V,E,R,S[500010],T[500010],D[500010];
int C[100010];
int main()
{
	cin >> V >> E >> R;
	for(int i = 0; i < E; ++i)
	{
		cin >> S[i] >> T[i] >> D[i];
	}
	
	for(int i = 0; i < V; ++i){
		C[i] = INF;
	}
	C[R] = 0;
	for(int t = 0; t < V; ++t)
	{
		bool update = false;
		for(int i = 0; i < E; ++i)
		{
			int s = S[i], t = T[i], d = D[i];
			if(C[s] < INF && C[t] > C[s] + D[i])
			{
				C[t] = C[s] + D[i];
				update = true;
			}
		}
		if(!update) break;
	}
	for(int i = 0 ;i < V; i++)
	{
		if(C[i] == INF)
			cout<<"INF"<<endl;
        else
            cout << C[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 9196
def f(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return 3 * n + 1

s = int(input())
a = [0]
for i in range(1, 1000001):
    if i == 1:
        a.append(s)
    else:
        a.append(f(a[i-1]))
        if a.count(a[-1]) == 2:
            print(i)
            break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long lcm(long long u, long long v){
    if(u == 0 || v == 0){
        return 0;
    }else{
        long long s=u*v;
        long long r;
        while (0 != v) {
        r = u % v; u = v; v = r;
        }
        s /= u;
        return s;
    }
}
int gcd(long long u, long long v) {
  long long r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
int main(){
    long long n,m;
    string s,t;
    cin >> n >> m;
    cin >> s >> t;
    long long l = lcm(n,m);
    long long o = gcd(n,m);
        long long x = n/o;
        long long y = m/o;
        for(long long i=0;i<o;i++){
            if(s[x*i] != t[y*i]){
                goto dame;
            }
        }
        goto oke;
    
    dame:
    cout << "-1" << endl;
    goto owari;
    oke:
    cout << l << endl;
    owari:
    return 0;
    
}

Measured memory_bytes: 512
import java.util.*;

class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next(); //Sringで一文字入力
        char C = S.charAt(0); //Stringをcharに切り出し
        int tmp = (int)C; //文字を10進に変換
        tmp = tmp + 1;
        String hex = Integer.toHexString((int)tmp); //10進を16進文字列に変換
        char hex2 = (char)Integer.parseInt(hex, 16); //16進文字列をcharに変換
        System.out.println(hex2);
    }
}

Measured memory_bytes: 23892
N = int(input())
a =  list(map(int,input().split(" ")))

free = 0
arr = [0] * 8

for i in a:
	limit = 400
	while (limit <= 3200):
		if i < limit:
			arr[(limit // 400)-1] +=  1
			break
		else:
			limit += 400

	if limit== 3600:
		free += 1

color =  0
for i in arr:
	if i > 0:
		color += 1


print(str(max(1,color)) + " " + str(color + free))




Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  cin>>n;
  string str[n];
  for(int i=0;i<n;i++)
  {
    cin>>str[i];
    
    sort(str[i].begin(),str[i].end());
  }
  sort(str,str+n);
  long long count=0;
  for(int i=0;i<n-1;i++)
  {
  	long long k=1;
 
    while((str[i].compare(str[i+1])==0)&&i<n-1)
    {
    	i++;
    	k++;
    }
    count+=((k-1)*(k))/2;
    
  }
  cout<<count;
  return 0;
}

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

long long k,i=0,a=0;

signed main()
{
	ios::sync_with_stdio(0);
	
	cin >> k;
	
	if (k%2==0 || k%5==0)
	{
		 cout << "-1" << endl;
		 return 0;
	}
	
	while (i<=10000000)
	{
		i++;
		
		a = (a*10+7)%k;
		
		if (a==0) 
		{
			cout << i << endl;
			return 0;
		} 
	}
	
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;

int gcd(int a, int b) {
    int r = a % b;
    if (r == 0) return b;
    return gcd(b, r);
}

ll lcm(ll a, ll b) {
    return a/gcd(a, b)*b;
}

const int MAX = 1000010;
ll fac[MAX], inv[MAX], finv[MAX]; 

void COMinit() {
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    FOR(i, 2, MAX) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[n-r] * finv[r] % mod) % mod;
}

ll modpow(ll m, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * m % mod;
        }
        m = m * m % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    ll n, m;
    cin >> m >> n;
    ll res = modpow(m, n);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3088
n = int(input())
h = list(map(int, input().split()))
ans = []

for i in range(n-1):
    if h[i]>=h[i+1]:
        ans.append(1)
    else:
        ans.append(0)

count = 0
s = []
for i in range(len(ans)):
    if ans[i]==1:
        count += 1
    else:
        s.append(count)
        count = 0
        continue
    s.append(count)

if s:
    print(max(s))
else:
    print(0)

Measured memory_bytes: 64996
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
int n,k;

int main() {
	read(n);read(k);
	printf("%s",(k<=(n+1)/2)?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4000000)
import itertools

n = int(input())

a = range(1, 10)
b = range(1, 10)
L = [x[0]*x[1] for x in itertools.product(a, b)]
if n in L:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    cout << N+1-K << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total = 0
for i in range(N):
	total += min(A[i], B[i])
	B[i] -= min(A[i], B[i])
	total += min(A[i+1], B[i])
	A[i+1] -= min(A[i+1], B[i])

print(total)

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

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int f (int i, int p) {
    return -(i / p * p) + i % p;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b; cin >> n >> a >> b;
    if (a + b > n + 1 || a * b < n) {
        cout << "-1\n";
        return 0;
    }

    rep (i, n - a, n) cout << i + 1 << " \n"[a == n && i == i_len - 1];
    if (a >= n) return 0;
    int t = n - a;
    rep (i, b - 1) {
        int k = (n - a) / (b - 1) + (i % (b - 1) < (n - a) % (b - 1));
        rep (j, t - k, t) cout << j + 1 << " ";
        t -= k;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3660
class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]


N,M=map(int, input().split())
P=list(map(int, input().split()))
uni=UnionFind(N)
for i in range(M):
  x,y=map(int, input().split())
  uni.Unite(x-1,y-1)
  
ans=0
for i,p in enumerate(P):
  if uni.isSameGroup(i,p-1):
    ans+=1
print(ans)


Measured memory_bytes: 13812
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();

    long h[] = new long[n];
    boolean fix[] = new boolean[n];
    Arrays.fill(fix, false);
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }

    for (int i = n - 1; i > 0; i--) {
      if (h[i] >= h[i - 1]) {
        continue;
      }
      if (h[i] == h[i - 1] - 1) {
        h[i - 1] = h[i - 1] - 1;
        continue;
      }

      System.out.println("No");
      return;
    }
    System.out.println("Yes");
  }
}


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

int main(void){
    int D, G;
    cin >> D >> G;
    int p[D], c[D];
    rep(i,D){
        cin >> p[i] >> c[i];
    }
    int ans = INT_MAX;
    rep(bit,1<<D){
        int point = 0;
        int solved = 0;
        rep(i,D){
            if(!(bit & 1<<i)) continue;
            point += p[i] * (i+1) * 100 + c[i];
            solved += p[i];
        }
        brep(i,D){
            if (point >= G)break;
            if (bit & 1<<i)continue;
            int add_solved = min(p[i], int(ceil((double(G - point) / ((i+1) * 100)))));
            solved += add_solved;
            point += add_solved * (i+1) * 100;
        }
        if(point >= G)ans = min(ans, solved);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

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

const LL  INF=1<<31;



int main(){
     int n,k;
     cin>>n>>k;
     
     if((n+1)/2>=k)cout<<"YES"<<endl;
          else cout<<"NO"<<endl;
}

Measured memory_bytes: 256