akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());

        var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var count = 0;

        for(var i = 0; i < N; i++)
        {
            for(var j = N - 1; j > i; j--)
            {
                if(A[j] < A[j - 1])
                {
                    var tmp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = tmp;
                    count++;
                }
            }
        }

        Console.WriteLine(string.Join(" ", A));
        Console.WriteLine(count);
    }
}



Measured memory_bytes: 20300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  string s;
  cin >> s;
  int n = sz(s) + 1;
  vector<ll> v(n);
  ll x = 0;
  for (int i = sz(s) - 1; i >= 0; --i) {
    (x += modpow(10, sz(s) - 1 - i, 2019) * (s[i] - '0')) %= 2019;
    v[i + 1] = x;
  }
  // cout << v << endl;
  map<ll, ll> mp;
  rep(i, n) mp[v[i]]++;
  ll ans = 0;
  for (auto e : mp) (ans += e.S * (e.S - 1) / 2);
  cout << ans << endl;
}


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

const ll INF = 1LL << 60;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    ll time = INF;
    for (int i = 0; i + K - 1 < N; ++i) {
        long long left = x[i], right = x[i + K - 1];
        time = min(time, min(abs(left), abs(right)) + right - left);
    }
    cout << time << endl;

    return 0;
}

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

int main() {
  int N, K, count = 0;
  cin >> N >> K;
  vector<vector<bool>> A(K, vector<bool>(N, false));
  for (int i = 0; i < K; i++){
    int d;
    cin >> d;
    for (int j = 0; j < d; j++){
      int has;
      cin >> has;
      A.at(i).at(has - 1) = true;
    }
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < K; j++){
      if(A.at(j).at(i) == true){
        goto CONTINUE_LABEL;
      }
    }
    count++;
    CONTINUE_LABEL:{}
  }
  cout << count << endl;
}

Measured memory_bytes: 3588
// https://atcoder.jp/contests/abc169/tasks/abc169_a
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
#define lli long long int

