akhauriyash/Code-Regression huggingface dataset:
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
int main(){
    init();

    cout<<"square1001"<<endl;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ll x;
    cin>>x;
    unordered_map<ll,int> mp;
    for(int i{1000};i--;){
        ll c{1};
        for(int j{};j<5;++j) c*=i;
        if(mp[c+x])
            return cout<<mp[c+x]<<" "<<i<<endl,0;
        if(mp[x-c])
            return cout<<mp[x-c]<<" "<<-i<<endl,0;
        mp[c]=i;
    }
}

Measured memory_bytes: 3704
INF = 10**12
n,m = gets.split.map(&:to_i)
e = Array.new(m){ gets.split.map(&:to_i) }.map{|a,b,c|[a-1,b-1,c]}
g = Array.new(n){ Array.new(n, INF) }
n.times { |i| g[i][i] = 0 }

e.each do |a,b,c|
  g[a][b] = c
  g[b][a] = c
end

n.times do |k|
  n.times do |i|
    n.times do |j|
      dist = g[i][k] + g[k][j]
      g[i][j] = dist if g[i][j] > dist
    end
  end
end

ans = 0
e.each do |i,j,cost|
  ans += 1 if g[i][j] < cost
end

puts ans


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;


 void test_cases()
{

ll n;
cin>>n;
 vector<ll>t(n);
 ll tot=0;
 for(auto &e:t)cin>>e,tot+=e;
 
 ll m;
 cin>>m;
 
 for(ll i=0;i<m;i++)
 {
 	ll new_tot=tot;
 	ll p,x;
 	cin>>p>>x;
 	new_tot+=x-t[p-1];
 	
 	cout<<new_tot<<"\n";
 
 }
 
 
 
}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {



	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int Y = scan.nextInt();
		int Z = scan.nextInt();

		int A = X;
		int B = Y;
		int C = Z;

		int tmp;

		tmp = A;
		// AをBに
		A = B;
		// BをAに
		B = tmp;

		tmp = A;
		// AをCに
		A = C;
		C = tmp;

		System.out.println(A + " " + B + " " + C);

	}
}


Measured memory_bytes: 27088
solve [] = []
solve (_:s) = if check s then s else solve s

check s = let n = length s
              in if n `mod` 2 == 0
                 then take (n `div` 2) s == drop (n `div` 2) s
                 else False

main = do
  s <- reverse <$> getLine
  putStrLn $ show $ length $ solve s
  


Measured memory_bytes: 508
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3132
import bisect

a,b,q=map(int,input().split())
s = []
t = []
for i in range(a):
  s.append(int(input()))
for i in range(b):
  t.append(int(input()))
for _ in range(q):
  x = int(input())
  
  ans = [0,0,0]
  
  i = bisect.bisect_left(s,x)
  if i == 0:
    sl = 100000000000
  else:
    sl = abs(s[i-1]-x)
  if i == a:
    sr = 100000000000
  else:
    sr = abs(s[i]-x)
  i = bisect.bisect_left(t,x)
  if i == 0:
    tl = 100000000000
  else:
    tl = abs(t[i-1]-x)
  if i == b:
    tr = 100000000000
  else:
    tr = abs(t[i]-x)
  ans[0] = max(tl,sl)
  ans[1] = max(tr,sr)
  ans[2] = min(2*tl+sr,2*sl+tr,2*sr+tl,2*tr+sl)
  print(min(ans))

Measured memory_bytes: 16736
N=int(input())
S=input()

n=0
for i in range(N-1):
    if (S[i]=='W' and S[i+1]=='R'):
        n+=1

if n==0 :
    ans = 0
else:
    ans=0
    p=N-1
    for i in range(N):
        if S[i]=='W':
            found = 0
            while p>i and found == 0:
                # print("i=",i," S[i]=",S[i]," p=",p," S[p]=",S[p])
                if S[p]=='R':
                    ans+=1
                    found = 1 

                p-=1


print(ans)


Measured memory_bytes: 9440
N = int(input())
T = [int(input()) for _ in range(N)]
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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


l = 1
for i in range(N):
    l = lcm(l, T[i])

print(l)

Measured memory_bytes: 3060
N,W = map(int,input().split())

max_size = 10**5
dp = [float("inf") for i in range(max_size+1)]
dp[0] = 0

for i in range(N) :
    weight,value = map(int,input().split())
    for j in range(max_size, value-1, -1) :
        if dp[j - value] + weight <= W :
            dp[j] = min(dp[j], dp[j-value] + weight)

for i in range(max_size, -1, -1) :
    if dp[i] < float("inf") :
        ans = i
        break

print(ans)


Measured memory_bytes: 54140
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using Point = pair<int, int>;
const int INF = (int)1e9;

int H, W;
char s[50][50];
int dist[50][50];
int white = 0;

