akhauriyash/Code-Regression huggingface dataset:
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

class Point {
 public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }

  double abs() { return sqrt(norm()); }
  double norm() {return x * x + y * y; }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

};

typedef Point Vector;

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

struct Segment {
  Point p1, p2;
};

typedef Segment Line;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
  if (cross(a, b) < -EPS) return CLOCKWISE;
  if (dot(a, b) < -EPS) return ONLINE_BACK;
  if (a.norm() < b.norm()) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
          ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool intersect(Segment s1, Segment s2) {
  return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double getDistance(Point p1, Point p2) {
  return (p2 - p1).abs();
}

double getDistanceLP(Line l, Point p) {
  return abs(cross(l.p2 - l.p1, p - l.p1) / (l.p2 - l.p1).abs());
}

double getDistanceSP(Segment s, Point p) {
  if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return (p - s.p1).abs();
  if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return (p - s.p2).abs();
  return getDistanceLP(s, p);
}

double getDistance(Segment s1, Segment s2) {
  if (intersect(s1, s2)) return 0.0;
  return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
             min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}

int main() {
  int n;
  cin >> n;
  Segment s1, s2;
  cout << fixed;
  for (int i = 0; i < n; i++) {
    cin >> s1.p1.x >> s1.p1.y >> s1.p2.x >> s1.p2.y;
    cin >> s2.p1.x >> s2.p1.y >> s2.p2.x >> s2.p2.y;
    cout << setprecision(10) << getDistance(s1, s2) << endl;
  }
  return 0;
}



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

int main() {
	int n,k;
	cin >> n >> k;
	if(k>=n) {
		cout << 1 << endl;
		return 0;
	}
	
	int a[1000001];
	int one=0;
	for(int i=0;i<n;i++){
		cin >>a[n];
	            if(a[i]==1)one=i;	
	}
	int ans=0;
	int f=one,b=n-one-1;
	if(f+1<k){
	   b = b -(k-f-1);
	   ans++;
	   f=0;
	}
	if(b+1<k){
	   f = f-(k-b-1);
	   ans++;
	   b=0;
	}
	k--;
	while(f>0){
		ans++;
		f=f-k;
	}
	while(b>0){
		ans++;
		b=b-k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
C = [list(map(int,input().split())) for i in range(3)]

list_a = [0, C[1][0] - C[0][0], C[2][0] - C[0][0]]
list_b = [C[0][0], C[0][1], C[0][2]]

for i in range(3) :
    for j in range(3) :
        if C[i][j] != list_a[i] + list_b[j] :
            print("No")
            exit()

print("Yes")


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

int a[21];
int b[21];
int c[21];

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

  long long ans = 0;

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

  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    ans += b[i];
  }

  for (int i = 1; i < n; i++) {
    cin >> c[i];
  }

  for (int i = 1; i < n ; i++) {
    if (a[i] == a[i + 1] - 1)
      ans += c[a[i]];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
n = int(input())
S = [input() for _ in range(n)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
  if s[0] == "M":
    M += 1
  elif s[0] == "A":
    A += 1
  elif s[0] == "R":
    R += 1
  elif s[0] == "C":
    C += 1
  elif s[0] == "H":
    H += 1
U = [M,A,R,C,H]
for x,y,z in itertools.combinations(U,3):
  ans += x * y * z
print(ans)

Measured memory_bytes: 9772
n,y = map(int,input().split())

ans = [-1,-1,-1]
for i in range(0,n+1):
  for j in range(0,n+1):
    if i*10000 + j*5000 + (n-i-j)*1000 == y and n-i-j>=0:
      ans = [i,j,n-i-j]
      
print(ans[0],ans[1],ans[2])

Measured memory_bytes: 3064
N = int(input())
A = [int(i) for i in input().split()]
che1 = sum(A)//N
che2 = sum(A)//N + 1
ans1 = 0
ans2 = 0

for i in A:
    ans1 += (i-che1)**2
    ans2 += (i-che2)**2
    
print(min(ans1, ans2))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String S = scanner.nextLine();

        int price = 700;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'o') {
                price += 100;
            }
        }

        System.out.println(price);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    if (A[0] & 1)
    {
        cout << 0 << endl;
        return 0;
    }
    A[1] -= A[0];
    A[2] -= A[0];
    int now = 0;
    while (true)
    {
        if ((A[1] & 1) || (A[2] & 1)) break;
        if (A[1] == 0 and A[2] == 0)
        {
            now = -1;
            break;
        }
        int a = A[1] / 2;
        int b = A[2] / 2;
        A[1] = b - a;
        A[2] = b;
        now++;
    }
    cout << now << endl;
}


Measured memory_bytes: 256
N = gets.to_i
$as = gets.split.map(&:to_i)

def f(m)
  ret = 0
  for i in 0..(N - 1) do
    a = $as[i]
    ret += m % a
  end
  ret
end

target = 1
$as.each do |a|
  target = target.lcm(a)
end

puts f(target - 1)

Measured memory_bytes: 11420
#include <iostream>
#include<cstdio>
#include <math.h>
using namespace std;
int main(void){

    

    int n,d,s;
    cin>>n;
    s=n/1.08;
    if(s*1.08>=n&&s*1.08<n+1){
        cout<<s<<endl;
    }else if((s-1)*1.08>=n&&(s-1)*1.08<n+1){
        cout<<s-1<<endl;
    }else if((s+1)*1.08>=n&&(s+1)*1.08<n+1){
        cout<<s+1<<endl;
    }
    else {
        cout<<":("<<endl;
    }

}

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

#include <cmath>
void _140() {
    int n;
    cin >> n;
    int b[100];
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
        if (i == 0) {
            sum += b[i];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    sum += b[n - 2];

    cout << sum << endl;
}

void _141() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[100000];
    int point[100000] = {0};
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
        point[a[i] - 1]++;
    }

    for (int i = 0; i < n; ++i) {
        if (k + point[i] - q > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 }

#include <vector>
#include <algorithm>
void _142() {
    int n;
    cin >> n;
    int a;
    vector<pair<int, int> > list;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        list.push_back(make_pair(a, i + 1));
    }

    sort(list.begin(), list.end());
    for (int i = 0; i < n; ++i) {
        cout << list[i].second;
        if (i == n - 1)
            cout << endl;
        else
            cout << " ";
    }
}

#include <string>
void _143() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    char prev_color = s[0];
    int count = 1;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != prev_color) {
            count++;
            prev_color = s[i];
        }
    }
    cout << count << endl;
}

