akhauriyash/Code-Regression huggingface dataset:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
H = LI()
H.sort()
ans = 0
if K >= len(H):
    print(0)
    sys.exit()

if K == 0:
    print(sum(H))
else:
    print(sum(H[:-K]))


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

using ll = long long;
using ld = long double;
using Graph = vector<vector<ll>>;

int main(void)
{
    ll x,money,count=0;
    cin >> x;
    money=100;
    while(money<x)
    {
        money+=money/100;
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3636
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    sum_a = sum(a)
    si = sum_a / (4*m)
    aa = [ea for ea in a if ea >= si]
    if len(aa) >= m:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int64_t arc062a()
{
    size_t n;
    cin >> n;
    vector<array<int64_t, 2>> arr(n);
    cin >> arr;

    array<int64_t, 2> x({1, 1});

    for(const auto & a: arr)
    {
        const auto x0 = x[0] + (a[0] - x[0] % a[0]) % a[0];
        const auto x1 = x0 / a[0] * a[1];

        const auto y1 = x[1] + (a[1] - x[1] % a[1]) % a[1];
        const auto y0 = y1 / a[1] * a[0];

        if(x1 < x[1])
            x = {y0, y1};
        else if (y0 < x[0])
            x = {x0, x1};
        else if (x0 + x1 < y0 + y1)
            x = {x0, x1};
        else
            x = {y0, y1};

        DEBUG(x);
    }

    return x[0] + x[1];
}

int main(const int argc, char * argv [])
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << arc062a();

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
def D():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    town = 1
    visited = {}
    count = 0
    while town not in visited:
        visited[town] = count
        if count == K:  #ends before cycle ends
            print(town)
            return
        town = A[town-1]
        count += 1
    start_of_cycle = visited[town]
    end_of_cycle = count
    length_of_cycle = end_of_cycle - start_of_cycle
    to_go = (K - end_of_cycle)%length_of_cycle
    # print(start_of_cycle, end_of_cycle, length_of_cycle, to_go)
    for i in range(to_go):
        town = A[town-1]
    print(town)
D()

Measured memory_bytes: 32276
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll 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 * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	return c - '0';
}
int keta(int a) {
	return to_string(a).size();
}
int a[200010], b[200010];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	b[0] = a[0];
	loop(i,1,n) {
		if (a[i] < b[i - 1]) b[i] = a[i];
		else b[i] = b[i - 1];
	}
	int ans = 0;
	rep(i, n) {
		if (a[i] <= b[i])ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

#define INF 1<<20
#define MAX_V 20

bool done[MAX_V];
int d[MAX_V];
int V;
int cost[MAX_V+1][MAX_V+1];

int dijkstra(int s, int t) {
  fill(done, done+V, false);
  fill(d, d+V, INF);
  
  d[s] = 0;

  while(1) {
    int v = -1;
    for(int u = 0; u < V; u++) {
      // find minimum
      if(!done[u] && ( v == -1 || d[u]<d[v] )) {
	v = u;
      }
    }
    if(v == -1) break;

    done[v] = true;

    // relax
    for(int u = 0; u < V; u++) {
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
  
  return d[t];
}

/*
struct edge{ int to, cost; };

typedef pair<int, int> Pii; // cost, vertex

int V;
int d[MAX_V];

vector<edge> G[MAX_V];

void dijkstra(int s) {
  priority_queue<Pii> Q;
  fill(d, d+V, INF);
  d[s] = 0;
  Q.push(Pii(0, s));

  while(!Q.empty()) {
    Pii p = Q.top(); Q.pop();
    int v = p.second;
    
    if(d[v] < p.first) continue;
    
    for(int i=0; i<G[v].size(); i++) {
      edge e = G[v][i];
      
      if(d[i] > d[v]+e.cost) {
	d[i] = d[v]+e.cost;
	Q.push(Pii(d[i], e.to));
      }
    }
  }
}

*/

int main() {
  
  int m;
  cin >> V >> m;
  char dd;

  fill(cost[0], cost[MAX_V], INF);
  
  for(int i=0; i<m; i++) {
    int a, b, c, d;
    cin >> a >> dd >> b >> dd >> c >> dd >> d;
    a--, b--;
    cost[a][b] = c;
    cost[b][a] = d;
  }
  
  int x1, x2, y1, y2;
  cin >> x1 >> dd >> x2 >> dd >> y1 >> dd >> y2;
  int ret = y1-y2;

  x1--, x2--;
  ret -= dijkstra(x1, x2);
  ret -= dijkstra(x2, x1);
  
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve()
{
 int r,b,g;cin>>r>>g>>b;
 int k;cin>>k;
 int count=0;
 while(g<=r)
 {
     count++;
     g*=2;
 }
 while(b<=g)
 {
     count++;
     b*=2;
 }
 if(count<=k)
 cout<<"Yes"<<endl;
 else
 cout<<"No"<<endl;
}

int32_t main()
{
    rapido;
    int t;
    //cin>>t;
    t=1;
    
   while(t--)
   solve();
}





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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(9);
    /*start*/
    int x;
    cin>>x;
    if (x>=30) {
        c("Yes");
    }
    else c("No");
}


Measured memory_bytes: 3628
n = int(input())
taro = 0
hanako = 0
for i in range(n):
    s = input().split()
    card_taro = s[0]
    card_hanako = s[1]
    s_sorted = sorted(s)
    if card_taro == card_hanako:
        taro = taro + 1
        hanako = hanako+1
    elif s_sorted.index(card_taro) > s_sorted.index(card_hanako):
        taro = taro + 3
    elif s_sorted.index(card_taro) < s_sorted.index(card_hanako):
        hanako = hanako + 3
    
print(f"{taro} {hanako}")



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

using namespace std;

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

      int i,j,k=1,l=2;;

      for(i=0;i<3;i++)
      {
         if(a[i]!=b[l]){
            k=0;
            break;
         }
          l--;
      }

      if(k==1)puts("YES");else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  
  int ans = 0;
  int max_count = 0;
  for(int i = 1; i <= n; i++){
    //printf("i=%d\n",i);
    int tmp = i;
    int count = 0;
    while(tmp%2 == 0){
      count++;
      tmp /= 2;
    }
    
    //printf("count=%d\n",count);
    if(max_count <= count){
      max_count = count;
      ans = i;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b=0,c=INT_MAX,e=0;cin>>a;
  vector<ll>d(a);
  rep(i,a){
    cin>>d[i];
    b+=d[i];
  }
  for(ll i=0;i<a-1;i++){
    e+=d[i];
    c=min(c,abs(b-e*2));
    //cout<<e;
  }
  cout<<c;
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, d, x, a;
  cin >> n >> d >> x;
  int ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    ans += 1 + (d - 1) / a;
  }
  cout << ans + x;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3648
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def main():
    MOD = 10 ** 9 + 7

    N, M = map(int, input().split())

    def decom(n) -> list:  # 恐らく因数分解がTLEの原因->1/2乗で打ち切り
        ret = []

        x = n
        d = 2
        cnt = 0
        while x % d == 0:
            x //= d
            cnt += 1
        ret.append(cnt)

        d = 3
        while d * d <= n:
            cnt = 0
            while x % d == 0:
                x //= d
                cnt += 1
            ret.append(cnt)
            d += 2

        if x > 1:
            ret.append(1)

        return ret

    dlis = decom(M)

    cal = Calc(max_value=N + 30, mod=MOD)

    ans = 1
    for cnt in dlis:
        ans = (ans * cal.combination(N + cnt - 1, cnt)) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12916
#include <stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	if( a+b+c == 17 )
		printf("YES\n");
	else
		printf("NO\n");
	
	return 0;
}


Measured memory_bytes: 760
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<=0&&b>=0){
    cout<<"Zero"<<endl;
  }
  else if(a>0&&b>0){
    cout<<"Positive"<<endl;
  }
  else if(a<0&&b<0&&(b-a)%2==0){
    cout<<"Negative"<<endl;
  }
  else{
    cout<<"Positive"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>>hito(n);
    for(int i=0;i<n;i++){
        int z;
        cin >> z;
        for(int j=0;j<z;j++){
            int a,aa;
            cin >> a >> aa;
            a--;
            hito.at(i).push_back(make_pair(a,aa));
        }//○○の人が××の人を正直者or不親切な人なのか分かる表づくり
    }
    int res = 0;//正直者の人数。
    for(int bit=0;bit<(1<<n);bit++){//全ビット探索。
    bool ans = true;
    int q = 0;
        for(int i=0;i<n;i++){//各ビットが立っているか判断。
            if(bit&(1<<i)){
                q++;
                for(int j=0;j<hito.at(i).size();j++){
                    int to = hito.at(i).at(j).first;
                    bool che = hito.at(i).at(j).second;
                    if(che&&!(bit&(1<<to)))ans=false;
                    if(!che&&(bit&(1<<to)))ans=false;
                }
            }
        }
        if(ans){//矛盾がなければ
            res = max(res,q);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;

vector<int> v[mx];
vector<vector<ll>> dp(mx, vector<ll>(2,0));

void dfs(int x, int p){
  dp[x][0]=dp[x][1]=1;
  for(auto to:v[x]){
    if(to==p){ continue; }
    dfs(to,x);
    (dp[x][0]*=(dp[to][0]+dp[to][1]))%=mod;
    (dp[x][1]*=dp[to][0])%=mod;
  }
}

int main(){
  int n;
  cin >> n;
  rep(i,n-1){
    int x,y; cin>>x>>y; x--; y--;
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  dfs(0,-1);
  ll ans = (dp[0][0]+dp[0][1])%mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18176
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}

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

int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	ll sum = 0;
	REP(i, n) {
		int a;
		cin >> a;
		sum += min(abs(k - a), abs(a));
	}
	cout << sum * 2 << endl;
}



Measured memory_bytes: 256
s = input()
ansi = 0
ansj = 0
for i in range(len(s)):
    if s[i] == 'A':
        ansi = i
        break
for j in range(len(s)-1, -1, -1):
    if s[j] == 'Z':
        ansj = j
        break
print(j - i + 1)


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

int N = 0;
pair<int, int> _list[3020];
set< pair<int, int> > point;

void init() {
  N = 0;
  for (int i = 0; i < 3020; i++) _list[i] = pair<int, int>(0, 0);
  point.clear();
}

bool input() {
  init();
  cin >> N;
  if (!N) return false;
  for (int i = 0; i < N; i++) {
    int x = 0;
    int y = 0;
    cin >> x >> y;
    _list[i] = pair<int, int>(x, y);
    point.insert(_list[i]);
  }
  sort(_list, _list+N);
  return true;
}

bool pointCheck(int elemNo1, int elemNo2, pair<int, int>* P2, pair<int, int>* P3) {
  pair<int, int> _point[4];
  _point[0] = _list[elemNo1];
  _point[1] = _list[elemNo2];
  int A = _point[0].first;
  int B = _point[0].second;
  int X = _point[1].first;
  int Y = _point[1].second;
  int P0x = A-(abs(B-Y));
  int P0y = B+(abs(A-X));
  int P1x = X-(abs(B-Y));
  int P1y = Y+(abs(A-X));
  if (P0x > 5000 || P0y > 5000 || P1x > 5000 || P1y > 5000) {
    P0x = A+(abs(B-Y));
    P0y = B-(abs(A-X));
    P1x = X+(abs(B-Y));
    P1y = Y-(abs(A-X));
  }
  _point[2] = pair<int, int>(P0x, P0y);
  _point[3] = pair<int, int>(P1x, P1y);
  for (int i = 2; i < 4; i++) {
    set< pair<int, int> >::iterator _iterator = point.find(_point[i]);
    if (_iterator == point.end()) {
      *P2 = pair<int, int>(0, 0);
      *P3 = pair<int, int>(0, 0);
      return false;
    }
  }
  *P2 = _point[2];
  *P3 = _point[3];
  return true;
}

int calcSquare(int elemNo1, int elemNo2) {
  int A = _list[elemNo1].first;
  int B = _list[elemNo1].second;
  int X = _list[elemNo2].first;
  int Y = _list[elemNo2].second;
  return (int)(pow(A-X, 2)+pow(B-Y,2));
}

int solve() {
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      pair<int, int> P[2];
      if (pointCheck(i, j, &P[0], &P[1])) {
        ans = max(ans, calcSquare(i, j));
      }
    }
  }
  return ans;
}

int main() {
  while (input()) {
    printf("%d\n", solve());
  }
  return 0;
}



Measured memory_bytes: 3292
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  // ans = sum of "vertex - edge"
  ll vertex = 0; // sum of vertex in (L,R)
  rep(i,n) {
    vertex += (i+1)*(n-i); // pick "i+1" from left, "n-i" from right
  }
  ll edge = 0; // sum of edge in (L,R)
  rep(iter,n-1) {
    ll u,v;
    cin >> u >> v;
    if (u > v) { swap(u,v); }
    // Here, u <= v
    edge += u*(n-v+1); // pick "u" from left, "n-v+1" from right
  }

  ll ans = vertex - edge;
  cout << ans << endl;
}


Measured memory_bytes: 3500
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <regex>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stack>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main () {
    ll N;
    cin >> N;
    vector<ll> p(N);
    vector<ll> q(N);
    iota(q.begin(), q.end(), 1);
    for(auto &a:p) cin >> a;
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(p[i] == q[i]) {
            ans++;
            if(i != N - 1) {
                ll tmp;
                tmp = p[i + 1];
                p[i + 1] = p[i];
                p[i] = tmp;
            }else {
                
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())
*A, = map(int, input().split())

def check(K):
    st = []
    for i, a in enumerate(A):
        #print(K, i, st, a)
        while st and a < st[-1][0]:
            st.pop()
        u = i > 0 and A[i-1] >= A[i]
        if not st:
            st.append([a, u])
            continue
        l = st[-1]
        if l[0] == a:
            l[1] += 1
            while st and l[1] == K:
                st.pop(); a -= 1
                if a == 0:
                    return 0
                if not st:
                    st.append([a, 1])
                    break
                l = st[-1]
                if l[0] == a:
                    l[1] += 1
                else:
                    st.append([a, 1])
                    break
            #print(l, st)
        else:
            st.append([a, u])
    #print(st)
    return 1

ok = 1
for i in range(N-1):
    if not A[i] < A[i+1]:
        ok = 0
if ok:
    print(1)
    exit(0)

left = 1; right = N+1
while left+1 < right:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 128608
#include<stdio.h>
int main()
{
int tc;
scanf("%d", &tc);
int AC=0,WA=0,TLE=0,RE=0;
for(int i=0; i < tc ; i++)
{
	char verdict[100];
	scanf("%s", verdict);
    if(verdict[0] == 'A')
	{
        AC++;
    }
    else if(verdict[0] == 'W')
	{
        WA++;
    }
    else if(verdict[0] == 'T')
	{
        TLE++;
    }
    else if (verdict[0] == 'R')
	{
        RE++;
    }
}
printf("AC x %d\n", AC);
printf("WA x %d\n", WA);
printf("TLE x %d\n", TLE);
printf("RE x %d\n", RE);
return 0;
}

Measured memory_bytes: 1708
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	int n;

	scn(n);

	ll ans=(n/500)*1LL*1000;

	n-=(n/500)*500;

	//cout<<n<<endl;

	ans+=(n/5)*5LL;

	lpri(ans);

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Main
//
//  Created by 田村雄太 on 2016/10/23.
//  Copyright © 2016年 田村雄太. All rights reserved.
//
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision

typedef long long ll;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}

int main(){
    omajinai();
    
    string s;
    cin>>s;
    bool hasC =false;
    for (char c: s){
        if(hasC && c == 'F') {
            cout<<"Yes"<<endl;
            return 0;
        }
        if(c == 'C') hasC = true;
    }
    cout<<"No"<<endl;
}

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

const int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> hs(n);
  rep(i, n) {
    cin >> hs.at(i);
  }

  vector<int> dps(n, INF);
  dps.at(0) = 0;
  dps.at(1) = abs(hs.at(1) - hs.at(0));
  rep(i, n) {
    if (i == 0 || i == 1) {
      continue;
    }
    for (int j = 1; j <= k; j++) {
      if (i - j < 0) {
        break;
      }
      dps.at(i) = min(dps.at(i), abs(hs.at(i) - hs.at(i - j)) + dps.at(i-j));

      // cout << dps.at(i) << endl;
    }
  }

  // rep(i,n) {
  //   cout << dps.at(i) << endl;
  // }


  cout << dps.at(n-1) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		if (i & 1)
			++cnt;
	cout << fixed << setprecision(7) << (double)cnt / n << '\n';
	return 0;
}

Measured memory_bytes: 384
#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();}

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef pair<int, int> Pii;
typedef struct{ int x, y; } Point;
const int INF = 1001001001;

int K, T;
vector<int> a;

int main(void)
{
    scanf("%d %d", &K, &T);
    for(int i = 0; i < T; i++){
        int t;
        cin >> t;
        a.push_back(t);
    }

    if(T == 1){
        printf("%d\n", a[0] -1);
        return 0;
    }
    
    int mi = 0;

    sort(a.begin(), a.end());
    for(int i = 0; i < K; i++){

        if(i%2==0){
            a[T-1]--;
            if(a[T-2] == 0){
                break;
            }
        }
        else{
             a[T-2]--;
             sort(a.begin(), a.end());
        }
    }
    printf("%d\n", a[T-1]);


    return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, x, y int
	fmt.Scan(&n, &x, &y)
	distanceMap := map[int]int{}
	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			orig := float64(j - i)
			viaX := math.Abs(float64(x-i)) + 1 + math.Abs(float64(y-j))
			distanceMap[int(math.Min(orig, viaX))]++
		}
	}
	io, flush := NewIO()
	defer flush()
	for i := 1; i < n; i++ {
		io.Println(distanceMap[i])
	}
}

func CombCount(left int, right int) int {
	rightFac := Factorial(right, right)
	if rightFac <= 0 {
		return 0
	}
	return Factorial(left, right) / rightFac
}

// Factorial returns factorial (n P times)
func Factorial(n int, times int) (res int) {
	facts := make([]int, n+1)
	if facts[n] != 0 {
		res = facts[n]
		return res
	}

	if n > 0 && times > 0 {
		res = n * Factorial(n-1, times-1)
		return res
	}

	return 1
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int n;
vi hi;
vi dp(100005, INT_MAX);

void printt(){
    dp[n]=0;
    dp[n-1]=abs(hi[n-2]-hi[n-1]);
    for(int i=n-2;i>0;i--) {
        dp[i] = min(abs(hi[i-1]-hi[i])+dp[i+1], abs(hi[i-1]-hi[i+1])+dp[i+2]);
    }
    cout<<dp[1]<<endl;
}

void take_inp() {
    cin>>n;
    hi.resize(n);
    fo(i,n){
        int temp;
        cin>>temp;
        hi[i]=temp;
    }
    // cout<<"done"<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    take_inp();
    printt();
    return 0;
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    N, W = map(int, input().split())
    wv = [tuple(map(int, input().split())) for i in range(N)]

    dp = [-1]*(10**3 * N + 1)
    dp[0] = 0
    ans = 0
    for w, v in wv:
        for j in range((10**3 * N) - v, -1, -1):
            if dp[j] >= 0 and dp[j] + w <= W:
                if dp[j+v] < 0 or dp[j+v] > dp[j] + w:
                    dp[j+v] = dp[j] + w
                if ans < j+v:
                    ans = j+v
    print(ans)


main()


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N, 0);
  int d, Ad;
  for (int i = 0; i < K; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> Ad;
      A.at(Ad - 1)++;
    }
  }
  int cnt = 0;
  for (int i = 0; i < A.size(); i++) {
    if (A.at(i) == 0) cnt++;
  }
  cout << cnt << endl;
}


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