int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int main(void){
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
            if(s[i][j] == '.') white++;
            dist[i][j] = INF;
        }
    }

    queue<Point> que;
    que.push(Point(0, 0));
    dist[0][0] = 0;

    while(not que.empty()){
        Point p = que.front(); que.pop();
        int y = p.first, x = p.second;

        for(int i = 0; i < 4; i++){
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 or H <= ny or nx < 0 or W <= nx) continue;

            if(dist[ny][nx] == INF and s[ny][nx] == '.'){
                dist[ny][nx] = dist[y][x] + 1;
                que.push(Point(ny, nx));
            }
        }
    }

    int res;

    if(dist[H-1][W-1] == INF){
        res = -1;
    }else{
        res = white - dist[H-1][W-1] - 1;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int N = 1e5 + 100;
const ll MX = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-9 ;


int _3102_{
	Gamed
	ll n, h[N], dp[N] ;
	cin >> n ;
	for ( int i = 0 ; i < n ; i ++ ){
		cin >> h[i] ;
	}
	dp[0] = 0 ;
	dp[1] = abs(h[1] - h[0]) ;
	for ( int i = 2 ; i < n ; i ++){
		dp[i] = min ( dp[i-1] + abs(h[i] - h[i-1]) , dp[i-2] + abs(h[i] - h[i-2])) ;
	}
	cout << dp[n-1] << endl ;
	return 0;
}


Measured memory_bytes: 5188
// https://beta.atcoder.jp/contests/abc113/submissions/3539848
import java.util.*;
 
public class Main {
 
    long INF = Long.MAX_VALUE;
 
    public static void main(String[] args) {
        new Main().solve();
    }
 
    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] pc = new int[N + 1];
        long[] P = new long[M];
        long[][] Y = new long[M][3];
        Arrays.fill(pc, 0);
        for (int i = 0; i < M; i++) {
            P[i] = sc.nextLong();
            Y[i][0] = sc.nextLong();
            Y[i][1] = i;
            Y[i][2] = P[i];
        }
        Arrays.sort(Y, (a, b) -> Long.compare(a[0], b[0]));
        for (int i = 0; i < M; i++) {
            pc[(int) Y[i][2]]++;
            Y[i][0] = pc[(int) Y[i][2]];
        }
        Arrays.sort(Y, (a, b) -> Long.compare(a[1], b[1]));
        for (int i = 0; i < M; i++) {
            if (String.valueOf(P[i]).length() == 2) {
                System.out.print("0000");
            } else if (String.valueOf(P[i]).length() == 3) {
                System.out.print("000");
            } else if (String.valueOf(P[i]).length() == 4) {
                System.out.print("00");
            } else if (String.valueOf(P[i]).length() == 5) {
                System.out.print("0");
            } else if (String.valueOf(P[i]).length() == 1) {
                System.out.print("00000");
            }
            System.out.println(P[i] * 1000000 + Y[i][0]);
        }
    }
}

Measured memory_bytes: 119584
#include <stdio.h>

int search(int s[],int key,int head,int tail){
    if(head>tail)return -1;
    
    int mid=(head+tail)/2;
    
    if(s[mid]==key)return mid;
    else if(s[mid]>key)tail=mid-1;
    else if(s[mid]<key)head=mid+1;
    
    return search(s,key,head,tail);
}
int getLB(int s[],int key,int head,int tail){
    if(head>tail){
        if(tail<0)return 0;
        else return tail+1;
    }
    
    int mid=(head+tail)/2;
    
    if(s[mid]==key)return -1;
    else if(s[mid]<key)head=mid+1;
    else if(s[mid]>key){
        if(mid-1>=0&&s[mid-1]<key)return mid;
        else tail=mid-1;
    }
    return getLB(s,key,head,tail);
}
void sort(int s[],int sCnt,int key,int d){
    int i;
    for(i=sCnt;i>d;i--)s[i]=s[i-1];
    s[i]=key;
    return;
}
int insert(int s[],int sCnt,int key){
    if(search(s,key,0,sCnt-1)!=-1)return -1;
    
    int d=getLB(s,key,0,sCnt-1);
    sort(s,sCnt,key,d);
    
    return 0;
}

int main(void){
    int q;
    scanf("%d\n",&q);
    
    int s[q];
    int sCnt=0;
    
    int com,x;
    while(q--){
        scanf("%d %d\n",&com,&x);
        switch(com){
            case 0:
                //insert
                if(insert(s,sCnt,x)==0)sCnt++;
                printf("%d\n",sCnt);
                break;
            case 1:
                //find
                if(search(s,x,0,sCnt-1)==-1)printf("0\n");
                else printf("1\n");
                break;
        }
    }
    
    return 0;
}