int main()
{
    int a,b;
    cin>>a>>b;
    a=a*b;
    cout<<a<<"\n";
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
  int N;
  int a[101];
  cin >> N;
  for(int i=0;i<N;++i) cin >> a[i];
  
  sort(a, a+N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  
  for(int i=0;i<N;++i){
    if(i%2 ==0) Alice += a[i];
    else Bob += a[i];
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    long long i,j,k,l,n,m,o,p,c;
    char a[9999];
    while(scanf("%lld %lld %lld %lld",&n,&m,&o,&p)==4)
    {
        c=0;
        for(i=0; i<p-m; i++)
        {
           printf("U");
        }
        for(i=0; i<o-n; i++)
        {
          printf("R");
        }
        for(i=0; i<p-m; i++)
        {
            printf("D");
        }
        for(i=0; i<o-n; i++)
        {
            printf("L");
        }
        for(i=0; i<1; i++)
        {
           printf("L");
        }
        for(i=0; i<p-m+1; i++)
        {
            printf("U");
        }
        for(i=0; i<o-n+1; i++)
        {
            printf("R");
        }
        for(i=0; i<1; i++)
        {
            printf("D");
        }
        for(i=0; i<1; i++)
        {
            printf("R");
        }
        for(i=0; i<p-m+1; i++)
        {
          printf("D");
        }
        for(i=0; i<o-n+1; i++)
        {
          printf("L");
        }
        for(i=0; i<1; i++)
        {
          printf("U");
        }

printf("\n");
    }

    return 0;







}


Measured memory_bytes: 128
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;




int main()
{
  int n; //かっている数//最大100
  cin >> n;
  vector<long> v(n);


  long ans = 0;

  vector<long> odd;
  vector<long> eve;

  vector<pair<long, long>> count_odd(100001, pair<long, long>(0, 0) );
  vector<pair<long, long>> count_eve(100001, pair<long, long>(0, 0) );



  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (i % 2 == 0) {
      odd.push_back(v[i]);
      count_odd[v[i]].first++;
      count_odd[v[i]].second = v[i];
    } else {
      eve.push_back(v[i]);
      count_eve[v[i]].first++;
      count_eve[v[i]].second = v[i];
    }

  }


  sort(count_odd.begin(), count_odd.end(), [](pair<long, long> & l, pair<long, long> & r) {
    return l.first > r.first;
  });

  sort(count_eve.begin(), count_eve.end(), [](pair<long, long> & l, pair<long, long> & r) {
    return l.first > r.first;
  });



  if (count_eve[0].second == count_odd[0].second) { //両方一致している場合
    long ans1,ans2;
    // if (count_eve[0].first > count_odd[0].first){
      ans1 = n / 2 - count_eve[0].first + n / 2 - count_odd[1].first;
    // }else{
      ans2 = n / 2 - count_odd[0].first + n / 2 - count_eve[1].first;
    // }
    ans = min(ans1,ans2);
    

    cerr << count_odd[0].first <<" : " <<count_odd[0].second <<endl;
    cerr << count_eve[0].first <<" : " <<count_eve[0].second <<endl;
  } else {
    ans = n / 2 - count_odd[0].first + n / 2 - count_eve[0].first;

    cerr << count_odd[0].first <<" : " <<count_odd[0].second <<endl;
    cerr << count_eve[0].first <<" : " <<count_eve[0].second <<endl;
  }






  cout << ans;
  return 0;
}



























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

int main()
{   
    int x;
    cin>>x;
    int ans=0;
    if(x==1){
        cout<<1<<endl;
        return 0;
    }
    else{
        for(int i=2;i<32;i++){
            for(int j=2;j<10;j++){
                if(pow(i,j)>x) continue;
                if(pow(i,j)>ans) ans=pow(i,j);
            }
        }
    }
    cout<<ans<<endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;

	int passed = 0;
	int foreign = 0;
	rep(i, n){
		if(s[i] == 'c'){
			cout << "No\n";
		}
		else if(s[i] == 'a' && passed < a+b){
			cout << "Yes\n";
			passed++;
		}
		else if(s[i] == 'b' && passed < a+b && foreign < b){
			cout << "Yes\n";
			passed++;
			foreign++;
		}
		else{
			cout << "No\n";
		}
	}
	return 0;
}

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

int main(){
    
int q;
cin >>q;
for(int i=0;i<q;i++){
    int c,a,n;
    cin >>c>>a>>n;
    int ans = 0;
    while(c!=0&&a!=0&&n!=0){
        ans += 1;
        c -= 1;
        a -= 1;
        n -= 1;
    }
    while(c>=2&&a!=0){
        ans += 1;
        c -= 2;
        a -= 1;
    }
    while(c>=3){
        ans += 1;
        c -= 3;
    }       
 
    cout <<ans<<endl;
}
    
    
return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) Perm(N);
    READVEC(Perm);
    int ret = 0;
    FOR(i, 1, N - 1)
        if (Perm[i] > min(Perm[i - 1], Perm[i + 1]) 
                && Perm[i] < max(Perm[i - 1], Perm[i + 1]))
            ret++;

    cout << ret << "\n";
    return 0;
};


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define mp make_pair
#define r0 return 0

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int a, b, t;
    cin >> a >> b >> t;
    if (t / a == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << t / a * b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

# Check bi >= ai is possible
a_s = sorted(a)
b_s = sorted(b)
for i, (aa, bb) in enumerate(zip(a_s, b_s)):
    if aa > bb:
        print("No")
        exit()

# Check there are pair such that ai <= ai+1 <= bi
for ai1, bi in zip(a_s[1:], b_s):
    if ai1 <= bi:
        print("Yes")
        exit()

# get ab's cyclic permutation
ba = []
for i, (aa, bb) in enumerate(zip(a, b)):
    ba.append((bb, aa))
ba.sort()

a_idx = []
for i, (bb, aa) in enumerate(ba):
    a_idx.append((aa, i))
a_idx.sort()

visited = [0] * n
cycle = 0
for i in range(n):
    curr = i
    if visited[curr] == 1:
        continue
    cycle += 1
    while visited[curr] == 0:
        visited[curr] = 1
        curr = a_idx[curr][1]
if cycle > 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 33116
import math
import collections
import itertools

def resolve():
    N=int(input())
    A=list(map(int,input().split()))

    B=[0]*N
    B[N-1]=A[N-1]
    MOD=10**9+7
    for j in range(N-2,0,-1):
        B[j]=(B[j+1]+A[j])%MOD
   
    ans=0
    for i in range(N-1):
        ans=ans%MOD+(A[i]*B[i+1])%MOD

    print(ans%MOD)

resolve()


Measured memory_bytes: 32324
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

#define EPS 0.0000000001 
#define equals(a, b) (fabs((a) - (b)) < EPS)

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

struct Segment {
	Point p1, p2;
};
typedef Segment Line;

class Circle{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef Point Vector;
typedef vector<Point> Polygon;

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

Point project(Segment s, Point p){
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}
Point reflect(Segment s, Point p){
	return p + (project(s, p) - p) * 2.0;
}

int main(void){
	Segment s;
	Point p;
	int q;
	cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
	cin >> q;
	for(int i=1;i<=q;i++){
		cin >> p.x >> p.y;
		Point reflection = reflect(s, p);
		printf("%.10f %.10f\n", reflection.x, reflection.y);
	}
	return 0;
}

Measured memory_bytes: 3280
from decimal import Decimal
from fractions import Fraction

import math
#import numpy as np
#n = int(input())
a,b = map(float,input().split())

#print(a)
#print(b)

aa = math.floor(a)

d1 = Decimal(str(a))
d2 = Decimal(str(b))

#print(str(d1)+' + '+str(d2)+' = '+str(Decimal(str(d1*d2))))
ans = math.floor(d1*d2)
print(ans)

Measured memory_bytes: 72876
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c=-4, n;
  string s;
  cin >> n;
  
  if(n%2==0) co(n);
  else co(2*n);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int people=scan.nextInt();
    int po=scan.nextInt();
    int prob=scan.nextInt();
    int[] pronum=new int[prob];
    int[] point=new int[people];
    for(int a=0;a<prob;a++){
      pronum[a]=scan.nextInt();
    }
    scan.close();
    for(int a=0;a<people;a++){
      point[a]=po-prob;
    }
    for(int a=0;a<prob;a++){
          point[pronum[a]-1]++;
    }
    for(int a=0;a<point.length;a++){
      if(point[a]>0){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 57252
#include <bits/stdc++.h>
using namespace std;
   
int main(void){
    int n;
    cin >> n;
    int tot=0, c=0;
    vector<int> wv(n);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a; 
        tot += a;
        wv[i] = tot;
    }
    auto it = upper_bound(wv.begin(), wv.end(), tot/2);
    int idx = distance(wv.begin(), it);
    int x = abs(tot - 2*wv[idx]);
    if (idx > 0) x = min(x, abs(tot - 2*wv[idx-1]));
    cout << x << endl;
    return 0;
}

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

void solve(long long L, long long R, long long d)
{
    long long counter = 0;
    for (long long i = L; i <= R; i++)
    {
        if (i % d == 0)
        {
            counter++;
        }
    }
    cout << counter << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long L;
    scanf("%lld", &L);
    long long R;
    scanf("%lld", &R);
    long long d;
    scanf("%lld", &d);
    solve(L, R, d);
    return 0;
}


Measured memory_bytes: 3756
# -*- coding: utf-8 -*-

import sys

a, b = [int(e) for e in raw_input().split()]
s = raw_input().split()[0]

sa = s[:a]
sh = s[a:a+1]
sb = s[a+1:]

if len(sa) == a:
    if  sa.isdigit():
        if sh == '-':
            if len(sb) == b:
                if sb.isdigit():
                    sys.stdout.write('Yes\n')
                    sys.stdout.flush()
                    sys.exit(0)

sys.stdout.write('No\n')
sys.stdout.flush()


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

int main(){
    double x1,y1,x2,y2,x3,y3,x4,y4;
    
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4){
        if(x4 < x1 || x2 < x3 || y2 < y3 || y4 < y1) cout << "NO" << endl;
        else cout << "YES" << endl;        
    }
    
    return 0;
}

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

int main(){
    int n;
    cin >>n;
    vector<int> a,b,c;
    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }

    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long ans = 0;
    for(int i=0;i<b.size();i++){
        long long  a_right = lower_bound(a.begin(),a.end(),b[i])-a.begin();
        long long  c_left =  c.end()-upper_bound(c.begin(),c.end(),b[i]);
        ans += a_right*c_left;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1784
#include "bits/stdc++.h"

using namespace std;

vector<long long> parents;
vector<long long> sizes;

void init(long long n) {
    parents = vector<long long>(n, 0LL);
    sizes = vector<long long>(n, 1LL);
    for (long long i = 0; i < n; ++i) {
        parents[i] = i;
    }
}

long long find(long long x) {
    if (parents[x] == x) {
        return x;
    }
    else {
        parents[x] = find(parents[x]);
        return parents[x];
    }
}

void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }
    if (sizes[x] > sizes[y]) {
        parents[y] = x;
        sizes[x] += sizes[y];
    }
    else { // (sizes[y] >= sizes[x])
        parents[x] = y;
        sizes[y] += sizes[x];
    }
}

bool same(long long x, long long y) {
    return find(x) == find(y);
}

void Main() {
    long long N, M;
    cin >> N >> M;
    vector<long long> A(M, 0), B(M, 0);
    for (long long i = 0; i < M; ++i) {
        cin >> A[i] >> B[i];
        A[i] -= 1LL;
        B[i] -= 1LL;
    }
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());

    init(N);
    vector<long long> ans(M, -1);
    ans[0] = N * (N - 1LL) / 2LL;
    for (long long i = 0; i < M - 1; ++i) {
        if (ans[i] == 0LL) {
            ans[i + 1] = 0LL;
        }
        else {
            if (!same(A[i], B[i])) {
                long long szA = sizes[find(A[i])];
                long long szB = sizes[find(B[i])];
                ans[i + 1] = ans[i] - szA * szB;
            }
            else {
                ans[i + 1] = ans[i];
            }
            unite(A[i], B[i]);
        }
    }
    reverse(ans.begin(), ans.end());

    for (long long i = 0; i < M; ++i) {
        cout << ans[i] << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7228
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll N, M;

    cin >> N >> M;

    vector<vector<ll> > d(N);
    ll t[N];
    ll A, B;
    queue<ll> q;

    for(ll i = 0; i < N; i++){
        t[i] = -1;

    }
    for(ll i = 0; i < M; i++){
        cin >> A >> B;
        d[A - 1].push_back(B - 1);
        d[B - 1].push_back(A - 1);
    }

    t[0] = 0;
    ll p = 0;
    q.push(0);
    while(!q.empty()){
        p = q.front();
        for(ll i = 0; i < d[p].size(); i++){
            if(t[d[p][i]] == -1){
                q.push(d[p][i]);
                t[d[p][i]] = p;
            }
        }
        q.pop();
    }

    cout << "Yes" << endl;
    for(ll i = 1; i < N; i++){
        cout << t[i] + 1 << endl;
    }

    return 0;
}


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

using namespace std;

struct Dice
{
  int x, y;
  int l, r, f, b, d, u;

  inline void RollF()
  {
    --y;
    int buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
  }

  inline void RollB()
  {
    ++y;
    int buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
  }

  inline void RollL()
  {
    --x;
    int buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
  }

  inline void RollR()
  {
    ++x;
    int buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
  }
};

int N;
Dice dice[15];
string rot[15];
int dp[1 << 15];
int v[2100][2100], buff[2100][2100];

inline void Roll(Dice& obj, char c)
{
  switch(c) {
    case 'L':
      obj.RollL();
      return;
    case 'R':
      obj.RollR();
      return;
    case 'B':
      obj.RollB();
      return;
    case 'F':
      obj.RollF();
      return;
    default:
      return;
  }
}

inline int AddDice(int idx)
{
  int ret = 0;
  Dice obj = dice[idx];
  for(char c : rot[idx]) {
    Roll(obj, c);
    if(v[obj.y][obj.x] == -1) {
      v[obj.y][obj.x] = idx;
      buff[obj.y][obj.x] = obj.d;
      ret += obj.d;
    } else if(v[obj.y][obj.x] == idx) {
      ret -= buff[obj.y][obj.x];
      ret += obj.d;
      buff[obj.y][obj.x] = obj.d;
    }
  }
  return (ret);
}

inline void DeleteDice(int idx)
{
  Dice obj = dice[idx];
  for(char c : rot[idx]) {
    Roll(obj, c);
    if(v[obj.y][obj.x] == idx) {
      v[obj.y][obj.x] = -1;
    }
  }
}

inline int rec(int bit)
{
  if(bit == (1 << N) - 1) return (0);
  if(~dp[bit]) return (dp[bit]);
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if((bit >> i) & 1) continue;
    int get = AddDice(i);
    ret = max(ret, rec(bit | (1 << i)) + get);
    DeleteDice(i);
  }
  return (dp[bit] = ret);
}

