akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
// use proconio::marker::Chars;

fn main() {
	input! {
		x: isize,
	}
	let en_500 = x / 500;
	let en_5 = x % 500 / 5;
	println!("{}", en_500 * 1000 + en_5 * 5);
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define iceil(n, x) ((n + x - 1) / x)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 100005
#define M 105
using namespace std;

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;

//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
			 tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.


main()
{	
	#ifdef CP
		freopen("/home/tarun/Desktop/input.txt", "r", stdin);
		//freopen("/home/tarun/Desktop/output.txt", "w", stdout);
	#endif
	sync;
	clock_t clk = clock();
	cerr << "I will return...\n";
	
	ll n; cin >> n;
	vector<bool> ans;
	while(n) {
		ans.pb(abs(n) & 1);
		n = floor(n / 2.0);
		n = -n;
		//db(n);
	}

	reverse(all(ans));
	if(!ans.sz) cout << 0;
	else for(bool b : ans) cout << b;
	cout << '\n';

	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}

//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment






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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    ull n;
    cin >> n;
    for(int i=ceil(sqrt(n)); i>=0; i--){
        if(!(n%i)){
            cout << i+n/i-2 << endl;
            break;
        }
    }
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
d = list(map(str, input().split()))

value = n

while(1):
    value_list = [s for s in str(value)]
    flag = 0

    for i in d:
        if i in value_list:
            flag = 1
            break

    if flag:
        value += 1
    else:
        break

print(value)



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

class ABC_142_C
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        List<Pair> list = new List<Pair>();
        for (int i = 0; i < N; i++)
        {
            int order = int.Parse(input[i]);
            Pair p = new Pair(i+1, order);
            list.Add(p);
        }

        list.Sort((a, b) => a.Order - b.Order);

        for (int i = 0; i < N; i++)
        {
            if(i!=0) Console.Write(" ");
            Console.Write(list[i].ID);
        }
    }

    class Pair
    {
        public Pair(int id, int order)
        {
            ID = id;
            Order = order;
        }
        public int ID;
        public int Order;
    }
}


Measured memory_bytes: 28504
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
      
      	if(a + b + c >= 22){
			System.out.println("bust");
        }else{
			System.out.println("win");
        }
	}
}

Measured memory_bytes: 21716
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s;
	cin >> s;
	bool ch = false;
	REP(i, 3) if(s[i] == '7') ch = true;
	if (ch) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	
	int a[n];
	int b[n];
	int c[n-1];
	
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%d",&b[i]);
	}
	for(int i=0; i<n-1; i++){
		scanf("%d",&c[i]);
	}
	
	int manzoku=0;

	
	for(int i=0; i<n; i++){
		manzoku += b[a[i]-1]; 
		if(i>0&&a[i]==a[i-1]+1){
			manzoku += c[a[i-1]-1]; 
		}
	}
	
	printf("%d",manzoku);
}

Measured memory_bytes: 128
fun main(arg: Array<String>) {
    val (N, Z, W) = listOfInt()
    val A = listOfInt()
    val ans =
        if (N == 1) Math.abs(A[0] - W)
        else Math.max(Math.abs(A[N - 1] - W), Math.abs(A[N - 2] - A[N - 1]))
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 38900
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();
        sc.close();
        for (int i = 0; i < 10; i++) {
            x = r * x - D;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21716
import itertools

n,k=map(int,input().split())
a=list(map(int,input().split()))

amin=10**9*20
for i in itertools.product([0,1], repeat=n):
    if sum(i)==k:
        hs=a[0]
        acnt=0
        h=[]
        for j in range(n):
            if i[j]==1 and j>0:
                if hs>=a[j]:
                    acnt+=hs-a[j]+1
                    hs=hs+1
            if hs<a[j]:
                hs=a[j]
            h.append(hs)
#        print(i,acnt,h)
        amin=min(amin,acnt)
        
print(amin)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    ios::sync_with_stdio(false);
    int n,k,ans=1;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        ans+=min(ans,k);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
 vector<string>xy;
  xy.push_back("A");
  xy.push_back("B");
  xy.push_back("C");
  xy.push_back("D");
  xy.push_back("E");
  xy.push_back("F");
string X,Y;
cin >> X >> Y;
int Xs,Ys;
for(int i=0;i<6;i++){
if(X == xy.at(i)) Xs = i;
if(Y == xy.at(i)) Ys = i;
}
if(Xs == Ys) cout << "=" << endl;
if(Xs > Ys) cout << ">" << endl;
if(Xs < Ys) cout << "<" << endl;
}


Measured memory_bytes: 256
import sys

#+++++
		
def main():
	_ = int(input())
	hs = list(map(int, input().split()))
	
	max_move=0
	cc_move=0
	ch=-1
	for h in hs:
		if ch < h:
			max_move=max(max_move,cc_move)
			cc_move=0
			ch=h
		else:
			cc_move+=1
			ch=h
	else:
		max_move=max(max_move,cc_move)
	
	print(max_move)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int& i: a) cin >> i;
    sort(a.begin(), a.end());
    cout << a.back() - a.front();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    int w;
    cin >> s >> w;
    for (int i = 0; i < s.size(); i += w)
        cout << s[i];
    cout << endl;
}

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