Measured memory_bytes: 2504
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInput_int()[0];
            var A_n = GetInput_long();
            Array.Sort(A_n);
            var maxNum = A_n[A_n.Length - 1];
            bool[] dp =new bool[maxNum + 1];
            for (int i = 0; i < dp.Length; i++)
            {
                dp[i] = false;
            }
            for (int i = 0; i < A_n.Length; i++)
            {
                dp[A_n[i]] = true;
            }

            for (int i = 0; i < A_n.Length; i++)
            {
                var target=A_n[i];
                //if (dp[target] == false) continue;
                for(long j = target*2; j < dp.Length; j+=target)
                {
                    dp[j] = false;
                }
            }
            //重複しているものを削除
            for(int i = 0; i < A_n.Length-1; i++)
            {
                if (A_n[i] == A_n[i + 1]) dp[A_n[i]] = false;
            }


            var result = dp.Where(x => x == true).Count();
            Console.WriteLine(result);
        }

        #region input


        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
        
    }
}

Measured memory_bytes: 45748
N,K = map(int,input().split())

ans = 0

p = list(map(int,input().split()))

now = 0

for i in range(N):

    if i < K-1:
        now += (1+p[i])

    else:
        now += (1+p[i])

        ans = max(ans,now)

        now -= (1 + p[i-(K-1)])

print (ans / 2)


Measured memory_bytes: 71792
x,n=map(int,input().split())
a_list=list(map(int,input().split()))
current_num=0
while(True) :
  t=x+current_num not in a_list
  s=x-current_num not in a_list
  if s:
    print(x-current_num)
    break
  elif t :
    print(x+current_num)
    break
  else :
    current_num+=1
    

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

void CHECK_NUM(int, int);
void INCLUDE3(int, int, int);
void END_CHECK_NUM(int, int);

int main()
{
	int n;
	cin >> n;

	CHECK_NUM(n, 1);

	return 0;
}

void CHECK_NUM(int n, int i)
{
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		END_CHECK_NUM(n, i);
	}
	INCLUDE3(x, i,n);
}

void INCLUDE3(int x, int i,int n)
{
	if (x % 10 == 3) {
		cout << " " << i;
		END_CHECK_NUM(n, i);
	}
	x /= 10;
	if (x) {
		INCLUDE3(x, i, n);
	}
	END_CHECK_NUM(n, i);
}

void END_CHECK_NUM(int n, int i)
{
	if (++i <= n) {
		CHECK_NUM(n, i);
	}
	cout << endl;

	exit(EXIT_SUCCESS);
}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

struct union_find {
	vector<ll> v; // ??????id?????¨???????????????????????´????????¨????????????*(-1)?????¨??????
	union_find(ll n) : v(n, -1) {}
	ll find(ll x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(ll x, ll y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y];
		v[y] = x;
	}
	bool same(ll x, ll y) { return find(x) == find(y); }
	ll size(ll x) { return -v[find(x)]; }
};

using E = tuple<ll, ll, ll>; // = {cost, u, v}
vector<E> kruskal(vector<E> & es, union_find & uf, ll year, const vector<ll> & h) {
	vector<E> res;
	for (auto e : es) {
		ll cost, u, v;
		tie(cost, u, v) = e;
		if (min(h[u], h[v]) < year) continue;
		if (uf.same(u, v)) continue;
		uf.unite(u, v);
		res.push_back(e);
	}
	return res;
}


int main() {
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0); // cin??¨cout?????£????????????
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	while (true) {
		ll n, m;
		cin >> n >> m;
		if (n == 0) break;
		vector<ll> h(n); REP(i, n) cin >> h[i];
		
		vector<E> es(m); REP(i, m) cin >> get<1>(es[i]) >> get<2>(es[i]) >> get<0>(es[i]);
		REP(i, m) {
			get<1>(es[i])--;
			get<2>(es[i])--;
		}
		sort(ALL(es));

		map<ll, ll> years;
		REP(i, n) years[h[i]]++;
		
		union_find uf(n);
		ll cost = 0;
		ll cur_n = 0;
		for (auto it = years.rbegin(); it != years.rend(); ++it) {
			cur_n += it->second;
			auto v = kruskal(es, uf, it->first, h);
			if (!v.empty() && uf.size(get<1>(v[0])) == cur_n) {
				for (auto e : v) cost += get<0>(e);
			} else {
				uf = union_find(n);
				cost = 0;
			}
		}
		cout << cost << endl;
	}
	return 0;
}

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

int main()
{
    int N;

    cin >> N;

    int d[N];

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

    sort(d, d + N);

    int i_small = N / 2 - 1;
    int i_big = N / 2;

    if (d[i_small] == d[i_big])
    {
        cout << "0" << endl;
    }
    else
    {
        int Ksel;
        Ksel = d[i_big] - d[i_small];
        cout << Ksel << endl;
    }

    return 0;
    /* 
    for (int i = i_small - 1; i >= 0; i--)
    {
        if (i == i_small)
        {
            i_small = i;
        }
        else
        {
            break;
        }
    }

    for (int i = i_big + 1; i < N; i++)
    {
        if (i == i_big)
        {
            i_big = i;
        }
        else
        {
            break;
        }
    }
*/
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a,b,ans=0;
  cin >> a >> b;
  if(a>12){
    ans=b;
  }
  else if(a>5&&13>a)
    ans=b/2;
  else
    ans=0;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e15+4;
const int Nmax=2e5+1;
const int Nd=61;
ll dfs[3003][3003][4];
ll  v[3003][3003];


int main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<ll> sumA(n+1,0);// a[i-1]までの和
  map<ll,ll> m;
  m[0]++;
  rep(i,n){
    cin>>a[i];
    sumA[i+1]=sumA[i]+a[i];
    m[sumA[i+1]]++;
  }
  ll ans=0;
  for(auto mi: m){
    ll j=mi.second;
    //cout<<mi.first<<" "<<mi.second<<endl;
    ans+=j*(j-1)/2;
  }
  cout<<ans<<endl;
  return 0;


}