int main()
{
  memset(v, -1, sizeof(v));
  while(cin >> N, N) {
    for(int i = 0; i < N; ++i) {
      cin >> dice[i].x >> dice[i].y;
      cin >> dice[i].l >> dice[i].r >> dice[i].f >> dice[i].b >> dice[i].d >> dice[i].u;
      cin >> rot[i];
      rot[i] = "~" + rot[i];
      dice[i].x += 1050, dice[i].y += 1050;
    }
    memset(dp, -1, sizeof(dp));
    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 23876
from sys import stdin
for line in stdin:
    mid, final, make = map(int, line.split())
    if mid == -1 and final == -1 and make == -1:
        break
    elif mid == -1 or final == -1:
        print('F')
    elif mid + final >= 80:
        print('A')
    elif mid + final >= 65:
        print('B')
    elif mid + final >= 50:
        print('C')
    elif mid + final >= 30:
        if make >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define N 100005
#define oo 1e18

using namespace std;
int n, d[N];
long long A[N], F[N];

long long Magic(int i)
{
    if(i>n) return oo;
    if(i==n) return 0;
    if(d[i]) return F[i];
    d[i]=1;
    long long res=oo;
    res = min(abs(A[i]-A[i+1])+Magic(i+1), abs(A[i]-A[i+2])+Magic(i+2));
    return F[i]=res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++) cin>>A[i];
    cout<<Magic(1);
    return 0;
}


Measured memory_bytes: 7884
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;

    int ans = 0;
    for(int i = 1; i <= n; i++){
        int x = i;
        int c = 0;
        while(x > 0){
            x /= 10;
            c++;
        }
        if(c % 2){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int sum;	
int main()
{
	string n;
	cin>>n;
	for(int i=0;i<=n.length();i++)
	{
	if(sum==0&&n[i]=='C')sum++;
	else if(sum==1&&n[i]=='F')sum++;
	}
	if(sum==2)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>

int mins(int x, int y, int z)
{
int min = x;
int max =x;
if (y < min) min = y;
if (z < min) min = z;
if (y > max) max = y;
if (z > max) max = z;
return max-min;
}

int main(){
int H,W,i,j,k,l,S;
scanf("%d %d",&H,&W);

j=(H/3)*W;
k=(H-H/3)/2*W;
l=W*H-j-k;
S=mins(j,k,l);

for(i=0;i<2;i++){
j=(H/3+i)*W;
k=W/2*(H-H/3-i);
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}

for(i=0;i<2;i++){
j=(W/3+i)*H;
k=(W-W/3-i)/2*H;
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}
  
for(i=0;i<2;i++){
j=(W/3+i)*H;
k=H/2*(W-W/3-i);
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}

printf("%d\n",S);  
return 0;
}

Measured memory_bytes: 128
S = input()
A = list(map(int, input().split()))
A.sort()
Y=0
Z=0
while Z < int(S)-1:
  if int(A[Z]) - int(A[Z+1]) == 0:
    print("NO")
    Y=1
    break
  else:
    Z = Z+1
    continue
if not Y ==1:
  print("YES")

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

int main(void){
    int D,N;
    cin>>D>>N;
    int ans=1,cnt=0;
    while(cnt!=D){
        ans*=100;
        cnt++;
    }

    if(N==100)
        N+=1;
    cout<<ans*N<<endl;
    return 0;
}


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

int dp[4][100][100];

//0 ツ債カツつゥツづァツ猟按づ篠淞づ可凝按つェツづェツづゥ
//1 ツ債カツつゥツづァツ猟按づ篠淞づ可凝按つェツづェツづ按つ「
//2 ツ可コツつゥツづァツ猟按づ篠淞づ可凝按つェツづェツづゥ
//3 ツ可コツつゥツづァツ猟按づ篠淞づ可凝按つェツづェツづ按つ「


int main(void)
{
	int w, h;
	
	while (1){
		memset(dp, 0, sizeof(dp));
		
		scanf("%d%d", &w, &h);
		if (w == 0 && h == 0){
			break;
		}
		
		for (int i = 1; i < w; i++){
			dp[0][i][0] = 1;
		}
		for (int i = 1; i < h; i++){
			dp[2][0][i] = 1;
		}
		
		for (int y = 1; y < h; y++){
			for (int x = 1; x < w; x++){
				dp[0][x][y] = (dp[0][x - 1][y] + dp[1][x - 1][y]) % 100000;
				dp[1][x][y] = dp[2][x - 1][y] % 100000;
				dp[2][x][y] = (dp[2][x][y - 1] + dp[3][x][y - 1]) % 100000;
				dp[3][x][y] = dp[0][x][y - 1] % 100000;
			}
		}
		
		printf("%d\n", (dp[0][w - 1][h - 1] + dp[1][w - 1][h - 1] + dp[2][w - 1][h - 1] + dp[3][w - 1][h - 1]) % 100000);
	}
	
	return (0);
}

Measured memory_bytes: 0
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func solve(N, A, B int) {
	diff := B - A
	if diff%2 == 0 {
		out(diff / 2)
		return
	}

	diff = min(A-1, N-B)
	diff = diff + 1 + (B-A-1)/2
	out(diff)
}

func main() {
	sc.Split(bufio.ScanWords)

	N, A, B := getInt(), getInt(), getInt()

	solve(N, A, B)

}


Measured memory_bytes: 640
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, cs, s;
    final int keta = 4;

    void run(){
	cs = 1;
	n = sc.nextInt();
	while(n>0){
	    s = sc.nextInt();
	    solve();
	    cs++;
	    n--;
	}
    }

    void solve(){
	System.out.println("Case "+cs+":");
	for(int i=0; i<10; i++){
	    s = s*s;
	    s = (s%1000000)/100;
	    System.out.println(s);
	}
    }
}

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

int main()
{
   vector<int> a(6);
   for(int i=1;i<=5;++i) cin>>a[i];
   for(int i=1;i<=5;++i) if(!a[i]) {
       cout<<i;break;
   }
   
}

Measured memory_bytes: 3628
// C.

#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> a(n), b(n), f(n);
	vector< pair<int, int> > c;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		c.push_back({ a[i] + b[i], i });
	}
	sort(c.rbegin(), c.rend());
	LL x = 0, y = 0, xi = 0, yi = 0;
	for (int i = 0; i < n; i += 2) {
		x += a[c[i].second];
		if (i + 1 < n) {
			y += b[c[i + 1].second];
		}
	}
	LL ans = x - y;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int n,m;
    cin >>n>>m;
    int a,b;
    pair<int,int> ans[n];
    for(int i=0;i<n;i++){
        cin>>a>>b;;
        ans[i]=make_pair(a,b);
    }
    sort(ans,ans+n);
    int u=0,t=0;
    cerr<<ans[0].first<<endl;
    while(m>0){
        if(m-ans[u].second>0){
            t+=ans[u].first*ans[u].second;
            cerr <<ans[u].first*ans[u].second<<endl;
        }
        else t+=ans[u].first*m;
        m-=ans[u].second;
        u+=1;
    }
    cout <<t;
    return 0;
}

Measured memory_bytes: 1792
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, mut p) = scan!(usize, usize);
    let mut m = HashMap::new();
    for i in 2.. {
        while p % i == 0 {
            *m.entry(i).or_insert(0) += 1;
            p /= i;
        }

        if p <= i * i {
            *m.entry(p).or_insert(0) += 1;
            break;
        }
    }
    let mut ans = 1;
    for (k, v) in m {
        if n <= v {
            ans *= k.pow((v / n) as u32);
        }
    }
    println!("{}", ans);
}


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