int main() {
  string a,b;
  cin >> a >> b;
  for(int i=0;i<3;i++){
    if(a.at(i) != b.at(2-i)){
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N), B(N), C(N);
  
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  for (int i = 0; i < N; i++) cin >> C.at(i);
  
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());
  
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int key = B.at(i);
    ll x = lower_bound(A.begin(), A.end(), key) - A.begin();
    ll y = upper_bound(C.begin(), C.end(), key) - C.begin();
    ans += x * (N - y);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC target ("avx")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

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;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)res=res*x%m;
		y>>=1;x=x*x%m;
	}
	return res;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int ans[100001];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	int res=0;
	for(int i=K;i>0;i--){
		int j=K/i;
		int k=mod_pow(j,N);
		REP(j,K+1){
			if(i*j>K)break;
			k-=ans[i*j];
			k=(k+mod)%mod;
		}
		ans[i]=k;
		res+=k*i;res%=mod;
	}
	cout<<res<<"\n";
}


Measured memory_bytes: 4432
#include <iostream>
#include <algorithm>

#define int long long

using namespace std;

signed main(){
    int n, a, b, c, d[10002] = {0};
    cin >> n >> a >> b >> c;
    for(int i = 0; i < n; ++i){
        cin >> d[i];
    }

    sort(d, d + n, greater<int>());
    int max = 0, cal = c;

    for(int i = 0; i < n; ++i){
        c += d[i];
        int t = c / (a + b * (i + 1));
        if(max < t) max = t;
    }

    cout <<  max << endl;
    return 0;
}