Measured memory_bytes: 17948
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    
    string s;
    cin>>s;
    int k;cin>>k;
    vector<string>sub;
    rep(i,s.length()){
        for(int j=1;j<=k&&i+j<=s.length();j++){
            sub.push_back(s.substr(i,j));
        }
    }

    sort(sub.begin(),sub.end());
    sub.erase(unique(sub.begin(),sub.end()),sub.end());
    cout<<sub[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
    long long N,K;
    cin>>N>>K;
    long long ABIG=LLONG_MAX/(N*K+10);
    mcf_graph<long long,long long> mcf(N*2+2);
    int s=0;
    int t=N*2+1;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int a;
            cin>>a;
            mcf.add_edge(i+1,N+1+j,1,ABIG-a);
        }
    }

    for(int i=0;i<N;i++){
        mcf.add_edge(s,i+1,K,0);
        mcf.add_edge(N+1+i,t,K,0);
    }

    mcf.add_edge(s,t,LLONG_MAX,ABIG);

    pair<long long,long long> ans=mcf.flow(s,t,N*K);
    cout<<N*K*ABIG-ans.second<<endl;
    //cout<<ans.second<<","<<ABIG<<endl;

    vector<mcf_graph<long long,long long>::edge> eg=mcf.edges();

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            bool f=false;
            for(int k=0;k<eg.size();k++){
                //cout<<eg[k].from<<","<<eg[k].to<<","<<eg[k].flow<<endl;
                if(eg[k].from==i+1&&eg[k].to==j+N+1&&eg[k].flow==1){
                    f=true;
                }
            }
            if(f) cout<<"X";
            else cout<<".";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
signed main() {
	cin >> n;
	int ma = -Inf, mi = Inf;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ma = max(ma, a[i]);
		mi = min(mi, a[i]);
	}
	int k, l;
	sort(a, a + n);
	//2人以上存在している色はk個ある
	//一人しか存在していない色はl個ある
	if (ma == mi && ma == n - 1) {
		cout << "Yes\n";
		return 0;
	}
	if (ma - mi > 1) {
		cout << "No\n";
		return 0;
	}
	else if (ma == mi) {
		k = ma;
		l = 0;
		if (k * 2 <= n) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
	else {
		int r = lower_bound(a, a + n, ma) - a;
		k = ma - r;
		l = r;
		//k色の2人以上
		//l人の独りぼっち
		int t = n - r;
		//2人以上の帽子をかぶっている人たち=t
		if (k * 2 <= t && l < ma) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> a >> b;

    if(a==1) a+=13;
    if(b==1) b+=13;

    if(a>b) cout <<  "Alice";
    if(a<b) cout <<  "Bob";
    if(a==b) cout <<  "Draw";
    return 0;
}

Measured memory_bytes: 256
D,G=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(D)]
r=1000
from itertools import product
for X in product(range(2),repeat=D):
    g,a=0,0
    for i,x in enumerate(X):
        if x:
            g+=pc[i][1]+pc[i][0]*(i+1)*100
            a+=pc[i][0]
    for i in range(D-1,-1,-1):
        if X[i]==1:
            continue
        if g>=G:
            break
        n=min(pc[i][0]-1,-((g-G)//((i+1)*100)))
        a+=n
        g+=n*(i+1)*100
    if g>=G:
        r=min(r,a)
print(r)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A ,B;
  cin >> A >> B;
  if(A == 1 && B != 1)
    cout << "Alice" << endl;
  if(B == 1 && A != 1)
    cout << "Bob" << endl;
  if(A == B)
     cout << "Draw" << endl;
  if(A > B && B != 1)
    cout << "Alice" << endl;
  if(A < B && A != 1)
    cout << "Bob" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1e9 + 7;
const int Maxn = 1e3 + 10;
const ll Inf = 1e16;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}
ll bin_pow(ll b, ll p){
	ll res = 1;
	for(ll pw = b, j = 1; j <= p; j += j, pw = mul(pw, pw)) if(p & j) res = mul(res, pw);
	return res;
}
ll f[Maxn], iv[Maxn];

ll nCr(ll n, ll r){
	if( (r < 0) || (n < r) || (n < 0)) return 0;
	return mul(f[n], mul(iv[r], iv[n - r]));
}

ll dp[Maxn][Maxn];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	f[0] = 1;
	for(int i = 1; i < Maxn; i++) f[i] = mul(f[i - 1], i);	
	for(int i = 0; i < Maxn; i++) iv[i] = bin_pow(f[i], Mod - 2);
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	dp[0][0] = 1;
	ll wy, wy2;
	for(int i = 1; i <= b; i++){
		for(int j = 0; j <= n; j++){
			wy = 1;
			for(int Fi = 0; j + Fi * i <= n; Fi ++){
				if((Fi == 0) || ((c <= Fi) && (Fi <= d) && (a <= i) && (i <= b)) ){
					wy2 = mul(wy, iv[Fi]);
					dp[i][j + Fi * i] += mul(dp[i - 1][j], wy2);
					dp[i][j + Fi * i] %= Mod;
				}
				
				wy *= nCr(n - j - (Fi * i), i);
				wy %= Mod;
			}
		}
	}
	cout << dp[b][n];
	return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }

int n, m, r = MOD, res;
vector<pair<int,int> > a;



int main(int argc, char const *argv[]) {
  cin >> n >> m;
	a.resize(m);
	rep(i,m) cin >> a[i].first >> a[i].second;
	sort(a.rbegin(), a.rend());
	rep(i,m) if (a[i].second<=r) res++, r = a[i].first;
	cout << res << endl;
  return 0;
}


Measured memory_bytes: 1152
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

def dfs(index, value, cost):
	if index == n:
		return value - cost 
	else:
		res0 = dfs(index + 1, value, cost)
		res1 = dfs(index + 1, value + v[index], cost + c[index])
		return max(res0, res1)

print(dfs(0,0,0))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
 
int main() {
 
	int n;
	cin >> n;
	
	int ord[n];
	for (int i=0; i<n; i++) {
		cin >> ord[i];
	}
	
	int sat[n];
	for (int i=0; i<n; i++) {
		cin >> sat[i];
	}
	
	int ext[n-1];
	for (int i=0; i<n-1; i++) {
		cin >> ext[i];
	}
	
	int gain = 0;
	for (int i=0; i<n; i++) {
		gain += sat[i];
		if (i == 0) continue;
		int ths = ord[i]-1;
		int las = ord[i-1]-1;
		if (las + 1 == ths) gain += ext[las];
	}
	cout << gain << endl;
 
}


Measured memory_bytes: 256
import math
n, p = map(int, input().split())
if n==1:
	print(p)
else:
	ans = 1
	limit = math.ceil(p**(1/n))
	while(limit>1):
		cnt = 0
		a = p
		while(a!=0):
			if a%limit == 0:
				cnt += 1
				a = a // limit
			else:
				break
		if cnt >= n:
			ans = limit
			break
		limit -= 1
	print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main(){
int a;
scanf("%d", &a);
int b;
scanf("%d", &b);
 
if(a != 3 && b != 3) printf("3\n");
if(a != 1 && b != 1) printf("1\n");
if(a != 2 && b != 2) printf("2\n");
 
return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (12)

bool plus[MAX_N];
int num[MAX_N];
int N;

ll dp[MAX_N][MAX_N];

ll calc( int f, int s ) {
    ll ret = 0;

    for ( int i = f; i <= s; i++ ) {
	ret *= 10;
	ret += num[i];
    }

    return ret;
}

ll solve( int f, int s ) {
    if ( s < f ) return 0;
    if ( dp[f][s] != -1 ) return dp[f][s];
    ll ret = 0;
    for ( int k = f; k <= s; k++ ) {
	ll tmp1 = solve(f, k-1);
	ll tmp2 = calc(k, s);
	if ( k - 1 - f > 0 ) tmp2 <<= (k-1-f);
	ret += tmp1 + tmp2;
    }
    
    return dp[f][s] = ret;
}

int main()
{
    string s;
    cin >> s;

    for ( int i = 0; i < s.size(); i++ ) {
	num[i] = s[i] - '0';
    }

    for ( int i = 0; i < s.size(); i++ ) {
	for ( int j = 0; j < s.size(); j++ ) {
	    dp[i][j] = -1;
	}
    }

    ll ans = solve(0, s.size() - 1);

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

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a[1000],b[1000],c[1000];
    int n=0;
    cin >> n;
    for (int i = 0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
   for(int i= 0;i<n;i++){
    if (a[i]*a[i] == b[i]*b[i] + c[i]*c[i] | b[i]*b[i] == a[i]*a[i] + c[i]*c[i] |c[i]*c[i] == a[i]*a[i] + b[i]*b[i]){
        cout << "YES" << endl;

    }
    else{
        cout << "NO" << endl;
    }
   }
    return 0;

}


Measured memory_bytes: 3072
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		
		long ans = 0;
		for (int k = 1; k <= N; k++) {
			ans += k * sum(N / k);
		}
		
		System.out.println(ans);
	}
	
	public static long sum(int N) {
		return (long) N * (N + 1) / 2;
	}
}