int main() {
	int N, H, W; cin >> N >> H >> W;
	int A[1010], B[1010];
	for(int i=0; i<N; ++i) cin >> A[i] >> B[i];
	int count=0;
	for(int i=0; i<N; ++i){
	    if(A[i]>=H && B[i]>=W) ++count;
	}
	cout << count << endl;
	return 0;
}


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

	int i, N, a[101], MAX = 0;
	cin >> N;

	for(i = 0; i< N; ++i){
		cin >> a[i];
		MAX += a[i];
	}

	sort(a, a + N, greater<int>());

	int A = 0;
	for(i = 0; i < N; i += 2)
		A += a[i];
	
	cout << (2 * A - MAX);

	return 0;

}


Measured memory_bytes: 256
n, m = map(int, input().split())

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

a = [0]*m
b = [0]*m

for i in range(m):
	a[i], b[i] = map(int, input().split())

s = set(range(n))

for i in range(m):
	if h[a[i]-1]>h[b[i]-1]:
		no = b[i]-1
	elif h[a[i]-1]<h[b[i]-1]:
		no = a[i]-1
	else:
		no = a[i]-1
		if no in s:
			s.remove(no)
		no = b[i]-1
		
	if no in s:
		s.remove(no)

print(len(s))

Measured memory_bytes: 30300
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
using ld = double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<pll> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

