akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int h,w;
    cin>>h>>w;
    char a[h][w];
    rep(i,h) rep(j,w) cin>>a[i][j];
    int b[h][w];
    int c[h][w];
    ll ans=0;
    rep(ii,h){
        rep(jj,w){
            if(a[ii][jj]=='#') continue;

    rep(i, h)
    {
        rep(j, w)
        {
            if (a[i][j] == '#')
            {
                b[i][j] = -1; // -1 = visited
                c[i][j]=-1;
            }
            else{
                b[i][j]=0;
            }
        }
    }
    queue<tuple<int, int, int>> Q; // x y cnt
    Q.push(make_tuple(ii,jj,0));
    b[ii][jj]=-1;
    c[ii][jj]=0;
    int cnt;
    while (!Q.empty())
    {
        int x = get<0>(Q.front());
        int y = get<1>(Q.front());
        cnt = get<2>(Q.front());
        Q.pop();
        rep(i, 4)
        {
            int cx = x + dx[i];
            int cy = y + dy[i];
            if (cx < 0 || cy < 0 || cx >= h || cy >= w || b[cx][cy] == -1)
            {
                continue;
            }
            b[cx][cy] = -1;
            Q.push(make_tuple(cx, cy, cnt + 1));
            c[cx][cy]=cnt+1;
            ans=max(ans,cnt+1);
        }
        //cout<<cnt<<endl;
    }
    // cout << cnt << endl;
    //cout<<ii<<" "<<jj<<endl;
    rep(i,h){
        rep(j,w){
            //cout<<c[i][j]<<"   ";
        }
        //cout<<endl;
    }

    }}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), X = sc.nextInt();
		sc.close();
		if (A > X) {
			System.out.println("NO");
		} else {
			if (A + B < X) {
				System.out.println("NO");
			} else {
				System.out.println("YES");
			}
		}
	}
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e9+7;

int main(){

    ll a,b;
    cin >>a>>b;
    if (b % a == 0){
        cout<< a+b;
    }else{
       cout << b-a;
    }

}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e5 + 7;
const int INF = 2e9;

void maxxer(int& val, int x) {
    val = max(val, x);
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    vector<vector<int>> vals(n,vector<int>(3,0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> vals[i][j];
        }
    }

    int dp[n][3];
    memset(dp,0,sizeof(dp));

    int ans = 0;

    for (int j = 0; j < 3; j++) {
        dp[0][j] = vals[0][j];
        maxxer(ans, dp[0][j]);
    }

    if (n == 1) {
        out(ans);
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                maxxer(dp[i][j], dp[i-1][k] + vals[i][j]);
            }
        }
    }

    for (int j = 0; j < 3; j++) {
        maxxer(ans, dp[n-1][j]);
    }

    out(ans);

    
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; typedef long long ll; const int M = 998244353;