Measured memory_bytes: 35804
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;i++)
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> PII;

int dp[(1<<16)+10];
bool calc[(1<< 16) +10];
vector<vector<int>> edge;
const int INF = 1e9;
   int n,m,k;
map<int,int> idx_to_node;
map<int,int> node_to_idx;
map<int,bool> memD;

void dijkstra(){
  int dist[1<<m];
  rep(i,1<<m) dist[i] = INF;
  dist[(1<<m) - 1 ] = 0;
  priority_queue< PII, vector<PII>, greater<PII>> que;
  que.push({0,(1<<m)-1});
  while(que.empty() == false){
    PII p = que.top(); que.pop();
    int cdist = p.first;
    int cbit = p.second;
    if(dist[cbit] < cdist) continue;
    rep(i,k){
        int newBit = 0;
        rep(j,m){
            if((cbit >> j & 1) && memD[ edge[ idx_to_node[j] ][ i ] ] ) newBit |= 1<< node_to_idx[edge[idx_to_node[j]][i]];
        }
        if(dist[newBit] > cdist + 1){
          dist[newBit] = cdist + 1;
          que.push({cdist+1,newBit});
        }
    }

  }
  cout << dist[0] << endl;

}


int main(){
    cin >> n >> m >> k;

    rep(i,m){
        int x;
        cin >> x;
        x--;
        idx_to_node[i] = x;
        node_to_idx[x] = i;
        memD[x] = true;
    }
    edge.resize(n);
    rep(i,n){
      rep(j,k){
          int v;
          cin >> v;
          v--;
          edge[i].push_back(v);
      }
    }
    dijkstra();

    return 0;
}



Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll n,k,h[100005],dp[100005];
int main(){
   cin>>n>>k;
   for(ll i=1;i<=n;i++){
      cin>>h[i];
      dp[i]=1000000000;
   }
   dp[1]=0;
   for(ll i=1;i<=n;i++){
      for(ll j=1;j<=k;j++){
         if(i+j>n) continue;
         dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      }
   }
   cout<<dp[n];
   return 0;
}

Measured memory_bytes: 5084
import java.util.Scanner;

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

        int count1 = 0;
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) != '1') {
                break;
            }
            count1++;
        }
        if(k > count1) {
            System.out.println(s.charAt(count1));
        } else {
            System.out.println("1");
        }
    }
}


Measured memory_bytes: 35944
s = input()
ok = True
if s[0] != 'A': ok = False
c = 0
# print(s)
for si in s[2:-1]:
    # print('si',si)
    if 'C' == si:
        c += 1
if c != 1: ok = False

for si in s[1:2]+s[-1]:
    # print('si2',si,si.lower())
    if si != si.lower(): ok = False

print('AC' if ok else 'WA')


Measured memory_bytes: 3060
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def run():
    N, H, *AB_ = map(int, read().split())
    AB = []
    for i in range(N):
        a,b = AB_[2*i], AB_[2*i+1]
        AB.append((a, 0, i))
        AB.append((b, 1, i))

    AB = sorted(AB, reverse=True)

    count = 0
    for val, a_b, idx in AB:
        if a_b == 0:
            count += math.ceil(H / val)
            break
        else:
            count += 1
            H -= val
        if H <= 0:
            break
    print(count)

if __name__ == "__main__":
    run()

Measured memory_bytes: 37112
import numpy as np

N,M,C = map(int,input().split())
B = np.array(list(map(int,input().split())))

cnt=0
for i in range(N):
    A = np.array(list(map(int,input().split())))
    # print(np.dot(A, B)+C > 0)
    cnt += int(np.dot(A, B)+C > 0)


print(cnt)

Measured memory_bytes: 21684
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	int x;
	cin >> a >> b >> c >> x;
	int sum = 0;
	int i,j,k;
	for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    sum++;
                }
            }
        }
    }
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