void _144() {
    LL n;
    cin >> n;
    LL m = floor(sqrt(n));

    LL result = 0;
    for (LL i = m; m > 0; --i) {
        if (n % i == 0) {
            result = i + n / i - 2;
            break;
        }
    }
    cout << result << endl;
}

int main()
{
    _144();

    return 0;
}



Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50==X:
                ans += 1

print(ans)

Measured memory_bytes: 67288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // candは前の日に試合をやった人
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int> (N-1));
    rep(i, N) rep(j, N-1) {
        cin >> A[i][j];
        --A[i][j];
    }
    rep(i, N) reverse(A[i].begin(), A[i].end());
    vector<P> cand;
    auto check = [&](int x) {
        if (A[x].empty()) return;
        int op = A[x].back();
        if (A[op].back() == x) {
            P p(x, op);
            if (p.second < p.first) swap(p.first, p.second);
            cand.push_back(p);
        }
    };
    rep(i, N) check(i);
    int ans = 0;
    while (!cand.empty()) {
        ans++;
        vector<P> prevCand;
        sort(cand.begin(), cand.end());
        cand.erase(unique(cand.begin(), cand.end()), cand.end());
        swap(cand, prevCand);
        for (auto p : prevCand) {
            int a = p.first, b = p.second;
            A[a].pop_back(); A[b].pop_back();
            check(a); check(b);            
        }
    }
    rep(i, N) {
        if (!A[i].empty()) {
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
    return 0;
}

// 15

Measured memory_bytes: 7544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double d = sc.nextDouble();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (Math.sqrt(Math.pow(sc.nextDouble(), 2) + Math.pow(sc.nextDouble(), 2)) <= d) {
				++count;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 65536
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;

int a[N * 3];
std::multiset <int> pre, sufbig, sufsmall;
std::vector <int> vec;
int n;

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n * 3; ++ i){
		scanf("%d", &a[i]);
	}
	ll sumpre = 0;
	for (int i = 0; i < n; ++ i){
		pre.insert(a[i]);
		sumpre += a[i];
	}
	for (int i = 0; i < n << 1; ++ i){
		vec.push_back(a[i + n]);
	}
	std::sort(vec.begin(), vec.end());
	ll sumsuf = 0;
	for (int i = 0; i < n; ++ i){
		sufsmall.insert(vec[i]);
		sumsuf += vec[i];
	}
	for (int i = 0; i < n; ++ i){
		sufbig.insert(vec[i + n]);
	}
	ll ans = sumpre - sumsuf;
	for (int i = n; i < n << 1; ++ i){
		if (sufbig.count(a[i])){
			sufbig.erase(sufbig.find(a[i]));
		}
		else{
			sufsmall.erase(sufsmall.find(a[i]));
			sumsuf -= a[i];
			int x = *(sufbig.begin());
			sumsuf += x;
			sufbig.erase(sufbig.begin());
			sufsmall.insert(x);
		}
		pre.insert(a[i]);
		sumpre += a[i];
		auto u = pre.begin();
		sumpre -= *u;
		pre.erase(u);
		ans = std::max(ans, sumpre - sumsuf);
	}
	return printf("%lld\n", ans), 0;
			
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    ll n,k,s; cin >> n >> k >> s;
    rep(i, n) {
        ll out = s;
        if(i >= k) {
            if(s == 1e9) out--;
            else out++;
        }
        if(i == n-1) {
            cout << out << endl;
        } else {
            cout << out << " " << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main(){

  string S;
  cin >> S;

  vector<int> counter(2);

  for(int i = 0; i < S.size(); i++){
    if(S[i] == '0'){
      counter[0] += 1;
    }else{
      counter[1] += 1;
    }
  }
  int vanish = min(counter[0], counter[1]);

  cout << vanish*2 << endl;
}


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

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

    string S;
    cin >> S;

    int f = (S[0] - '0') * 10 + (S[1] - '0');
    int l = (S[2] - '0') * 10 + (S[3] - '0');

    if ((f == 0 || f >= 13) && (1 <= l && l <= 12))
    {
        cout << "YYMM" << endl;
    }
    else if ((1 <= f && f <= 12) && (l == 0 || l >= 13))
    {
        cout << "MMYY" << endl;
    }
    else if ((f == 0 || f >= 13) && (l == 0 || l >= 13))
    {
        cout << "NA" << endl;
    }
    else
    {
        cout << "AMBIGUOUS" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,K;
int R,S,P;
char T[N];
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int ans;
char sta[N];
bool mk[N];
inline int calc(int p) {
	memset(mk,false,sizeof(mk));
	int ret=0,tot=0;
	for (register int i=p;i<=n;i+=K) {
		sta[++tot]=T[i];
	}
	for (register int i=1;i<=tot;++i) {
		if (sta[i]==sta[i-1]&&mk[i-1]) continue;
		if (sta[i]=='r') ret+=P;
		else if (sta[i]=='s') ret+=R;
		else ret+=S;
		mk[i]=true;
	}
	return ret;
}
int main() {
//	freopen("in.txt","r",stdin);
	n=read(),K=read();
	R=read(),S=read(),P=read();
	scanf("%s",T+1);
	for (register int s=1;s<=K;++s) {
		ans+=calc(s);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4048
#include <cstdio>
#include <algorithm>
#include <cstdint>
#include <vector>

using namespace std;

int main() {
    size_t N;
    scanf("%zu", &N);

    vector<int64_t> A(N);
    int64_t sum=0;
    for (size_t i=0; i<N; ++i) {
        scanf("%lld", &A[i]);
        sum += A[i];
    }

    int64_t num=N*(N+1LL)/2;

    if (sum % num)
        return !printf("NO\n");

    vector<int64_t> B(N, A[N-1]-A[0]);
    for (size_t i=0; i<N-1; ++i)
        B[i] = A[i] - A[i+1];

    for (size_t i=0; i<N; ++i) {
        if (B[i]) break;
        if (i == N-1)
            return !printf("YES\n");
    }

    int64_t k=sum/num, d=k;
    for (size_t i=0; i<N; ++i) {
        if ((B[i]+d) % N)
            return !printf("NO\n");

        k -= (B[i]+d) / N;
    }

    printf("%s\n", k? "NO":"YES");
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, A, B;
int X[100100];

signed main() {
    cin >> N >> A >> B;
    rep(i, N) {
        cin >> X[i];
    }
    int ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        int costA = (X[i + 1] - X[i]) * A;
        ans += min(costA, B);
    }
    cout << ans << endl;
    return 0;
}


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

int a[200002];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    int lo = 1, hi = 1e9, ans;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        long long sum = 0;
        for(int i=1;i<=n;i++){
            sum += (a[i]+mid-1)/mid;
        }
        sum -= n;
        if(sum <= k) ans = mid, hi = mid-1;
        else lo = mid+1;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 4600
n = gets.chomp.to_i
ary = gets.chomp.split(" ").map(&:to_i)[0..n-1]

dist = {}
ary.each do |num|
  dist[num.to_s] = dist[num.to_s].to_i + 1
end

ary_sum = ary.inject(:+)
dist_case_num = dist.sort_by {|k, v| -v}.first[0].to_i
avg_case_num = (ary_sum.to_f/ary.count).round
avg_case_sum = ary.inject(0) {|sum, num| sum + ((avg_case_num - num).abs ** 2) }
dist_case_sum = ary.inject(0) {|sum, num| sum + ((dist_case_num - num).abs ** 2) }

puts avg_case_sum > dist_case_sum ? dist_case_sum : avg_case_sum


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

const int MAXN = 2001;
const long long MODX = 1000000007;
int BIT[MAXN];
void add(int p, int v) {
	for (; p<MAXN; p+=p&-p)
		BIT[p] += v;
}
int sum(int p) {
	if (p <= 0)
		return 0;
	int ans = 0;
	for (; p>0; p-=p&-p)
		ans += BIT[p];
	return ans;
}

long long largebef[MAXN], largeall[MAXN];
int main() {
	memset(BIT, 0, sizeof(BIT));
	long long n, k;
	int a[MAXN];
	cin>>n>>k;
	for (int i=0; i<n; i++) {
		cin>>a[i];
		add(a[i], 1);
		largebef[i] = sum(a[i] - 1);
	}
	for (int i=0; i<n; i++)
		largeall[i] = sum(a[i] - 1);

	long long ans = 0;
	for (int i=0; i<n; i++) {
		// cout<<i<<"] "<<largebef[i]<<" "<<largeall[i]<<endl;
		ans += (largeall[i]%MODX) * (k*(k+1ll)/2ll%MODX) + MODX - largebef[i]*k%MODX;
		ans %= MODX;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
for i in range(1, n+1):
    cnt = 0
    for x in range(1, int(math.sqrt(i+1))):
        for y in range(1, int(math.sqrt(i+1))):
            d = (x+y)**2 -4*(x*x + y*y + x*y - i)
            if d < 0:
                pass
            else:
                z = (-(x+y)+math.sqrt(d))/2
                if z == int(z) and z >= 1:
                    cnt += 1
    print(cnt)

Measured memory_bytes: 75788
N,M = map(int,input().split())
P = []
S = []
for _ in range(M):
  p,s = map(str,input().split())
  P.append(int(p))
  S.append(s)
ac = ['WA']*N
wa = [0]*N

for i in range(M):
  if S[i] == 'WA':
    if ac[P[i]-1] == 'WA':
      wa[P[i]-1] += 1
  else:
    ac[P[i]-1] = 'AC'
for j in range(N):
  if ac[j] == 'WA':
    wa[j] = 0
print(ac.count('AC'),sum(wa))

Measured memory_bytes: 15404
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

template<typename T>
struct BIT{
    private:
        vector<T> array;
        const int n;
    public:
        BIT(int _n) : array(_n + 1, 0), n(_n) {}
        T sum(int i){
            T s = 0;
            while(i > 0){
                s += array[i];
                i -= i & -i;
            }
            return s;
        }
        T sum(int i, int j){
            T ret_i = sum(i-1);
            T ret_j = sum(j);
            return ret_j - ret_i;
        }
        void add(int i, T x){
            while(i <= n){
                array[i] += x;
                i += i & -i;
            }
        }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	BIT<int> bit(n+1);
	int c, x, y;
	rep(i,q){
		cin >> c >> x >> y;
		if(c == 0) bit.add(x, y);
		else cout << bit.sum(x, y) << endl;
	}
	return 0;
}


Measured memory_bytes: 3356
N, M = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for i in range(M):
  b, c = map(int, input().split())
  CB.append([c, b])

D = [[a, 1] for a in A] + CB

D.sort()

ans = 0
while N > 0:
  c, b = D.pop()
  ans += min(N, b)*c
  N -= b

print(ans)

Measured memory_bytes: 35772
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int n,x,y;
    cin >>n>>x>>y;
    x =x-1;
    y =y-1;
    
    Graph G(n);
    vector<int>ans(n);
    rep(i,n){
        if(i>0)G.at(i).push_back(i-1);
        if(i<n-1)G.at(i).push_back(i+1);
        if(i==x)G.at(i).push_back(y);
        if(i==y)G.at(i).push_back(x);
    }
    
    rep(i,n-1){
        
    vector<int>dist(n,-1);
    queue<int>que;
    
    dist[i]=0;
    que.push(i);
    
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        
        for(int nv:G[v]){
            if(dist[nv]!=-1) continue;
            //if(nv<i)continue;
            dist[nv] = dist[v]+1;
            if(nv>i)ans[dist[nv]]++;
            que.push(nv);
        }
    }
        
    }
    
    for(int i=1;i<n;i++)
        cout<<ans[i]<<endl;
    
    
}


Measured memory_bytes: 512
#!/usr/bin/env python3.4

# abc128_d

import collections

def find_index(iterable, func):
    i = 0
    for it in iterable:
        if func(it):
            break
        i += 1
    return i

def main():
    # Input
    n, k = [int(s) for s in input().split()]
    vs = [int(s) for s in input().split()]
    # Get ans
    R = min(n, k)
    def gene_lr():
        for i in range(1, R+1):
            for j in range(i+1):
                yield(i-j, j)
    def gene_tv():
        for l, r in gene_lr():
            tv = 0
            temp = vs[:l] + vs[n-r:]
            temp.sort()
            i = find_index(temp, lambda x: x>0)
            s = k-(l+r)
            s = min(i, s)
            yield sum(temp[s:])
    ans = max(gene_tv())
    ans = max(ans, 0)
    # Output
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
def resolve():
    n, k = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    h = sorted(h)
    ans = 10**9+1
    for i in range(0, n-k+1):
        ans = min(ans, abs(h[k-1+i] - h[i]))
    print(ans)
resolve()

Measured memory_bytes: 51032
import math

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

if (a ==1 and b==1 and x ==1) or (a*a*b == x):
    print(0)    

elif x < a*a*b/2:
    print(90-math.degrees(math.atan(2*x/(a * (b**2)))))
    
else:
    print(90-math.degrees(math.atan(a**3 / (2*(a*a*b-x)))))


Measured memory_bytes: 3060
const main = (lst,N) => {
    var count = 0
    for(var i = 0;i<lst.length;i++) {
        if(lst[i] != i+1) {
            count++
        }

    }
    if(count <= 2) {
        return "YES"
    }
    return "NO"
}

const input = require('fs').readFileSync('/dev/stdin','utf8').split("\n")
const N = Number(input[0])
const P = input[1].split(" ").map(x => Number(x))
console.log(main(P))

Measured memory_bytes: 7620
import itertools

N = int(input())
p = list(map(int, input().split(' ')))
q = list(map(int, input().split(' ')))

tp = tuple(p)
tq = tuple(q)

l = []
for i in range(1, N+1):
    l.append(i)

L = list(itertools.permutations(l))

tp_ind = L.index(tp)
tq_ind = L.index(tq)

ans = (tp_ind+1) - (tq_ind+1)
print(abs(ans))

Measured memory_bytes: 8052
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream','#')
f=1
for it in s:
    if it !='#':
        f=0
        break

if f==1:
    print("YES")
else :
    print("NO")

Measured memory_bytes: 9184
# B
n, a, b = map(int, input().split())
s = input()
count = 0
bcount = 0
for i in s:
    # print(i)
    if i == "a":
        if a + b > count:
            print('Yes')
            count += 1
        else:
            print('No')
    if i == 'b':
        if a + b > count and b > bcount:
            print('Yes')
            count += 1
            bcount += 1
        else:
            print('No')
    if i == "c":
        print('No')
    # print(count,bcount)


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

using namespace std;
using ll = long long;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=2e5+10;
const ll mod=1e9+7;

int ans=0,fans=-1e9;
vector<bool> vis(maxn,false);
vector<vector<int>> g(maxn);
void dfs(int v){
	vis[v]=true;
	++ans;
	for(int to : g[v]){
		if(!vis[to])
			dfs(to);
	}
}

void kx(int n){
	for(int i=0;i<n;i++){
		if(!vis[i]){
			ans=0;
			dfs(i);	
		}
		fans=max(ans,fans);
	}
}

int main(){
	fast;
	int n,m,i,j,k,u,v;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>u>>v;
		--u,--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	kx(n);
	cout<<fans;
	
}

Measured memory_bytes: 20332
#include <iostream>
#include <math.h>
using namespace std;
int main(){
  int e = 1;
  while(1){
    int z = 0, y = 0, x = 0;
    int min_m = 1000000000;
    cin >> e;
    if(e == 0) break;
    // cout << "e: " << e << endl;
    while( e - pow(y,2) >= 0){
      z = 0;
      while(e - y*y - z*z*z >= 0){
        x = e - y*y - z*z*z;
        int m = x + y + z;
        // cout << "x" << x << "y" << y << "z" << z << endl;
        if (m < min_m){
          min_m = m;
        }
        z++;
      }
      y++;
    }
    cout << min_m << endl;
  }
}

Measured memory_bytes: 3104
#include<stdio.h>
#include<string.h>

#define M  1500000/* your task*/
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1+(key %(M-1)); }

int find(char str[]){ 
    long long key,i,h;
    key =getKey(str);
    for(i=0;;i++)
      {
	h=(h1(key)+i *h2 (key))%M;
	if(strcmp(H[h],str)==0) return 1;
	else if(strlen(H[h])==0) return 0;
      }
    return 0;
  }

int insert(char str[]){
  long long  key,i,h;
  key =getKey(str);
  for(i=0;;i++)
      {
	h=(h1(key)+i *h2 (key))%M;
	if(strcmp(H[h],str)==0)  return 1;
	else if(strlen(H[h])==0)
	  {
      strcpy(H[h],str);
      return 0;
	  }
      }
  /* your task */
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ )
      {
	H[i][0] = '\0';
      }
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ )
      {
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' )
	  {
	    insert(str);
	  }
	else
	  {
	    if (find(str))
	      {
		printf("yes\n");
	      }
	    else
	      {
		printf("no\n");
	      }
	  }
      }

    return 0;
}



Measured memory_bytes: 22300
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first;
#define Y second;
#define mp make_pair;
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int MOD = 1000000007;


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

// 	int t{},T{};
// 	cin>>t;T=t;
// 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        ll n{},m{},k{},a{},b{},c{},f{},q=0;
        cin>>n>>m;
        Fl(i,0,n){
            cin>>a>>b;
            c=a*a+b*b;
            if(sqrt(c)<=m){
                ++f;
            }
        }
        cout<<f<<endl;
        
 //   }
    
    
	return 0;
}

Measured memory_bytes: 3700
#include <stdio.h>

int main(void){
    int a;
    int b;
    int c;
    scanf("%d %d %d", &a, &b, &c);
    if(a < b && b < c)
    {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int count1=0,count2=0;
    for(int i=0;i<int(s.length());i++){
    if(i%2==0){
        if(s[i]=='1')
        count2++;
        if(s[i]=='0')
        count1++;
    }
    else{
        if(s[i]=='0')
        count2++;
        if(s[i]=='1')
        count1++;
    }
}
    cout<<min(count1,count2)<<endl;
}
    

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = long long;

const ll INF = static_cast<ll>(1e18);

template <typename T>
bool ch_min(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    ll max_v = accumulate(v.begin(), v.end(), static_cast<ll>(1));
    vector<vector<ll>> DP(N + 1, vector<ll>(max_v, INF));
    DP[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < max_v; j++) {
            ch_min(DP[i + 1][j], DP[i][j]);
            if (j - v[i] >= 0)
                ch_min(DP[i + 1][j], DP[i][j - v[i]] + w[i]);
        }
    }
    ll ans = 0;
    for (int i = 0; i < max_v; i++) {
        if (DP[N][i] <= W) {
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 80256
N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

sums = []
current_sum = 0
for a in A[1:][::-1]:
    current_sum += a
    sums.append(current_sum)
sums = sums[::-1]

ans = 0
for a, b in zip(A[:-1], sums):
    ans += a * b
    ans = ans % mod

print(ans)

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

int main( int argc, char *argv[] )
{
int A;
int B;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;

	if( A + B >= 10 )
		cout << "error" << endl;
	else
		cout << A + B << endl;

	return 0;
}




Measured memory_bytes: 256
n=int(input())
k=len(str(n))

from itertools import product

ans=0


for j in range(3,k+1):
    p=list(product([3,5,7],repeat=j)) 

    for c in p:
        if (3 not in c) or (5 not in c) or (7 not in c):
            continue
        
        tmp=''
        for i in c:
            tmp+=str(i)

        if int(tmp)<=n:
            ans+=1

print(ans)  

Measured memory_bytes: 12140
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    }else{
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
  public boolean hasNext() { skipUnprintable(); return hasNextByte();}
  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while(isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }
  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while(true){
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      }else if(b == -1 || !isPrintableChar(b)){
        return minus ? -n : n;
      }else{
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
  public int nextInt() {
    return (int)nextLong();
  }
}

public class Main {

  static FastScanner sc = new FastScanner();

  public static void main(String[] args) {

    int N = sc.nextInt();
    int M = sc.nextInt();

    ArrayList<City> cities = new ArrayList();
    for (int i=0; i<M; i++) {
      cities.add(new City(i, sc.nextInt(), sc.nextInt()));
    }

    cities.sort((x, y) -> {
      if (x.p == y.p) {
        return x.y - y.y;
      } else {
        return x.p - y.p;
      }
    });

    String[] ids = new String[M];

    int count = 0;
    for (int i=0; i<M; i++) {
      City c = cities.get(i);
      if (i == 0 || c.p != cities.get(i-1).p) count = 0;
      else count++;
      ids[c.i] = padding0(c.p, 6) + padding0(count+1, 6);
    }

    for (int i=0; i<M; i++) {
      System.out.println(ids[i]);
    }

  }

  static String padding0(int n, int m) {
    String s = Integer.toString(n);
    while (m - s.length() > 0) s = "0" + s;
    return s;
  }


  static class City {
    int i, p, y;
    City (int i, int p, int y) {
      this.i = i;
      this.p = p;
      this.y = y;
    }
  }

}


Measured memory_bytes: 73532
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    string s; cin >> s;
    if (s == ".") break;
    string t; cin >> t;
    auto fn = [](const string& s) -> pair< string, V<string> > {
      bool b = false;
      pair< string, V<string> > res;
      string curr;
      for (char c : s) {
        if (c == '"') {
          if (b) {
            res.first += '#';
            res.second.push_back(curr);
            curr = "";
          }
          b ^= true;
        } else {
          (b ? curr : res.first) += c;
        }
      }
      return res;
    };
    auto a = fn(s), b = fn(t);
    if (a == b) cout << "IDENTICAL\n";
    else if (a.first != b.first) cout << "DIFFERENT\n";
    else {
      bool f = true;
      if (a.second.size() != b.second.size()) f = false;
      int c = 0;
      if (f) {
        for (int i = 0; i < (int)a.second.size(); ++i) {
          c += a.second[i] != b.second[i];
        }
        if (c != 1) f = false;
      }
      cout << (f ? "CLOSE\n" : "DIFFERENT\n");
    }
  }
}


Measured memory_bytes: 3220
N=int(input())
S=input()
ans = 0
for i in range(0,N):
  for j in range(i+1,N):
    if S[i] != S[j]:
      k = j+j-i
      if k < N:
        if S[i] != S[k] and S[j] != S[k]:
          #print(i,j,k)
          ans += 1
ans = (S.count('R') * S.count('G') * S.count('B')) - ans
print(ans)



Measured memory_bytes: 9148
N,M = map(int,input().split())
edge = []
p = 'POSSIBLE'
i = 'IMPOSSIBLE'
for _ in range(M):
    edge.append(list(map(int,input().split())))

from1 = set()
is_reach = False
for go,to in sorted(edge,key=lambda x:x[0]):
    if go == 1:
        from1.add(to)
    else:
        if go in from1 and to == N:
            is_reach = True
            break
print(p if is_reach else i)

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

int main(){

 int64_t A,b;
 cin>>A;
 double B;
 cin>>B;

 b=100*B+0.1;
 int64_t ans=A*b/100;
 cout<<ans<<endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
using namespace std;
int main (){
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i<s.length(); i++){
		s[i] = s[i] + n;
		if (s[i]>90){
			s[i] = s[i] - 90 + 64;
		}
	}
	cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(N), cnt(100010, 0);
    REP (i, N) {
        cin >> X[i];
        cnt[X[i]]++;
    }
    vector<vector<int>> cntM(M, vector<int>());
    REP (i, 100010) if (cnt[i] > 0) {
        cntM[i % M].push_back(cnt[i]);
    }
    REP (i, M) sort(cntM[i].begin(), cntM[i].end(), greater<int>());
    int ans = accumulate(cntM[0].begin(), cntM[0].end(), 0LL) / 2;
    if (M >= 2 && M % 2 == 0) ans += accumulate(cntM[M / 2].begin(), cntM[M / 2].end(), 0LL) / 2;
    FOR (i, 1, (M + 1) / 2) {
        int suma = 0, sumb = 0;
        REP (j, cntM[i].size()) suma += cntM[i][j];
        REP (j, cntM[M - i].size()) sumb += cntM[M - i][j];
        int a = i, b = M - i;
        if (suma > sumb) {
            swap(a, b);
            swap(suma, sumb);
        }
        REP (j, cntM[b].size()) {
            while (cntM[b][j] >= 2 && sumb - 2 >= suma) {
                cntM[b][j] -= 2;
                sumb -= 2;
                ans++;
            }
            if (sumb - 2 < suma) break;
        }
        ans += suma;
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M, K;
        public const long MOD = 1000000007;
        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
                K = line[2];
            }

            int D = (N + M - 1) / (K - 1);

            var DP = new long[D + 1, M + 1]; // 使った桁数、1を使った個数
            DP[0, 0] = 1;

            for (int d = 1; d <= D; d++)
            {
                for (int m = 0; m <= M; m++)
                {
                    for (int k = 0; k < K && m + k <= M; k++)
                    {
                        DP[d, m + k] += DP[d - 1, m];
                        DP[d, m + k] %= MOD;
                    }
                }
            }

            long ret = 0;
            {
                int m = M;
                while (m > 0)
                {
                    int d = (N + m - 1) / (K - 1);
                    ret += DP[d, m];
                    ret %= MOD;
                    m -= K - 1;
                }
            }

            Console.WriteLine(ret);

       
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 73568
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
P = inintl()

min_l = []
now_min = P[0]
ans = 0

for p in P:
    if p < now_min:
        now_min = p
    min_l.append(now_min)

for i in range(n):
    if min_l[i] == P[i]:
        ans += 1

print(ans)


Measured memory_bytes: 101028
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	vector<pl> v(2);
	cin>>v[0].fi>>v[0].se>>v[1].fi>>v[1].se;
	sort(all(v));
	ll ans = min(v[0].se,v[1].se)-v[1].fi; 
	cout<<((ans>0)?ans:0)<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    if(k == 1) {
        cout << 0 << endl;
    }else{
        cout << n - k << endl;
    }

    return 0;
}



Measured memory_bytes: 256
// B - fLIP

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans = "No";
	for (int i=0; i<=N; i++) {
		for (int j=0; j<=M; j++) {
			int k = i * M + j * N - 2 * i * j;
			if (k == K) {
				ans = "Yes";
				break;
			}
		}
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
import itertools

n = int(input())
l = [i+1 for i in range(n)]
perm = list(map(list, list(itertools.permutations(l, n))))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
print(abs(perm.index(p)-perm.index(q)))

Measured memory_bytes: 50800
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt()-1;
        }
        boolean[] used = new boolean[n];
        used[0] = true;
        int nex = a[0];
        long size = 1L;
        for (int i = 0; i < n; i++) {
            if(used[nex]){
                break;
            }
            used[nex] = true;
            size++;
            nex = a[nex];
        }
        int ztor = 1;
        int r = nex;
        nex = a[0];
        for (int i = 0; i < size; i++) {
            if(nex == r) break;
            ztor++;
            nex = a[nex];
        }
        if(size != ztor) size -= ztor;
        int ans = 0;
        long rest = 0;
        if(ztor < k){
            k -= ztor;
            rest = k % size;
            ans = r;
        }else{
            rest = k;
        }
        for (int i = 0; i < rest; i++) {
            ans = a[ans];
        }
        System.out.println(ans+1);
        sc.close();

    }

}


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

int main () {
  int N;
  cin >> N;
  
  vector<int> map(N);
  for (int i = 0; i < N; i++)
    cin >> map.at(i);
  
  int button, count = 1;
  button = map.at(0);
  for (int i = 0; i < N; i++) {
    if (button == 2) {
      cout << count << endl;
      break;
    }
    else if (count == N) {
      cout << -1 << endl;
      break;
    }
    button = map.at(button - 1);
    count++;
  }
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int64_t k;
	std::cin >> k;
	k--;
	k *= 2;
	int a[n];
	for (auto &i : a) i = ri();
	std::sort(a, a + n);
	int64_t l = -1000000000000000001, r = 1000000000000000001;
	while (r - l > 1) {
		int64_t m = l + (r - l) / 2;
		int64_t cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > 0) cnt += std::lower_bound(a, a + n, a[i], [&] (int i, int j) { return (int64_t) i * j <= m; }) - a;
			else if (a[i] < 0) cnt += a + n - std::lower_bound(a, a + n, a[i], [&] (int i, int j) { return (int64_t) i * j > m; });
			else cnt += m >= 0 ? n : 0;
			if ((int64_t) a[i] * a[i] <= m) cnt--;
		}
		if (cnt <= k) l = m;
		else r = m;
	}
	printf("%lld\n", (long long) r);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

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

  while(ka<=b){
    ka+=k;
  }
  ka-=k;
  if(ka>=a){cout<<"OK"<<endl;}
  else{cout<<"NG"<<endl;}
  
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#pragma warning (disable:4996)
int main()
{
	int a,i,b;
	while (scanf("%d",&a)!= EOF)
	{
		for (i = 1;; i++)
		{
			if (i*i > a) {
				b = i - 1; break;
			}
		}
		printf("%d", b*b);
	}
}

Measured memory_bytes: 128
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int a,b,c;
   int arr[100005][3];
   int count1=0;
   int count2=0;
   int count=0;
   char temp,temp1;
   bool flag;
   while(cin>>a>>temp>>b>>temp1>>c)
   {
     if(a*a+b*b==c*c) count1++;
     else if(a==b) count2++;                              
   }
   cout<<count1<<endl;
   cout<<count2<<endl;  
   //while(1);     
   return 0;  
 }
 

Measured memory_bytes: 3004
#include <stdio.h>
#include <string.h>
int main()
{   int w,i=0;
    char s[1000];
    scanf("%s",s);
    scanf("%d",&w);
    
    while(i<strlen(s)){
    printf("%c",s[i]);
    i = i + w;
    
    }
    
    return 0;
}


Measured memory_bytes: 128