int main() {
  int n,s; cin>>n>>s;
  int a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll u[s+1]; fill(u,u+s+1,0); ll an=0;
  for(int i=0;i<n;i++) {
    int e=a[i];
    if (e == s) {
      an += (i+1) * (n-i); an%=M;
      continue;
    }
    for(int j=s;j>=e && j-e>=0;j--) {
      if (j == s) {
        an += u[s-e] * (n-i); an%=M;
      }
      if (u[j-e] > 0) u[j] += u[j-e];
      if (j-e == 0) u[j] += (i+1);
      u[j] %= M;
    }
    //for(int j=0;j<s;j++) cout<<u[j]<<" "; cout<<endl;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = N / 3;

    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    S = input()

    t = N//2
    if N%2==0 and S[:t] == S[t:]:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


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

#define int int64_t
#define INF LONG_LONG_MAX/2
#define MAX 3005

using namespace std;

char str1[MAX];
char str2[MAX];

int lenA;
int lenB;

int dp[MAX][MAX];
int sp[MAX][MAX];

//3 -> digonal
//2 -> right
//1 -> bottom

int f(int a, int b) {
    if(a >= lenA || b >= lenB) return 0;

    if(dp[a][b] != -1)return dp[a][b];

    if(str1[a] == str2[b]) {
        dp[a][b] = 1+f(a+1,b+1);
        sp[a][b] = 3;
        return dp[a][b];
    }else {
        int left = f(a+1,b);
        int right = f(a,b+1);
        
        int r = left;
        if(left > right) {
            sp[a][b] = 2;
        }else {
            sp[a][b] = 1;
            r = right;
        }

        dp[a][b] = r;
        return r;
    }
}

signed main() {
    scanf("%s", &(str1[0]));
    scanf("%s", &(str2[0]));

    lenA = strlen(str1);
    lenB = strlen(str2);

    str1[lenA] = '\0';
    str2[lenB] = '\0';

    for(int y=0; y<MAX; y++) {
        for(int x=0; x<MAX;x++){
            dp[y][x] = -1;
        }
    }

    //printf("%lld\n", f(0,0));
    f(0,0);

    int a = 0;
    int b = 0;
    while(1 == 1){
        if(sp[a][b] == 3){
            printf("%c", str1[a]);
            a++;
            b++;
        }else if(sp[a][b] == 2){
            a++;
        }else if(sp[a][b] == 1){
            b++;
        }else{
            break;
        }
    }
}

Measured memory_bytes: 141568
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 998244353
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> l(n), r(n), dp(n + 10), sum(n + 10);
  for (int i = 0; i <= n + 5; i++) {
    dp[i] = 0;
    sum[i] = 0;
  }
  sum[1] = 0;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < k; i++) {
    sum[l[i] + 1] += 1;
    sum[r[i] + 2] += MOD - 1;
  }
  for (int i = 2; i <= n; i++) {
    sum[i] += sum[i - 1];
    sum[i] %= MOD;
    if (sum[i] < 0) {
      sum[i] += MOD;
    }
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n) {
        sum[i + l[j]] += sum[i];
        sum[i + l[j]] % MOD;
      }
      if (i + r[j] + 1 <= n) {
        sum[i + r[j] + 1] += MOD - sum[i];
        sum[i + r[j] + 1] % MOD;
      }
    }
  }
  cout << sum[n] << endl;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	sort(a , a+n);
	
	int ans = 0;
	
	for(int i = 0; i < n; ++i) {
		for(int j = i+1; j < n; ++j) {
			if(a[i] != a[j]) {
				for(int z = j+1; z < n; ++z) {
					if(a[i] != a[z] && a[j] != a[z] && a[i]+a[j] > a[z]) {
						ans++;
						//cout << a[i] << " " << a[j] << " " << a[z] << endl;
					}
				}
			}
		}
	}
	
	cout << ans;
}

signed main() {
    fast;

    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3608
MOD = 998244353
n, s = map(int, input().split())
A = map(int, input().split())
dp = [0]*(s+1)
dp[0] = 1
inv_2 = (MOD+1)//2
for a in A:
    for j in reversed(range(s+1)):
        if j-a < 0:
            continue
        dp[j] += dp[j-a]*inv_2
        dp[j] %= MOD

print(dp[-1]*pow(2, n, MOD) % MOD)

Measured memory_bytes: 68636
from collections import defaultdict

def r(i) :
  if i < 2:
    return 1
  else :
    return i*(i-1)/2

a = int(input())
b = list(map(int,input().split()))

total = 0
c = defaultdict(int)
for j in range(a):
  c[b[j]] += 1
for key in c.keys():
  if c[key] > 1:
    total += r(c[key])

for j in range(a):
  print(int(total - c[b[j]]+1))




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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int a[maxn];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
  {
    cin >> a[i];
  }
  int tortoise = a[1];
  int hare = a[a[1]];
  while(tortoise != hare)
  {
    tortoise = a[tortoise];
    hare = a[a[hare]];
  }

  ll mu = 0;
  tortoise = 1;

  while(tortoise != hare)
  {
    tortoise = a[tortoise];
    hare = a[hare];
    mu++;
  }

  int ans = tortoise;
  
  if(k < mu)
  {
    ans = 1;  
  }
  else
  {
    ll lam = 1;
    
    hare = a[tortoise];
    while(tortoise != hare)
    {
      hare = a[hare];
      lam++;
    }
    k -= mu;
    k = max(k, 0LL);
    k %= lam;
  }
  
  while(k)
  {
    ans = a[ans];
    k--;
  }


  cout << ans << endl;

  return 0;
}

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

size_t N, a, b, ans;
vector<pair<int, int>> v(101010), w(101010);