char A[55], B[55];
int n;
int main(){
	cin >> n;
	for(int i = 0; i<n; i++) cin >> A[i];
	for(int i = 0; i<n; i++) cin >> B[i];
	vector<int> v;
	for(int i = 0; i<n; ){
		if(A[i] == B[i]){
			v.push_back(0);
			i++;
		}else{
			v.push_back(1);
			i+=2;
		}
	}
//	for(auto i : v) printf("%d", i); printf("\n");
	long long ans = (v[0] == 0 ? 3 : 6);
	for(int i = 1; i<v.size(); i++){
		if(v[i] == 0){ // vertical
			if(v[i-1] == 0) ans *= 2; //vv: 3
			else ans *= 1; // hv: 1
		}else{ // horizontal
			if(v[i-1] == 0) ans *= 2; // vh: 2
			else ans *= 3; // hh: 3
		}
		ans %= mod;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
LL max(LL a, LL b)
{
  if (a<b) {
    a = b;
  }
  return a;
}

void swap(int *a, int *b)
{
  int temp;
  temp = *a;*a = *b;*b = temp;
}
//-------------------------------------------------------
int main(void)
{
  int a, b, c, d;
  int takahashi;
  int aoki;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  while (1) {
    c-=b;
    if (c <= 0) {
      printf("Yes\n");
      break;
    }
    a-=d;
    if (a <= 0) {
      printf("No\n");
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1664
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

n_list = [i + 1 for i in range(N)]
p_list = list(itertools.permutations(n_list))

ans = abs(p_list.index(P) - p_list.index(Q))

print(ans)


Measured memory_bytes: 8052
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
int A[12][12], row_price[12], alg_und[12];
int N, M, X;
int min_price = 1e9;
bitset<12> is_done_alg;


void solve(const int &cur_row, const int &cur_price)
{
    if (is_done_alg.count() == M)
    {
        min_price = min(min_price, cur_price);
        return;
    }
    if (cur_row == N)
    {
        return;
    }

    for (int j = 0; j < M; ++j)
    {
        alg_und[j] += A[cur_row][j];
        if (alg_und[j] >= X)
        {
            is_done_alg[j] = true;
        }
    }

    solve(cur_row + 1, cur_price + row_price[cur_row]);

    for (int j = 0; j < M; ++j)
    {
        alg_und[j] -= A[cur_row][j];
        if (alg_und[j] < X)
        {
            is_done_alg[j] = false;
        }
    }

    solve(cur_row + 1, cur_price);
}


int main()
{
    cin.sync_with_stdio(0);

    cin >> N >> M >> X;

    for (int i = 0; i < N; ++i)
    {
        cin >> row_price[i];

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

    solve(0, 0);

    cout << (min_price == 1e9 ? -1 : min_price);
}


Measured memory_bytes: 3632
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)

#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;


const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    //fast
    int n;
    scanf("%d",&n);
    int a[n+4];
    vector<int>alive;
    f(i,1,n)scanf("%d",&a[i]),alive.pb(i);
    int two=(1<<30);
    int ses=0;
    int vis[n+4];clr(vis);
    for(int j=30;j>=1;j--)
    {

         unordered_map<int,vector<int>>cnt;
         for(auto i:alive)
         {
             if(vis[i]==1)continue;
             if(cnt[a[i]].size())
             {
                 int id=cnt[a[i]].back();
                 cnt[a[i]].pop_back();
                 vis[id]=1;
                 vis[i]=1;
                 ses++;
                // cout<<i<<" "<<id<<endl;
                 continue;
             }
             if(two<a[i])continue;
             int val=two-a[i];
             cnt[val].pb(i);
         }
         two=two/2;
         if(two<=1)break;
         vector<int>tmp;
         for(auto i:alive)
         {
             if(vis[i]==0)
             {
                 tmp.pb(i);
             }
         }
         alive=tmp;

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

}





































Measured memory_bytes: 33476
#!/usr/bin/env python3
from itertools import product
import sys
 
 
def solve(AA: int, BB: int, CC: int, XX: int):
    print(sum(
        1
        for a, b, c in product(range(AA + 1), range(BB + 1), range(CC + 1))
        if a * 500 + b * 100 + c * 50 == XX
    ))
 
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(A, B, C, X)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
# input
A, B, K = map(int, input().split())

# check
if A + K > B:
    res = list(range(A, B + 1))
else:
    res = set(list(range(A, A + K)) + list(range(B, B - K, -1)))
    
for n in sorted(list(res)):
    print(n)

Measured memory_bytes: 8992
#include<cstdio>
#include<algorithm>
int n,m,a[400010];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i),a[i]*=2;
	scanf("%d",&m);
	for(int i=0;i<m;i++)scanf("%d",a+n+i),a[n+i]=a[n+i]*2+1;
	std::sort(a,a+n+m);
	for(int i=0,j,k;i<n+m;i=k){
		for(j=i;j<n+m&&a[i]/2==a[j]/2&&a[j]%2==0;j++);
		for(k=j;k<n+m&&a[i]/2==a[k]/2&&a[k]%2==1;k++);
		if(k-j>j-i){puts("NO");return 0;}
	}
	puts("YES");
}

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

int main(){
  int a,b;
  cin >> a >> b;
  // aをb回 s_a 
  string s_a,s_b;
  string stra = to_string(a);
  string strb = to_string(b);
  for(int i=0;i<b;i++){
    s_a += stra;
  }
  for(int i=0;i<a;i++){
    s_b += strb;
  }
  string ans;
  ans = min(s_a,s_b);
  cout << ans << endl;
}

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

p2 = sorted(p)

cnt = 0
for i in range(N):
    if p[i] != p2[i]:
        cnt += 1
    if cnt == 3:
        break

if cnt == 3:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            double N = double.Parse(Console.ReadLine());
            double a = 1;
            
            while(true)
            {
                if(Math.Pow(a+1,2) > N)
                {
                    break;
                }
                else
                {
                    a++;
                }
            }
            Console.WriteLine(Math.Pow(a,2));
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int a[m];
    int sum=0;
    for(int i=0;i<m;i++){
      cin>>a[i];
      sum+=a[i]*b[i];
    }
    if(sum+c>0) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

typedef long long ll;
const int N = 200005;
const ll MOD = 1e9+7;

int n,m;
vector<int> adj[N];


bool vstd[N];
void dfs(int x){
	vstd[x] = true;
	for(int y:adj[x]){
		if(!vstd[y])dfs(y);
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int x;
			cin>>x;
			adj[i].push_back(x+n);
			adj[x+n].push_back(i);
		}
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		if(!vstd[i]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES";
	
	return 0;
}


Measured memory_bytes: 11960
#include<stdio.h>

int main() {
    int a,b;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    if (c == '-') {
        printf("%d\n", a-b);
    }
    else {
        printf("%d\n", a+b);
    }
    return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>

int main(){
    int H, W;
    int i, j;
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0)break;

        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                printf("#%s", (j == W - 1) ? "\n" : "");
            }
            if(i == H - 1)printf("\n");
        }
    }
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  int64_t ans=a*c;
  ans=max(ans, b*d);
  ans=max(ans, b*c);
  ans=max(ans, a*d);
  cout<<ans<<endl;
  
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
bool cmp1 (pii a, pii b) {
  return (a.fi > b.fi);
}
bool cmp2 (pii a, pii b) {
  return a.se + b.fi > b.se + a.fi;
}
vector<pii> t1, t2;
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int h = 0;
  FOR(i, 1, n) {
    string S;
    cin >> S;
    int s = S.length();
    int v = 0, mn = 0;
    FOR(j, 0, s - 1) {
      if (S[j] == '(') ++v;
      else --v;
      mn = min(mn, v);
    }
    if (v >= 0) {
      if (mn == 0) h += v;
      else t1.pb({mn, v});
    } else {
      t2.pb({mn, v});
    }
  }
  sort(t1.begin(), t1.end(), cmp1);
  sort(t2.begin(), t2.end(), cmp2);
  t1.insert(t1.end(), t2.begin(), t2.end());
  for (auto u : t1) {
    if (h + u.fi < 0) {
      printf("No\n"); return 0;
    }
    h += u.se;
  }
  if (h == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 11036
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 110
int vis[N],a[N],b[N],t[N];
int m,s;
void dfs(int x,int y)
{
    if(y>=75)
    {
        if(y==75)
            s++;
        return;
    }
    int i,j,k;
    for(i=x;i<m;i++)
    {
        for(j=1;j<=t[i];j++)
            dfs(i+1,y*(j+1));
    }
}
int main()
{
    int i,j,k,tot,n;
    tot=0;
    memset(vis,0,sizeof(vis));
    for(i=2;i<=100;i++)
    {
        if(vis[i]==0)
            a[tot++]=i;
        for(j=0;j<i&&i*a[j]<=100;j++)
        {
            vis[i*a[j]]=1;
            if(i%a[j]==0)
                break;
        }
    }
    scanf("%d",&n);
    for(i=2;i<=n;i++)
    {
        k=i;
        for(j=0;j<tot;j++)
        if(k%a[j]==0)
        {
            while(k%a[j]==0)
            {
                b[j]++;
                k=k/a[j];
            }
        }
    }
    m=0;
    for(i=0;i<tot;i++)
    if(b[i])
        t[m++]=b[i];
    s=0;
    dfs(0,1);
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int64

()
|> readIntArray
|> fun [| a; b; c; d |] ->
    if a >= 0L && c >= 0L then b * d
    else if b <= 0L && d <= 0L then a * c
    else if b <= 0L && c >= 0L then b * c
    else if a >= 0L && d <= 0L then a * d
    else if a * c > b * d then a * c
    else b * d
|> printfn "%d"


Measured memory_bytes: 30020
unittest
{
	assert( [ "4", "2 4 4 3" ].parse.expand.solve == "4\n3\n3\n4" );
	assert( [ "2", "1 2" ].parse.expand.solve == "2\n1" );
	assert( [ "6", "5 5 4 4 3 3" ].parse.expand.solve == "4\n4\n4\n4\n4\n4" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( T )( T input )
if( isInputRange!T && is( ElementType!T == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	
	return tuple( xs );
}

auto solve( long[] xs )
{
	auto rs = new long[ xs.length ];
	
	auto xs_s = xs.dup.sort();
	auto cl = xs_s[ ( xs_s.length - 1 ) / 2 ];
	auto cr = xs_s[ ( xs_s.length + 1 ) / 2 ];
	
	foreach( i, x; xs )
	{
		if( x <= cl ) rs[ i ] = cr;
		else          rs[ i ] = cl;
	}
	
	return rs.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 26544