int main() {
	int n,k,q;cin>>n>>k>>q;
	vector<int> a(q),c(n,0);
	for(int i=0;i<q;i++){
		cin>>a[i];
		c[a[i]-1]++;
	}
	for(int i=0;i<n;i++){
		if(q-k<c[i]){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1408
#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()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  ll N, M;
  cin >> N >> M;
  M = (M / 2) * 2;

  ll res = 0;
  if(N >= M / 2) {
    res = M / 2;
  }else{
    res = N;
    res += (M - 2 * N) / 4;
  }
  cout << res << endl;
  return 0;
}



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

#define ll          long long
#define int            ll
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define	endl		'\n' 
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define vs          vector<string>
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>

int solve()
{
	int n,w;
	cin>>n>>w;
	vii arr(n);
	rep(i,0,n)
	{
		int a,b;
		cin>>a>>b;
		arr[i]=mp(a,b);
	}
	sort(all(arr));
	int weight[100001];
	rep(i,0,100001)
	{
		weight[i]=1000000000000;
	}
	weight[0]=0;
	int sum=0;
	rep(j,0,n)
	{
		sum+=arr[j].S;
		for(int i=sum;i>=arr[j].S;i--)
		{
			weight[i]=min(weight[i],weight[i-arr[j].S]+arr[j].F);
		}
	}
	for(int i=100000;i>=0;i--)
	{
		if(weight[i]<=w)
		{
			cout<<i;
			break;
		}
	}
    return 0;
}
signed main()
{
    FAST
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    int t=1;
    //cin>>t;
    while(t)
    {
        solve();
        t--;
    }
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 4556
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 5000
#define MOD int(1e9+7)
#define LL long long
#define INF 0x3f3f3f3f
char str[MAXN+5];
LL dp[MAXN+5][MAXN+5];
LL QuPow(LL x,LL y){
	LL ret=1;
	while(y){
		if(y&1) ret=ret*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return ret;
}
int main(){//前i次操作后长度为字符长度为j的方案数
	LL ans=0;
	int n=read(),len;
	scanf("%s",str);
	len=strlen(str);
	dp[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++){
			dp[i+1][j+1]=(dp[i+1][j+1]+2*dp[i][j])%MOD;
			dp[i+1][max(j-1,0)]=(dp[i+1][max(j-1,0)]+dp[i][j])%MOD;
		}
	printf("%lld\n",QuPow(QuPow(2,len)%MOD,MOD-2)*dp[n][len]%MOD);
    return 0;
}

Measured memory_bytes: 194048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define MOD ((int)(1e9+7))
const int z=200001;

vl fact_mod(z,1), fact_invmod(z);

ll modpow(ll a, ll n){
	if(n==1)return a;
	ll half=modpow(a,n/2);
	return (n%2?modpow(a,n-1)*a:half*half)%MOD;
}

void calc(){
	range(i,1,z) fact_mod[i]=fact_mod[i-1]*i%MOD;
	fact_invmod[z-1]=modpow(fact_mod[z-1],MOD-2);
	for(int i=z-2;i>=0;i--) fact_invmod[i]=fact_invmod[i+1]*(i+1)%MOD;
}

ll nCr_mod(int n,int r){
	return fact_mod[n] * fact_invmod[r]%MOD * fact_invmod[n-r]%MOD;
}

int main(){
	calc();
	int h,w,a,b,n,r;
	cin>>h>>w>>a>>b;
	ll ans=0;
	rep(i,h-a){
		r=b-1;
		n=i+r;
		ll nCr_l=nCr_mod(n,r);
		r=w-b-1;
		n=h-i-1+r;
		ll nCr_r=nCr_mod(n,r);
		ans+=nCr_l*nCr_r%MOD;
	}
	cout<<ans%MOD<<endl;

	return 0;
}


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

int main() {
  int n;
  cin>>n;
  ll Sn=0;
  rep(i,n){
    Sn+=i;
  }
  cout<<Sn<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#define LL long long

using namespace std;

LL n,m;

int main()
{
    scanf("%lld%lld",&n,&m);
    if (n==1 || m==1)
    {
        printf("1\n");
        return 0;
    }
    printf("%lld\n",(n*m)%2 ? n*m/2+1:n*m/2);
    return 0;
}


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

int main() {
	while (1) {
		char grade;
		int m, f, r;
		(void)scanf("%d %d %d", &m, &r, &f);
		if (m == -1 && r == -1 && f == -1) break;
		if (m == -1 || r == -1) grade = 'F';
		else if(m+r >= 80) grade = 'A';
		else if (m + r >= 65) grade = 'B';
		else if (m + r >= 50) grade = 'C';
		else if (m + r >= 30) grade = f >= 50 ? 'C': 'D';
		else grade = 'F';
		printf("%c\n", grade);
	}
	return 0;
}


Measured memory_bytes: 2592
import sys
from pprint import pprint
import math

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

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


# main
n, k = map(int, sys.stdin.readline().strip().split(" "))
a = list(map(int, sys.stdin.readline().strip().split(" ")))
a.sort()

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

min_sum = 0
max_sum = 0
for i in range(n):
	min_sum += a[i] * cmb(n-1-i, k-1, mod)
	min_sum %= mod
	max_sum += a[n-1-i] * cmb(n-1-i, k-1, mod)
	max_sum %= mod

print((max_sum - min_sum) % mod)

Measured memory_bytes: 76896
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'

int mod = 998244353;

int pw(int a, int k) {
    if (k == 0) return 1;
    if (k % 2) return ((long long) pw(a, k - 1) * a) % mod;
    int t = pw(a, k / 2);
    return ((long long) t * t) % mod;
}

int rv(int a) {
    return pw(a, mod - 2);
}

int ml(int a, int b) {
    return ((long long)a * b) % mod;
}

int ml(int a, int b, int c) {
    return ml(ml(a, b), c);
}

int dv(int a, int b) {
    return ml(a, rv(b));
}

int sm(int a, int b) {
    return (a + b) % mod;
}

int df(int a, int b) {
    return ((long long)a + mod - b) % mod;
}

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

string yy = "Yes\n";
string nn = "No\n";
string imp = "IMPOSSIBLE\n";

int maxn = 2e5 + 5;
int n;

vector<vector<int>> t(2, vector<int>(4 * maxn, maxn));
vector<vector<int>> add(2, vector<int>(4 * maxn, maxn));

void build(int tp, int v, int l, int r) {
    add[tp][v] = n;
    t[tp][v] = n;
    if (l + 1 == r) {
        return;
    }
    int m = (l + r) / 2;
    build(tp, 2 * v + 1, l, m);
    build(tp, 2 * v + 2, m, r);
    return;
}

void push(int tp, int v) {
    add[tp][2 * v + 1] = min(add[tp][2 * v + 1], add[tp][v]);
    add[tp][2 * v + 2] = min(add[tp][2 * v + 2], add[tp][v]);
    add[tp][v] = n;
    return;
}

int get_val(int tp, int v) {
    return min(t[tp][v], add[tp][v]);
}

int get(int tp, int v, int l, int r, int pos) {
    if (pos >= r || pos < l) return n;
    if (l + 1 == r) {
        return get_val(tp, v);
    }
    push(tp, v);
    int m = (l + r) / 2;
    int ans = min(get(tp, 2 * v + 1, l, m, pos), get(tp, 2 * v + 2, m, r, pos));
    t[tp][v] = min(get_val(tp, 2 * v + 1), get_val(tp, 2 * v + 2));
    return ans;
}

void upd(int tp, int v, int l, int r, int ll, int rr, int val) {
    if (ll >= r || rr <= l) return;
    if (ll <= l && r <= rr) {
        add[tp][v] = min(add[tp][v], val);
        return;
    }
    push(tp, v);
    int m = (l + r) / 2;
    upd(tp, 2 * v + 1, l, m, ll, rr, val);
    upd(tp, 2 * v + 2, m, r, ll, rr, val);
    t[tp][v] = min(get_val(tp, 2 * v + 1), get_val(tp, 2 * v + 2));
    return;

}



int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q; cin >> n >> q;
    build(0, 0, 0, n);
    build(1, 0, 0, n);
    int ans = (n - 2) * (n - 2);
    while (q--){
        int t, x; cin >> t >> x;
        x--;
        t--;
        int rght = get((t + 1) % 2, 0, 0, n, x);
        ans -= rght - 2;
        upd(t, 0, 0, n, 0, rght, x + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34440
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    int total = k * pow(k - 1, n - 1);
    cout << total << endl;

    return 0;
}

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

int n,m,flag[8][28],ans=0;

int find(int p,int aleady[],int count)
{
	int i,num=0;
	if(count ==n)return 1;
    else {
    	aleady[p] = 1;
	    for (i = 0; i < n; ++i)
	    {
    		if(flag[p][i] == 1 && aleady[i] == 0)
    		{
    		    num = num + find(i,aleady,count+1);
    		}

	    }
	    aleady[p]=0;
        return num;
    }
}

int main()
{
	int a,b,i,j,ans,aleady[8],count;

	scanf("%d%d",&n,&m);
    ans = 0;
    for (i = 0; i < n; ++i)
    {
    	for (j = 0; j < m; ++j)
	    {
	    	flag[i][j] = 0;
	    }
	    aleady[i] = 0;
    }
    for (i = 0; i < m; ++i)
    {
    	scanf("%d%d",&a,&b);
        flag[a-1][b-1] = 1;
        flag[b-1][a-1] = 1;
    }



    aleady[0] = 1 ;

    printf("%d\n", find(0,aleady,1));
	return 0;
}

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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define int long long
#define ld long double
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mod 1000000007

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n, m;

int dfs(const vector<vector<int> > &g, vector<int> &dp, vector<bool> &vis, int ver){
  vis[ver] = true;
  if(g[ver].size()==0){
    dp[ver] = 0;
    return dp[ver];
  }
  if(dp[ver] != -1) return dp[ver];
  dp[ver] = 0;
  for(auto x : g[ver])
  dp[ver] = max(dp[ver], 1+ dfs(g,dp,vis,x));
  return dp[ver];
}
int longestPath(const vector<vector<int> > &g){
  vector<int> dp(n,-1);
  vector<bool> vis(n,false);
  for(int i=0;i<n;i++)
  if(!vis[i])
    int store = dfs(g,dp,vis,i);
  return *max_element(all(dp));
}
int32_t main(){
    cin>>n>>m;
  vector<vector<int> >g(n);
  fr(i,0,m){
    int u,v;  cin>>u>>v;
    u--;v--;
    g[u].pb(v);
  }
  cout<<longestPath(g)<<endl;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  string s;
  cin >> s;
  for (char c = 'a'; c <= 'z'; c++) {
    int cnt = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == c) {
        cnt++;
      }
    }
    if (cnt == 0) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


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

int main()
{
    int N;
    scanf("%d", &N);
    while(N >= 1000){
        N = N - 1000;
    }
    if(N == 0){
        printf("0");
    } else {
        cout << 1000 - N;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



int n, k, a[105], ans;
set <int> A, B;

int getLeft(int i)
{
    if (i < 1) return 0;
    int sum = 0, global = 0;
    A.clear();

    for (int t1 = 1; t1 <= i; ++t1)
    {
        A.insert(a[t1]);
        sum += a[t1];
        int toRemove = i-t1, cnt = 0, removed = 0;

        for (ci &it: A)
        {
            if (it < 0 && cnt+1 <= toRemove)
            {
                removed += it;
                cnt += 1;
            }
            else break;
        }

        global = max(global, sum-removed);
    }

    return global;
}

int getRight(int i)
{
    if (i < 1) return 0;
    int sum = 0, global = 0;
    B.clear();

    for (int t1 = n; t1 >= n-i+1; --t1)
    {
        B.insert(a[t1]);
        sum += a[t1];
        int mirror = n-t1+1;
        int toRemove = i-mirror, cnt = 0, removed = 0;

        for (ci &it: B)
        {
            if (it < 0 && cnt+1 <= toRemove)
            {
                removed += it;
                cnt += 1;
            }
            else break;
        }

        global = max(global, sum-removed);
    }

    return global;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

    cin >> n >> k;

    for (int t1 = 1; t1 <= n; ++t1)
        cin >> a[t1];

    if (n*2 <= k)
    {
        int sum = 0;
        for (int t1 = 1; t1 <= n; ++t1)
            if (a[t1] > 0) sum += a[t1];

        cout << sum << '\n';
        return 0;
    }

    for (int operations = k; operations > 0; --operations)
    {
        for (int lft = operations; lft >= 0; --lft)
        {
            int rgt = operations-lft;
            ans = max(ans, getLeft(lft) + getRight(rgt));
        }
    }

    cout << ans << '\n';





































    return 0;
}

Measured memory_bytes: 256
import sys
from sys import stdin

cnt = 0

def BubbleSort(L):
    global cnt
    for i in range(len(L)):
        for j in range(len(L)-1, i, -1):
            if L[j-1] > L[j]:
                L[j-1], L[j] = L[j], L[j-1]
                cnt += 1
    
n = int(input())
NUM_LIST = list(map(int, input().split()))

BubbleSort(NUM_LIST)
STR = list(map(str, NUM_LIST))
print(" ".join(STR))
print(cnt)


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

// const ll INF = 1e18L + 9;

int main(){
    string s, t, ans = "";
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n+1][m+1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i==0||j==0)
                dp[i][j] = 0;
            else if (s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int i = n, j = m;
    while(i && j){
        if(s[i-1]==t[j-1]){
            ans += s[i-1];
            i--; j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else 
            j--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 38780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	int n, k[202], ans = 0;;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> k[i];
	sort(k, k + 2 * n);
	for (int i = 0; i < 2*n; i += 2)
		ans += k[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

struct SegTree{
  int n;
  vll dat;
  SegTree(int n_): n(), dat(4*n_, 0){
    int x = 1;
    while(n_ > x){
      x *= 2;
    }
    n = x;
  }

  void build(){
    for(int i = n-2; i >= 0; i--){
      dat.at(i) = __gcd(dat.at(2*i+1), dat.at(2*i+2));
    }
  }

  ll query_sub(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return 0;
    else if(a <= l && r <= b) return dat.at(k);
    else{
      ll left = query_sub(a, b, 2*k+1, l, (l+r)/2);
      ll right = query_sub(a, b, 2*k+2, (l+r)/2, r);
      return __gcd(left, right);
    }
  }
  ll query(int a, int b){return query_sub(a, b, 0, 0, n);}
};

int main(){
  int N;
  cin >> N;
  SegTree tree(N);
  for(int i = 0; i < N; i++){
    int ii = i + tree.n - 1;
    cin >> tree.dat.at(ii);
  }
  tree.build();
  ll ans = 0;
  for(int i = 0; i < N; i++){
    chmax(ans, __gcd(tree.query(0, i), tree.query(i+1, N)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
x1, y1, x2, y2 = list(map(int, input().split()))

x = x2 - x1
y = y2 - y1

x3 = x2 - y
y3 = y2 + x

x4 = x1 - y
y4 = y1 + x

print(str(x3) + ' ' + str(y3) + ' ' + str(x4) + ' ' + str(y4))


Measured memory_bytes: 2940
n,m = map(int,input().split(" "))
ar = [0 for i in range(m)]
for i in range(n):
    l = list(map(int,input().split(" ")))
    for j in range(len(l)):
        if j != 0:
            ar[l[j]-1] += 1
count = 0
for r in ar:
    if r == n:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll dp[110][4][4][4] = {};


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

    ll a = 0;
    ll g = 1;
    ll c = 2;
    ll t = 3;

    // input
    ll N;
    cin >> N;

    FOR(i, 0, 4){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                dp[2][i][j][k] = 1;
            }
        }
    }
    // agc
    dp[2][a][g][c] = 0;
    dp[2][a][c][g] = 0;
    dp[2][g][a][c] = 0;

    FOR(i, 3, N){
        FOR(l, 0, 4){
            FOR(m, 0, 4){
                FOR(n, 0, 4){
                    FOR(o, 0, 4){
                        if(l==a && m==g && n==c) continue;
                        if(l==a && m==c && n==g) continue;
                        if(l==g && m==a && n==c) continue;
                        
                        // A*GC
                        if(o==c && l==a && n==g) continue;
                        // AG*C
                        if(o==c && l==a && m==g) continue;

                        dp[i][m][n][o] += dp[i-1][l][m][n];
                        dp[i][m][n][o] %= mod;
                    }
                }
            }
        }

        dp[i][a][g][c] = 0;
        dp[i][a][c][g] = 0;
        dp[i][g][a][c] = 0;
    }

    ll sum = 0;
    FOR(l, 0, 4){
        FOR(m, 0, 4){
            FOR(n, 0, 4){
                sum += dp[N-1][l][m][n];
                sum %= mod;
            }
        }
    }

    p(sum);

    return 0;
}

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

price = 0
L = sorted(L, key=lambda x:x[0])
for l in L:
    if M <= l[1]:
        price += l[0] * M
        break
    else:
        price += l[0] * l[1]
        M -= l[1]
        
print(price)

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

int main() {
	while (1){
		string n1;
		cin >> n1;
		int m1 = 0, m2 = 0;
		if (cin. eof()) break;
		for (int i = 0; i < n1.size(); i++){
			if (n1[i] == 'J'){
				if (n1[i + 1] == 'O'){
					if (n1[i + 2] == 'I'){
						m1 += 1;
					}
				}
			}
			else if (n1[i] == 'I'){
				if (n1[i + 1] == 'O'){
					if (n1[i + 2] == 'I'){
						m2 += 1;
					}
				}
			}
		}
		cout << m1 << endl;
		cout << m2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int x[50];
ll dp[51][51][50 * 50 + 1];

int main()
{
	int N, A;
	cin >> N >> A;
	REP(i, N)
	{
		cin >> x[i];
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	FOR(i, N + 1, 1)
	{
		REP(j, N + 1)
		{
			REP(k, N * 50 + 1)
			{
				dp[i][j][k] = dp[i - 1][j][k];
				if (j >= 1 && k - x[i - 1] >= 0)
				{
					dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
				}
			}
		}
	}

	ll ans = 0;
	FOR(j, N + 1, 1)
	{
		FOR(k, N * 50 + 1, 1)
		{
			if (k%j == 0 && k / j == A)
			{
				ans += dp[N][j][k];
			}
		}
	}

	cout << ans << endl;
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    int t, cnt = 0;
    bool f = false;
    for (int i = 0; i < n; i++) {
      cin >> t;
      if (t > 0) cnt++;
      if (t > 1) f = true;
    }
    if (f) cout << cnt + 1 << "\n";
    else cout << "NA\n";
  }
}


Measured memory_bytes: 3112
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    string S;  cin >> S;

    string yy = S.substr(0, 2);
    string mm = S.substr(2, 2);

    string ans;
    if ((stoi(yy)==0 || 13 <= stoi(yy)) && 1 <= stoi(mm) && stoi(mm) <=12) {
        ans = "YYMM";
    } else if (1 <= stoi(yy) && stoi(yy) <= 12 && 1 <= stoi(mm) && stoi(mm) <=12) {
        ans = "AMBIGUOUS";
    } else if (1 <= stoi(yy) && stoi(yy) <=12 && (stoi(mm) == 0 || 13 <= stoi(mm))) {
        ans = "MMYY";
    } else {
        ans = "NA";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int N, maxp, sump = 0, times = 1;
	cin >> N;
	int p[N];
	for(int i = 0; i < N; i++){
		cin >> p[i];
		if(i == 0){
			maxp = p[i];
			continue;
		}
		else{
			if(p[i] > maxp){
				maxp = p[i];
				times = 1;
			}
			else if(p[i] == maxp){
				times++;
			}
		}
	}
	for(int i = 0; i < N; i++){
		if(p[i] == maxp){
			continue;
		}
		else{
			sump += p[i];
		}
	}
	cout << sump + maxp / 2 + maxp * (times - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from bisect import bisect_right

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    N = int(input())
    A = tuple(int(input()) for _ in range(N))
    B = [-A[0]]

    for a in A[1:]:
        if a <= -B[-1]:
            B.append(-a)
        else:
            B[bisect_right(B, -a)] = -a

    print(len(B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11764
N, A, B, C, D = map(int, input().split())

#N = 48792
#A = 105960835
#B = 5
#C = 2
#D = 4

num = abs(B-A)
ans = False
for i in range(N-1, N):
    if(i%2==1):
        for j in range(i//2+1, i+1):
            if(j*C-(i-j)*D<=num and num<=j*D-(i-j)*C):
                ans = True
    else:
        for j in range(i//2, i+1):
            if(j*C-(i-j)*D<=num and num<= j*D-(i-j)*C):
                ans = True
if(ans):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    string S = "ACL";
    int K;
    cin >> K;
    string ans = "";
    rep(i,0,K) {
        ans += S;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
from collections import defaultdict, deque

def main():
    n = int(input())
    edges = defaultdict(list)

    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v - 1, w))
        edges[v-1].append((u - 1, w))
    
    vertexes = solve(edges, n)
    for v in vertexes:
        print(v)

def solve(edges, n):
    vertexes = [None for _ in range(n)]
    vertexes[0] = 0

    q = deque()
    q.append(0)

    while q:
        u = q.popleft()

        for v, w in edges[u]:
            if vertexes[v] is not None:
                continue
            if w % 2 == 0:
                vertexes[v] = vertexes[u]
            else:
                vertexes[v] = 1 - vertexes[u]
            q.append(v)
    
    return vertexes
    
main()


Measured memory_bytes: 47628
#include<iostream>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    bool p[4][n];
    p[0][0]=p[0][1]=p[1][0]=p[2][1]=true;
    p[1][1]=p[2][0]=p[3][0]=p[3][1]=false;
    for(int i=1;i<n-1;i++)for(int k=0;k<4;k++)p[k][i+1]=p[k][i-1]^(s[i]!='o')^(!p[k][i]);
    for(int k=0;k<4;k++){
        if((p[k][n-2]==p[k][0])==(p[k][n-1])^(s[n-1]!='o')&&(p[k][n-1]==p[k][1])==(p[k][0])^(s[0]!='o')){
            for(int i=0;i<n;i++)cout<<(p[k][i]?'S':'W');
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main(){
  ll N;
  cin>>N;
  vector<string> S (N);
  rep(i,N){
    cin>>S[i];
    sort(S[i].begin(),S[i].end());
  }
  
  sort(S.begin(),S.end());
  ll count=1;
  ll ans=0;
  rep(i,N-1){
    if(S[i]==S[i+1]) count++;
    else if(S[i]!=S[i+1]){
        ans+=count*(count-1)/2;
        count=1;
    }  
    if(i==N-2) ans+=count*(count-1)/2;
  }
    
  
  cout<<ans<<endl;
}

      

Measured memory_bytes: 7296
def judge():
    cnt = 0  # 今何連続でゾロ目が出ているか記録しておきます

    for _ in range(N):
        x, y = map(int, input().split())
        if x == y:
            # ゾロ目ストリークが1増えました
            cnt += 1
        else:
            # ゾロ目ストリークが切れました
            cnt = 0

        if cnt == 3:
            # 3連続になった瞬間、return True していいです
            return True

    # ダメでした
    return False

N = int(input())

if judge():
    # judge() で Trueが返ってくるとこっちに進みます
    print("Yes")
else:
    # Falseだとこっちです
    print("No")

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

string dp[10010];
int d[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

string cmp(string s, string t) {
    if (s == "-" || s.size() < t.size()) {
        return t;
    } else if (s.size() > t.size()) {
        return s;
    } else {
        return s < t ? t : s;
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    int a[m];
    for (int i = 0; i < m; i++) cin >> a[i];
    for (int i = 0; i < 10010; i++) dp[i] = "-";
    dp[0] = "";
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (dp[i] == "-") continue;
            string nx = dp[i] + (char)(a[j] + '0');
            dp[i + d[a[j] - 1]] = cmp(dp[i + d[a[j] - 1]], nx);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 44928
program main
    implicit none
    integer(8) n,m,h(100000),a,b,good(100000),ans,i
    read(*,*) n,m
    read(*,*) (h(i), i = 1, n)
    do i = 1, n
        good(i)=1
    end do
    do i = 1, m
        read(*,*) a,b
        if ( h(a)<=h(b) ) then
            good(a)=0
        end if
        if ( h(b)<=h(a) ) then
            good(b)=0
        end if
    end do
    ans=0
    do i = 1, n
        if ( good(i)==1 ) then
            ans=ans+1
        end if
    end do
    write(*,*) ans
end program main

Measured memory_bytes: 4656
#include <algorithm>
#include <iostream>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 2000;
const int MaxM = 2000;
const int L = MaxN * MaxM;

int n;
int a[MaxN + 1];

bitset<L + 1> f;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];

	f.set(0);
	for (int i = 1; i <= n; ++i)
		f |= f << a[i];

	int s = 0;
	for (int i = 1; i <= n; ++i)
		s += a[i];
	s = (s - 1) / 2 + 1;

	for (int i = s; i <= L; ++i)
		if (f[i])
		{
			cout << i << endl;
			break;
		}

	return 0;
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
2 3 -10
1 2 3
3 2 1
1 2 2
'''

test_data2 = '''\
5 3
1 -2 3
-4 5 -6
7 -8 -9
-10 11 -12
13 -14 15
'''

test_data3 = '''\
10 5
10 -80 21
23 8 38
-94 28 11
-26 -2 18
-69 72 79
-26 -86 -54
-72 -50 59
21 65 -32
40 -94 87
-62 18 82
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3
    
if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        n,m=map(int,f.readline().split())
        a=[[0 for i in range(n)] for j in range(8)]
        for i in range(n):
            x,y,z=map(int,f.readline().split())
            t=0
            for p in range(2):
                for q in range(2):
                    for r in range(2):
                        a[t][i]=x*(1-2*p)+y*(1-2*q)+z*(1-2*r)
                        t+=1

        # End Input code ---------------------------------------
else:
    # Start Input code ---------------------------------------
    n,m=map(int,input().split())
    a=[[0 for i in range(n)] for j in range(8)]
    for i in range(n):
        x,y,z=map(int,input().split())
        t=0
        for p in range(2):
            for q in range(2):
                for r in range(2):
                    a[t][i]=x*(1-2*p)+y*(1-2*q)+z*(1-2*r)
                    t+=1
    # End Input code ---------------------------------------

ans=0
for i in range(8):
    b=a[i]
    b.sort(reverse=True)
    ans=max(ans,sum(b[:m]))
print(ans)
#print('n,m=',n,m,' a=',a,' b=',b,' c=',c)

Measured memory_bytes: 3400
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);


	string s;
	cin >> s;
	
	bool ans = true;

	if (s[0] != 'A') {
		ans = false;
	}

	int cnt = 0;
	rep(i, 1, s.size()) {
		if (isupper(s[i])) {
			if (i == 1 || i == s.size() - 1 || s[i] != 'C') {
				ans = false;
			}
			cnt++;
		}

	}
	if (cnt != 1) {
		ans = false;
	}
	if (ans) {
		cout << "AC" << endl;
	}
	else cout << "WA" << endl;


}
	

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

int main()
{

	int d;
	
	while (cin >> d)
	{
		int c = 0;
		for (int i = 0; i <= 9; i++)
		{
			for (int j = 0; j <= 9; j++)
			{
				for (int k = 0; k <= 9; k++)
				{
					for (int l = 0; l <= 9; l++)
					{
						bool ju = i + j + k + l == d;
						if (ju)
						{
							c++;
						}
					}
				}
			}
		}
		cout << c << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,Q;
  long long result = 0;
  cin >> N;
  vector<int> A(N,0);
  vector<int> D(100001,0);
  for(int a = 1;a <= N;a++){
   cin >> A[a-1];
    D[A[a-1]]++;
    result += A[a-1];
  }
  cin >> Q;
    vector<int> B(Q);
  vector<int> C(Q);
  for(int a = 1;a <= Q;a++){
   cin >> B[a-1] >> C[a-1]; 
    result += D[B[a-1]] * (C[a-1] - B[a-1]);
    D[C[a-1]] += D[B[a-1]];
    D[B[a-1]] = 0;
    cout << result << endl;
  }
  
}

Measured memory_bytes: 4768
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a, U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll a, b, c;
    cin>>a>>b>>c;

    if(c>(a-b) and 4*a*b<(c-a-b)*(c-a-b)) {
        cout<<"Yes\n";
    }
    else cout<<"No\n";
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    loop(Case,1,t+1)
    {
        cerr<<"Case #"<<Case<<'\n';
        solve(Case);
    }
    return 0;
}

Measured memory_bytes: 256