int main(){
    scanf("%lu", &N);
    for(int i = 0; i < 101010; ++i){
        v[i].second = w[i].second = i;
    }
    for(int i = 0; i < N; ++i){
        scanf("%lu", &a);
        ++(i & 1 ? v : w)[a].first;
    }
    sort(v.rbegin(), v.rend());
    sort(w.rbegin(), w.rend());
    if(v[0].second == w[0].second){
        cout << min(N - v[0].first - w[1].first, N - v[1].first - w[0].first) << endl;
    }else{
        cout << N - v[0].first - w[0].first << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int x; cin >> x;
  int ans = 0;
  if(x >= 1 && x <= 3){
    cout << 1 << endl;
    return;
  }
  for(int i = 2; i < 33; i++){
    int j = i * i;
    if(j > x) break;
    while(j <= x){
      j *= i;
    }
    int a = j / i;
    ans = max(a, ans);
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = 0;

    rep(i, n) {
        ll num = i + 1;
        ll sum = 0;
        while (num != 0) {
            sum += num % 10;
            num /= 10;
        }

        if (a <= sum && sum <= b) {
            ans += i + 1;
        }
    }

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



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

int main()
{
    int a,b,c,d;
    cin >> a >> b >>c >> d;
    /*
    int a[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    */

    while(1){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3636
module ABC081

	! <module>s to import
	use, intrinsic :: iso_fortran_env


	! require all variables to be explicitly declared
	implicit none


	! accessibility of <subroutine>s and <function>s in this <module>
	public  :: ABC081_A


	! constants for this <module>
	integer( kind=INT32 ), parameter, private :: num_char = 3


	! contained <subroutine>s and <function>s are below
	contains


	subroutine ABC081_A

		! variables for this <subroutine>
		character(len=num_char, kind=1) :: buffer
		integer( kind=INT16 )           :: itr, count

		! STEP.01
		! read out the target positive integers
		read *, buffer

		! STEP.02
		! count the number of the `1`
		count = 0

		do itr = 1, num_char, 1
			if( ichar( buffer(itr:itr) ) .eq. ichar('1') ) count = count+1
		end do

		! STEP.03
		! output the result
		write( unit=OUTPUT_UNIT, fmt='(I0)', advance='yes' ) count

		! STEP.END
		return

	end subroutine ABC081_A

end module ABC081


program main

	! <module>s to import
	use, non_intrinsic :: ABC081

	! require all variables to be explicitly declared
	implicit none

	call ABC081_A


end program main


Measured memory_bytes: 256
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])

Measured memory_bytes: 43100
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	ll n,m;
	ll ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[i]-1;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        String date = scanner.nextLine();
        char[] date_c = date.toCharArray();
        date_c[3] = '8';
        for(int i = 0; i < 10; i++)
        {
            System.out.print(date_c[i]);
        }
    }
}


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

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  vector<int> r(n, s == (int)1e9 ? 1 : (int)1e9);
  fill(r.begin(), r.begin() + k, s);
  for (auto e : r) cout << e << ' ';
  cout << endl;
}