pair<ld,ld> line(ll x1,ll x2,ll y1,ll y2){
	pair<ld,ld> res ;
	if(x1==x2){
		res.first = INF ;
		res.second = x1 ;
	}else{
		ld y = y2-y1 ;
		ld x = x2-x1 ;
		res.first = y/x ;
		res.second = y1-res.first*x1 ;
	}
	return res ;
}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll x(n),y(n) ;
	for(int i=0;i<n;i++) cin >> x.at(i) >> y.at(i) ;
	vector<pair<ld,ld>> cnt ;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			pair<ld,ld> sub ;
			if(x.at(i)<x.at(j)) sub = line(x.at(i),x.at(j),y.at(i),y.at(j)) ;
			else sub = line(x.at(j),x.at(i),y.at(j),y.at(i)) ;
			cnt.push_back(sub) ;
//			cout << '(' << p.at(i).first << ',' << p.at(i).second << ")(" << p.at(j).first << ',' << p.at(j).second << ")\n" ;
//			cout << sub.first << " " << sub.second << endl ;
		}
	}
	sort(cnt.begin(),cnt.end()) ;
	bool ok = false ;
	k = k*(k-1)/2 ;
	for(int i=0;i<cnt.size()-k+1;i++){
		if(cnt.at(i)==cnt.at(i+k-1)){
			ok = true ;
			break ;
		}
	}
	cout << (int)ok << endl ;