Measured memory_bytes: 1252
// Michael Pfeifer
// Version 04, 2018/02/17

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ld  pi   = 4.0*atanl(1.0);
const int iinf = 1e9 + 10;
const ll  inf  = 1e18 + iinf + 10;
const int mod  = 1000000007;
const ld  prec = .000001;

#define enld endl
#define pb push_back
#define debug(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define umap unordered_map
#define uset unordered_set

template<class TIn>
using indexed_set = tree<
        TIn, null_type, less<TIn>,
        rb_tree_tag, tree_order_statistics_node_update>;

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

void file() {
    auto a = freopen("a.in",  "r", stdin);
    auto b = freopen("a.out", "w", stdout);
    if(!a || !b) cout << "uh oh" << endl;
}





string s;

vector<pair<int,int>> edges;
vector<bool> selfloop;
vector<vector<int>> adj;
vector<bool> valid;

bool both(int curr) {
    bool a = false;
    bool b = false;
    for(auto next : adj[curr]) {
        if(valid[next]) {
            if(s[next] == 'A') a = true;
            if(s[next] == 'B') b = true;
        }
    }

    return a && b;
}

int main() {
    //file();
    //fast();

    int n, m;
    cin >> n >> m;
    cin >> s;

    selfloop.resize(n, false);
    adj.resize(n);
    valid.resize(n, true);

    for(int i = 0; i < m; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--; n2--;

        edges.pb({n1,n2});
        if(n1 == n2) selfloop[n1] == true;

        adj[n1].pb(n2);
        adj[n2].pb(n1);
    }

    queue<int> removal;
    for(int i = 0; i < n; i++) {
        if(!both(i)) {
            removal.push(i);
        }
    }

    int removed = 0;
    while(!removal.empty()) {
        int curr = removal.front();
        removal.pop();

	if(!valid[curr]) continue;
	valid[curr] = false;
        removed++;

        for(auto next : adj[curr]) {
            if(!valid[next]) continue;

            if(!both(next)) {
                removal.push(next);
            }
        }
    }

    if(removed < n) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 12148
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e17;
const ll N = 2e5+100;
const ll bits = 35;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;
 

int main(){
    FASTIO;
    PRECISION;

    ll n,a,b;

    cin>>n>>a>>b;

    ll ans = n/(a+b);
    n-=ans*(a+b);
    ans*=a;
    ans+=min(a,n);
    cout<<ans<<"\n";




    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char a[10000],b[10000],c[10000];
int i,j,k,l,m,n;

int main(){
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
k=strlen(a);
l=strlen(b);

if(a[k-1]==b[0]&&b[l-1]==c[0])
    printf("YES\n");
else
    printf("NO\n");
    return 0;


}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
  if (x == 0) return 1;
  if (fact_memo[x]) return fact_memo[x];
  return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 fact_inv(i64 x) {
  return ipow(fact(x), mod - 2);
}
i64 perm(i64 a, i64 b) {
  return fact(a) * fact_inv(a - b) % mod;
}
i64 conb(i64 a, i64 b) {
  return fact(a) * fact_inv(b) % mod * fact_inv(a - b) % mod;
}

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

  i64 ans = 0;
  for (i64 i = 0; i < 2; ++i) {
    for (i64 d = 1; d < m; ++d) {
      ans = (ans + 
          (m - d) * n * n % mod * conb(n * m - 2, k - 2) % mod * d % mod)
          % mod;
    }
    swap(n, m);
  }
  cout << ans << '\n';
  return 0;
}


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

int H, W;

bool outOfBound(int i, int j) {
    return i < 0 || i >= H || j < 0 || j >= W;
}

int main() {
    int CH, CW, DH, DW;
    cin >> H >> W >> CH >> CW >> DH >> DW;
    CH--, CW--, DH--, DW--;

    vector<string> S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }

    int cost[H][W];
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cost[i][j] = 1e7;
        }
    }

    map<pair<int, int>, bool> MAP_MOVE_A;
    MAP_MOVE_A[{-1, 0}] = true;
    MAP_MOVE_A[{0, -1}] = true;
    MAP_MOVE_A[{1, 0}] = true;
    MAP_MOVE_A[{0, 1}] = true;

    deque<pair<int, int> > dq;
    cost[CH][CW] = 0;
    dq.push_back({CH, CW});
    while(!dq.empty()) {
        pair<int, int> cur = dq.front();
        dq.pop_front();
        if(cur.first == DH && cur.second == DW) {
            break;
        }

        for(int di = -2; di <= 2; di++) {
            for(int dj = -2; dj <= 2; dj++) {
                int i = cur.first + di;
                int j = cur.second + dj;

                if(outOfBound(i, j) || S[i][j] == '#' || (di == 0 && dj == 0)) continue;

                int magic = 1;
                if(MAP_MOVE_A.find({di, dj}) != MAP_MOVE_A.end()) {
                    magic = 0;
                }

                if(cost[cur.first][cur.second] + magic < cost[i][j]) {
                    cost[i][j] = cost[cur.first][cur.second] + magic;
                    if(magic == 0) {
                        dq.push_front({i, j});
                    } else {
                        dq.push_back({i, j});
                    }
                }
            }
        }
    }

    if(cost[DH][DW] == 1e7) {
        cout << -1 << endl;
    } else {
        cout << cost[DH][DW] << endl;
    }
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int res = 0;
    vector<int> cnt(MAX);
    rep (i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int even = 0;
    rep (i, MAX) {
        if (!cnt[i]) continue;
        if (cnt[i] % 2 == 0) even++;
        res++;
    }
    if (even % 2) res--;
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 4224
N = 1_000_000

def unbounded_knapsack(items, budget)
	table = [0]
	items.sort_by!(&:first)
	valid_items = []
	for i in 1..budget
		table[i] = -Float::INFINITY
		valid_items << items.shift while !items.empty? && items[0][0] <= i
		valid_items.each{|c, v|
			x = table[i-c] + v
			table[i] = x if x > table[i]
		}
	end
	table
end

t = -> n { n * (n+1) * (n+2) / 6 }
n = 1
items = []
odd_items = []
while t[n] < N
	items << [t[n], -1] 
	odd_items << items[-1]  if items[-1][0].odd?
	n += 1
end

pollock = unbounded_knapsack(items, N)
odd_pollock = unbounded_knapsack(odd_items, N)

loop do
	n = gets.to_i
	break if n == 0
	puts [-pollock[n], -odd_pollock[n]] * ' '
end

Measured memory_bytes: 24520
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    vector<int> arr(100000, 0);
    int n, min_ = 100000, max_ = 0, input, ret, sum;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> input;
        arr[input]++;
        if( input < min_) min_ = input;
        if(max_ < input) max_ = input;
    }
    ret = 0;
    if(max_ - min_ < 2){
        cout << n << endl;
        return 0;
    }

    for(int i = min_; i <= max_ - 2; i++){
        sum = arr[i] + arr[i + 1] + arr[i + 2];
        if(ret < sum) ret = sum;
    }
    cout << ret << endl;;
    return 0;
}


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

