akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	A = list(rli())
	indices = defaultdict(lambda: [])
	Amax = NINF
	if 1 in indices:
		print(1 if len(indices[1]) == 1 else 0)
		return
	A.sort()	
	for i, num in enumerate(A):
		indices[num].append(i)
		Amax = max(Amax, num)
	set_false = set()
	dp = [1 for _ in range(n)]
	for i, num in enumerate(A):
		if i in set_false: continue
		if len(indices[num]) > 1:
			dp[i] = 0
		curr = num
		while curr <= Amax:
			for j in indices[curr]:
				if i == j: continue
				dp[j] = 0
				set_false.add(j)
			curr += num
	print(sum(dp))
	stdout.close()

if __name__ == "__main__":
	main()

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int l[210];
	for(int i=1;i<=2*n;i++)
		cin >> l[i-1];
	
	sort(l,l+2*n);

	int ans = 0;
	
	for(int i=1;i<=n;i++)
		ans+=l[i*2-1-1];

	cout << ans << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

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

    string s;
    cin >> s;

    int ind1 = -2, ind2 = -2;
    int ss=s.size();

    for(int i=0; i<ss-2; i++){
        if(ss==1)
            break;
        
        if(s[i]==s[i+1]){
            ind1 = i;
            ind2 = i+1;
            break;
        }

        if(s[i]==s[i+2] && s[i] != s[i+1]){
            ind1 = i;
            ind2 = i+2;
            break;        
        }
    }

    if(s[ss-1] == s[ss-2]){
        ind1=ss-2;
        ind2=ss-1;
    }

    cout << ind1+1 << " " << ind2+1;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
#define lli long ling int;

