akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

class contest {
public:
    vector<int> c;
    vector<vector<int>> s;
    contest() : c(26), s(D, vi(26)) {
    }
};

int calcScore(contest &atc, vector<int> &t) {
    vector<int> last(26, 0);
    int res = 0;
    REP(i, D) {
        int score = atc.s[i][t[i]];
        res += score;
        last[t[i]] = i + 1;
        REP(j, 26) {
            res -= atc.c[j] * (i + 1 - last[j]);
        }
        cout << res << endl;
    }
    return res;
}

signed main() {
    cin >> D;
    contest atc;
    cin >> atc.c;
    REP(i, D) {
        cin >> atc.s[i];
    }
    vector<int> t(D);
    REP(i, D) {
        cin >> t[i];
        t[i]--;
    }
    calcScore(atc, t);
}

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

#define maxn 100000008
#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	scanf("%d", &n);
	int len = 3 * n;
	int a[len];
	for (int i = 0; i < len; ++i) {
		scanf("%d", &a[i]);
	}

	sort(a, a + len);

	ll ans = 0;
	int index = len - 1;
	for (int i = 0; i < n; ++i) {
		ans += a[index - 1];	
		index -= 2;
	}

	cout << ans << endl;

	return 0;
}


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

int main(int argc, char const* argv[])
{
    int x;
    cin >> x;

    int m=0;

    if ( (x == 1) || (x == 1000) ) {
        cout << x << endl;
    }else{
        for (int b = 2; b < sqrt(x); b++) {
            int p = 2;
            while (true) {
                if (pow(b, p) <= x) {
                    m = max(m, (int)pow(b, p));
                    p++;
                }else{
                    break;
                }
            }
        }

        cout << m << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//小数的四舍五入 
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  int n;
  cin>>n;
  double t=0;
  for(int i=1;i<=n;i++)
  if(i%2==1) t++; 
  double x;
  t/=n;
  cout<<setprecision(10)<<fixed<<t<<endl;
  return 0;
}

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

string s, t;
int n, m;

int main() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
  int res = m;
  for (int i = 0; i + m <= n; ++i) {
    int cnt = 0;
    for (int j = 0; j < m; ++j) cnt += s[i + j] != t[j];
    res = min(res, cnt);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = 3e3 + 5;
ll dp[MAX][MAX] = {};
ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	return x * y%MOD;
}

ll l[MAX], r[MAX];
ll sum0[MAX] = {}, sum1[MAX] = {};

int main() {
	ll n, m;
	string s;
	cin >> n >> m >> s;
	REP(i, 1, m) {
		cin >> l[i] >> r[i];
	}
	ll cur_0 = 0, cur_1 = 0;
	ll header = 0;
	ll cur_i = 1;
	dp[0][0] = 1;
	REP(i, 1, n) {
		sum0[i] = sum0[i - 1] + (s[i - 1] == '0');
		sum1[i] = sum1[i - 1] + (s[i - 1] == '1');
	}
	l[m + 1] = n + 1; r[m + 1] = n + 1;
	REP(i, 1, m + 1) {
		while (cur_i < l[i]) {
			header = max(header, cur_i);
			ll t1 = max(ll(0), cur_i - sum0[header]);
			ll t2 = min(cur_i, sum1[header]);
			REP(j, t1,t2) {
				dp[cur_i][j] = mod_p(dp[cur_i][j], dp[cur_i - 1][j]);
				if (j >= 1) {
					dp[cur_i][j] = mod_p(dp[cur_i][j], dp[cur_i - 1][j - 1]);
				}
			}
			cur_i++;
		}	
		header = max(header, r[i]);

	}
	cout << dp[n][sum1[n]] << endl;
	/*
	REP(i, 0, n) {
		REP(j, 0, n) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,q,x,y;
vector<int> G[200007];
int a[200007],sum=0,ans[200007];

void dfs(int now,int p)
{
    sum+=a[now];
    ans[now]=sum;
    for (int i:G[now])
    {
        if (i!=p)
        {
            dfs(i,now);
        }
    }
    sum-=a[now];
}

int32_t main()
{
    IOS
    cin>>n>>q;
    for (int i=1;i<=n-1;i++)
    {
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    for (int i=1;i<=q;i++)
    {
        cin>>x>>y;
        a[x]+=y;
    }
    dfs(1,-1);
    for (int i=1;i<=n;i++) cout<<ans[i]<<' ';
}



Measured memory_bytes: 24064
N = int(input())
a = list(map(int, input().split(" ")))
a_list = []

a_small = a[0]
for i in range(1, len(a)):
    a_large = a[i]
    if a_small == a_large:
        a_list.append(1)
    else:
        a_list.append(0)
    
    a_small = a_large

count = 0

i = 0
while i < len(a_list):
    if a_list[i] == 1:
        count += 1
        i = i + 2
    else:
        i = i + 1
print(count)       

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
long long N, A, B;
void Solve()
{
    N -= 2;
    if(N == -1 && A == B)
    {
        cout << "1\n";
        return;
    }
    if(A > B || N < 0)
    {
        cout << "0\n";
        return;
    }
    long long x = A * N;
    long long y = B * N;
    cout << y - x + 1 << "\n";
}
int main()
{
    cin >> N >> A >> B;
    Solve();
    return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	string s;

	cin >> s;

	if (s[2] == s[3] && s[4]==s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}




	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < INF else -1)



if __name__ == "__main__":
  main()


Measured memory_bytes: 83800
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		// 入力を受け取るためのクラスを利用するための準備
		Scanner sc = new Scanner(System.in);
		
		String w = sc.next();
		String t;
		int cnt = 0;
		while(true) {
			t = sc.next();
			if (t.equals("END_OF_TEXT")) break;
			
			// 大文字小文字を区別せずに2つの文字列を比較
			if (t.equalsIgnoreCase(w)) cnt++;
		}
		System.out.println(cnt);

	}

}



Measured memory_bytes: 26136
s=input()
l=len(s)
cnt=0
A=[]
A.append(0)
for i in range(l):
  A.append(int(s[i]))
for i in reversed(range(l+1)):
  if A[i]<5 or (A[i]==5 and A[i-1]<5):
    cnt+=A[i]
  else:
    A[i-1]+=1
    cnt+=(10-A[i])
    A[i]=0
print(cnt)

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

int main(){
    int N,X;
    int m[N];
    cin >> N >> X;
    for(int i=0;i<N;i++){
        cin >> m[i];
    }
    int sum = 0;
    for(int i=0;i<N;i++){
        sum += m[i];
    }
    sort(m,m+N);
    cout << (N+(X - sum)/m[0]) << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b, r = c + d;
  if (l > r)
    cout << "Left" << endl;
  else if (l == r)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N,A,B;
  cin>>N>>A>>B;
  if(N%(A+B)>A){
    cout<<N/(A+B)*A+A<<endl;
  }
  else{
    cout<<N/(A+B)*A+N%(A+B)<<endl;
  }
      

}

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

typedef long long int ll;
using namespace std;

const ll MOD = 1e9 + 7;

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

int main()
{
	int n; cin>>n; ll g; cin>>g;
	for(int i=0;i<n-1;i++){
		ll x; cin>>x; g = gcd(g,x);
	}

	cout<<g;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

StNode* fnFind(StNode* poRoot, int nNo)
{
  StNode* poNode = poRoot;
  while (poNode != nullptr)
    if (nNo == poNode->m_nKey)
      return poNode;
    else if (nNo < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;

  return nullptr;
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'f')
    {
      int nNo;
      cin >> nNo;
      if (fnFind(rpoRoot, nNo))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
  fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 21868
def isLeapYear? year
    return true if (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
    false
end

answers = []
while true
    year1, year2 = gets.chomp.split.map(&:to_i)
    break if year1 == 0 && year2 == 0
    answers << []
    year1.upto(year2){|year| answers.last << year if isLeapYear?(year)}
end

answers.each_with_index{|answer, index|
    puts if index != 0
    if answer.size == 0
        puts "NA"
    else
        puts answer
    end
}

Measured memory_bytes: 8716
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define sz(x) (long long)x.size()
#define int long long
int a[105];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n, s = 0;
	cin >> n;
	for(int i = 0; i < 2 * n; i++)
		cin >> a[i];
	sort(a , a + 2 * n, greater < int > ());
	for(int i = 1; i < 2 * n; i += 2){
//		cout << a[i] << endl;
		s += a[i];
	}
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 256
let n, t, a = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let hs = Array.init n @@ fun i -> Scanf.scanf " %d" @@ fun a -> a, i + 1
let f x = abs @@ 1000 * t - 6 * x - 1000 * a
let _ = Array.fold_left (fun m (h, i) -> min m (f h, i)) (max_int, -1) hs |> snd |> Printf.printf "%d\n"

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

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

int sx[10];
int sy[10];

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

	int px, py;
	while(cin >> px >> py, px + py) {
		int n;
		cin >> n;
		for(int i = 0; i < n; i++) {
			cin >> sx[i] >> sy[i];
		}

		int dp[11][10][10] = { 0 };
		dp[0][py][px] = 1;
		for(int i = 0; i < n; i++) {
			for(int x = 0; x < 10; x++) {
				for(int y = 0; y < 10; y++) {
					if(dp[i][y][x] == 0) continue;
					for(int k = 0; k < 12; k++) {
						int nx = x + dx[k], ny = y + dy[k];
						if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
						if(abs(nx - sx[i]) > 1 || abs(ny - sy[i]) > 1) continue;
						dp[i + 1][ny][nx] = 1;
					}
				}
			}
		}

		int ok = false;
		for(int x = 0; x < 10; x++) {
			for(int y = 0; y < 10; y++) {
				if(dp[n][y][x] == 1) {
					ok = true;
				}
			}
		}
		if(ok) {
			cout << "OK" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
int a[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    forn (i, n)
        cin >> a[i];
    int cur = 1;
    ll res = 0;
    forn (i, n) {
        ll steps = (a[i] - 1) / cur;
        res += steps;
        a[i] -= steps * cur;
        if (steps == 0 || cur == 1)
            cur = max(cur, a[i] + 1);
    }
    cout << res << '\n';
}


Measured memory_bytes: 640
#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()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,t,m,n,a)vector<vector<t> > name(m,vector<t> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	int n,m,l;
	std::cin >> n>>m>>l;
	vvector(a,ll,n,m,0);
	vvector(v,ll,m,l,0);
	vvector(b,ll,n,l,0);
	//std::vector<int> v(m);
	rep(i,n)rep(j,m)std::cin >> a[i][j];
	rep(i,m)rep(j,l)std::cin >> v[i][j];
	//rep(i,m)std::cin >> v[i];
	
	rep(i,n)rep(j,l){
		rep(k,m)b[i][j]+=a[i][k]*v[k][j];
	}
	rep(i,n){
		rep(j,l){
			std::cout << b[i][j] ;//<< std::endl;
			if(j!=l-1)std::cout << " " ;//<< std::endl;
		}
		std::cout  << std::endl;
	}
}



Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int main() {
  int a, b, k; cin >> a >> b >> k;

  vector<int> c;
  for(int i=1; i<=max(a, b); i++) {
    if(a%i == 0 && b%i == 0) c.push_back(i);
  }
  cout << c[c.size()-k] << endl;

  return 0;
}







//EOF


Measured memory_bytes: 256
def resolve():
    s = [input() for i in range(3)]
    player_list = ["a", "b", "c"]
    current_card = s[0][0]
    s[0] = s[0][1:]
    # カードは全部で300枚以内
    for i in range(300):
        current_player_index = player_list.index(current_card)

        # カードが0枚で捨てられなければ勝ち
        if len(s[current_player_index]) == 0:
            print(player_list[current_player_index].upper())
            return

        # カードを捨てる
        current_card = s[current_player_index][0]
        s[current_player_index] = s[current_player_index][1:]

resolve()

Measured memory_bytes: 9140
K,N=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A.append(A[0]+K)
i=0
b=0
for i in range(N):
    if b<A[i+1]-A[i]:
        b=A[i+1]-A[i]
print(K-b)

Measured memory_bytes: 25840
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const long long INF = 1LL << 60;

struct Edge {
    long long from;
    long long to;
    long long cost;
    Edge(int s, int d) : to(s),cost(d) {}
};

using Graph = vector<vector<Edge>>;
using Edges = vector<Edge>;
 
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}    
 
/* bellman_ford(Es,s,t,dis)
    入力: 全ての辺Es, 頂点数V, 開始点 s, 最短経路を記録するdis
    出力: 負の閉路が存在するなら ture
    計算量：O(|E||V|)
    副作用：dis が書き換えられる
*/
bool bellman_ford(const Edges &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V, INF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    return (cnt == V);
}

int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>cnt(100010);
    rep(i,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }    
    ll sum = 0;
    rep(i,n) sum += a[i];
    ll q;
    cin >> q;
    vector<ll>b(q),c(q);
    vector<ll>ans(q);
    rep(i,q) {
        cin >> b[i] >> c[i];
        ll tmp = cnt[b[i]];
        cnt[b[i]] = 0;
        sum = sum - b[i] * tmp + c[i] * tmp;
        ans[i] = sum;
        cnt[c[i]] += tmp;
    }
    rep(i,q) {
        cout << ans[i] << endl;
    }
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};


int main() {
    int N,H,W;
    cin >> N >> H >> W;

    int ans=0;
    REP(i,N){
        int h,w;
        cin >> h >> w;

        if(h >= H && w >= W) ans++;
    }

    pl(ans)

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
// const int INF = 1001001001;
const int MOD = 1000000007;

const long long INF = 1e18;

int ans[MAX];

struct dijkstra{
    struct edge {
        int to; long long cost;
        edge(int a, long long b) { to = a; cost = b; }
    };
    
    int V;
    vector<vector<edge>> G;
    vector<long long> d;
 
    dijkstra(int v) {
        V = v;
        G = vector<vector<edge>>(V);
        d = vector<long long>(V);
    }

    void addEdge(int from, int to, long long cost) {
        G[from].emplace_back(edge(to, cost));
    }

    vector<long long>& shortest_path(int s) {
        priority_queue<
            pair<long long, int>,
            vector<pair<long long, int>>,
            greater<pair<long long, int>>
        > que;
        for (long long& i : d) i = INF;
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            auto p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (const edge& e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                    ans[e.to] = v;
                }
            }
        }
        return d;
    }
};

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

    dijkstra d(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        d.addEdge(a, b, 1);
        d.addEdge(b, a, 1);
    }

    auto res = d.shortest_path(0);

    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) cout << ans[i]+1 << endl;
}