char isprime[10000001];

int main() {
  memset(isprime, 0, sizeof(isprime));
  for(int i=4; i<10000001; i+=2) isprime[i] = 1;
  for(int i=3; i*i<10000001; i+=2)
    if(isprime[i] == 0)
      for(int j=2; i*j<10000001; ++j) isprime[i*j] = 1;

  int n;
  while(cin>>n, n) {
    for(int i=n; i>=13; --i) {
      if(isprime[i] == 0 && isprime[i-2] == 0
	 && isprime[i-6] == 0 && isprime[i-8] == 0) {
	cout<<i<<endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 10000
#include <iostream>
#include <vector>

using namespace std;

struct Node
{
    vector<pair<int, int>> edges;
    int value = -1;
    bool assigned = false;

    bool Assign(int new_value)
    {
        if (assigned && value != new_value) {
            return false;
        }

        value = new_value;
        assigned = true;
        return true;
    }
};

using Graph = vector<Node>;

bool Dfs(Graph &g, int node)
{
    for (const auto &e : g[node].edges) {
        auto next = e.first;
        auto value = g[node].value + e.second;

        if (g[next].assigned && g[next].value != value) {
            return false;
        }
        if (!g[next].assigned) {
            g[next].Assign(value);
            if (!Dfs(g, next)) {
                return false;
            }
        }
    }
    return true;
}

bool Valid(Graph &g)
{
    for (size_t i = 0; i < g.size(); i += 1) {
        if (g[i].assigned) {
            continue;
        }

        g[i].Assign(0);
        if (!Dfs(g, i)) {
            return false;
        }
    }
    return true;
}

int main()
{
    int nodes, edges;
    cin >> nodes >> edges;

    Graph graph(nodes);
    for (int i = 0; i < edges; i += 1) {
        int a, b, dist;
        cin >> a >> b >> dist;
        graph[a - 1].edges.push_back({b - 1, dist});
        graph[b - 1].edges.push_back({a - 1, -dist});
    }

    cout << (Valid(graph) ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 12416