int main()
{
    while(1) {
        int H, W;
        scanf("%d %d", &H, &W);

        if (H == 0 && W == 0)
            break;
        
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
               if (i == 0 || i == H - 1) {
                   printf("#");
               } 
               else {
                   if (j == 0 || j == W - 1) {
                       printf("#");
                   }
                   else {
                       printf(".");
                   }
               }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int INT_INF = 1e9;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)

template<int mod,int base=10007>
struct rolliha{
    vector<ll> hsh,pwr;
    ll umod(ll n) { return (n % mod + mod) % mod; }
    rolliha() {}
    rolliha(const string &s){
        int sz = (int)s.size();
        hsh.assign(sz+1,0);
        pwr.assign(sz + 1, 0);
        pwr[0] = 1;
        rep(i,sz){
            hsh[i + 1] = umod(hsh[i] * base + s[i]);
            pwr[i + 1] = umod(pwr[i] * base);
        }
    }
    ll get(int l,int r){
        return umod(hsh[r] - hsh[l] * pwr[r - l]);
    }
    ll join(ll h1,ll h2,int h2_sz){
        return umod(h1 * pwr[h2_sz] + h2);
    }
    ll rotate(ll idx,int len_s){
        return join(get(idx, len_s), get(0, idx), idx);
    }
};
using rh1=rolliha<(int)1e9+7>;
using rh2 = rolliha<(int)1e9 + 9>;
using rh=pair<rh1,rh2>;
using H = pair<ll, ll>;
rh init(const string &s) { return make_pair(rh1(s), rh2(s)); }
H get(rh &Rh, int l, int r) { return make_pair(Rh.first.get(l, r),Rh.second.get(l, r)); }
H rotate(rh &Rh, int n, int sz) { return make_pair(Rh.first.rotate(n, sz), Rh.second.rotate(n, sz)); }

int N;
string str;

bool check(int len,rh &Rh){
    map<H, vector<int>> mp;
    rep(frm,N-len+1){
        int to = frm + len;
        mp[get(Rh, frm, to)].emplace_back(frm);
    }
    for(auto& e : mp){
        int sz = e.second.size();
        if(sz==1)
            continue;
        int mn = e.second[0];
        int mx = e.second[sz - 1];
        if(mn+len<=mx)
            return true;
    }
    return false;
}

int main(){
    cin >> N >> str;
    rh Rh = init(str);
    ll ok = 0, ng = N / 2 + 1;
    while(abs(ok-ng)>1){
        ll mid = (ok + ng) / 2;
        if(check(mid,Rh)){
            ok = mid;
        }else{
            ng = mid;
        }
    }

    cout << ok << endl;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>

using namespace std;

const int INF = numeric_limits<int>::max();

// [begin, end) of an array
// [left, right): range of the query
// current_idx: index of the node in segment_tree corresponding to a range in the original array
int query(int segment_tree[], int left, int right, int current_idx, int begin, int end){
	if(end <= left || begin >= right){
		return INF;
	}
	if(left <= begin && right >= end){
		return segment_tree[current_idx];
	}

	int left_val = query(segment_tree, left, right, 2 * current_idx + 1, begin, (begin + end) / 2); // value of the left child (left half range)
	int right_val = query(segment_tree, left, right, 2 * current_idx + 2, (begin + end) / 2, end); // value of the right child (right half range)
	return min(left_val, right_val);
}

// [left, right]
int find(int segment_tree[], int n, int left, int right){
	return query(segment_tree, left, right + 1, 0, 0, n);
}

void update(int segment_tree[], int n, int i, int x){
	int current_idx = i + n - 1; // tree index corresponding to the element i in array A
	segment_tree[current_idx] = x;
	while(current_idx > 0){
		current_idx = (current_idx - 1) / 2; // get the parent index
		segment_tree[current_idx] = min(segment_tree[2 * current_idx + 1], segment_tree[2 * current_idx + 2]); // update the child nodes
	}
}

int initRMQ(int original_size){
	int n = 1;
	// make the size of the array to be power of n
	while(n < original_size){
		n *= 2;
	}
	return n;
}

int main(){
	int original_size, q;
	cin >> original_size >> q;
	int n = initRMQ(original_size);
	int segment_tree[2 * n - 1];
	
	for(auto i = 0; i < 2 * n - 1; ++i){
		segment_tree[i] = INF;
	}

	for(auto i = 0; i < q; ++i){
		int cmd;
		int x,y;
		cin >> cmd >> x >> y;
		if(cmd == 0){
			update(segment_tree, n, x, y);
		}else if(cmd == 1){
			cout << find(segment_tree, n, x, y) << endl;
		}
	}
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; 
        if (total == X) ++res; 
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int geko[100][100] = {};

void solve() {
	int dx[7] = {-1,0,-1,0,1,0,1};
	int dy[7] = { 1,1,0,0,0,-1,-1 };
	set<pair<int, int>> goa;
	REP(i, 7) {
		REP(q, 7) {
			goa.insert(mp(dx[i] + dx[q] + 3, dy[i] + dy[q] + 3));
		}
	}
	vector<pair<int, int>> next;
	for (auto x : goa) {
		next.push_back(x);
	}
	while (true) {
		string s;
		cin >> s;
		if (s == "#") return;
		int ok = 1;
		for (int i = 0; i < (1 << next.size()); ++i) {
			int now = i;
			for (auto x : next) {
				geko[x.first][x.second] = now % 2;
				now /= 2;
			}
			int final_go = 0;
			REP(i, 7) {
				int x = dx[i] + 3;
				int y = dy[i] + 3;
				int now = 0;
				REP(q, 7) {
					if (geko[x + dx[q]][y + dy[q]] == 1) {
						now += (1 << q);
					}
				}
				if (s[now] - '0' == 1) {
					final_go += (1 << i);
				}
			}
			if (s[final_go] - '0' != (final_go & 8) >> 3) {
				ok = 0;
				break;
			}
		}
		if (ok == 1) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;

int _;

//========================================================================
char s[maxn];
//========================================================================
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    int num1=0,num2=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W') num1++;
        else num2++;
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(i<num2) 
        {
            if(s[i]!='R') cnt++;
        }
        else 
        {
            if(s[i]!='W') cnt++;
        } 
    }
    printf("%d\n",min(num1,min(num2,cnt/2)));
    return 0;
}


Measured memory_bytes: 4008
N = 10**8


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Measured memory_bytes: 64972
#include <cstdio>
#include <algorithm>
int a[9],b[9];
int main2(){
  int i,j,s,t,g;
  double x=362880;
  for(i=0;i<9;i++)scanf("%d",a+i);
  for(i=0;i<9;i++)scanf("%d",b+i);
  for(g=i=0;i<x;i++){
    for(s=t=j=0;j<9;j++)
      if(a[j]>b[j])s+=a[j]+b[j];else t+=a[j]+b[j];
    if(s>t)g++;
    std::next_permutation(b,b+9);
  }
  printf("%.5f %.5f\n",g/x,(x-g)/x);
}
int main(){int n;for(scanf("%d",&n);n--;)main2();}

Measured memory_bytes: 788
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N=int(input())
T = [int(input()) for _ in range(N)]
a = T[0]
for i in range(1,N):
    b = T[i]
    c = gcd(a,b)
    a = (a//c)*b
print(a)

Measured memory_bytes: 61788
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N;
    cin >> N;

    if (N%1000 == 0) ans = 0;
    else ans = 1000-(N%1000);
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc173/abc173_a && sh shellscripts/submit_cpp.sh
*/


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

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;

    bool existOne = false;
    for (int i = 0; i < n; i++) {
        s[i]--;
        if (s[i] == '1')existOne = true;
    }

    if (existOne) {
        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '1') {
                int x = n - 1, y = n - i - 1;
                ret += (x & y) == y;
            }
        }
        cout << ret % 2 << endl;
    } else {
        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '2') {
                int x = n - 1, y = n - i - 1;
                ret += (x & y) == y;
            }
        }
        cout << (ret % 2) * 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1412
def main():
    box, limit = map(int, input().split())
    candies = list(map(int, input().split()))
    answer = 0
    for i in range(1, box):
        candy_sum = candies[i - 1] + candies[i]
        if candy_sum > limit:
            candies[i] -= min(candy_sum - limit, candies[i])
            answer += candy_sum - limit
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 15636
#include<iostream>
using namespace std;
int main(){
  char joi[11111];
  int countj,counti;
  while(cin>>joi){
    countj=0;
    counti=0;
    int i=0;
    while(1){
      if(joi[i+2]=='\0') break;
      if(joi[i]=='J' && joi[i+1]=='O' && joi[i+2]=='I'){
	countj++;
      }
      if(joi[i]=='I' && joi[i+1]=='O' && joi[i+2]=='I'){
	counti++;
      }
      i++;
    }
    cout<<countj<<endl;
    cout<<counti<<endl;
  }
}

  

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll sum(ll l, ll r) {
  return (l+r)*(r-l+1)/2;
}

int main() {
  int n, k;
  cin >> n >> k;
  mint ans;
  FORe(i, k, n+1) {
    ll l = sum(0, i-1), r = sum(n-i+1, n);
    ans += r-l+1;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#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 double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    string ans;
    ll i, n, l;
    cin >> n >> l;
    vector <string> s(n);
    for(i = 0; i < n; i++)
        cin >> s[i];
    sort(all(s));
    for(auto x : s)
        ans += x;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> coin(m);
  rep(i, m) cin >> coin[i];
  vector<int> dp(n+1, 100000);
  dp[0] = 0;
  
  rep(i, n+1)rep(j, m){
    if (i >= coin[j])
      dp[i] = min(dp[i], dp[i-coin[j]] + 1);
  }
  cout << dp[n] << endl;
  
  return 0;
}


Measured memory_bytes: 3164
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)

  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =
    if(m.length != count) false
    else if(count==2) { if(m.head==m.last) true else false }
    else
      (u to 8).exists(i=> check(m diff seq1(i),count-3,i+1,v)) || (0 to 6).exists(i=> check(m diff seq2(i),count-3,u,i))

  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i => l.count( _==i ) < 4 && check(i::l,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}

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

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

    int j = 0;
    for (int i = a; i <= b; ++i) {
        if ((c % i) == 0) {
            ++j;
        }
    }

    cout << j << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll F(ll a, ll b){
  string s = to_string(a);
  string t = to_string(b);
  
  return max((ll) s.size(), (ll) t.size());}

int main(){
  ll N; cin >> N; 
  ll ans = 1LL << 60;
  ll c; c = (ll)sqrt((double) N);
  
  for(ll A = 1; A <= c; A++){
    if( N % A != 0){ continue;}
    else{
     ll B = N / A;
      
      ans = min( ans, F(A,B));}}
  
  cout  << ans << endl; return 0;}

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

using namespace std;

#define MAX 102

int h;
int w;

char r[MAX][MAX];

struct MaximumFlow {
	typedef int Index;
	typedef long long int Flow;
	static const Flow InfCapacity = LLONG_MAX;
	struct Edge {
		Index to;
		Flow capacity;
		Index rev;
	};
	vector<vector<Edge> > g;
	void init(Index n) { g.assign(n, vector<Edge>()); }
	void add(Index i, Index j, Flow capacity) {
		Edge e, f; e.to = j, f.to = i; e.capacity = capacity, f.capacity = 0;
		g[i].push_back(e); g[j].push_back(f);
		g[i].back().rev = (Index)g[j].size() - 1; g[j].back().rev = (Index)g[i].size() - 1;
	}
	void addB(Index i, Index j, Flow capacity) {  //双方向
		Edge e, f; e.to = j, f.to = i; e.capacity = capacity, f.capacity = capacity;
		g[i].push_back(e); g[j].push_back(f);
		g[i].back().rev = (Index)g[j].size() - 1; g[j].back().rev = (Index)g[i].size() - 1;
	}
	//gを破壊する
	Flow maximumFlow(int s, int t) {
		int n = g.size();
		vector<Index> level(n);
		Flow total = 0; bool update;
		do {
			update = false;
			fill(level.begin(), level.end(), -1); level[s] = 0;
			queue<Index> q; q.push(s);
			for (Index d = n; !q.empty() && level[q.front()] < d;) {
				int u = q.front(); q.pop();
				if (u == t) d = level[u];
				for (auto e = g[u].begin(); e != g[u].end(); e++) if (e->capacity > 0 && level[e->to] == -1)
					q.push(e->to), level[e->to] = level[u] + 1;
			}
			vector<Index> iter(n);
			for (Index i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;
			while (1) {
				Flow f = augment(level, iter, s, t, InfCapacity);
				if (f == 0) break;
				total += f; update = true;
			}
		} while (update);
		return total;
	}
	Flow augment(vector<Index> &level, vector<Index> &iter, Index u, Index t, Flow f) {
		if (u == t || f == 0) return f;
		Index lv = level[u];
		if (lv == -1) return 0;
		level[u] = -1;
		for (; iter[u] >= 0; --iter[u]) {
			Edge &e = g[u][iter[u]];
			if (level[e.to] <= lv) continue;
			Flow l = augment(level, iter, e.to, t, min(f, e.capacity));
			if (l == 0) continue;
			e.capacity -= l; g[e.to][e.rev].capacity += l;
			level[u] = lv;
			return l;
		}
		return 0;
	}
} d;
int main(){
	cin >> h >> w;
	pair<int, int> star;
	pair<int, int> en;
	d.init(MAX*MAX + 2);
	for (int i = 0; i < h; i++){
		scanf("%s", r[i]);
		for (int j = 0; j < w; j++){
			if (r[i][j] == 'o'){
				d.addB(i, h + j,1);
			}
			if (r[i][j] == 'S'){
				star = make_pair(i, j);
			}
			if (r[i][j] == 'T'){
				en = make_pair(i, j);
			}
		}
	}
	int S = h + w;
	int E = S + 1;
	d.add(S, star.first, 1145141919);
	d.add(S, star.second + h, 1145141919);
	d.add(en.first, E, 1145141919);
	d.add(en.second + h, E, 1145141919);
	int F = d.maximumFlow(S, E);
	if (F >= h*w){
		puts("-1");
	}
	else{
		cout << F << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	float n, m, x, to;
	vector<float> d;
	cin >> n >> m;
	to = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		d.push_back(x);
		to += x;
	}
	double y = to / (4 * m);
	sort(d.begin(), d.end(),greater<int>());
	if (d[m - 1] >= y) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> IP;
vector<IP> ans,fans;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n,k;cin>>n>>k;
  vector<int> v(3*n);
  for(int i=0;i<3*n;i++)v[i]=i+k;
  int r=2*n-1;
  for(int i=0;i<n;i+=2)ans.push_back(IP(v[i]+v[r],P(v[i],v[r]))),r--;
  for(int i=1;i<n;i+=2)ans.push_back(IP(v[i]+v[r],P(v[i],v[r]))),r--;
  sort(ans.rbegin(),ans.rend());
  for(int i=0;i<n;i++){
    fans.push_back(IP(ans[i].second.first,P(ans[i].second.second,v[3*n-1-i])));
    if(fans[i].first+fans[i].second.first>fans[i].second.second)fin(-1);
  }
  for(auto p:fans)cout<<p.first<<" "<<p.second.first<<" "<<p.second.second<<endl;
}


Measured memory_bytes: 5876
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Runtime.InteropServices;

namespace Contest
{


    class Program
    {

        
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            int[] ans = new int[4];

            for(int i = 0; i < n; i++)
            {
                var res = Console.ReadLine();
                switch(res){
                    case "AC":
                        ans[0]++;
                        break;
                    case "WA":
                        ans[1]++;
                        break;
                    case "TLE":
                        ans[2]++;
                        break;
                    default:
                        ans[3]++;
                        break;
                }
            }

            Console.WriteLine("AC x " + ans[0]);
            Console.WriteLine("WA x " + ans[1]);
            Console.WriteLine("TLE x " + ans[2]);
            Console.WriteLine("RE x " + ans[3]);

        }
    }
}

Measured memory_bytes: 30696
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> vp(n, make_pair(0, 0));
	for (int i = 0; i < n; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	sort(vp.begin(), vp.end());
	int index = 0;
	priority_queue<int> pq;
	int res = 0;
	for (int i = 1; i <= m; i++) {
		while (index < vp.size() && vp[index].first <= i) {
			pq.push(vp[index].second);
			index++;
		}
		if (pq.size() > 0) {
			res += pq.top();
			pq.pop();
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 4708
/*
  AtCoder Beginner Contest 089
  C - March
*/

#include<iostream>
#include<string>
#include<vector>
using namespace std;

long long N;
string S;

int main() {
  scanf("%lld", &N);
  long long ans = 0;

  long long n[5] = {0};
  for (int i = 0; i < N; ++i) {
    cin >> S;
    if (S[0] == 'M') n[0] += 1;
    else if (S[0] == 'A') n[1] += 1;
    else if (S[0] == 'R') n[2] += 1;
    else if (S[0] == 'C') n[3] += 1;
    else if (S[0] == 'H') n[4] += 1;
  }

  long long cnt = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i + 1; j < 5; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        cnt += n[i] * n[j] * n[k];
      }
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i > 0 && i < 10)
        {
            count++;
        }
        else if(i > 99 && i < 1000)
        {
            count++;
        }
        else if(i > 9999 && i < 100000)
        {
            count++;
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
L=list(map(int,input().split()))
N=a[0]
X=a[1]
l=[0]
n=0
n1=0
while True:
    l.append(L[n]+l[n])
    n=n+1
    if n==N:
        break
while True:
    if l[n1]<=X:
        n1+=1
    else:
        print(n1)
        break
    if n1==N:
        if X>=l[-1]:
            print(n1+1)
            break
        else:            
            print(n1)
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans=0;
        for(int i=0,x,y,h,w;i<n;i++){
            cin>>x>>y>>h>>w;
            x+=y+h;
            if(x<=60&&w<=2)ans+=600;
            else if(x<=80&&w<=5)ans+=800;
            else if(x<=100&&w<=10)ans+=1000;
            else if(x<=120&&w<=15)ans+=1200;
            else if(x<=140&&w<=20)ans+=1400;
            else if(x<=160&&w<=25) ans+=1600;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int inf = 0x3f3f3f3f;
 void solve()
 {
     ll i,j,k,l,m,n,o,p,q,r,a[300001],prefix[300001];
     string s,t;
     cin>>s>>t;
     m=LLONG_MAX;
     for(i=0;i<=s.length()-t.length();i++)
     {
         k=0;
         for(j=i;j<i+t.length();j++)
         {
             if(s[j]!=t[j-i])
             k++;
         }
         m=min(m,k);
     }
     cout<<m<<endl;
 }
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     ll t=1;
    // cin>>t;
     while(t--)
     {
         solve();
     }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    double A, B; cin >> A >> B;
    int H, M; cin >> H >> M;
    // cout << A << B << endl;
    // cout << H << M << endl;

    double PI = acos(-1);

    double tyou = PI / 2.0 - (PI * (H + M / 60.0) / 6.0),
        tan = PI / 2.0 - (PI * M / 30.0);
    // cout << tyou / PI << " " << tan / PI << endl;
    // cout << tyou / PI + 2.0 / 3.0 << endl;

    double tyou_x = A * cos(tyou), tyou_y = A * sin(tyou),
        tan_x = B * cos(tan), tan_y = B * sin(tan);

    double ans = sqrt(pow(abs(tyou_x - tan_x), 2) + pow(abs(tyou_y - tan_y), 2));

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

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

#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); ++i)
#define RREP(i, a, b) for (int64_t i = (int64_t)(a)-1; i >= (int64_t)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    int64_t x; cin >> x;
    REP(i, -200, 200) {
        REP(j, -200, 200) {
            int64_t n = (i*i*i*i*i) - (j*j*j*j*j);
            if (n == x) {
                cout << i << " " << j << endl;
                return;
            }
        }
    }
}


Measured memory_bytes: 3652
n, k = map(int, input().split())

l = list(map(int, input().split()))
dp = [0.5+0.5*i for i in range(max(l)+1)]
dp[0] = 0

# print(dp)
tmp = 0
for i in range(k-1):
    tmp += dp[l[i]]

ans = 0
for i in range(k-1, n):
    tmp += dp[l[i]]
    ans = max(ans, tmp)
    tmp -= dp[l[i-(k-1)]]
print(ans)


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

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string r = string(ty-sy, 'U') + string(tx-sx, 'R') + string(ty-sy, 'D') + string(tx-sx, 'L');
	r += 'L' + string(ty-sy+1, 'U') + string(tx-sx+1, 'R') + "DR" + string(ty-sy+1, 'D') + string(tx-sx+1, 'L') + 'U';
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin>>a;
  if(a<9)
    cout<<a<<endl;
  else if(a<99)
    cout<<9<<endl;
  else if(a<999)
    cout<<a-90<<endl;
  else if(a<9999)
    cout<<909<<endl;
  else if(a<99999)
    cout<<a-9090<<endl;
  else
    cout<<90909<<endl;
}

Measured memory_bytes: 256
n = int(input())
mat = []
for _ in range(n):
    mat.append(list(map(int, input().split())))
inf = int(1e11 + 10)
dp = [[inf]*(n + 1) for _ in range(n + 1)]
for i in range(n):
    dp[i][i] = 0
for l in range(2, n + 1):
    for i in range(n):
        j = i + l - 1
        if i + l > n:
            break
        for k in range(i, j):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + mat[i][0]*mat[k][1]*mat[j][1])
print(dp[0][n - 1])


Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
struct st{
  int p,d,c,h;
  st(){}
  st(int p,int d,int c,int h):p(p),d(d),c(c),h(h){}
  bool operator<(const st& a) const{
    return d>a.d;
  }
};
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> G[10001];
short dp[10001][201][201];
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  for(int i=0;i<m;i++){
    int a,b,d;
    cin>>a>>b>>d;
    a--;b--;
    G[a].push_back(edge(b,d));
    G[b].push_back(edge(a,d));
  }
  memset(dp,-1,sizeof(dp));
  priority_queue<st> q;
  q.push(st(0,0,x,0));
  int ans=0;
  while(!q.empty()){
    st t=q.top();q.pop();
    if(~dp[t.p][t.c][t.h]&&dp[t.p][t.c][t.h]<=t.d) continue;
    dp[t.p][t.c][t.h]=t.d;
    if(t.p==n-1){
      ans=t.d;
      break;
    }
    for(int i=0;i<(int)G[t.p].size();i++){
      int v=G[t.p][i].to,u=G[t.p][i].cost;
      int c=max(0,t.c-u),h=max(0,t.h-u);
      if(~dp[v][c][h]&&dp[v][c][h]<=t.d+u) continue;
      if(s[v]==0){
	if(h>0) continue;
	q.push(st(v,t.d+u,x,h));
      }
      if(s[v]==1){
	q.push(st(v,t.d+u,c,h));
      }
      if(s[v]==2){
      	if(c>0) continue;
	q.push(st(v,t.d+u,c,x));
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 793336
#include<iostream>
#include<algorithm>
#include<tuple>
using namespace std;
pair<int, int>x[1000000]; tuple<int, int, int>y[1000000]; int Hush[1000000], Hush2[1000000], n, a; char c, T[5] = "HDSC";
int partition(int p, int r) { int X = x[r].second; int I = p - 1; for (int i = p; i < r; i++) { if (x[i].second <= X) { I++; swap(x[I], x[i]); } }swap(x[I + 1], x[r]); return I + 1; }
void quicksort(int p, int r) { if (p < r) { int q = partition(p, r); quicksort(p, q - 1); quicksort(q + 1, r); } }
int main() {
	cin >> n; for (int i = 0; i < n; i++) { cin >> c >> a; int R = 0; for (int j = 0; j < 4; j++) { if (T[j] == c) { R = j; } }x[i] = make_pair(R, a); y[i] = make_tuple(a, i, R); }
	quicksort(0, n - 1); sort(y, y + n); for (int i = 0; i < n; i++) { Hush[i] = x[i].second * 100 + x[i].first; Hush2[i] = get<0>(y[i]) * 100 + get<2>(y[i]); }
	int Stable = 1; for (int i = 0; i < n; i++) { if (Hush[i] != Hush2[i]) { Stable = 0; } }if (Stable == 1) { cout << "Stable" << endl; }
	else { cout << "Not stable" << endl; }for (int i = 0; i < n; i++) { cout << T[x[i].first] << ' ' << x[i].second << endl; }return 0;
}

Measured memory_bytes: 5744
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n,m,sum=0,p,x;
    cin >> n;
    int t[n];
    rep(i,n){
        cin >> t[i];
        sum+=t[i];
    }
    cin >> m;
    int ans[m];
    rep(i,m){
        int tmp=sum;
        cin >> p >> x;
        ans[i]=tmp-t[p-1]+x;
    }
    rep(i,m) cout << ans[i] << endl;;
	return 0;
}


Measured memory_bytes: 256
//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define fr first
#define sc second

using namespace std;

long long k;
int n, m;
int a[100020], A[100020], B[100020], C[100020], dif[100020];

void add()
{
  for(int i = 1; i < n; ++ i)
    C[i] = A[B[i]];
  for(int i = 1; i < n; ++ i)
    A[i] = C[i];
}

void pw()
{
  for(int i = 1; i < n; ++ i)
    C[i] = B[B[i]];
  for(int i = 1; i < n; ++ i)
    B[i] = C[i];
}

void go()
{
  while(k)
  {
    if(k % 2 == 1)
      add();
    pw(); k /= 2;
  }
}

int main()
{
  scanf("%d", &n);
  for(int i = 1; i <= n; ++ i)
  {
    scanf("%d", &a[i]);
    if(i == 1) continue;
    dif[i - 1] = a[i] - a[i - 1];
  }
  for(int i = 1; i < n; ++ i)
    A[i] = i, B[i] = i;

  scanf("%d%lld", &m, &k);
  for(int i = 1; i <= m; ++ i)
  {
    int x;
    scanf("%d", &x);
    swap(B[x - 1], B[x]);
  }
  go();
  printf("%d\n", a[1]);
  long long s = a[1];
  for(int i = 1; i < n; ++ i)
  {
    s += dif[A[i]];
    printf("%lld\n", s);
  }
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
static const int INFTY = (1<<20);

//ABC156_c
int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	rep(i, N) {
		cin >> vec.at(i);
	}

	int power = INFTY;
	for (int x=0; x<=100; x++) {
		int sum = 0;
		rep(i, N) {
			int dist = (vec.at(i)-x)*(vec.at(i)-x);
			sum += dist;
		}
		if (power > sum) {
			power = sum;
		}
	}
	cout << power << endl;
}

Measured memory_bytes: 256
# 0 or 1 Swap
n = int(input())
a_list = list(map(int, input().split()))
b_list = range(1, n+1)
cnt = 0
for a, b in zip(a_list, b_list):
    if a != b:
        cnt+= 1
if cnt <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
k = int(input())
c = 0
if k%2 ==0 or k%5==0:
    print(-1)
    c=1
elif k==1:
    print(1)
    c=1
if c==0:
    t = 7

    for i in range(k):
        if int(t)%k==0 :
            print(i+1)
            break
        t = (10*t+7)%k

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b;
    cin >> a >> b;
    REP(i,1,b+1){
        if((a*i) % b == 0){
            cout << a*i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi A(n);
	int pre = -1;
	int ans = 0;
	REP(i,n){
		int a;
		cin >> a;
		if(pre == a){
			ans++;
			pre = -1;
		}else{
			pre = a;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(void) {
	int n,k;
	cin >> n>>k;
	int ans = 0;
	vector<bool> a(n,false);
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int temp;
			cin >> temp;
			a[temp - 1] = true;
		}
	}

	for (int j = 0; j < n; j++) {
		if (a[j] == false) {
			ans++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3208
(a, b, c, d) = gets.chars.map(&:to_i)

['+', '-'].each do |op1|
  ['+', '-'].each do |op2|
    ['+', '-'].each do |op3|
      e = sprintf("%d%s%d%s%d%s%d", a, op1, b, op2, c, op3, d)
      if eval(e) == 7
        puts e+'=7'
        exit(0)
      end
    end
  end
end


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

int main(void)
{
    string ans[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    int    n;
    cin >> n;
    cout << ans[(n % 10)] << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;
long long cnt[100100];
int d[100100];
int n;
long long pow(long long a,long long b){
	long long res=1LL;
	while(b){
		if(b&1)
			res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res%MOD;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>d[i];
	if(d[1]!=0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
		cnt[d[i]]+=1LL;
	if(cnt[0]>1){
		cout<<0<<endl;
		return 0;
	}
	long long res=1LL;
	for(int i=2;i<=n;i++){
		res*=pow(cnt[i-1],cnt[i]);
		res%=MOD;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1408
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;

signed main(){
    int a,b,n;cin>>n>>a>>b;
    cout<<min(b,n*a)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w,n;
int a[1005][1005],l=1;
int wypisz[1005];
int main()
{
    ios_base::sync_with_stdio(0);

    cin>>h>>w;

    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin >> a[i][j];
        }
    }

    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(a[i][j]%2 == 0) continue;
            else
            {
                if(a[i][j+1]%2!=0)
                {
                     wypisz[l]=i; wypisz [l+1]=j; wypisz[l+2]=i; wypisz[l+3]=j+1;
                     l+=4;
                    a[i][j]--; a[i][j+1]++;
                    n++;
                    continue;
                }
                if(a[i+1][j]%2!=0 && i+1!=w+1)
                {
                    wypisz[l]=i; wypisz [l+1]=j; wypisz[l+2]=i+1; wypisz[l+3]=j;
                    l+=4;
                     a[i][j]--; a[i+1][j]++;
                    n++;
                    continue;
                }
                else
                {
                  if(j+1!=w+1)
                  {
                      wypisz[l]=i; wypisz [l+1]=j; wypisz[l+2]=i; wypisz[l+3]=j+1;
                      l+=4;
                    a[i][j]--; a[i][j+1]++;
                    n++;
                    continue;
                  }
                  else if (i+1!=h+1)
                  {
                       wypisz[l]=i; wypisz [l+1]=j; wypisz[l+2]=i+1; wypisz[l+3]=j;
                       l+=4;
                     a[i][j]--; a[i+1][j]++;
                    n++;
                    continue;
                  }
                    }
                }
            }
        }
        cout<<n<<endl;
        for(int i=1;i<l;i++)
        {
            cout<<wypisz[i];
            if(i%4!=0) cout<<" ";
            if(i%4==0) cout<<endl;
        }
    }


Measured memory_bytes: 4096
def test():

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

	r = inputs[0]
	c = inputs[1]

	sheet = [[0 for i in range(c+1)] for j in range(r+1)]

	for i in range(r):

		inputs = list(map(int,input().split()))
		
		for j in range(c):
			sheet[i][j] = inputs[j]
			sheet[i][c] += sheet[i][j]
			sheet[r][j] += sheet[i][j]
			sheet[r][c] += sheet[i][j]


	for i in range(r+1):
		for j in range(c+1):
			print(f"{sheet[i][j]}",end='')
			if j != c:
				print(" ",end='')

		print("")

if __name__ == "__main__":
	test()


Measured memory_bytes: 6748
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int func(int x){
	return max(0, 1001 - abs(1000 - x));
}

int main(){
	int n;
	while(cin >> n){
		int ans = 0;
		for(int i = 0; i <= n; ++i){
			ans += func(i) * func(n - i);
		}
		cout << ans << '\n';
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(void){
    long long n;
    int i;
    scanf("%lld",&n);
    long long a=1, b=n;
    long long c=n+1;
    for(i=2;i<1000000+1;i++){
        if(n%i == 0 && (int)(n/i)+i <= c){
            a = i;
            b = n/i;
            if(a>b) break;
            c = a + b;
        }
    }
    printf("%lld\n",c-2);
    return 0; 
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
  private static List<Integer> getPrime(int n) {
    Deque<Integer> seek = new ArrayDeque<>();
    seek.add(2);
    for (int i = 3; i <= n; i += 2) {
      seek.add(i);
    }
    List<Integer> primes = new ArrayList<>();
    while (true) {
      int prime = seek.poll();
      primes.add(prime);
      if ((double) prime >= Math.sqrt(n)) {
        primes.addAll(seek);
        break;
      }
      Deque<Integer> newSeek = new ArrayDeque<>();
      while (!seek.isEmpty()) {
        int val = seek.poll();
        if (val % prime == 0) continue;
        newSeek.add(val);
      }
      seek.clear();
      seek.addAll(newSeek);
    }
    return primes;
  }
  private static int countPair(int n, Set<Integer> primeSet) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
      if (primeSet.contains(i) && primeSet.contains(n + 1 - i)) {
        count++;
      }
    }
    return count;
  }
  private static void solve(List<Integer> n) {
    int max = 1;
    for (int val : n) max = Math.max(max, val);
    List<Integer> primes = getPrime(max);
    Set<Integer> primeSet = new HashSet<>();
    primeSet.addAll(primes);
    int count = 0;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n.size(); i++) {
      if (i > 0) sb.append("\n");
      sb.append(countPair(n.get(i), primeSet));
    }
    System.out.println(sb.toString());
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> n = new ArrayList<>();
    while (sc.hasNextLine()) {
      String line = sc.nextLine();
      n.add(Integer.parseInt(line));
    }
    sc.close();
    solve(n);
  }
}



Measured memory_bytes: 60740
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int n,p[5005],pa[5005],sze[5005];
bool flag[5005];
ll f[5005][5005],fact[5005];
int find(int x)
{
	return x==pa[x]?x:pa[x]=find(pa[x]);
}
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)pa[i]=i,sze[i]=1;
	int num=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		if(p[i]==-1)continue;
		num--;
		int u=find(i),v=find(p[i]);
		if(u!=v)
		{
			pa[u]=v;
			sze[v]+=sze[u];
		}
	}
	for(int i=1;i<=n;i++)
	  if(p[i]==-1)flag[find(i)]=1;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		if(find(i)!=i||!flag[find(i)])
		{
			for(int j=0;j<=n;j++)
			  f[i][j]=f[i-1][j];
			continue;
		}
		for(int j=1;j<=n;j++)
		  f[i][j]=(f[i-1][j]*(n-1)+f[i-1][j-1]*sze[i])%MOD;
		f[i][0]=f[i-1][0]*(n-1)%MOD;
	}
	ll ans=n*quick_pow(n-1,num)%MOD;
	fact[0]=1;
	for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
	for(int i=2;i<=n;i++)ans=(ans-f[n][i]*fact[i-1])%MOD;
	for(int i=1;i<=n;i++)
	{
		if(find(i)!=i)continue;
		if(flag[i])ans=(ans-(sze[i]-1)*quick_pow(n-1,num-1))%MOD;
		else ans=(ans-quick_pow(n-1,num))%MOD;
	}
	if(ans<0)ans+=MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 197304
import heapq
N = int(input())

hq = []
heapq.heapify(hq)  # リストhqのheap化
for i in range(N):
    X, L = map(int, input().split())
    heapq.heappush(hq, (X+L, X-L))  # heap化されたリストhqに要素xを追加

T = -10**10
ans = 0
for i in range(N):
    t, s = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    # print(t, s, T)
    if s >= T:
        ans += 1
        T = t
print(ans)


Measured memory_bytes: 63576