Measured memory_bytes: 19084
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define enter "\n"

typedef long long ll;


int abc098_b(){
    //入力
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    
    //処理
    for(int i=1 ; i<n-1 ; i++ ){
        int tmp = 0;
        int str1[26]={};
        int str2[26]={};
        for(int j=0 ; j<i ; j++){
            str1[s[j]-'a']++;
        }
        for(int j=i ; j<n ; j++){
            str2[s[j]-'a']++;
        }
        REP(j,26){
            if(str1[j]>0 && str2[j]>0) tmp++;
        }
        ans = max(tmp , ans);
    }
    
    //出力
    cout << ans << enter;
    return 0;
}

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


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func contain(P []int, x int) bool {
	for _, p := range P {
		if p == x {
			return true
		}
	}
	return false
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func main() {
	var x, n, ans int
	fmt.Scan(&x, &n)
	P := make([]int, n)
	for i := range P {
		fmt.Scan(&P[i])
	}
	diff := 200
	for i := 0; i < 102; i++ {
		if contain(P, i) {
			continue
		}
		if abs(x-i) >= diff {
			continue
		}
		diff = abs(x - i)
		ans = i
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1760
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int a, b, c, tmp;
    cin >> a >> b >> c;
    
    if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    } if(b > c) {
        tmp = b;
        b = c;
        c = tmp;
    } if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll k;
    cin >> k;
    ll cnt = k%10;
    if (cnt%2==0 | cnt%5==0){
        cout << -1 << endl;
        return 0;
    }
    ll a = 7;
    for (ll i=1; i<1e7; i++){
        if (a%k==0){
            cout << i << endl;
            return 0;
        }
        else a = 10*(a%k)+7;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<iterator>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<stack>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);


    long long int n,k,ab;
    cin>>n>>k;
    ab=abs(k-(n%k));
    if(ab>(n%k))cout<<n%k;
    else cout<<ab;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int n,a,b,e,f;
    while(~scanf("%d%d%d",&n,&a,&b))
    {
        int sum=0;
        e=n*a;
        sum=e<b?e:b;
        printf("%d\n",sum);
    }
    return 0;
}


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

bool cmp(const int &a, const int &b){
  return abs(b)>abs(a);
}

int main(){

  int N,L,ans=0;
  cin >> N >> L;
  int a[N];
  for(int i=0; i<N; i++){
    a[i] = L + i;
  }
  sort(a,a+N,cmp);
  for(int i=0; i<N; i++){
    ans += a[i];
  }
  ans -= a[0];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {

  string s;	
  cin >> s;
  for (int i = 0; i<3; ++i)  {
    if (s.substr(i,1)=="7") {
      cout << "Yes" << "\n";
      return 0;
    }
  }
  cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll N=1001;
const ll INF=1e18+7;
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second

class dijkstra{ 
//0indexed 
public: 
	ll v,startv; 
	vector<ll> d; 
	vector<vector<pair<ll,ll> > >e; 

	void initsize(ll n0){ 
		d.resize(n0); 
		for(ll i=0;i<n0;i++)d[i]=INF; 
		vector<pair<ll,ll> > ep; 
		for(ll i=0;i<n0;i++)e.push_back(ep); 
		v=n0; 
	} 

	void initstart(ll s){ 
		startv=s;
		d[s]=0;
	}

	void make_edge(ll x,ll y,ll cost){ 
		e[x].push_back(make_pair(y,cost)); 
		e[y].push_back(make_pair(x,cost)); 
	}

	void make_edgedir(ll x,ll y,ll cost){ 
		e[x].push_back(make_pair(y,cost)); 
	}

	void calcdistance(){ 
		// <-cost,x> 
		//cost startv->x 
		priority_queue<pair<ll,ll> > q; 
		pair<ll,ll> p; 
		vector<bool> did; 
		for(ll i=0;i<v;i++)did.push_back(false); 
		did[startv]=true; 
		for(ll i=0;i<e[startv].size();i++){ 
			p.first=-e[startv][i].second; 
			p.second=e[startv][i].first; 
			q.push(p); 
		}
		while(q.size()!=0){
			pair<ll,ll> p;
			p=q.top();
			q.pop();
			ll x,costsx;
			x=p.second;
			costsx=-p.first;
			if(did[x]==true)continue;
			did[x]=true;
			d[x]=costsx;
			for(ll i=0;i<e[x].size();i++){
				p.first=-(d[x]+e[x][i].second);
				p.second=e[x][i].first;
				if(did[p.second]==false)q.push(p);
			}
		}
	}
};
priority_queue<P> q;
ll n,m,s,t;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	dijkstra d1,d2;
	cin>>n>>m>>s>>t;
	d1.initsize(n+1);
	d2.initsize(n+1);
	FOR(i,0,m){
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		d1.make_edge(u,v,a);
		d2.make_edge(u,v,b);
	}
	d1.initstart(s);
	d2.initstart(t);
	d1.calcdistance();
	d2.calcdistance();
	FOR(i,1,n+1){
		q.push(mp(-d1.d[i]-d2.d[i],i));
	}
	FOR(i,0,n){
		P p = q.top();
		while(p.se<=i){
			q.pop();
			p = q.top();
		}
		ll ans = 1e15;
		ans += p.fi;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 22256
import sys

K, N = map(int, input().split())
P = 998244353


kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+K):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or r < 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


inv_2 = pow(2, P - 2, P)
anss = ''
for i in range(2, 2 * K + 1):
    ans = 0
    n_pair = min((i - 1) // 2, (2 * K - i + 1) // 2)
    out_pair = max(0, K - i + 1, i - K - 1)
    which_use = pow(2, n_pair+1, P)
    for j in range(n_pair + 1):
        if n_pair - j > N:
            which_use = (which_use * inv_2) % P
            continue
        not_use = comb(n_pair, j)
        which_use = (which_use * inv_2) % P
        dice_cnt = comb(N - 1 + out_pair, n_pair - j - 1 + out_pair)
        if i % 2 == 0:
            dice_cnt = (dice_cnt + comb(N - 2 + out_pair,
                                        n_pair - j - 1 + out_pair)) % P
        tmp = (not_use * which_use) % P
        tmp = (tmp * dice_cnt) % P
        ans = (ans + tmp) % P
    anss += str(ans) + '\n'
print(anss.rstrip())


Measured memory_bytes: 77372
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n, k, s;
	cin >> n >> k >> s;
	rep(i, k) {
		cout << s << " ";
	}
	rep(i, n - k) {
		if (s != 1000000000) cout << 1000000000 << " ";
		else cout << 99999999 << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int func( int a ) {
    int i;
    
    for ( i = 1; i <= 8; i++ ) {
        if ( a < 400*i ) { return i; }
    }
    return i;
}


int main() {
    
    int N;
    int a[10] = {0};
    vector<int> A;
    
    int a_min = 0;
    int a_max;
    
    int ncolor_not_over = 0;
    
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
        int temp;
        cin >> temp;
        
        a[func(temp)]++;
    }
    
    for ( int i = 1; i <= 8; i++ ) {
        if ( a[i] ) { ncolor_not_over++;}
    }
    
    if ( ncolor_not_over ) {
        a_min = ncolor_not_over;
    }
    else { a_min = 1; }
    
    
    a_max = ncolor_not_over + a[9];
    
    
    
    
    
    cout << a_min << " " << a_max << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		int n;
		int[] R;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		R = new int[n];
		for(int i = 0; i < n; i++) {
			R[i] = sc.nextInt();
		}
		System.out.println(compute_maxprofit(n,R));
	}
	
	public static int compute_maxprofit(int n, int[] R) {
		int max_profit = R[1] - R[0];
		int min_profit = R[0];
		for(int i = 1; i < n; i++) {
		    if(max_profit < R[i] - min_profit){
		        max_profit = R[i] - min_profit;
		    }
		    if(min_profit > R[i]){
		        min_profit = R[i];
		    }
		}
		return max_profit;
	}
}



Measured memory_bytes: 71008
n = gets.to_i
txy =
  readlines.map do |i|
    i.chomp.split.map(&:to_i)
  end.sort{ |a, b| a[0] <=> b[0] }

can = true
prev = [0,0,0]
txy.each do |ar|
  # t-(x+y)
  cond = (ar[0]-prev[0]) - ((ar[1]-prev[1]) + (ar[2]-prev[2]))
  if cond < 0 || cond % 2 == 1
    can = false
    break
  end
  prev = ar
end
puts can ? 'Yes' : 'No'

Measured memory_bytes: 17512
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

int main(void)
{
	ll n, k, i, ans = 0;

	scanf("%lld %lld" ,&n, &k);

	if (k == 0)
	{
		printf("%lld" ,n * n);
		return 0;
	}

	for (i = k + 1; i <= n; i++)
	{
		ll st = n / i;
		ans += (i - k) * st;
		ll left = st * i + k;

		ans += max(0LL, n - left + 1);
	}

	printf("%lld" ,ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int num_unique (vector<int> s, int n, int j) {
    map<int, int> mat;
    FOR(i, j, n) {
        mat[s[i]] = 1;
    }
    ll ans = 0;
    REP(i, 9) {
        ans += mat[i];
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    string S;
    cin >> S;
    vector<int> s(n);
    REP(i, n) {
        s[i] = S[i] - '0';
    }
    int ans = 0;
    REP(j, 1000){
        int i = j;
        int c = i % 10;
        i /= 10;
        int b = i % 10;
        i /= 10;
        int a = i % 10;
        
        int p1 = 1000000, p2 = 1000000, p3 = 1000000;

        REP(i, n) {
            if(s[i] == a) {
                p1 = i;
                //cout << p1 << ' ';
                break;
            }
        }
        FOR(i, p1 + 1, n) {
            if(s[i] == b) {
                p2 = i;
                //cout << p2 << ' ';
                break;
            }
        }
        FOR(i, p2 + 1, n) {
            if(s[i] == c) {
                p3 = i;
                ans += 1;
                //cout << p3 << endl;
                break;
            }
        }
        
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};

bool tpz(vector<vector<edge>> g, vector<pair<int,int>>& ans) {
    int v = g.size(); ans.clear();
    VI in(v, 0);
    for (auto es : g)for (edge e : es)in[e.to]++;
    set<int> set;
    FOR(i, 0, v)if (in[i] == 0) {
        set.insert(i);
        ans.push_back({ i, -1 });
    }

    while (!set.empty()) {
        int now = *set.begin(); set.erase(now);
        for (edge next : g[now]) {
            if (--in[next.to] == 0) {
                set.insert(next.to);
                ans.push_back({ next.to,now });
            }
        }
    }
    return v == ans.size();
}

int main() {
    init();

    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    int a, b;
    FOR(i, 0, n - 1 + m) {
        cin >> a >> b;
        g[--a].push_back({ a,--b });
    }

    vector<pair<int,int>> ans;
    if (tpz(g, ans)) {
        SORT(ans);
        FOR(i, 0, n)cout << ans[i].second + 1 << "\n";
    }
    else cout << "-1\n";
}


Measured memory_bytes: 13908
#include <climits>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int val = r * 100 + g * 10 + b;
    cout << ((val % 4) ? "NO" : "YES") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define zrep(i, a, b, c) for (int i = int(a); i < int(b); i+=int(c))
using ll = long long;
const int INF = 1001001001;

void SelectionSort(vector<int> &A) {
    int N = A.size();
    int cnt = 0;
    for(int i=0; i<N; i++) {
        int minj = i;
        for(int j=i+1; j<N; j++) {
            if(A[minj]>A[j]) {
                minj = j;
            }
        }
        if(i!=minj) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }
    
    print(A);
    print(cnt);
} 



int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    SelectionSort(A);
    return 0;
}


Measured memory_bytes: 3088
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  string s;
  cin >> s;
  int n = s.size(), ret = 0;
  for (int i = 0, j; i < n; i = j) {
    for (; i < n && s[i] == 'S'; ++i);
    if (i == n) break;
    for (j = i + 1; j < n && s[j] == 'R'; ++j);
    ret = max(ret, j - i);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3168
def main():
    n = int(input())
    s = str(n)
    if s[-1] == '2' or s[-1] == '4' or s[-1] == '5' or s[-1] == '7' or s[-1] == '9':
        print('hon')
        return
    if s[-1] == '3' :
        print('bon')
        return
    print('pon')
if __name__=='__main__':
    main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll h, w, d;
	cin >> h >> w >> d;
	vector<vector<ll>> a(h, vector<ll>(w));
	map<ll, vector<ll>> mp;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> a[i][j];
			a[i][j]--;
			mp[a[i][j]] = {i, j};
		}
	}

	vector<vector<ll>> sum(d, vector<ll>(h * w / d + 2, 0));
	for (ll i = 0; i < d; i++) {
		for (ll j = i; j < h * w - d; j += d) {
			ll x = abs(mp[j][0] - mp[j + d][0]) + abs(mp[j][1] - mp[j + d][1]);
			sum[i][j / d + 1] = x;
		}
	}

	for (ll i = 0; i < d; i++) {
		for (ll j = 1; j < h * w / d + 2; j++) {
			sum[i][j] += sum[i][j - 1];
		}
	}

	ll q;
	cin >> q;
	while (q--) {
		ll l, r;
		cin >> l >> r;
		l--; r--;
		ll i = l % d;
		cout << sum[i][r / d] - sum[i][l / d] << endl;
	}
}


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

#define ll long long

void solve() {
	int n;
	cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	ll amt = 1000, stc;
	for (int i = 0; i < n; ++i) {
		ll j = i;
		while (v[i] <= v[i + 1] && i < n - 1) i++;
		if (i != j) {
			stc = amt / v[j];
			amt -= stc * v[j];
			amt += stc * v[i];
		}
	}
	cout << amt;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	while (t--)
		solve();
}

Measured memory_bytes: 3660