//	cout << mx << endl ;
}



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

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

    vector<long long int> a(n), b(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    long long int memo1, memo2, memo3, memo4;

    long long int upper = 1e9 + 1, lower = 1, mid;
    while(upper - lower > 1){
        mid = (upper + lower) / 2;

        int small = 0;
        for(int i=0; i<n; i++){
            if(b[i] < mid) small += 1;
        }
        //cout << mid << " " << small << endl;
        if(small > n/2) upper = mid;
        else lower = mid;
    }
    memo1 = lower;

    upper = 1e9 + 1, lower = 1;
    while(upper - lower > 1){
        mid = (upper + lower) / 2;

        int small = 0;
        for(int i=0; i<n; i++){
            if(b[i] < mid) small += 1;
        }
        //cout << mid << " " << small << endl;
        if(small > n/2 - 1) upper = mid;
        else lower = mid;
    }
    memo3 = lower;

    upper = 1e9, lower = 0;
    while(upper - lower > 1){
        mid = (upper + lower) / 2;

        int large = 0;
        for(int i=0; i<n; i++){
            if(a[i] > mid) large += 1;
        }
        //cout << mid << " " << large << endl;
        if(large > n/2) lower = mid;
        else upper = mid;
    }
    memo2 = upper;

    upper = 1e9, lower = 0;
    while(upper - lower > 1){
        mid = (upper + lower) / 2;

        int large = 0;
        for(int i=0; i<n; i++){
            if(a[i] > mid) large += 1;
        }
        //cout << mid << " " << large << endl;
        if(large > n/2 - 1) lower = mid;
        else upper = mid;
    }
    memo4 = upper;

    //cout << memo1 << " " << memo2 << " " << memo3 << " " << memo4 << endl;
    
    long long int ans;
    if(n % 2 == 0) ans = (memo1 + memo3) - (memo2 + memo4) + 1;
    if(n % 2 == 1) ans = memo1 - memo2 + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  unordered_map<int, int> wa;
  unordered_set<int> solved;
  int penalty = 0;
  for (int i = 0; i < M; i++) {
    int p;
    string S;
    cin >> p >> S;
    if (S == "WA") {
      wa[p]++;
    } else if (solved.count(p) == 0) {
      solved.insert(p);
      penalty += wa[p];
    }
  }
  cout << solved.size() << " " << penalty << endl;
 
  return 0;
}

