akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

bool pair_compair_blue(pair<int, int> a, pair<int, int> b)
{
  if (a.first != b.first)
  {
    return a.first < b.first;
  }
  else
  {
    return a.second > b.second;
  }
}

bool pair_compair_red(pair<int, int> a, pair<int, int> b)
{
  if (a.second != b.second)
  {
    return a.second > b.second;
  }
  else
  {
    return a.first > b.first;
  }
}

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

  vector<pair<int, int>> r, b;
  bool used[110] = {};

  rep(i, n)
  {
    int x, y;
    cin >> x >> y;
    r.push_back({x, y});
  }

  rep(i, n)
  {
    int x, y;
    cin >> x >> y;
    b.push_back({x, y});
  }

  sort(r.begin(), r.end(), pair_compair_red);
  sort(b.begin(), b.end(), pair_compair_blue);

  int ans = 0;
  for (auto blue : b)
  {
    rep(i, n)
    {
      if (used[i])
        continue;

      auto red = r[i];
      if (blue.first >= red.first + 1 && blue.second >= red.second + 1)
      {
        ans++;
        used[i] = true;
        // cout << "blue: " << blue.first << " " << blue.second << endl;
        // cout << "red: " << red.first << " " << red.second << endl;
        break;
      }
    }
  }

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

Measured memory_bytes: 256
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+2;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;

int main()
{
    IOS();
    ll n,k,i,j,ans=0;
    cin>>n>>k;
    ivc v(n);
    ll a[n],b[n]={0},c[n]={0};
    ll r=n;
    f(i,0,n)
    {
      cin>>v[i];
      a[i]=v[i];
    }
    sort(all(v));
    f(i,0,n)
    {
        auto x=lower_bound(all(v),a[i]);
        if(x!=v.end())
          b[i]=x-v.begin();
    }
    ll w=0;
    f(i,0,n)
    {
        w=0;
        f(j,i+1,n)
        {
          if(a[i]>a[j])
              w++;
        }
        c[i]=w;
    }
     // f(i,0,n)
     //    cout<<c[i]<<" ";
    f(i,0,n)
    {
      ans=(ans%MOD+(b[i]*(((k*(k-1))/2)%MOD))%MOD)%MOD;
    }
    f(i,0,n)
      ans=(ans%MOD+((c[i]*k)%MOD))%MOD;
    cout<<ans;




  return 0;
  
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b[4]={0};
    bool v=true;
    cin>>a;
    for(int x=0;x<4;x++)
    {
        b[x]=a%10;
        a=a/10;
    }
    for(int x=0;x<3;x++)
    {
        if(b[x]==b[x+1])
        {cout<<"Bad"<<endl;
         v=false;
        break;}
    }
    if(v==true)
    {
        cout<<"Good"<<endl;
    }
    return 0;
}

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

