akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void) {
    
    
    ll ac=0,wa=0;
    ll n,m;
    cin>>n>>m;
    vb v(n,false);
    vi WA(n,0);

    rep(i,m){
        ll p;
        string s;
        cin>>p>>s;
        p--;
        if(v[p])continue;
        if(s=="AC"){
            ac++;
            v[p]=1;
        } else {
            WA[p]++;
        }
    }
    rep(i,n)if(v[i])wa+=WA[i];
    cout<<ac<<" "<<wa<<endl;
    
    
}


Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[i]+a[i])
ans=10**9+10**9+1
for i in range(1,n):
    ans=min(ans,abs(s[n]-s[i]-s[i]))
print(ans)

Measured memory_bytes: 24832
use v6;

my Int $x = get.Int;
my Int $rot = $x div 11;
given $x % 11 {
  when 0 {
    say 2 * $rot;
  }
  when $_ <= 6 {
    say $rot * 2 + 1;
  }
  when (*) {
    say $rot * 2 + 2
  }
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(ll a,b,c;cin>>a>>b>>c && a|b|c;){
		if(a%2==0 || b%2==0 || c%2==0)
			cout<<0<<endl;
		else
			cout<<min({a*b,b*c,c*a})<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll N,A,B; 
int ans[140000][18];
int jun[18];
bool used[140000][18];

int BITS(ll x){
    int ret=0;
    while(x>0){
        if(x%2) ret++;
        x/=2;
    }
    return ret;
}

void kinyu(ll a, ll x){
    rep(i,N) {
        ans[x][i]=a%2;
        a/=2;
    }
    return;
}

void exc(ll i, ll j){
    ans[i][j]=1-ans[i][j];
    return;
}

void solve(ll a, ll b){
    ll A=(a+b)/2;
    ll B=A+1;
    int x=-1,y=-1;
    rep(i,N) if(!used[a][i] && !used[b][i] && ans[a][i]!=ans[b][i]) {x=i; break;}
    REP(i,a,b+1) used[i][x]=true;
    rep(i,N) if(!used[a][i] && !used[b][i]) {y=i;break;}
    rep(i,N) ans[A][i]=ans[a][i];
    exc(A,y);
    rep(i,N) ans[B][i]=ans[A][i];
    exc(B,x);
    return;    
}



int main(){
    cin>>N>>A>>B;
    int a=BITS(A), b=BITS(B);
    rep(i,140000) rep(j,18) ans[i][j]=-1;
    if((a-b)%2==0) cout<<"NO"<<endl;
    else{
        cout<<"YES"<<endl;
        ll MAXN=(1<<N);
        kinyu(A,0);
        kinyu(B,MAXN-1);
        int x=-1;
        rep(i,N) if(ans[0][i]!=ans[MAXN-1][i]) x=i;
        rep(i,N) jun[i]=(x+i)%N;

        rep(i,N-1){
            ll Haba=(1<<(N-i));
            rep(j,(1<<i)) solve(Haba*j, Haba*(j+1)-1);
        }
        rep(i,MAXN) {
            ll kari=0;
            rep(j,N) if(ans[i][j]) kari+=(1<<j);
            cout<<kari<<' ';
        }
        cout<<endl;
        
        
        

    }
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> p(5), t(5);
    for (int i = 1; i <= 4; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= 4; i++) {
        cin >> t[i];
    }
    vector<vector<int>> dp(5, vector<int>(300, 1e9));
    dp[0][0] = 0;
    for (int i = 1; i <= 4; i++) {
        for (int j = 0; j < 300; j++) {
            if (j - t[i] >= 0) {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - t[i]] + p[i]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
        
    int ans = 1e9;
    for (int i = n; i < 300; i++) {
        ans = min(ans, dp[4][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3156
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
a1, a2, *_ = Counter(V[0::2]).most_common() + [(0, 0)]
b1, b2, *_ = Counter(V[1::2]).most_common() + [(0, 0)]
print(N - max(a1[1] + b2[1], a2[1] + b1[1]) if a1[0] == b1[0] else N - (a1[1] + b1[1]))


Measured memory_bytes: 20572
N, A, B = gets.split.map(&:to_i)
H = []
N.times do
  H << gets.to_i
end
H.sort!.reverse!
C = A - B
Cf = C.to_f

tmin = (H.inject(:+) / (N * B + Cf)).ceil

def f(t)
  need = 0
  base = B * t
  H.each do |h|
    x = h - base
    break if x <= 0
    need += (x / Cf).ceil
  end
  need
end

puts (tmin..[tmin, f(tmin)].max).bsearch{|t| f(t) <= t}

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

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    n -= a;
  }
  if (n < 0) n = -1;

  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3604
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for i in range(0, X):
  if i in A:
    B.append(i)
for j in range(X, N):
  if j in A:
    C.append(j)
print(min(len(B), len(C)))

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

int main() {
    string card; cin >> card;
    while(card != "-") {
        int m; cin >> m;
        for (int i = 0; i < m; ++i) {
            int h; cin >> h;
            card = card.substr(h, card.size() - h) + card.substr(0, h);
        }
        cout << card << endl;
        
        cin >> card;
    }
    
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){

    int n,m;

    cin >> n >> m;

    int a[m],b[m];
    
    for(int i=0;i<m;i++)cin >> a[i] >> b[i];

    int A[n+1][n+1];

    for(int i=0;i<n+1;i++){
        for(int j=0;j<n+1;j++){
            A[i][j] = 0;
        }
    }

    for(int i=0;i<m;i++){
            A[a[i]][b[i]]++;
            A[b[i]][a[i]]++;
    }

    int B[n];

    int s=0;

    for(int i=0;i<n;i++)B[i] =i+1;

    do {
        bool is_ok = true;
        for (int i = 0; i < n-1; i++) {
            if(A[B[i]][B[i+1]] == 0){
                is_ok = false ;
                break;
            }
        }
        if(is_ok)s++;
        /*if(is_ok){
            for(int i=0;i<n;i++)cout << B[i] << endl;
        }*/
    } while(next_permutation(B+1, B +n));

    cout << s << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100+10;
int n, t[MAX], wynik;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> t[i];
    sort(t + 1, t + n + 1);
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++)
            for(int k = j + 1; k <= n; k++)
                wynik += (t[k] < t[i] + t[j] && t[k] != t[j] && t[j] != t[i] && t[i] != t[k]);
    cout << wynik << "\n";
}


Measured memory_bytes: 3660
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (intercalate)

main :: IO ()
main = do
  (k : x : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  putStrLn . intercalate " " . map show $ [(x - k + 1)..(x + k - 1)]

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
}p[10];
int a[10];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,m,f=0,h=0;
	cin >> n >> m;
	a[1]=1;
	for(int i=0;i<m;i++){
		cin >> p[i].x >> p[i].y;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			if(p[i].x==p[j].x&&p[i].y!=p[j].y) f=1;
		}
		if(p[i].x==1){
			if(p[i].y==0 && n!=1) f=1;
		}
		a[p[i].x]=p[i].y;
	}
	if(n==1&&m==0) cout << 0 << endl;
	else if(f==1) cout << -1 << endl;
	else if(f==0){
		for(int i=1;i<=n;i++){
			cout << a[i] ;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a, b;
  for(int i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if(tmp < 0) {
      b.push_back(tmp);
    } else {
      a.push_back(tmp);
    }
  }
  sort(a.rbegin(), a.rend());
  sort(b.begin(), b.end());
  if(b.size() == n) {
    if(k % 2 != 0) {
      reverse(b.begin(), b.end());
    }
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= b[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else if(a.size() >= n - 1 && k <= a.size()) {
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= a[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else {
    ll ans = 1;
    vector<ll> c;
    if(b.size() > 1) {
      for(int i = 0; i < b.size() - 1; i += 2) {
        c.push_back(b[i] * b[i + 1]);
      }
    }
    if(b.size() % 2 != 0) {
      c.push_back(*(b.end() - 1));
    }
    int ac = 0, cc = 0;
    for(int i = 0; i < k; i++) {
      if((a[ac] * a[ac + 1] < c[cc] && i < k - 1) || ac >= a.size()) {
        c[cc] %= MOD;
        ans *= c[cc];
        ans %= MOD;
        i++;
        cc++;
      } else {
        ans *= a[ac];
        ans %= MOD;
        ac++;
      }
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 6552
x, n = map(int, input().split())

if n == 0:
    print(x)
    exit()

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

left = 0
right = 101

i = 1
while i <= x:
    if i not in p:
        left = i
    i += 1
while right == 101:
    if i not in p:
        right = i
        break
    i += 1

if x - left <= right - x:
    print(left)
else:
    print(right)


Measured memory_bytes: 9136
## coding: UTF-8


H,W = map(int,input().split())

c = []
for i in range(H):
    c.append(input())

fresh = [True] * (H*W)
#print(fresh)


queue = []
n = []
for i in range(H):
    for j in range(W):
        if(c[i][j] == '#'):
            fresh[i*W+j] = False
            queue.append(i*W+j)
#print('initial')
#print('fresh:{}'.format(fresh))
#print('queue:{}'.format(queue))

step = 0
status = True
while status:
    if(len(queue)>0):
        #処理を行う
        pivot = queue.pop()
        #print('pivot:{}, queue:{}, n:{}'.format(pivot, queue, n))        
        #右へ移動
        if(pivot%W != W-1 and fresh[pivot+1]):
            n.append(pivot+1)
            fresh[pivot+1] = False
        #左へ移動
        if(pivot%W != 0 and fresh[pivot-1]):
            n.append(pivot-1)
            fresh[pivot-1] = False
        #下へ移動
        if( int(pivot/W)<(H-1) and fresh[pivot+W]):
            n.append(pivot+W)
            fresh[pivot+W] = False
        #上へ移動
        if( int(pivot/W)>0 and fresh[pivot-W] ):
            n.append(pivot-W)
            fresh[pivot-W] = False
        #print('pivot:{}, queue:{}, n:{}'.format(pivot, queue, n))
    elif(len(n)>0):
        queue = n
        n = []
        #歩数を増やそう
        step += 1
        #print('step{}end,queue:{}, n:{}'.format(step, queue, n))
    else:
        status = False


print(step)


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

bool judge(long long int middle, long long int a, long long int b, vector<long long int>& h){
  int n = h.size();
  long long int sum = 0;
  for(int i = 0; i < n; i++){
    long long int need_a = (h[i] - b * middle + a - b - 1) / (a - b);
    if(need_a > 0){ sum += need_a; }
  }

  return sum <= middle;
}


int main(void){
  long long int n, a, b;
  cin >> n >> a >> b;
  vector<long long int> h(n);
  long long int middle, left = 0, right = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    right = max(right, h[i]);
  }

  while(true){
    middle = (left + right) / 2;
    if(right - left <= 1){ break; }
    
    // もし、合計middle回の爆破で全滅させられるなら
    if(judge(middle, a, b, h)){ right = middle; }
    else{ left = middle; }
  }

  cout << right << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int a,b,buf;
  char str[64];
  while(1){
    if(NULL==fgets(str,64,stdin)) break;
    sscanf(str,"%d %d\n",&a,&b);
    if(a<b){
      buf=a;
      a=b;
      b=buf;
    }
    while(a%b){
      buf=a%b;
      a=b;
      b=buf;
    }
    printf("%d\n",b);
  }
  return 0;
}

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

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

	int64_t ans = 0;
	for (int64_t i = 1; i <= n; i++)
	{
		for (int64_t j = 1; j <= n; j++)
		{
			for (int64_t k = 1; k <= n; k++)
			{
				ans += gcd(i, gcd(j, k));
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

int n, nRow, nCol;

pair<int,int> ps[200000+10];
vector<pair<int,int> > rs[200000+10];

int main(void) {
  scanf("%d%d%d", &nCol, &nRow, &n);
  REP(i, n) {
    int c, r;
    scanf("%d%d", &c, &r);
    ps[i] = make_pair(r-1, c-1);
  }
  sort(ps, ps + n);

  // 各行をrangeに分割
  int lastR = 0;
  int lastC = 0;
  REP(idx, n) {
    int r = ps[idx].first;
    int c = ps[idx].second;
    for(; lastR < r; ++lastR) {
      int ced = nCol;
      if(lastC < ced) {
        rs[lastR].push_back(make_pair(lastC, ced));
      }
      lastC = 0;
    }
    int ced = c;
    if(lastC < ced) {
      rs[r].push_back(make_pair(lastC, ced));
    }
    lastC = c+1;
  }
  for(; lastR < nRow; ++lastR) {
    int ced = nCol;
    if(lastC < ced) {
      rs[lastR].push_back(make_pair(lastC, ced));
    }
    lastC = 0;
  }
  // 上から、到達可能なrangeを保持しながら進む
  // 答えはminC
  int res = nCol;
  pair<int,int> curRange = make_pair(-1, 1);
  REP(i, nRow) {
    const vector<pair<int,int> > &row = rs[i];
    int bg1 = curRange.first + 1;
    int ed1 = curRange.second;
    REP(i2, row.size()) {
      int bg2 = row[i2].first;
      int ed2 = row[i2].second;
      if(ed2 <= bg1) {
        continue;
      } else if(ed1 <= bg2) {
        break;
      } else {
        res = min(res, ed2);
        curRange = make_pair(max(bg1, bg2), ed2);
        break;
      }
    }
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 13568
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 20
#define int long long
#define MOD 998244353


int32_t main()
{
	IOS
	int n;cin>>n;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++)cin>>a[i];
	vector<int> p,q;
	for(int i=1;i<=n;i++)
	{
		p.push_back(a[i]+i);
		q.push_back(i-a[i]);
	}
	sort(p.begin(),p.end());
	int ans=0;
	for(int i=0;i<q.size();i++)
	{
		int x = lower_bound(p.begin(),p.end(),q[i])-p.begin();
		int y = upper_bound(p.begin(),p.end(),q[i])-p.begin();
		ans+=(y-x);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8256
n, m = map(int, input().split())
left = 0
right = n
ls = list(range(n))

for i in range(m):
    l, r = map(int, input().split())
    if left < l-1:
        left = l-1
    if right > r:
        right = r
print(len(ls[left:right]))

Measured memory_bytes: 8948
integer(16) N,K,aka
integer(16) mo
integer(16) ans
integer(16) i
integer(16),allocatable,dimension(:)::Kaijo

read*,n,k
aka=n-k
mo=10**9+7

allocate(Kaijo(0:N))
Kaijo(0)=1
do i=1,N
  Kaijo(i)=mod(Kaijo(i-1)*i,mo)
end do


do i=1,K
  ans=0
  if(aka==0.and.i==1)ans=1
  if(aka>=i-1.and.i-2>=0)then
    ans=mod(ans +mod(combination(K-1,i-1,mo)*combination(aka-1,i-2,mo),mo),mo)
  endif

  if(aka>=i)then
    ans=mod(ans +mod(combination(K-1,i-1,mo)*combination(aka-1,i-1,mo)*2,mo),mo)
  endif

  if(aka>=i+1)then
    ans=mod(ans +mod(combination(K-1,i-1,mo)*combination(aka-1,i,mo),mo),mo)
  endif
  
  print"(i0)",ans
end do


contains

function combination(n,k,l)
integer(16),intent(in)::n,k,l
integer(16) combination,i

combination=mod(Kaijo(N)*inv(Kaijo(K),l)*inv(Kaijo(N-K),l),l)

end function combination

function inv(K,L)
integer(16),intent(in)::k,l
integer(16) l2,y
integer(16) inv
inv=1
l2=l-2
y=k
do
  if(mod(l2,2)==1)inv=mod(inv*y,l)
  y=mod(y*y,l)
  l2=l2/2
  if(l2==0)exit
end do
end function inv

end

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i,j,k,h,w,min,minh,minw;

    for(i=0;i<100;i++){
        scanf("%d %d", &h, &w);
        if(h==0&&w==0) break;
        min =150*150 +150 * 150;
        minh = 150;
        minw = 150;
        for(j=1;j<=150;j++){
            for(k=j+1;k<=150;k++){
                if((j*j+k*k)>(h*h+w*w)&&(j*j+k*k)<min){
                    min = j*j+k*k;
                    minh = j;
                    minw = k;
                }
                if(((j*j+k*k)==(h*h+w*w)&&h<j &&min != h*h+w*w)){
                    min = j*j+k*k;
                    minh = j;
                    minw = k;
                }
            }
        }
        printf("%d %d\n",minh,minw);
    }
    return 0;
}

Measured memory_bytes: 596
N = gets.to_i
Cs = gets.chomp.split('')

w, r = 0, Cs.count('R')
ws, rs = [w], [r]
Cs.each do |c|
  c == 'W' ? w += 1 : r -= 1
  ws << w; rs << r
end
puts ws.zip(rs).map{[_1, _2].max}.min

Measured memory_bytes: 40200
MOD = 10 ** 9 + 7
n, k = gets.split.map(&:to_i)
count = 0
for i in k..(n + 1) do
  tmp1 = (i - 1) * i / 2
  tmp2 = (n * 2 - i + 1) * i / 2
  tmp =  tmp2 - tmp1 + 1
#  puts "i=#{i} #{tmp1} #{tmp2} #{tmp}"
  count = (count + tmp) % MOD
end
puts count


Measured memory_bytes: 14364
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int N,K;
    int cnt = 0;

    cin >> N >> K;

    while(N){
        cnt++;
        N /= K;
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define REP(i, n) FOR(i, 0, n)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
#define PB push_back
#define MP make_pair

ld dst(ld x1, ld y1, ld x2, ld y2){
	x1-=x2;
	y1-=y2;
	return sqrt(x1*x1+y1*y1);
}
int sgn(ld a){
	if(a>0) return 1;
	else if(a<0) return -1;
	else return 0;
}
int linsgn(ld a, ld b, ld c, ld d, ld x, ld y){
	return sgn((d-b)*x-(c-a)*y-a*d+b*c);
}
bool cross(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3, ld x4, ld y4){
	return linsgn(x1,y1,x2,y2,x3,y3)*linsgn(x1,y1,x2,y2,x4,y4)<=0 &&
		linsgn(x3,y3,x4,y4,x1,y1)*linsgn(x3,y3,x4,y4,x2,y2)<=0;
}
void tim(ld &a, ld &b, ld c, ld d){
	ld e=a, f=b;
	a=c*e-d*f;
	b=c*f+d*e;
}
void flp(ld &p, ld &q, ld a, ld b, ld x, ld y){
	p-=a; x-=a;
	q-=b; y-=b;
	ld r=dst(0,0,x,y);
	tim(x, y, x, y);
	q*=-1;
	tim(p, q, x, y);
	p/=r*r; q/=r*r;
	p+=a;
	q+=b;
}
void cpt(ld &p, ld &q, ld x1, ld y1, ld x2, ld y2, ld x3, ld y3, ld x4, ld y4){
	ld a=y2-y1, b=x2-x1, c=x1*y2-x2*y1, d=y4-y3, e=x4-x3, f=x3*y4-x4*y3;
	p=(b*f-c*e)/(b*d-a*e);
	q=-(a*f-c*d)/(a*e-b*d);
}

struct edge{
	int to; ld cost;
};

#define N 240
int n;
ld x[N], y[N];
ld s[N], t[N];

vector<edge> e[N];
void add_edge(int p, int q, ld a, ld b, ld c, ld d){
	//printf("%d->%d: (%Lf, %Lf)-(%Lf, %Lf)\n", p, q, a, b, c, d);
	ld f=dst(a,b,c,d);
	e[p].PB(edge{q, f});
	e[q].PB(edge{p, f});
}

typedef pair<ld, int> pld;
bool used[N];
priority_queue<pld, vector<pld>, greater<pld> > que;
ld cst[N];

int main(){
	REP(i, 2) scanf("%Lf%Lf", s+i, t+i);
	scanf("%d", &n);
	REP(i, n) scanf("%Lf%Lf", x+i, y+i);
	REP(i, n){
		add_edge(i, (i+1)%n, x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
	}
	REP(i, n){
		REP(j, 2){
			FOR(k, i+1, i+n-1){
				if(cross(s[j],t[j],x[i],y[i],x[k%n],y[k%n],x[(k+1)%n],y[(k+1)%n]))
					goto nxt;
			}
			add_edge(n+j, i, s[j],t[j],x[i],y[i]);
			nxt:;
		}
	}
	REP(i, n){
		// printf("i=%d\n", i);
		ld p=s[1], q=t[1];
		flp(p, q, x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
		// printf("(%Lf, %Lf)\n", p, q);
		if(!cross(s[0],t[0],p,q,x[i], y[i], x[(i+1)%n], y[(i+1)%n])) continue;
		ld u, v;
		cpt(u, v, s[0], t[0], p, q, x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
		REP(j, 2){
			FOR(k, i+1, i+n-1){
				if(cross(s[j],t[j],u,v,x[k%n],y[k%n],x[(k+1)%n],y[(k+1)%n]))
					goto fal;
			}
		}
		REP(j, 2) add_edge(n+j, n+2+i, s[j], t[j], u, v);
fal:;
	}
	fill(cst, cst+N, 1e18);
	fill(used, used+N, false);
	cst[n]=0;
	que.push(MP(0, n));
	while(!used[n+1]){
		pld tp=que.top(); que.pop();
		int nw=tp.second;
		if(used[nw]) continue;
		used[nw]=true;
		REP(i, e[nw].size()){
			edge &ed=e[nw][i];
			ld ncst=cst[nw]+ed.cost;
			int dst=ed.to;
			if(cst[dst]>ncst){
				cst[dst]=ncst;
				que.push(MP(ncst, dst));
			}
		}
	}
	printf("%Lf\n", cst[n+1]);
}

Measured memory_bytes: 3316
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int64
    let cs = reads int64
    let ds = reads int64

    let rec loop acc rem xs ys =
        match (xs, ys) with
        | ([x], []) ->
            acc + min x rem
        | (x :: xs, y :: ys) ->
            let x' = max 0L (x - rem)
            let rem' = max 0L (y - x')
            let a = min x (y + rem)
            loop (acc + a) rem' xs ys

    loop 0L 0L cs ds
    |> printfn "%i"
    0

Measured memory_bytes: 37136
//dp[i][v_sum] = w_sum
//v_sum以上になるiまでのwiの和の最小値
//dp[N][v_sum] W以下なるv_sum最大値が答え
//dp[0][any] = 0 ほんまか？ ほんまじゃない…
//むり～～～～～～～～～～～～～～
//配るDP
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i,N) for (int i = 0; i < N; i++)

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

const long long inf = 1LL << 60;
const long long maxN = 110;
const long long maxV = 100010;
long long N, W;
vector<long long> w, v;
long long dp[maxN][maxV]; 

int main() {
    scanf("%Ld %Ld", &N, &W);
    w.resize(N); v.resize(N);
    rep(i,N) scanf("%Ld %Ld", & w[i], & v[i]);
    rep(i,maxN)rep(j,maxV) dp[i][j] = inf;
    dp[0][0] = 0;
    long long V = accumulate(v.begin(), v.end(), 0);



    rep(i,N){
        rep(v_sum,maxV){
            if (v_sum >= v[i]) chmin(dp[i+1][v_sum], dp[i][v_sum-v[i]]+w[i]);
            chmin(dp[i+1][v_sum], dp[i][v_sum]);
            //cout << i <<  " " << v_sum << " " << dp[i+1][v_sum] << endl;
        }
    }

    long long ans = 0;
    rep(sum_v,maxV) if(dp[N][sum_v] <= W) ans = sum_v;
    printf("%Ld\n", ans);
    return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main(){
	int n,m,d,h,i,j,r,s;
	string str;
	for(;cin>>n,n;cout<<r<<endl){
		vector<int>monster(n);
		for(h=i=0;i<n;i++){
			cin>>monster[i];
			if(h<monster[i])h=monster[i];
		}
		vector<pair<int,int> >_all,_single;
		vector<int>all(h+1),single(h+1);
		for(cin>>i;i--;){
			cin>>str>>m>>str>>d;
			if(d){
				if(str=="All")_all.push_back(make_pair(m,d));
				else _single.push_back(make_pair(m,d));
			}
		}
		for(i=1;i<=h;i++){
			all[i]=9999999;
			single[i]=9999999;
			for(j=0;j<_all.size();j++){
				all[i]=min(all[i],all[max(0,i-_all[j].second)]+_all[j].first);
			}
			for(j=0;j<_single.size();j++){
				single[i]=min(single[i],single[max(0,i-_single[j].second)]+_single[j].first);
			}
		}

			r=9999999;
			for(i=0;i<=h;i++){
				s=all[i];
				for(j=0;j<monster.size();j++)s+=single[max(0,monster[j]-i)];
				if(r>s)r=s;
			}
	}
}

Measured memory_bytes: 1968
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#define int long long
#define INF 10000000000000000LL
using namespace std;
typedef pair<int, int> P;

signed main() {
  int N;
  cin >> N;
  vector<vector<P>> graph(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    graph[a - 1].push_back(make_pair(b - 1, c));
    graph[b - 1].push_back(make_pair(a - 1, c));
  }
  int Q, K;
  cin >> Q >> K;
  vector<int> x(Q), y(Q);
  for (int i = 0; i < Q; ++i) cin >> x[i] >> y[i];
  
  vector<int> cost(N, INF);
  vector<int> used(N, false);
  priority_queue<P> pq;
  cost[K - 1] = 0;
  pq.push(make_pair(0, K - 1));
  while (pq.size() > 0) {
    int minCost = pq.top().first;
    int minVertex = pq.top().second;
    pq.pop();
    if (used[minVertex]) continue;
    for (int i = 0; i < graph[minVertex].size(); ++i) {
      int alt = minCost + graph[minVertex][i].second;
      if (alt < cost[graph[minVertex][i].first]) {
        cost[graph[minVertex][i].first] = alt;
        pq.push(make_pair(alt, graph[minVertex][i].first));
      }
    }
    used[minVertex] = true;
  }
  
  for (int i = 0; i < Q; ++i) cout << cost[x[i] - 1] + cost[y[i] - 1] << endl;
  return 0;
}

Measured memory_bytes: 13424
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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 T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  ll n; cin >>n;
  vector<ll> A(n, 0); rep(i, n) cin >>A[i];
  ll j = A[0];
  ll res = -INF;
  for (ll k=1; k<n; k++){
    res = max(res, A[k] - j);
    j = min(j, A[k]);
  }
  cout <<res <<endl;
}



Measured memory_bytes: 4456
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        for(int n=0; n<N; n++) P[n]=sc.nextInt();

        TreeMap<Integer,Integer> valueToIndex = new TreeMap<>();
        for(int n=0; n<N; n++) valueToIndex.put(P[n], n);

        Integer[] largerLeft1 = new Integer[N];
        Integer[] largerLeft2 = new Integer[N];
        Integer[] largerRight1 = new Integer[N];
        Integer[] largerRight2 = new Integer[N];


        TreeMap<Integer,Integer> indexToValue = new TreeMap<>();
        for(int v=N; v>0; v--){
            int i = valueToIndex.get(v);
            indexToValue.put(i,v);
            largerLeft1[i]  = indexToValue.lowerKey(i);
            if(largerLeft1[i]!=null) largerLeft2[i]  = indexToValue.lowerKey(largerLeft1[i]);
            largerRight1[i] = indexToValue.higherKey(i);
            if(largerRight1[i]!=null) largerRight2[i] = indexToValue.higherKey(largerRight1[i]);
        }

        long ans = 0;
        for(int i=0; i<N; i++){
            if(largerLeft1[i]!=null){
                if(largerLeft2[i]==null)largerLeft2[i] = -1;
                if(largerRight1[i]==null)largerRight1[i] = N;
                ans += 1L * (largerLeft1[i]-largerLeft2[i]) * (largerRight1[i] - i) * P[i];
            }
            if(largerRight1[i]!=null){
                if(largerRight2[i]==null) largerRight2[i] = N;
                if(largerLeft1[i]==null) largerLeft1[i] = -1;
                ans += 1L * (largerRight2[i]-largerRight1[i]) * (i - largerLeft1[i]) * P[i];
            }
        }
        System.out.println(ans);
    }
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        Long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong();
        if(c-(a+b)>0&&(c-(a+b))*(c-(a+b))>a*b*4){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
/*
ID: jerrymo4
TASK:
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

string s;
int x,y;
int a[8010];
bool dp[8000][16010];
bool ans;

int main(){
	cin>>s;
	cin>>x>>y;
	int k=0,w=0;
	int i,j;
	for (i=0;i<s.size();i++){
		if (s[i]=='T'){
			k++;
			a[k]=w;
			w=0;
		}
		else{
			w++;
		}
	}
	k++;
	a[k]=w;
	
	dp[1][a[1]+8000]=1;
	for (i=3;i<=k;i+=2){
		for (j=0;j<=16000;j++){
			if (j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if (j>=a[i])
				dp[i][j]=dp[i][j] || dp[i-2][j-a[i]];
		}
	}
	
	dp[0][8000]=1;
	for (i=2;i<=k;i+=2){
		for (j=0;j<=16000;j++){
			if (j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if (j>=a[i])
				dp[i][j]=dp[i][j] || dp[i-2][j-a[i]];
		}
	}
	
	if (k%2==0){
		ans=dp[k][y+8000] && dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000] && dp[k-1][y+8000];
	}
	if (ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 125184
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint64 n, m;
	std::cin >> n >> m;
	if (n * 2 >= m) {
		std::cout << std::min(n, m / 2) << "\n";
		return 0;
	}
	m -= n * 2;
	std::cout << n + (m / 4) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

struct P {
  int x, y, id;
  P(int x=0, int y=0, int id=0): x(x), y(y), id(id) {};
};

struct Edge {
  int prev, to, cost;
  Edge(int a=0, int b=0, int c=0): prev(a), to(b), cost(c) {}
  bool operator < (const Edge &rhs) const { return (cost < rhs.cost); }
  bool operator > (const Edge &rhs) const { return (cost > rhs.cost); }
};

struct UnionFind {
  vector<int> uni;
  explicit UnionFind(int n): uni(n+5, -1) {}
  int  root(int x)        { return (uni[x] < 0)? x : uni[x] = root(uni[x]); }
  int  size(int i)        { return (-uni[root(i)]); }
  bool same(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y){
    if ( (x=root(x)) == (y=root(y)) )return false;
    if ( uni[y] < uni[x] ) swap(x,y);
    uni[x] += uni[y];  uni[y] = x;
    return true;
  }
};

i64 kruskal(int N, vector<Edge> G)
{
  i64 ans = 0;
  UnionFind uf(N);

  sort(ALL(G));
  for(const auto &e : G) {
    if (uf.unite(e.prev, e.to)) ans += e.cost;
  }
  return ans;
}

signed main()
{
  int N;
  vector<Edge> G;
  P p[100100];

  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y; cin >> x >> y;
    p[i] = P(x, y, i);
  }

  sort(p, p+N, [](const auto &a, const auto &b){return a.x < b.x; });
  for (int i= 1; i < N; ++i) {
    G.emplace_back(p[i].id, p[i-1].id, abs(p[i].x - p[i-1].x));
  }
  sort(p, p+N, [](const auto &a, const auto &b){return a.y < b.y; });
  for (int i= 1; i < N; ++i) {
    G.emplace_back(p[i].id, p[i-1].id, abs(p[i].y - p[i-1].y));
  }

  cout << kruskal(N, G) << endl;
  return 0;
}



Measured memory_bytes: 7152
N=int(input())
MP=[list(map(int,input().split())) for i in range(N)]
MP2=[]
for li in MP:
    MP2.append([i for i in li])

MP3=[[-1]*N for _ in range(N)]

# ワーシャルフロイド
for k in range(N):
    for i in range(N):
        for j in range(N):
            cand = MP2[i][k] + MP2[k][j]
            if cand <= MP2[i][j]:
                MP2[i][j] = cand
                if (i != k and j != k):
                    MP3[i][j] = k

for i in range(N):
    for j in range(N):
        if MP[i][j] != MP2[i][j]:
            print(-1)
            exit()

checked=set()

res = set()
def dfs(i,j):
    k = MP3[i][j]
    if k == -1:
        k = i
    if (i,j) in checked:
        return
    checked.add((i,j))
    if (i == k or j == k):
        if i < j:
            res.add((i,j))
    else:
        dfs(i,k)
        dfs(k,j)

for i in range(N):
    for j in range(N):
        dfs(i,j)

ressum = 0
for i,j in res:
    ressum += MP[i][j]

# for li in MP3:
#     print(li)
# print(res)
print(ressum)


Measured memory_bytes: 85084
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

int main()
{
    long N;
    std::cin >> N;
    std::vector<std::string> s;
    std::vector<long> t;
    for(long i=0; i<N; i++){
        long temp;
        std::string stemp;
        std::cin >> stemp >> temp;
        s.push_back(stemp);
        t.push_back(temp);
    }
    std::string X;
    std::cin >> X;
    bool flag=0;
    long count=0;
    for(long i=0; i<N; i++){
        if(flag==1){
            count+=t[i];
        }
        if(s[i]==X){
            flag=1;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int a,b;
   for(int i = 0;i<4;i++){
       cin>>a>>b;
switch(a)
  { case 1:
     cout<<6000*b<<endl;
     break;
      case 2:
     cout<<4000*b<<endl;
     break;
      case 3:
     cout<<3000*b<<endl;
     break;
      case 4:
     cout<<2000*b<<endl;
     break;
  }
   }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  cin >> A >> B;
  int C = 0;
  C = A + B;
  if(C%3 == 0 || A%3 == 0 || B%3 == 0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vp=vector<P>;
using vs=vector<string>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////

//abc09d;present

struct Seg {
private:
    int n;
    vector<int> node;

public:
    // 元配列 v をセグメント木で表現する
    Seg(vector<int> v) {
        // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        // セグメント木全体で必要なノード数は 2n-1 個である
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);

        // 最下段に値を入れたあとに、下の段から順番に値を入れる
        // 値を入れるには、自分の子の 2 値を参照すれば良い
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1]+ node[2*i+2];
    }
    void update(int a,int b){
        a+=n-1;
        node[a]+=b;
        while(a>0){
            a=(a-1)/2;
            node[a]=node[2*a+1]+node[2*a+2];
        }
    }
    int query_sub(int a,int b,int k,int l,int r){
        if(r<=a||b<=l){
            return 0;
        }
        else if(a<=l&&r<=b){
            return node[k];
        }
        else {
            int res1=query_sub(a,b,k*2+1,l,(l+r)/2);
            int res2=query_sub(a,b,2*k+2,(l+r)/2,r);
            return res1+res2;
        }
    }
    int getnum(int a,int b){return query_sub(a,b,0,0,n);}

    
};
using mt=tuple<int,int,int>;
bool cmp(mt a, mt b){
    if(get<0>(a)!=get<0>(b))return get<0>(a)<get<0>(b);
    return get<2>(a)<get<2>(b);
}

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    
    vector<tuple<int ,int, int>> ins(m+q);
    rep(i,m){
        int l,r;
        cin>>l>>r;
        --l,--r;
        get<0>(ins[i])=r;
        get<1>(ins[i])=l;
        get<2>(ins[i])=-1;
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        --l,--r;
        
        get<0>(ins[m+i])=r;
        get<1>(ins[m+i])=l;
        get<2>(ins[m+i])=i;
    }
    sort(all(ins),cmp);
    vi ans(q);
    Seg seg(vi (n,0));
    rep(i,m+q){
        int l=get<1>(ins[i]);
        int r=get<0>(ins[i]);
        int a=get<2>(ins[i]);
        if(a>=0){
            int res=seg.getnum(l,r+1);
            ans[a]=res;
        }
        else seg.update(l,1);
    }
    rep(i,q)cout<<ans[i]<<endl;
    return 0;
}

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  long long j = 100,x;
  cin >> x;
  for (long long i = 0; i <= 10000; i ++){
    if (j >= x){
      cout << i << '\n';
      return 0;
    }
    j += j * 0.01;
  }
  return 0;
}

Measured memory_bytes: 3640
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))
        if h >= 1:
            hint = (x, y, h)

    for px in range(101):
        for py in range(101):
            H = hint[2] + abs(px-hint[0]) + abs(py-hint[1])
            clearflag = True
            for point in points:
                x, y, h = point
                val = max([H - abs(px-x) - abs(py-y), 0])
                if val != h:
                    clearflag = False

            if clearflag:
                print(px, py, H)
                return
if __name__ == '__main__':
    main()

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

typedef long long ll;
const ll inf(1e14);
const int N(3009);


int n, m, ans;
ll a[N];
ll f[N][N][2];

ll dfs(int l, int r, int player)
{
	if (l > r) return 0;
	if (f[l][r][player] < inf) return f[l][r][player];
	if (player) f[l][r][player] = max(dfs(l + 1, r, !player) + a[l], dfs(l, r - 1, !player) + a[r]);
	else f[l][r][player] = min(dfs(l + 1, r, !player) - a[l], dfs(l, r - 1, !player) - a[r]);
	return f[l][r][player];
}

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			f[i][j][0] = f[i][j][1] = inf;
		}
	}
	cout<<dfs(1, n, 1)<<endl;
	return 0;
}

Measured memory_bytes: 141696
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N,A;
    cin >> N >> A;
    int mod;
    mod = N % 500;
    if (mod > A) {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    A, B, C, K = map(int, input().split())
    answer = 0
    if K <= A:
        answer = K
    elif K <= A+B:
        answer = A
    else:
        answer = A - (K -A -B)
    print(answer)

if __name__ == "__main__":
    main()




Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    ll n,ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if(i %3 != 0 && i%5 != 0) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
n = int(input())

#約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    # divisors.sort()
    return divisors

list_n = make_divisors(n)

a = len(list_n)
ans = []
for i in range(0, a-1, 2):
    ans.append(list_n[i]+list_n[i+1])

ans.sort()

print(ans[0]-2)

Measured memory_bytes: 3296
N, M = map(int, input().split())
D = [[float("inf")]*N for i in range(N)]
for i in range(N):
  D[i][i] = 0
abcs = []
for i in range(M):
  a, b, c = map(int, input().split())
  a, b = a-1, b-1
  abcs.append((a, b, c))
  D[a][b] = c
  D[b][a] = c
for k in range(N):
  for a in range(N):
    for b in range(N):
      D[a][b] = min(D[a][b], D[a][k]+D[k][b])
#print(D)
r = 0
for m in range(M):
  a, b, c = abcs[m]
  if c > D[a][b]:
    r += 1
print(r)


Measured memory_bytes: 3444
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        P[] ps = new P[n];
        for (int i = 1; i <= n; i++) {
            String s = sc.next();
            int c = sc.nextInt();
            ps[i - 1] = new P(s, c, i);
        }
        Arrays.sort(ps);
        for (int i = 0; i < n; i++) {
            System.out.println(ps[i].i);
        }
    }

    class P implements Comparable<P> {

        String s;
        int c, i;
        P(String s, int c, int i) {
            this.s = s;
            this.c = c;
            this.i = i;
        }

        @Override
        public int compareTo(P o) {
            if (s.equals(o.s)) {
                return o.c - c;
            }
            return s.compareTo(o.s);
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 22996
#include<stdio.h>

int main(){
	int N,change;
	
	scanf("%d",&N);
	
	if(N<=1000){
		printf("%d",1000-N);
	}
	else if(N<=2000){
	    printf("%d",2000-N);
	}
    else if(N<=3000){
	    printf("%d",3000-N);
	}
    else if(N<=4000){
	    printf("%d",4000-N);
	}
	else if(N<=5000){
	    printf("%d",5000-N);
	}
    else if(N<=6000){
	    printf("%d",6000-N);
	}
	else if(N<=7000){
	    printf("%d",7000-N);
	}
	else if(N<=8000){
	    printf("%d",8000-N);
	}
	else if(N<=9000){
	    printf("%d",9000-N);
	}
	else{
	    printf("%d",10000-N);
	}
	
	return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
int main() {
    int n;
    cin >> n;
    vector <int> d(n);
    for(int i=0;i<n;++i) cin >> d[i];
    int sum=0;
    for(int i=0;i<n-1;++i) {
        for(int j=i+1;j<n;++j) {
            sum+=d[i]*d[j];
        }
    }
    cout << sum << endl;
}




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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll a,b,c,k;

int main(){
    cin >> a >> b >> c >> k;
    if(a >= k)
    {
        cout << k << endl;
    }
    else
    {
        if(a+b>=k)
        {
            cout << a << endl;
        }
        else
        {
            cout << (a-(k-(a+b))) << endl;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

long N, M;
typedef pair<long long, long long> X;
vector<X> AB;

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

    for (int i = 0; i < N; i++) {
        long long a; cin >> a;
        long long b; cin >> b;

        AB.push_back(X(a, b));
    }

    sort(AB.begin(), AB.end());

    long long ans = 0;

    for (int i = 0; i < N; i++) {
        if (M - AB[i].second >= 0) {
            ans += AB[i].first * AB[i].second;
            M -= AB[i].second;
            if (M < 0) M = 0;
        }
        else {
            ans += AB[i].first * M;
            M = 0;
        }
    }

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

Measured memory_bytes: 2420