Measured memory_bytes: 8520
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){

  int c=0,i,N;
  char s[103];
  scanf("%s",&s);
  N=strlen(s);
  
  for(i=0;i<N/2;i++){
    if(s[i]!=s[N-i-1])
      c++;
  }
  printf("%d",c);
}

Measured memory_bytes: 128
i=input()
a,b=int(i[:2]),int(i[-2:])
def x(n):
    if n>12 or n==0:return True
def y(n):
    if n<13 and n!=0:return True
if y(a) and y(b):
    print ("AMBIGUOUS")
if y(a) and x(b):
    print ("MMYY")
if x(a) and y(b):
    print ("YYMM")
if x(a) and x(b):
    print ("NA") 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 10007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 400005

string a[105][105];
int n, m;

int main()
{
//	gen();
//	freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    int r, c;
    For(i, 1, n) For(j, 1, m){
    	cin >> a[i][j];
    	if(a[i][j].compare("snuke") == 0){
    		r = i;
    		c = j;
    	}
    }

    char res = 'A' + c - 1;
    cout << res << r << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int min(int a,int b){
	if(a<=b) return a;
	else return b;
}

int main(){
	int data[500][500];
	int posX[201];
	int posY[201];

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

	while(cin>>n){
		if(n==0)break;

	for(int i=0;i<500;i++){
		for(int j=0;j<500;j++){
			data[i][j]=-1;
		}
	}

	for(int i=0;i<201;i++){
		posX[i]=-1;
		posY[i]=-1;
	}

	
	data[250][250]=0;
	posX[0]=250;
	posY[0]=250;

	for(int i=1;i<n;i++){
		int num,pos;
		cin>>num>>pos;

		data[posY[num]+dy[pos]][posX[num]+dx[pos]]=i;
		posY[i] = posY[num]+dy[pos];
		posX[i] = posX[num]+dx[pos];

	}

	int maxX=0;
	int minX=100000;
	int maxY=0;
	int minY=100000;

	for(int i=0;i<n;i++){
	//	cout<<"i="<<i<<" X= "<<posX[i]<<" Y= "<<posY[i]<<endl;
		maxX=max(posX[i],maxX);
		maxY=max(posY[i],maxY);
		minX=min(posX[i],minX);
		minY=min(posY[i],minY);
	}

	cout<<maxX-minX+1<<" "<<maxY-minY+1<<endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, K = map(int, readline().split())
    Hs = list(map(int, readline().split()))
    Hs.sort(reverse=True)
    print(sum(Hs[K:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main(void){
    unsigned long long N;
    unsigned long long x[5];
    int count = 0;
    unsigned long long res = 0;
    
    cin >> N;
    for (int i = 0; i < 5; i++) {
        cin >> x[i];
        if (x[i] >= N) count++;
    }
    
    if (count == 5) {
        cout << 5 << endl;
        return 0;
    }
    
    int min_idx = 0;
    unsigned long long min = x[min_idx];
    for (int i = 1; i < 5; i++) {
        if (min > x[i]) {
            min_idx = i;
            min = x[i];
        }
    }
    if (N % x[min_idx] == 0) {
        res += N / x[min_idx];
    } else {
        res += (N + x[min_idx]) / x[min_idx];
    }
    res += 4;
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn=1e5+5;
const int base=1e9+7;
int n;
vector<int> adj[maxn];
int64 f[maxn][2];
void Input()
{
    cin >> n;
    FOR(i,2,n) {
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}
void DFS(int u, int p)
{
    f[u][0]=f[u][1]=1;
    for (int v:adj[u]) {
        if (v==p) continue;
        DFS(v,u);
        f[u][0]=f[u][0]*(f[v][0]+f[v][1]) mod base;
        f[u][1]=f[u][1]*f[v][0] mod base;
    }
}
void Solve()
{
    DFS(1,1);
    cout << (f[1][0]+f[1][1]) mod base << endl;
}
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".out","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n,sum1=0,sum2=0,a[105];
    cin >> n ;
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
            sum1+=a[i];
        else
            sum2+=a[i];
    }
    cout << abs(sum1-sum2) <<endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++14

//Difficulty according to solve count during contest:
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W

#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9 + 7;

int n;
vector<vector<int> > a;
vector<vector<int> > dp;

int func(int ind, int women){
  if(ind == n and women == (1<<n) - 1)
    return 1;
  else if(ind == n)
    return 0;
  if(dp[ind][women] != -1)
    return dp[ind][women];
  dp[ind][women] = 0;
  for(int i = 0; i < n; i++){
    if(a[ind][i] == 1 and (women&(1<<i)) == 0){
      dp[ind][women] += func(ind + 1, (women | (1<<i)));
      dp[ind][women] %= mod;
    }
  }
  return dp[ind][women];
}


int32_t main(){
  cin >> n;
  a.resize(n, vector<int>(n));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> a[i][j];
    }
  }
  dp.resize(n, vector<int>((1<<n), -1));
  int ans = func(0, 0);
  cout << ans << endl;

}


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


int main( void) {
	long long n, h; cin >> n >> h;
	long long a[n], b[n];
	for (int i = 0; i < n; i++) 
		cin >> a[i] >> b[i];

	int s = sizeof(b)/sizeof(b[0]);
    sort(b, b+s);
	//find max a
	long long mx_a = -1;
	for (int i = 0; i < n; i++) 
		if (mx_a < a[i])
			mx_a = a[i];
	long long c = 0;
	for (int i = n-1; i>=0; i--) {
		if (h > 0 && b[i] > mx_a) {
			h -= b[i];
			c++;
		}
		else 
			break;
		
	}
	if (h > 0) {
		c += h/mx_a;
		h -= mx_a*(h/mx_a);
		if (h > 0) {
			c++;
		}
	}
	cout << c << endl;

	// int r = h / mx_a + 1;
	// int l = 0;
	// int result = binary_search(mx_a,b,l,r, n);

	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    double N = sc.nextDouble();

    double a = N%2;
    double b;

    if(a == 0){
       b = N/(2*N);
    }
    else{
       b = (N+1)/(2*N);
    }
    
    System.out.println(String.format("%.10f",b));

  }
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[220];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int maxn=-110;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            maxn=max(a[i],maxn);
        }
        ll maxN=Inf;
        for(int i=-110;i<=maxn;i++)
        {
            ll sum=0;
            for(int j=0;j<n;j++)
            {
                sum+=(a[j]-i)*(a[j]-i);
            }
            maxN=min(maxN,sum);
        }
        printf("%lld\n",maxN);

    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256