int h, w;
bool valid(int s, int t) {
    if (s >= 0 && s < h && t >= 0 && t < w) return 1;
    return 0;
}
int main() {
    int i, j;
    cin >> h >> w;
    char a[h][w];
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }

    int dx[4] = {-2, -1, -1, 0};
    int dy[4] = {0, -1, -1, -2};
    int mdx[4] = {-1, -1, 0, 0};
    int mdy[4] = {0, 0, -1, -1};

    map<ll, ll> ma[h][w];

    ma[0][0][a[0][0] - '0'] = 0;

    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            if ((i + j) % 2 == 1) continue;
            if (i == 0 && j == 0) continue;
            for (int k = 0; k < 4; k++) {
                int x = i + dx[k];
                int y = j + dy[k];
                int mx = i + mdx[k];
                int my = j + mdy[k];
                if (!valid(x, y)) continue;
                int z = a[i][j] - '0';

                for (auto it = ma[x][y].begin(); it != ma[x][y].end(); ++it) {
                    if (a[mx][my] == '+')
                        ma[i][j][z] = max(ma[i][j][z], it->first + it->second);
                    else
                        ma[i][j][z * it->first] = max(ma[i][j][z * it->first], it->second);
                    if (it->second + it->first > pow(10, 15)) {
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for (auto it = ma[h - 1][w - 1].begin(); it != ma[h - 1][w - 1].end(); ++it) {
        ans = max(ans, it->first + it->second);
    }
    if (ans > pow(10, 15)) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	int cnt = 0;
	int x = 1;
	int y = 0;
	while (cnt <= N) {
		cnt += x;
		x++;
		y++;
	}
	int a = cnt - N;
	rep(i, 0, y) {
		if (i + 1 == a)continue;
		cout << i + 1 << "\n";
	}


	return 0;
}

Measured memory_bytes: 256
func gcd(x:Int,_ y:Int)->Int{return y>0 ?gcd(y,x%y):x}
let N=Int(readLine()!)!
var ans=1
for _ in 0..<N{
  let T=Int(readLine()!)!
  ans*=T/gcd(T,ans)
}
print(ans)

Measured memory_bytes: 2936
using System;
using System.Collections.Generic;
using System.Linq;
class abc164_c{
  public static void Main(){
    List<String> prize = new List<String>();
    int n= int.Parse(Console.ReadLine());
    for(int i=0; i<n; i++){
      String str = Console.ReadLine();
      prize.Add(str);
    }
    prize = prize.Distinct().ToList();
    Console.WriteLine(prize.Count());
  }
}


Measured memory_bytes: 42736
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Max=0;
    int Min=MOD; 
    REP(i,3){
        int input;
        cin >> input;
        Max=max(input,Max);
        Min=min(input,Min);
    }
    cout << Max-Min << endl;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func main() {
    sc = initScanner(os.Stdin)
    fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
    n := scanInt(sc)
    player := make([]int, n)
    for i := 0; i < n; i++ {
        player[i] = scanInt(sc)
    }
    return n, player
}

func resolve(n int, player []int) int {
    //フレンドリーを逆順にソートする
    sort.Sort(sort.Reverse(sort.IntSlice(player)))

    comfort := 0
    for i := 1; i < n; i++ {
        comfort += player[i/2]
    }
    return comfort
}

func initScanner(r io.Reader) *bufio.Scanner {
    sc := bufio.NewScanner(r)
    sc.Split(bufio.ScanWords)
    return sc
}

func scanInt(sc *bufio.Scanner) int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return int(i)
}

func scanString(sc *bufio.Scanner) string {
    sc.Scan()
    return sc.Text()
}


Measured memory_bytes: 5920
#include<iostream>
#define LL long long
LL node[300010];
LL add[300010];
int n, q;

void init(int &n_) {
	int N = 1;
	while (N < n_)N *= 2;
	n_ = N;
}

void judge(int k, int l, int r) {
	if (add[k]) {
		node[k] += add[k];
		if (r - l > 1) {
			add[k * 2 + 1] += add[k] / 2;
			add[k * 2 + 2] += add[k] / 2;
		}
		add[k] = 0;
	}
}

void update(int a, int b, LL x, int k, int l, int r) {
	judge(k, l, r);
	if (b <= l || r <= a)return ;
	if (a <= l && r <= b) {
		add[k] += ((LL)r - (LL)l)*x;
		judge(k, l, r);
	}
	else {
		update(a, b, x, k * 2 + 1, l, (r + l) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		node[k] = node[k * 2 + 1] + node[k * 2 + 2];
	}
}

LL getsum(int a, int b, int k, int l, int r) {
	judge(k, l, r);
	if (r <= a || b <= l)return 0LL;
	if (a <= l && r <= b)return node[k];
	LL vl = getsum(a, b, k * 2 + 1, l, (l + r) / 2);
	LL vr = getsum(a, b, k * 2 + 2, (l + r) / 2, r);
	return vl + vr;
}

int main() {
	std::cin >> n >> q;
	init(n);
	for (int i = 0; i < q; i++) {
		int a;
		std::cin >> a;
		if (!a) {
			int s, t;
			LL x;
			std::cin >> s >> t >> x;
			update(s - 1, t, x, 0, 0, n);
		}
		else {
			int s, t;
			std::cin >> s >> t;
			std::cout << getsum(s - 1, t, 0, 0, n) << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6252
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long > > gra;
long long  n,m;
long long  dp[100010];

long long  recur(long long  nod){
    if(gra[nod].size() == 0) return 0;
    if(dp[nod] != -1) return dp[nod];
    else{
        long long  ans = 0;
        for(auto x: gra[nod]){
            ans = max(ans,recur(x) + 1);
        }
        return dp[nod] = ans;
    }
}

int main(){
    cin>>n>>m;
    gra.resize(n+1);
    memset(dp,-1,sizeof dp);
    for(long long  i = 0 ; i < m; i++){
        long long  x,y;
        cin>>x>>y;
        gra[x].push_back(y);
    }
    long long  ans = 0;
    for(long long  i = 1; i <= n; i++){
        ans = max(ans,recur(i));
    }
    cout<<ans;
}


Measured memory_bytes: 8576
n = gets.to_i
a = gets.split.map(&:to_i)

$m = a[0] - 1

def increse?(a, b)
  if a < b
    if $m != a
      $m = b - 1
    end
  end

  if a > b
    if a - 1 != b || $m > b
      return false
    end
  end
  true
end

for i in 0..n-2
  unless increse?(a[i], a[i+1])
    puts 'No'
    exit
  end
end
puts 'Yes'

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

int main() {
    int n;
    cin>>n;
    vector<int> p(n);
    int count=0;
    rep(i,n){
        cin>>p[i];
        if(p[i]!=i+1) count++;
    }
    if(count==2 || count==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main() {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') {
        if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
            cout << "3" << endl;
        } else
            cout << "2" << endl;
    } else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S')
        cout << "0" << endl;
    else
        cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 3620
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
s = [''.join(sorted(list(STR()))) for _ in range(n)]
t = set(s)
u = Counter(s)
ans = 0
for i in t:
    ans += u[i] * (u[i] - 1) // 2
print(ans)

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

int main(){
  ll i,j,cnt=0;
  int n,k;
  cin>>n>>k;
  ll x[n];
  for(i=0;i<n;i++)cin>>x[i];
  int left=0,right=n-1;
  if(x[left]>=0){
    cout<<x[k-1]<<endl;
    return 0;
  }
  if(x[right]<=0){
    cout<<-x[right-k+1]<<endl;
    return 0;
  }
  for(i=0;i<n;i++){
    if(x[i]>=0){
      left=i;
      break;
    }
  }
  for(i=left;i<n;i++){
    if(x[i]>0){
      right=i;
      break;
    }
  }
  k-=right-left;
  if(k<=0){
    cout<<0<<endl;
    return 0;
  }
  
  ll a[n],b[n];
  for(i=0;i<n;i++){
    a[i]=100000000000000;
    b[i]=100000000000000;
  }
  for(i=0;i<left;i++)a[i]=-x[left-1-i];
  for(i=0;i<n-right;i++)b[i]=x[right+i];
  ll mi=min(a[k-1],b[k-1]);
  for(i=1;i<k;i++){
    mi=min(2*a[i-1]+b[k-i-1],mi);
    mi=min(2*b[i-1]+a[k-i-1],mi);
  }
  cout<<mi;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			String[] ch = new String[n];
			for(int i = 0;i < n;i++){
				ch[i] = "#";
			}
			for(int i = 0;i < m;i++){
				String t = scan.next();
				if(t.equals("A")){
					sitA(ch,t);
				}else if(t.equals("B")){
					sitB(ch,t);
				}else if(t.equals("C")){
					sitC(ch,t);
				}else if(t.equals("D")){
					if(i == 0){
						sitA(ch,t);
					}else{
						sitD(ch,t);
					}
				}
			}
			for(int i = 0;i < n;i++){
				System.out.print(ch[i] + ((i == n-1)?"\n":""));
			}
		}
	}
	
	public static void sitA(String[] ch,String t){
		for(int i = 0;i < ch.length;i++){
			if(ch[i].equals("#")){
				ch[i] = t;
				return;
			}
		}
	}
	
	public static void sitB(String[] ch,String t){
		for(int i = ch.length-1;i >= 0;i--){
			if(ch[i].equals("#")){
				if(i == 0){
					if(!ch[i+1].equals("A")){
						ch[i] = t;
						return;
					}
				}else if(i == ch.length-1){
					if(!ch[i-1].equals("A")){
						ch[i] = t;
						return;
					}
				}else{
					if(!ch[i+1].equals("A") && !ch[i-1].equals("A")){
						ch[i] = t;
						return;
					}
				}
			}
		}
		sitA(ch,t);
	}
	
	public static void sitC(String[] ch,String t){
		for(int i = 0;i < ch.length-1;i++){
			if(!ch[i].equals("#")){
				if(ch[i+1].equals("#")){
					ch[i+1] = t;
					return;
				}else if(i == 0){
				}else if(ch[i-1].equals("#")){
					ch[i-1] = t;
					return;
				}
			}
		}
		int n = ch.length;
		int nc = (n%2==0)?n/2:(n+1)/2-1;
		ch[nc] = t;
	}
	
	public static void sitD(String[] ch,String t){
		int tI = 0;
		int sCount = 0;
		int max = 0;
		boolean sw = true;
		int mtI = 0;
		for(int i = 0;i < ch.length;i++){
			if(ch[i].equals("#")){
				if(sw){
					tI = i;
					sCount++;
					sw = false;
				}else{
					sCount++;
				}
			}else{
				if(!sw){
					int a = (tI == 0)?sCount:(sCount % 2 == 0)?sCount/2:sCount/2+1;
					if(max == 0 || max < a){
						max = a;
						mtI = tI;
					}
					sw = true;
					sCount = 0;
				}
			}
		}
		if(!sw){
			int a = sCount;
			if(max == 0 || max < a){
				max = a;
				mtI = tI;
			}
		}
		ch[(mtI==0)?0:mtI+max-1] = t;
	}
}

Measured memory_bytes: 24116
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;





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



    string s = "";
    ll m, r;
    while (n > 0) {
        m = n / 26;
        r = n % 26;

        n = m;
        s += ('a' + (int)(r - 1));
    }



    reverse(s.begin(), s.end());

    //cout << s << endl;

    int pos;
    while ((pos = s.find("`")) != string::npos) {
        if (pos == 1 && s[0] == 'a') {
            s[pos] = 'z';
            s.erase(0, 1);
        }
        else {
            s[pos - 1] = s[pos - 1] - 1;
            s[pos] = 'z';
        }
    }

    cout << s;

}




Measured memory_bytes: 3608
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);

    int a = n/100;
    int c = n%10;
    int b = (n%100)/10;
    if (a == 7 || b == 7 || c == 7){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1620
import java.util.*;class Main{public static void main(String[]z){int i=0,e=2,t=10000;int[]p=new int[t];for(;i<t;i++){for(;f(p,e)<1;e++);p[i]=e++;}for(i=1;i<t;++i)p[i]+=p[i-1];for(Scanner s=new Scanner(System.in);(i=s.nextInt())>0;)System.out.println(p[i-1]);}static int f(int[]p,int n){for(int e:p)if(e>0&&n!=e&&n%e<1)return 0;return 1;}}

Measured memory_bytes: 12000
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
	n=II()
	X=[]
	Y=[]
	for i in range(n):
		x,y=MI()
		X.append((x,i))
		Y.append((y,i))
	X.sort()
	Y.sort()
	#print(X,Y)

	li=[]
	for i in range(n-1):
		li.append((X[i+1][0]-X[i][0],X[i+1][1],X[i][1]))
		li.append((Y[i+1][0]-Y[i][0],Y[i+1][1],Y[i][1]))
	li.sort()
	#rint(li)

	UF=UnionFind(n)
	k=0
	ans=0
	for d,s,t in li:
		if k==n-1:
			break
		if UF.same(s,t):
			continue
		else:
			ans+=d
			UF.union(s,t)
			k+=1
	print(ans)

if __name__ == "__main__":
	main()

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    vector<int> count(n,0);
    for(int i = 0; i < m; ++i){
        cin >> a.at(i) >> b.at(i);
        count.at(a.at(i)-1)++;
        count.at(b.at(i)-1)++;
    }
    for(int i=0; i<n; ++i){
        cout << count.at(i) << endl;
    }
}


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

int main(){ 
  int n,x,d=0,cnt=0,sum=0,result=0,mini=101;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  for(int i=1;i<n-1;i++){
    if((v[i-1]<v[i] and v[i]<v[i+1]) or (v[i-1]>v[i] and v[i]>v[i+1])) result++;
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;


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

	int a[3];
	int i,j;

	for(j=0 ; j<N ; j++){

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

		sort(a, a+3);

		if(a[2]*a[2] == (a[0]*a[0] + a[1]*a[1])){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}

	}
	return 0;
}

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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define alll(it,A) for(it=A.begin();it!=A.end();it++)

#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>

const ll N=100005;
const ll M = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll A[n+1];
    rep(i,1,n+1)	cin>>A[i];
    ll dp[n+1]={0};
    dp[0]=0;dp[1]=0,dp[2]=abs(A[2]-A[1]);
    rep(i,3,n+1){
    	dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    }
    cout<<dp[n];
    return 0;
}

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

int main(){
  ll L,R;
  cin>>L>>R;
  ll li=L/2019,ri=R/2019;
  if (li!=ri){
    cout << 0 << endl;
    return 0;
  }
  ll mini(100000);
  for (ll i(L);i<=R;i++){
    for (ll j(i+1);j<=R;j++){
      mini=min(mini,(i*j)%2019);
    }
  }
  cout << mini << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n,j;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0) {
			cout << ' ' << i;
		}
		else if (i % 10 == 3) {
			cout << ' ' << i;
		}
		else {
			for (j = i / 10; j > 0; j = j / 10) {
				if (j % 10 == 3) {
					cout << ' ' << i;
					break;
				}
			}
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;


int main(){

    long long a, b, c; cin >> a >> b >> c;

     long long add = a%b;

    if(add == 0){
         if(add == c)
         cout<<"YES"<<endl;
         else cout<<"NO"<<endl;

        return 0;
    }

    for(long long i=add; i<=10000; i+=add)
    {
        if(i%b == c){
            cout<<"YES";
          return 0; }
    }


    cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;
int main(){
  int n,k,sum=0,max=0;
  int m_cnt=0;
  cin >>n >> k;
  vector<int> v(n),vc;
  for(int i=0;i<n;i++){
    cin >> v[i];
    sum+=v[i];
  }
  copy(v.begin(),v.end(),back_inserter(vc));
  if(k>=n){
    int tmp=k-n;
    int i=0;
    sort(vc.begin(),vc.end());
    while(tmp>=0&&i<vc.size()){
      if(vc[i]>0) break;
      else{
        sum-=vc[i];
        i++;
        tmp--;
      }
    }
    max = (sum>max)?sum:max;
  }
  for(int a=0;a<=k;a++){
    for(int b=0;b<=k;b++){
      if(k-a-b<0||a+b>n||(a==0&&b==0)) continue;
      if(a>n||b>n) continue;
      vector<int> n_list;
      sum=0;
      for(int i=0;i<a;i++){
        sum+=v[i];
        if(v[i]<0) n_list.push_back(v[i]);
      }
      for(int i=0;i<b;i++){
        sum+=v[n-1-i];
        if(v[n-1-i]<0) n_list.push_back(v[n-1-i]);
      }
      sort(n_list.begin(),n_list.end());
      int tmp = k-a-b,j=0;
      while(tmp!=0&&n_list.size()>j){
        if(n_list[j]>0) break;
        else{
          sum-=n_list[j];
          j++;
          tmp--;
        }
      }
      max = (max>sum)?max:sum;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
s = gets.chomp
k = gets.chomp.to_i

n = s.length

arr = []
n.times do |i|
  (1..5).each do |j|
    break if i+j > n
    str = s[i,j]
    if arr.length < 5 && !arr.include?(str)
      arr[arr.length] = str
      arr.sort!
    else
      pos = (0..arr.length-1).bsearch{|i| arr[i] >= str}
      break if !pos
      if str != arr[pos]
        arr.insert(pos,str)
        arr.delete_at(5)
      end
    end
  end
end

printf("%s\n",arr[k-1])

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG

// ARC061C

int main(){
  
  string n;
  cin >> n;
  int len = (int)n.size();
  if(len == 1){
    cout << n << endl;
    return 0;
  }

  ll ans = 0;
  rep(i, (1 << len-1)){
    bitset<9> bs(i);

    int cut = 0;
    ll t = 0;
    rep(j, len-1){
      if(bs[j]){
        t += stoll(n.substr(cut,j-cut+1));
        cut = j + 1;
      }
    }
    ans += t + stoll(n.substr(cut));
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,r; cin >> n >> r;
		if(n==0 && r==0) break;
		vl a(n); rep(i,n) a[i] = i+1;
		while(r--){
			ll p,c; cin >> p >> c;
			vl v;
			REP(i,n-p-c+1,n-p+1){
				v.push_back(a[i]);
			}
			a.erase(a.begin()+n-p-c+1,a.begin()+n-p+1);
			for(auto i : v) a.push_back(i);
		}
		cout << a[n-1] << endl;
	}
}


Measured memory_bytes: 3148
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

LL N,A,B;
vector<LL> h;

int ok(LL nb){
    LL r=0;
    auto ch = h;
    REP(i,N){
        ch[i]-=B*nb;
        if(0<ch[i])
            r+=(ch[i]+A-B-1)/(A-B);
    }
    return r<=nb;
}

int main(void){
    cin>>N>>A>>B;
    REP(i,N){LL hh;cin>>hh;h.pb(hh);}
    LL u=2e9,b=0;
    while(1<u-b){
        LL m=(u+b)/2;
        if(ok(m))u=m;
        else b=m;
    }
    LL r;
    if(ok(b))
        r=b;
    else
        r=u;
    cout<<r<<endl;
     return 0;
}

Measured memory_bytes: 1908
S = input()

f = int(S[:2])
b = int(S[2:])


if f>0 and f<13 and b>0 and b<13:
    print('AMBIGUOUS')
elif b>0 and b<13:
    print('YYMM')
elif f>0 and f<13:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif




	int n, x, t;
	cin >> n >> x >> t;

	if (n % x == 0) {
		cout << (n / x)*t << endl;
	}
	else {
		cout << ((n / x) + 1)*t << endl;
	}


}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    int a=sa.size();
    int b=sb.size();
    int c=sc.size();
    int aa=0,bb=0,cc=0,x=0;
    while(1){
        if(x==0){
            if(aa==a){
                cout << "A" << "\n";
                return 0;
            }
            x=sa[aa] - 'a';
            ++aa;
        }else if(x==1){
            if(bb==b){
                cout << "B" << "\n";
                return 0;
            }
            x=sb[bb] - 'a';
            ++bb;
        }else{
            if(cc==c){
                cout << "C" << "\n";
                return 0;
            }
            x=sc[cc] - 'a';
            ++cc;
        }
    }
}   

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
const int MOD = 1e9 + 7;
int n, x, y, z;
int f[41][(1 << 17) + 1];

void add(int &x, int y){
	x += y;
	if (x >= MOD)  x -= MOD;
}

int main(){
	int i, j, mask;
	scanf("%d%d%d%d", &n, &x, &y, &z);
	int m = 1 << (x + y + z);
	int tas = (1 << (z - 1)) | (1 << (y + z - 1)) | (1 << (x + y + z - 1));
	f[0][0] = 1;
	for (i = 0; i < n; ++ i){
		for (mask = 0; mask <= m; ++ mask) if (f[i][mask]) {
			//printf("i == %d mask == %d\n", i, mask);
			for (j = 1; j <= 10; ++ j){
				if (mask == m) {
					add(f[i + 1][m], f[i][m]);
					continue;
				}
				int nmask = ((mask << j) | (1 << (j - 1)) ) & (m - 1);
				if ((nmask & tas) == tas) nmask = m;
				add(f[i + 1][nmask], f[i][mask]);
			}
		}
	}
	printf("%d\n", f[n][m]);
	return 0;
}

Measured memory_bytes: 18944
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define reps(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
 
int n, a, b, c;
string s;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> c;
    cout << (a + b) * c / 2 << '\n';
    return 0;
}

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

int main() {
	char b;
	cin >> b;
	if (b == 'A')
		cout << "T" << endl;
	else if (b == 'C')
		cout << "G" << endl;
	else if (b == 'T')
		cout << "A" << endl;
	else
		cout << "C" << endl;


	return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
E = M.times.map{ gets.split.map(&:to_i) }
G = Array.new(N+1){ [] }
X = Array.new(N+1)
E.each do |l,r,d|
  G[l] << [r,d]
  G[r] << [l,-d]
end

def bfs(s)
  X[s] = 0
  q = [s]
  until q.empty?
    u = q.shift
    G[u].each do |v,d|
      if X[v].nil?
        X[v] = X[u] + d
        q << v
      else
        return false unless X[v] == X[u] + d
      end        
    end
  end
  return true
end

puts (1 .. N).all?{|v| X[v] || bfs(v) } ? "Yes" : "No"


Measured memory_bytes: 44540
#include <stdio.h>

int main(void){
    int x,h,m,s;
    
    scanf("%d",&x);
    h=x/3600;
    m=(x%3600)/60;
    s=(x%3600)%60;
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2096
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

input = sys.stdin.readline

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

B = list(itertools.accumulate(A))
C = [0] + [x % M for x in B]

ans = 0

CNT = collections.Counter(C)

for k, v in CNT.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 19828
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;


int main()
{
	int n;
	ll l[87];
	l[0]=2;
	l[1]=1;
	for(int i=2;i<87;i++)
	{
		l[i]=l[i-1]+l[i-2];
	}
	ll ans=0;
	
	cin>>n;
	ans = l[n];
	cout<<ans<<endl;
	return 0;
}

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


def solve(K: int, N: int, A: "List[int]"):
    D = []
    for i in range(N-1) :
        D.append(A[i+1] - A[i])
    D.append(A[0] + (K - A[N-1]))

    max_D = max(D)

    print(sum(D) - max(D))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(K, N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27764
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string S, T;
    cin >> S;
    int size, d;
    int a = 0;
    size = S.size();
    if (size % 2 == 1){
        d = (size - 1) / 2;
    }
    else{
        d = size / 2;
    }
    T = S;
    reverse(T.begin(), T.end());
    for (int i = 0; i < d; i++){
        char s = S[i];
        char t = T[i];
        if (s != t){
            a += 1;
        }
    }
    cout << a;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
S = input()
s = []
for i in range(N):
    x = S[i]
    if i == K-1:
        if x == 'A':
            x = 'a'
        elif x == 'B':
            x = 'b'
        else:
            x = 'c'
    s.append(x)
ans = s[0]
for i in range(1,N):
    ans += s[i]
print(ans)

Measured memory_bytes: 3064
// C - Sentou
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,T; cin>>N>>T;
	long long ans = 0;
	int pre; cin>>pre;
	while(--N){
		int now; cin>>now;
		ans += min(T, now-pre);
		pre = now;
	}
	cout<< ans + T <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
typedef long long lint;

struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) {return find(x) == find(y);}
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return false;
        --cnt;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> rs(N);
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        rs[p-1] = i;
    }
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        uf.unite(x, y);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(i, rs[i])) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
A,B,C,D,E,F=map(int,input().split())
noudo=0
water=[]
for i in range(31):
  for j in range(31):
    w=100*A*i+100*B*j
    if w<=F and w!=0:
      water.append(w)
sugar=[]
for i in range(F//C+1):
  for j in range(F//D+1):
    w=C*i+D*j
    if w<=F:
      sugar.append(w)
ans1=0
ans2=0
for i in range(len(water)):
  for j in range(len(sugar)):
    if water[i]+sugar[j]<=F:
      if sugar[j]/water[i]<=E/100:
        if noudo<sugar[j]/water[i]:
          ans1=sugar[j]+water[i]
          ans2=sugar[j]
          noudo=sugar[j]/water[i]
if ans2==0:
  print(water[0],0)
else:
  print(ans1,ans2)


Measured memory_bytes: 88056
n = int(input())
x = list(map(int, input().split()))
sum = 0
for i in range(n):
    sum += x[i]
i = 0
while (sum-x[i]*2) >= 0:
    sum -= x[i]*2
    i += 1
temp = sum
sum = 0 - (sum - x[i]*2)
print(min(temp, sum))


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

// dp[i] := i が親のとき、その木の最長有効パスの長さ。子のとき、そこまでの最長有効パスの長さ
lli dp[100001];
vector<lli> G[100001];
lli counts[100001];

int main() {
    lli n, m;
    cin2(n, m);
    REP(i,0,m) {
        lli x, y;
        cin >> x >> y;
        G[x].push_back(y);
        counts[y]++;
    }
    queue<P> que;
    REPE(i,1,n) {
        if (counts[i] == 0)
            que.push(P(i, 0));
    }
    lli ans = 0;
    while (!que.empty()) {
        lli node, len;
        tie(node, len) = que.front();
        que.pop();
        if (dp[node] != 0 && dp[node] >= len)
            continue;
        dp[node] = len;
        ans = max(ans, dp[node]);
        REP(i,0,G[node].size()) {
            lli next = G[node][i];
            counts[next]--;
            if (counts[next] == 0)
                que.push(P(next, len+1));
        }
    }
    cout << ans << endl;
}


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

static const auto do_fast_io = [] {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return nullptr;
}();

int main() {
    long long n;
    cin >> n;
    long long n_copy = n;
    int ans = 0;
    for (long long i = 2; i * i <= n_copy; ++i) {
        int temp = i;
        while (n % temp == 0) {
            ++ans;
            n /= temp;
            temp *= i;
        }
        while (n % i == 0) {
            n /= i;
        }
    }
    if (n != 1) {
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

/**
 * References
 */


Measured memory_bytes: 3636
from math import ceil

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

A.sort()

if N % 2 == 1:
    num = (N - 1) // 2
    if A[0] != 0:
        print(0)
        exit()
    for i in range(1, N):
        if A[i] == ceil(i / 2) * 2:
            continue
        else:
            print(0)
            exit()
else:
    num = N // 2
    for i in range(N - 1):
        if A[i] == (i // 2) * 2 + 1:
            continue
        else:
            print(0)
            exit()

print((2**num) % (10**9 + 7))


Measured memory_bytes: 13812
# coding: utf-8
# Your code here!
s=input()
K=int(input())

ans=[]
#122
for item in s[:len(s)-1]:
    cost=(123-ord(item))
    if item=="a":
        ans.append(item)
        continue
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

K%=26
last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))
    

Measured memory_bytes: 4216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    
	    double probability = 0;
	    
	    if (N % 2 == 0) {
	    	probability = (double)1 / 2;
	    } else {
	    	probability = (N - N/2) / (double)N;
	    }
	    
	    System.out.println(probability);
	}	
}	

Measured memory_bytes: 22740
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var ti = Sarray();
            var vi = Sarray();
            var totalT = ti.Sum();
            var dp = Enumerable.Repeat((double)(long.MaxValue / 2), (int)totalT * 2 + 1).ToArray();
            for (var d = 0; d < 2; ++d)
            {
                dp[0] = 0;
                var now = 0L;
                for (var i = 0; i < N; ++i)
                {
                    var t = ti[i];
                    var v = vi[i];
                    for (var j = 0; j < t * 2; ++j)
                    {
                        ++now;
                        dp[now] = Min(dp[now], Min(v, dp[now - 1] + 0.5));
                    }
                }
                dp = dp.Reverse().ToArray();
                vi = vi.Reverse().ToArray();
                ti = ti.Reverse().ToArray();
            }
            var sum = 0d;
            for (var i = 0; i < totalT * 2; ++i)
                sum += (dp[i] + dp[i + 1]) / 2.0 / 2.0;
            WriteLine(sum);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const int64_t LINF = 1000000000000000; // = 10^15

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり
 
int main() {
  int64_t X;
  cin >> X;
  int64_t ans = 2 * (X / 11);
  if (X % 11 == 0) {
    cout << ans << endl;
  }
  else if (X % 11 <= 6) {
    cout << ans + 1 << endl;
  }
  else {
    cout << ans + 2 << endl;
  }
}

Measured memory_bytes: 3628