Measured memory_bytes: 1664
#include <stdio.h>
int main(){
  int i,n,f=0,r=0;
  scanf("%d",&n);
  for(i=10;i<1e6;i*=10)if(i==n)f=1;
  if(f)r=10;
  else for(;n;n/=10)r+=n%10;
  printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String args[]){
		int H, W;
		Scanner scan = new Scanner(System.in);

		while(true){
			H = scan.nextInt();
			W = scan.nextInt();
			
			if(H == 0 && W == 0){break;}

			for(int i=0; i<H; i++){
				for(int k=0; k<W; k++){
					if(k==0 || k ==(W-1) || i==0 || i==(H-1)){
						System.out.print("#");
					}
					else{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 31956
a,b,k = map(int, input().split())
cmn_dvs=[]

for i in range(1,101):
    if a%i==0 and b%i==0:
        cmn_dvs.append(i)

list.sort(cmn_dvs, reverse = True)
#print(cmn_dvs)
print(cmn_dvs[k-1])

Measured memory_bytes: 2940
#include<stdio.h>

int main(){
    int i,j,n;
    scanf("%d",&n);
    
    for(i=0;i<20;i++){
    
        for(j=0;j<20;j++){
            if(n==((4*i)+(7*j))){
            printf("Yes\n");
            i=22;
            }
        }
    }
    if(i!=23)
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) {
        a--;
    }
    else b--;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n,m;
	cin>>n;
	double a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	double temp=0;
	for(int i=0;i<n-1;i++){
		temp=(a[i]+a[i+1])/2;
		a[i+1]=temp;
	}
	cout<<a[n-1]<<endl;
    return 0;
}


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

#define MAX(a,b) ((a)>(b)?(a):(b))

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  graph *g=newGraph(n,m);
  while(m--){
    int x,y;
    scanf("%d%d",&x,&y);
    x--;y--;
    addEdge(g,x,y);
  }
  int *dp=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) dp[i]=-1;
  int ans=0;
  int *stack=(int *)calloc(2*n,sizeof(int));
  for(i=0;i<n;i++){
    if(dp[i]>=0) continue;
    int top=0;
    stack[top++]=i;
    while(top>0){
      int v=stack[--top];
      if(v>=n){
	v-=n;
	int max=-1;
	for(int p=g->start[v];p!=-1;p=g->next[p]) max=MAX(max,dp[g->vertex[p]]);
	dp[v]=max+1;
      } else {
	stack[top++]=v+n;
	for(int p=g->start[v];p!=-1;p=g->next[p]){
	  int u=g->vertex[p];
	  if(dp[u]<0){
	    stack[top++]=u;
	  }
	}
      }
    }
    ans=MAX(ans,dp[i]);
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
    #include<cstdio>
    #include<math.h>
    #include<string>
    #include<algorithm>
    #include<functional>
    #include<vector>
    #include<set>
    #include<map>
    #define INF 999999
    #define EPS 1.0e-6
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<int, int> P;
     
    int n, a;
    set<int>s;
     
    int main()
    {
    	cin >> n;
    	for (int i = 0; i < n; i++) {
    		cin >> a;
    		auto itr = s.find(a);
    		if (itr != s.end())s.erase(a);
    		else s.insert(a);
    	}
    	cout << (int)s.size() << endl;
     
    	return 0;
    }

Measured memory_bytes: 4864
package main

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

var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func main() {
	nextReader = newScanner()
	s := nextString()
	for i := 0; i < len(s); i++ {
		fmt.Print("x")
	}
	fmt.Println("")
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int mx = 0;
    rep(i,n){
        cin >> a[i];
        mx = max(mx,a[i]);
    }
    int g=a[0];
    for(int i = 1;i<=n-1;i++) g = __gcd(g,a[i]);

    if((mx-k)%g == 0 && k<=mx) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 3772
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class UnionFind {
public:
    vector<int> par, rank;
    int cnt;

    UnionFind(int n) : cnt(n) {
        par = vector<int>(n);
        iota(par.begin(), par.end(), 0);
        rank = vector<int>(n, 0);
    }

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        cnt--;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

signed main() {
    int N, M;
    cin >> N >> M;

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

    UnionFind uf = UnionFind(N);

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        uf.unite(a, b);
    }

    int ret = 0;

    for (int i = 0; i < N; i++) {
        if (uf.same(i, a[i] - 1)) ret++;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main(void){

	int n[4];
	int check[4] = {0,0,0,0};
	int i;

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

	for(i=0;i<4;i++){
		if(n[i] == 1){
			if(check[0] == 0){
				check[0] = 1;
			}else{
				check[0] = 0;
				break;
			}
		}
		else if(n[i] == 9){
			if(check[1] == 0){
				check[1] = 1;
			}else{
				check[1] = 0;
				break;
			}
		}
		else if(n[i] == 7){
			if(check[2] == 0){
				check[2] = 1;
			}else{
				check[2] = 0;
				break;
			}
		}
		else if(n[i] == 4){
			if(check[3] == 0){
				check[3] = 1;
			}else{
				check[3] = 0;
				break;
			}
		}
		else{
			break;
		}
	}

	if(check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;

}

Measured memory_bytes: 128
X=int(input())

def isPrime(n):
  if n==2:
    return True
  for p in range(2,n):
    if n%p==0:
      return False
    elif p*p>n:
      break
  return True

while(True):
  if isPrime(X):
    print(X)
    break
  else:
    X+=1

Measured memory_bytes: 2940
from collections import defaultdict
class UnionFind:
    def __init__(self, num):
        self.table = [-1 for _ in range(num)]
        self.sz = defaultdict(lambda:1)

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)

        if s1 != s2:
            size = self.sz[s1]+self.sz[s2]
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            s = self.find(x)
            self.sz[s] = size
            return True
        return False

    def size(self, x):
        s = self.find(x)
        return self.sz[s]

N,M = map(int,input().split())
u = UnionFind(N)
AB = [list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
AB = AB[::-1]
ans = [N*(N-1)//2]*M
for i in range(M-1):
    A,B = AB[i]
    ans[i+1] = ans[i]
    if u.find(A) != u.find(B):
        ans[i+1] -= u.size(A)*u.size(B)
        u.union(A,B)
ans = ans[::-1]
for i in range(M):
    print(ans[i])

Measured memory_bytes: 135136
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n; cin >> n;
  for(int range(i,0,n)){
    string l; cin >> l;
    deque<vector<int>> s;
    s.push_back(vector<int>());
    for(int range(k,0,l.size())){
      int res = 0;
      vector<int> ls;
        //cout << "@" << l[k] << endl;
        //cout << "l"  << s.size() << endl;
      switch(l[k]){
        case '[':
          s.push_back(vector<int>());
          break;
        case ']':
          res = 0;
          ls = s.back();
          s.pop_back();
          sort(all(ls));
          for(int range(u,0,(ls.size()+1)/2)){
            res += ls[u];
          }
          s.back().push_back(res);
          //cout << "<- " << res << endl;
          break;
        default:
          res = l[k] - '0';
          k++;
          while(k < l.size() && isdigit(l[k])){
            res = res * 10 + (l[k] - '0');
            k++;
          }
          res = (res + 1) / 2;
          k--;
          //cout << "d " << res << endl;
          s.back().push_back(res);
      }
    }
    cout << s[0][0] << endl;
  }
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N , K , Q;
    
    cin >> N >> K >> Q;
    
    vector<ll> player(N, K - Q);
    
    rep(i, Q){
        ll inp;
        cin >> inp;
        inp --;
        player[inp] ++;
    }
    
    rep(i, N){
        if(player[i] <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
        
    }

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int>a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        if(i) {
            if(a[i] == a[i-1]) {
                ans++;
                a[i] = 10000+i;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, w = 0, k = 0;
    string s;
    cin >> n >> s; 
    for (long long i = 0; i < n; ++i) if (s[i] == 'W') w++;
    for (long long i = n - w; i < n; ++i) if (s[i] != 'W') k++;
    cout << k;
}

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

bool trace( int a[6][6], int b, int& index )
{
    int c;
    bool judge = false;
    for( int i = 0; i < 6; i++ )
        if( a[index][i] == b )
        {
            c = i;
            judge = true;
        }
    index = c;
    return judge;
}

int main()
{
    int a[6][6] = { { -1, -1, -1, 0, 1, -1 }, { -1, -1, -1, 1, 0, -1 },
                    { -1, 0, -1, -1, 1, -1 }, { -1, -1, -1, -1, -1, 1 },
                    { -1, -1, -1, 0, -1, -1 }, { -1, 1, 0, -1, -1, -1 } };

    string s;
    while( cin >> s )
    {
        if( s == "#" )
            break;

        int index = 0;
        for( int i = 0; i < s.size(); i++ )
            if( !trace( a, s[i] - '0', index ) )
            {
                index = 100;
                break;
            }

        if( index == 1 )
            cout << "Yes" << endl;
        else
            cout << "No" << endl;

    }

    return 0;
}


Measured memory_bytes: 3208
n = int(input())
array = [int(x) for x in input().split()]
sum_array = [0]
now = 0
for i in range(n):
    sum_array.append(sum_array[i] + abs(array[i] - now))
    now = array[i]
else:
    sum_array.append(sum_array[-1] + abs(array[-1] - 0))

for j in range(n):
    if j == 0:
        print(sum_array[-1] -
              (sum_array[j + 1] - sum_array[j]) -
              (sum_array[j + 2] - sum_array[j + 1]) +
              (abs(array[j + 1] - 0))
              )
    elif j == n - 1:
        print(sum_array[-3] + abs(array[-2]))
    else:
        print(sum_array[-1] -
              (sum_array[j + 1] - sum_array[j]) -
              (sum_array[j + 2] - sum_array[j + 1]) +
              (abs(array[j + 1] - array[j - 1]))
              )

Measured memory_bytes: 14048
def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    WORDS = 'dream', 'dreamer', 'erase', 'eraser'

    S = input()
    N = len(S)

    @lru_cache(maxsize=None)
    def dfs(cur=N):
        if cur == 0:
            return True

        for word in WORDS:
            if S[cur - len(word):cur] == word:
                if dfs(cur - len(word)):
                    return True

        return False

    cond = dfs()
    print('YES' if cond else 'NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 35624
#include<stdio.h>

int main()
{
    long long int n,a[100005],i,ans,min,temp;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    ans=0;min=1;
    ans+=a[0]-1;
    min=2;
    for(i=1;i<n;i++)
    {
        if(a[i]<min)
        {
            temp++;
        }
        else if(a[i] == min)
        {
            min++;
        }
        else if(a[i]%min!=0)
        {
            ans+=(a[i]/min);
        }
        else if(a[i]%min==0)
        {
            ans+=(a[i]/min)-1;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int s[101];
	int mx=0;
	int mn=1e9;
	for (int i=0;i<n;i++){
		cin>>s[i];
		mx=max(mx,s[i]);
	}
	for (int i=1;i<=mx;i++){
		int cnt=0;
		for (int j=0;j<n;j++) cnt+=(s[j]-i)*(s[j]-i);
		mn=min(mn,cnt);
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
v1 = [x2-x1, y2-y1]
v2 = [-v1[1], v1[0]]
x3 = x2+v2[0]
y3  = y2+v2[1]
x4 = x3+x1-x2
y4 = y3+y1-y2
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
n, *s = open(0).read().split()
n = int(n)
slist = []
for i  in range(5):
  slist.append([])
for ss in s:
  if ss[0] == "M":
    slist[0].append(ss)
  elif ss[0] == "A": 
    slist[1].append(ss)
  elif ss[0] == "R": 
    slist[2].append(ss)
  elif ss[0] == "C": 
    slist[3].append(ss)
  elif ss[0] == "H": 
    slist[4].append(ss)
  else:
    continue

ans = 0 
for i in range(5):
  for j in range(i+1,5):
    for k  in range(j+1,5):
      ans+= len(slist[i])*len(slist[j])*len(slist[k])
print(ans)

Measured memory_bytes: 11036
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int x,y,A,B,C; cin>>x>>y>>A>>B>>C;
    vi a = READ<int>(A);
    vi b = READ<int>(B);
    vi c = READ<int>(C);
    priority_queue<pii> pq;
    for(int d : a) pq.push({d, 0});
    for(int d : b) pq.push({d, 1});
    for(int d : c) pq.push({d, 2});

    ll sum=0;
    int eat=0, XY=x+y;
    while(pq.size() && eat<XY) {
        pii top = pq.top(); pq.pop();
        if(top.second==0) {
            if(x) {
                eat++;
                x--;
                sum += top.first;
            }
        } else if(top.second==1) {
            if(y) {
                eat++;
                y--;
                sum += top.first;
            }
        } else {
            eat++;
            sum += top.first;
        }
    }

    cout<<sum<<endl;
}

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


int main()
{
	int N;
	cin>>N;
	vector<int> ans(N+1,0);
	for(int x=1;x<=100;x++)
	{
		for(int y=1;y<=100;y++)
		{
			for(int z=1;z<=100;z++)
			{
				if((pow(x,2)+pow(y,2)+pow(z,2)+x*y+y*z+z*x)>N) continue;
				ans[pow(x,2)+pow(y,2)+pow(z,2)+x*y+y*z+z*x]++;
			}
		}
	}
	for(int i=1;i<=N;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
	cout.precision(10);
	cout << (double)(n-n/2)/(double)n << endl;
    //cout.precision(10);
    //cout << (double)(N - N / 2) / (double)N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll N;
    string A[200020];
    map<string,int> b;
    cin >> N;
    for(ll i = 0;i < N;i++){
        cin >> A[i];
        if(b[A[i]] == 1){cout << "NO";return 0;}
        b[A[i]]++;
    }
    cout << "YES";
}



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

int main(void){

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


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct UnionFind{
    vector<int> par; // par[i]:iの親の番号
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) par[i] = i;
    }
    
    int root(int x){ // xが属する木の根
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){ // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
    }
    
    bool same(int x, int y){ // xとyが同じ木に属するかどうか
        return root(x) == root(y);
    }
};

int main(void){
    int N,M; cin >> N >> M;
    int a[M],b[M]; REP(i,M){cin >> a[i] >> b[i]; a[i]--; b[i]--;}

    int ans=0;
    REP(i,M){
        UnionFind uf(N);
        REP(j,M){
            if(i==j) continue;
            uf.unite(a[j], b[j]);
        }
        bool flag=false;
        REP(j,N-1)FOR(k,j+1,N){
            if(uf.same(j,k) == false){flag=true; break;}
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
int m,n,c[21],dp[22][50010];

int main()
{
	cin>>n>>m;
	FOR(i,1,m+1)cin>>c[i];
	sort(c,c+m);
	FOR(i,1,n+1)dp[1][i]=i;
	FOR(i,2,m+1)
	{
		FOR(j,1,n+1)
		{
			if(j>=c[i])
			{
				dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[m][n]<<endl;
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll k;
	cin >>k;
	
	if(k==7||k==1){cout<<"1\n"; return 0;}
	ll w=7;
	rep(i, 1e7){
		w = w*10 + 7;
		w %= k;
		if(w==0){
			cout << i+2 <<"\n";
			return 0;
		}
	}
	
	cout<<"-1\n";
	return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)

int main(){

    int m, d; cin >> m >> d;


    int ans = 0;
    for(int i=1; i<=m; i++){
        for(int j=1; j<=d; j++){

            int d1 = j % 10;
            int d2 = j / 10; 

            if(d1 <= 1) continue;
            if(d2 <= 1) continue;

            // if(d2 == 0) d2 = 1;

            if(i == d1*d2){
                ans++;
                // cout << i << " " << j << endl;
            }

        }
    }

    cout << ans;

    return 0;
}

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

using namespace std;

#define long long long

bool next(vector<int> &a) {
    for (int &i : a) {
        if (i == 0) {
            i = 1;
            return true;
        }
        i = 0;
    }
    return false;
}

int count(vector<int> a) {
    int ans = 0;

    for (int aa : a) ans += aa == 1;

    return ans;
}

int main() {

    int n;
    cin >> n;

    vector<long> a(60, 0);
    vector<long> b(60, 0);

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

        int tmp = 0;
        while (x > 0) {
            if (x % 2 == 0) {
                a[tmp++]++;
            } else {
                b[tmp++]++;
            }
            x /= 2;
        }
        for (int j = tmp; j < 60; j++) {
            a[j]++;
        }
    }

    long ans = 0;

    long p = 1;
    for (int i = 0; i < 60; i++) {
        ans += (a[i] * b[i] % 1000000007) * (p % 1000000007);
        p *= 2;
        ans %= 1000000007;
    }

    cout << ans;
    return 0;
}


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

int main(){
int A, B, C, D;
cin>> A >> B >> C >> D;

if(A+B==C+D) {
    cout << "Balanced" << endl;
}
else if(A+B>=C+D) {
    cout << "Left" << endl;
}
else  {
    cout << "Right" << endl;
    }
}




Measured memory_bytes: 3572
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//for
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//range
#define all_range(C) begin(C), end(C)
//STL
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//chmin&chmax
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//GCD
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//LCM
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//POW
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

//main.cpp----------------------------


int main() {

  string s;
  cin >> s;

  int L = (s[0]-'0')*10 + (s[1]-'0');
  int R = (s[2]-'0')*10 + (s[3]-'0');

  if(1<=L&&L<=12) {
    if(1<=R&&R<=12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }else {
    if(1<=R&&R<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }


  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    priority_queue<ll, vector<ll>, function<bool(ll, ll)>> q([](ll a, ll b) { return a < b; });
    REP(i, N) {
        ll a;
        cin >> a;
        q.push(a);
    }
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A, A + M, [](pll a, pll b) { return a.second > b.second; });
    REP(i, M) {
        REP(j, A[i].first) {
            q.push(A[i].second);
        }
        if (q.size() > 2 * N)
            break;
    }

    ll ans = 0;
    REP(i, N) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6640
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,A;
    ll f=0,s=0,i,fn;
    cin >> N;
    for(i=0;i<N;i++){
        cin >> A;
        if(f<A)s=f,f=A,fn=i;else s=max(s,A);
    }
    for(i=0;i<N;i++){
        if(i==fn)cout << s<<endl;else cout << f<<endl;
    }
}

Measured memory_bytes: 1664