akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        n: usize,
        aa: [isize; n],
    }
    let mut aa = aa;
    for i in 0..n {
        aa[i] = aa[i] - i as isize + 1;
    }
    aa.sort();
    let mi = aa.len() / 2;

    if n == 1 {
        println!("{}", 0);
        return;
    }

    let mut ans1 = 0;
    let mut ans2 = 0;
    for i in 0..n {
        ans1 += (aa[i] - aa[mi]).abs();
        ans2 += (aa[i] - aa[mi+1]).abs();
    }
    println!("{}", cmp::min(ans1, ans2));
}


Measured memory_bytes: 6396
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

signed main()
{
    int n;
    cin >> n;
    
    vi a(n*2);
    rep(i, n*2) cin >> a[i];
    
    sort(a.begin(), a.end());
    
    int ans = 0;
    rep(i, n){
        ans += a[2*i];
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,c=0,d=0,e=0,f=0,g=0;
	cin>>a>>b>>c>>d;
    e=a-b;
    f=a-c;
    g=b-c;
    if(f<0)
    {
    	f=-f;
	}
	if(e<0)
	{
		e=-e;
	}
	if(g<0)
	{
		g=-g;
	}
	if(f<=d)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(e<=d && g<=d)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<string> v,vv;
	for(int i=0;i<n;i++){
		string s,t,r; cin >> s;
		t=""; r="";
		for(int i=0;i<s.size();i++){
			if(s[i]=='?'){
				t+='a';
			}
			else{
				t+=s[i];
			}
		}
		for(int i=0;i<s.size();i++){
			if(s[i]=='?'){
				r+='z';
			}
			else{
				r+=s[i];
			}
		}
		v.push_back(t);
		vv.push_back(r);
	}
	string s; cin >> s;
	v.push_back(s);
	vv.push_back(s);
	sort(v.begin(),v.end());
	sort(vv.begin(),vv.end());
	int a,b;
	for(int i=n;i>=0;i--){
		if(s==v[i]){
			b=i;
			break;
		}
	}
	for(int i=0;i<n+1;i++){
		if(s==vv[i]){
			a=i;
			break;
		}
	}

	for(int i=a;i<b;i++){
		cout << i+1 << " ";
	}
	cout << b+1 << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N[4];
    REP(i, 4)
    {
        cin >> N[i];
    }
    sort(N, N + 4);
    if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**5+10
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
n = int(input())
a = arrIN()

heap = []
heappush(heap,a[0])
ans = 1
for i in range(1,n):
    x = heappop(heap)
    if x>a[i]:
        ans+=1
    heappush(heap,x)
    heappush(heap,a[i])
print(ans)


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

int main() {
  long long N, x;
  cin>>N>>x;
  long long a[N];
  for (int i=0; i<N; i++) cin>>a[i];

  long long min_a[N];
  for (int i=0; i<N; i++) min_a[i] = 1e13;

  long long ans = 1e13;

  for (int limit=0; limit<N; limit++) {
    long long t = 0;
    for (int i=0; i<N; i++) {
      int j = (i - limit + N) % N;
      if (a[j] < min_a[i]) {
        min_a[i] = min(a[j], min_a[i]);
      }
      t += min_a[i];
    }
    ans = min(t + limit * x, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

    long long n;
    cin >> n;
    long long sol = __LONG_LONG_MAX__;
    for(int i = 1; i<= (int) sqrt(n); ++i)
    {
        if(n%i == 0)
        {
            sol = min(sol, (i-1) + ((n/i)-1));
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c ;
  if(a==5&&b==5&&c==7) cout << "YES" ;
  else if(a==5&&b==7&&c==5) cout << "YES" ;
  else if(a==7&&b==5&&c==5) cout << "YES" ;
  else cout << "NO" ;
}


Measured memory_bytes: 256
import java.time.Instant;
import java.util.*;
import java.util.function.ToLongFunction;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Long> A = new ArrayList<>();
		List<Pair<Integer, Long>> BC = new ArrayList<>();
		List<Long> D = new ArrayList<>();
		for(int i=0; i<N; i++){
			A.add(sc.nextLong());
		}

		Collections.sort(A);

		for(int i=0; i<M; i++){
			int B = sc.nextInt();
			Long C = sc.nextLong();
			BC.add(new Pair<Integer, Long>(B, C));
		}


		Comparator<Pair<Integer, Long>> comp = Comparator.comparingLong(new ToLongFunction<Pair<Integer, Long>>() {
	        @Override
	        public long applyAsLong(Pair<Integer, Long> pair) {
	            return pair.b;
	        }
	    });

		BC = BC.stream().sorted(comp.reversed()).collect(Collectors.toList());

		out : for(Pair<Integer, Long> pair : BC){
			for(int i=0; i< pair.a; i++ ){
				D.add(pair.b);
				if(D.size()>N){
					break out;
				}
			}
		}


		 for(int i=0; i<N && i<D.size(); i++){
			 if(A.get(i)<D.get(i)){
				 A.set(i, D.get(i));
			 }else{
				 break;
			 }
		 }

		System.out.println(A.stream().reduce((a, b) -> a+b).get());


	}

	static class Pair<T1, T2> {
	    T1 a;
	    T2 b;
	    public Pair(T1 a,T2 b) {
	        this.a = a;
	        this.b = b;
	    }
	}
}




Measured memory_bytes: 104032
#include<stdio.h>
int main()
{
  long long int a;
  int x,i;
  x=scanf("%lld",&a);
  while(a>3)
    { 
      if(a%3!=0)
	i=1;
      else
	i=0;
      a/=3;
      a+=i;    
      x++;
    }
  printf("%d\n",x);
  exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;
int main() {
  string s;
  cin >> s;
  int counter = 0;
  for (int i = 0;i < 3;i++)
    if(s[i] == '1'){
      counter++;
    }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	return !printf("%d\n", max(0, a - b));
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k) {
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= MOD;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= MOD;
    }
    return x * modinv(y, MOD) % MOD;
}

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

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

    return 0;
}


Measured memory_bytes: 3676
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int count = 0;
    for (int a = 0; a <= A; a++) {
      for (int b = 0; b <= B; b++) {
        for (int c = 0; c <= C; c++) {
          int price = 500 * a + 100 * b + 50 * c;
          if (price == X) {
            count++;
          }
        }
      }
    }
    System.out.println(count);
  }
}

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

#define DAMAGE 10000
#define N 1000
#define INF ((1<<31)-1)

int dp[N+1][DAMAGE+1];

int main(void){
    int h, n;
    cin >> h >> n;
    int damage[N+1], cost[N+1];
    for (int i = 1; i <= n; i++){
        cin >> damage[i] >> cost[i];
    }

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

    for (int i = 1; i <= n ; i++){
        for (int j = 0; j <= h; j++){
            if( dp[i][j] == INF ){
                continue;
            }
            if ( i+1 <= n ){
                dp[i+1][j] = min( dp[i+1][j], dp[i][j] );
            }
            
            if( j+damage[i] > h ){
                dp[i][h] = min( dp[i][h], dp[i][j] + cost[i] );
            }
            else{
                dp[i][j+damage[i]] = min( dp[i][j+damage[i]], dp[i][j] + cost[i] );
            }
            if( i+1 <= n && j+damage[i+1] > h ){
                dp[i+1][h] = min( dp[i+1][h], dp[i][j] + cost[i+1] );
            }
            else if( i+1 <= n && j+damage[i+1] <= h ){
                dp[i+1][j+damage[i+1]] = min( dp[i+1][j+damage[i+1]], dp[i][j] + cost[i+1] );
            }
        }
    }

    cout << dp[n][h] << endl;

    return 0;
}


Measured memory_bytes: 42716
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  rep (i, n) {
    cin >> v[i];
  }
  ll ans = 0;
  rep (i, n - 1) {
    if (v[i] + v[i + 1] > x) {
      // P(v[i + 1] - x);
      ans += v[i + 1] - x + v[i];
      v[i + 1] = x - v[i];
      if (v[i + 1] < 0) v[i + 1] = 0;
    }
  }

  // rep (i, n) {
  //   cout << v[i] << " ";
  // }
  // cout << endl;
  P(ans);


  return 0;
}



Measured memory_bytes: 768
using System;

class Untitled
{
  static void Main(string[] args)
  {
    bool parsed = false;
    int seconds = 0;
    string s = Console.ReadLine();
    if (!String.IsNullOrEmpty (s)) {
     parsed = Int32.TryParse(s, out seconds);
    }
    if (parsed && 0 <= seconds && seconds < 86400) {
      TimeSpan time = TimeSpan.FromSeconds(seconds);
      string answer = string.Format("{0:D}:{1:D}:{2:D}", 
      time.Hours, 
      time.Minutes, 
      time.Seconds);
      System.Console.WriteLine (answer);
    }
  }
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    int H,N;
    cin>>H>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    ll sum = 0;
    rep(i,N)sum+=A[i];
    cout<<((sum >= H) ? "Yes":"No")<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
		int N = input[0];
		int M = input[1];
		List<int> list = new List<int>();
        for(var i = 0; i < N; i++)
		{
			var inputa = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            for(var j = 1; j < inputa.Length; j++)
			{
				list.Add(inputa[j]);
			}
		}
		int ans = 0;
        for(var i = 1; i <=M; i++)
		{
			int l=list.Count(x => x == i);
			if (l == N) { ans++; }
		}

		Console.WriteLine(ans);
	}
}


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

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

  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int> sorted_vec= vec;
  sort(sorted_vec.begin(), sorted_vec.end());

  int Nflip= 0;
  for(int i=0; i<N; i++){
    auto itr= lower_bound(sorted_vec.begin(), sorted_vec.end(), vec.at(i));
    if(distance(sorted_vec.begin(), itr) % 2 != i % 2){
      Nflip++;
    }
  }
  assert(Nflip%2==0);
  int ans= Nflip/2;

  cout << ans << endl;
}

Measured memory_bytes: 4044
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, K = next(it), next(it)
    P = list(it)
    P.sort()
    print(sum(P[:K]))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 62256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, A, B;
  std::cin >> N >> A >> B;

  ll ans = 0LL;
  for (ll i = 1; i <= N; i++) {
    ll x = i;
    ll sum = 0LL;
    while (x > 0) {
      sum += x % 10;
      x /= 10;
    }
    if (sum >= A && sum <= B) ans += i;
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n;
    cin>>n;
    ll p;
    cin>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    ll ret=1;
    rep(i,10000000){
        int cnt=0;
        if(i<2)continue;
        while(p%i==0){
            p/=i;
            cnt++;
        }
        if(cnt>=n){
            cnt/=n;
            ret*=pow(i,cnt);
        }
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 384
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define MOD1 998244353
#define endl "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn1(i, n) for(int i = 1; i <= int(n); i++)
#define int ll
using namespace std;
typedef long double ld;
typedef long long ll;
typedef set <int> si;
typedef multiset <int> msi;
typedef unordered_set <int> usi;
typedef unordered_multiset <int> umsi;
typedef pair<int,int> pairs;
typedef vector <int> VI;
typedef map<int,int> mii;
typedef multimap <int,int> mmii;
typedef unordered_map <int,int> umii;
typedef unordered_multimap<int,int> ummii;
double pi = 2 * acos(0.0);
inline int two(int n) { return 1 << n; }
struct cmp{
    /////call by set<pair<int, int>, cmp>
    bool operator() (const pair<int, int>& a, const pair<int, int>& b) const{
        int lena= a.second - a.first + 1;
        int lenb = b.second - b.first + 1;
        if(lena == lenb) return a.first < b.first;
        return lena > lenb;
    }
};
bool isPrime(int n) { 
    if (n <= 1)  return false; if (n <= 3)  return true; if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; 
    return true; 
}

const int N = 1e18;

int index(int n) {
    int t = 0;
    n/=10;
    while(n) {
        n/=10;
        t++;
    }
    return t;
}

signed main()  {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif 
    //
    int t=1;
    //cin>>t;
    while(t--) {
        int n;
        float f;
        cin>>n>>f;

        // cout << n <<" " << f << endl;
        f = f*100;

        int i = (((int) (f + 32768.5)) - 32768);

        // cout << f << " " << i << endl;
        n = n*i;
        //cout << n << endl;
        n /= 100;
        cout << n << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3752
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n):
    for j in range(i+1,n):
        x=0
        for z in range(d):
            x+=(l[i][z]-l[j][z])**2
        if x**0.5%1==0:
            ans+=1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n;

void solve()
{
    cin >> n;
    if (n%2==0) {
        nout("0.5000000000");
    }else{
        int k =n/2 + 1;
        cout << fixed << setprecision(8) << (float) k / (float) n << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define LENGTH 256

int main( void ) {
  char input[LENGTH];
  int N;

  fgets(input, 256, stdin);
  sscanf(input, "%d", &N);
  if(N%1000 == 0){
    printf("%d\n", 0);
  }else{
    printf("%d\n", 1000-N%1000);
  }
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  rep(i,8) {
    int sum = s[0]-'0';
    string ans = "";
    ans += s[0];
    rep(j,3) {
      if(i>>j&1) {
        sum += s[j+1]-'0';
        ans += '+';
      } else {
        sum -= s[j+1]-'0';
        ans += '-';
      }
      ans += s[j+1];
    }
    if(sum==7) {
      cout << ans << "=7" << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
N,K,C = map(int,input().split())
S = str(input())

L = [] #0index
R = []
now = 0
times = 0
while times < K:
  #print(L)
  if S[now] == "o":
    L.append(now)
    now += C
    times += 1
  now += 1

now = N-1
times = 0
while times < K:
  if S[now] == "o":
    R.append(now)
    now -= C
    times +=1
  now -= 1
R.sort()

#print(L,R)
for i in range(K):
  if L[i] == R[i]:
    print(L[i]+1)
    

Measured memory_bytes: 100304
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<assert.h>
#define i64  long long
#define vi32 vector<int>
#define vi64 vector< long long>
#define  ii pair<int,int>
const  long long mod = 1e9 + 7, inf = 1e9, linf = 1 << 30;//linf = 9223372036854775807;
const long long hashmod[4] = { (int)1e9 + 2277, (int)1e9 + 5277, (int)1e9 + 8277, (int)1e9 + 9277 };
const long double EPS = 0.000000001L, pi = acos(-1);
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1000006
//i64 base = 311;
int dx[] = { 0,-1,-1,-1,0,1,1,1 };
int dy[] = { -1,-1,0,1,1,1,0,-1 };
// God of debug OPP
#define debugg assert
using namespace std;
i64 dp[N][14];
i64 fast(i64 a, i64 b)
{
	i64 cnt = 1;
	while (b)
	{
		if (b % 2)cnt = (cnt * a) % 13;
		a = a * a%13;
		b = b /2;
	}
	return cnt%13;
}
int main()
{
	string s;
	cin >> s;
	int n = s.size();
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			for (int d = 0; d < 10; d++)
			{
				if (s[i] == '?' || s[i] - '0' == d)
				{
					dp[i + 1][(j * 10 + d) % 13] = (dp[i+1][(j*10+d)%13]+dp[i][j])%mod;
				}
			}
		}
	}
	cout << dp[n][5]%mod;
}


Measured memory_bytes: 12800
fun main(args: Array<String>) {
    val (n, k, s) = readIntList()

    val ans = StringBuilder()

    repeat(k) {
        ans.append("$s ")
    }
    if (s == 1000000000) {
        repeat(n - k) {
            ans.append("1 ")
        }
    } else {
        repeat(n - k) {
            ans.append("1000000000 ")
        }
    }
    println(ans.toString())
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 54044
n = int(input())
dp = [0 for i in range(n)]
min = float("inf")
for i in range(1, n//2):
    a_sum = sum(map(int, list(str(i))))
    b_sum = sum(map(int, list(str(n - i))))
    c = a_sum + b_sum
    if(min > c):
        min = c
if min == float("inf"):
    min = n
print(min)


Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pii a,pii b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n;cin>>n;
  ll cnt=0;
  rep(i,n){
    ll a;
    cin>>a;
    if(a%2==1) cnt++;
  }
  cout<<((cnt%2==0)? "YES":"NO" );
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    long long t,n,m,a,b,i,j,k,x,y,cnt=1;
    bool flag = false;
    cin>>n;
    lve v(n);
    for(auto &ss:v) cin>>ss;
    sort(all(v));
    double ans = v[0];
    for (i = 1; i < n; i++){
        ans = (ans + v[i]) / 2.0;
    }
    cout << ans << endl;

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

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // ll tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}

Measured memory_bytes: 3808
#include<stdio.h>
int ex(int n)
{
    if(n == 0)return 1;
    return ex(n - 1) * 2;
}
int main()
{
    int n;
    while(scanf("%d",&n) != -1)
    {
        int mem[10] = {0};
        for(int i = 9; i >= 0; i--)
        {
            if(n >= ex(i))mem[i] = 1,n -= ex(i);
        }
        n = 0;
        for(int i = 0; i < 10; i++)
        {
            if(mem[i] == 1)
            {
                if(n != 0)printf(" ");
                printf("%d",ex(i)),n++;
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1028
package main

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

func main() {
	H, N := ReadInt(), ReadInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i] = ReadInt(), ReadInt()
	}

	dp := make([]int, H)
	for i := 0; i < H; i++ {
		dp[i] = 1 << 60
	}
	for i := 0; i < N; i++ {
		for j := H - 1; j >= 0; j-- {
			if j+A[i] >= H {
				dp[j] = Min(dp[j], B[i])
			} else {
				dp[j] = Min(
					dp[j],
					dp[j+A[i]]+B[i],
				)
			}
		}
	}
	fmt.Println(dp[0])
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2000
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;
    Point(){}
    Point(double x0, double y0){
        x = x0; y = y0;
    }

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

    bool operator == (const Point &p){
        return equals(x, p.x) && equals(y, p.y);
    }

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

};

double norm(Point p){
    return p.x * p.x + p.y * p.y;
}

double v_abs(Point p){
    return sqrt(norm(p));
}

typedef Point Vector;

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

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

struct Circle{
    Point c;
    double r;
    Circle(){}
    Circle(Point c0, double r0){
        c.x = c0.x;
        c.y = c0.y;
        r = r0;
    }
    Circle(double x0, double y0, double r0){
        c.x = x0;
        c.y = y0;
        r = r0;
    }
};

int main(){
    Point p0, p1;
    cin >> p0.x >> p0.y;
    cin >> p1.x >> p1.y;
    int Q;
    cin >> Q;
    rep(i, Q){
        Point p2;
        cin >> p2.x >> p2.y;
        Vector v1 = p1 - p0, v2 = p2 - p0;
        if(cross(v1, v2) > EPS) cout << "COUNTER_CLOCKWISE" << endl;
        else if (cross(v1, v2) < -EPS) cout << "CLOCKWISE" << endl;
        // else {
        //     double r;
        //     if(equals(v2.y, 0.0)) r = v2.x / v1.x;
        //     else r = v2.y / v1.y;
        //     if(r < 0) cout << "ONLINE_BACK" << endl;
        //     else if(r > 1) cout << "ONLINE_FRONT" << endl;
        //     else cout << "ON_SEGMENT" << endl;
        // }
        else if (dot(v1, v2) < -EPS) cout << "ONLINE_BACK" << endl;
        else if (norm(v2) > norm(v1)) cout << "ONLINE_FRONT" << endl;
        else cout << "ON_SEGMENT" << endl;
    }
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const int MOD=(ll)1e10+7;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
int t[101],v[101];
double minv[40004];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n;
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>t[i];
    t[i]*=2;
    sum+=t[i];
  }
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  int t1[101];
  for(int i=0;i<n;i++){
    if(i==0){
      t1[i]=t[0];
      continue;
    }
    t1[i]=t1[i-1]+t[i];
  }
  int t2[101];
  for(int i=n-1;i>=0;i--){
    if(i==n-1){
      t2[i]=sum-t[i];
      continue;
    }
    t2[i]=t2[i+1]-t[i];
  }
  int now=0;
  for(int i=0;i<=sum;i++){
    if(i>t1[now])now++;
    if(i==0){
      minv[i]=0;
      continue;
    }
    minv[i]=min(minv[i-1]+0.5,(double)v[now]);
  }
  //for(int i=0;i<=sum;i++){
    //cout<<minv[i]<<" ";
  //}
  //cout<<endl;
  now=n-1;
  for(int i=sum;i>=0;i--){
    if(i<t2[now])now--;
    if(i==sum){
      minv[i]=0;
      continue;
    }
    minv[i]=min({minv[i+1]+0.5,(double)v[now],minv[i]});
  }
  /*for(int i=0;i<=sum;i++){
    printf("%.2f ",minv[i]);
  }
  printf("\n");*/
  double ans=0;
  for(int i=0;i<sum;i++){
    if(i==0){
      ans+=(minv[i+1]+minv[i])/4;
    }else{
      ans+=(minv[i]+minv[i+1])/4;
    }
  }
  printf("%.10f\n",ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
    return 0;
}






Measured memory_bytes: 640
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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

s = input()
t = input()

DP = [[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            DP[i+1][j+1] = max(DP[i+1][j+1],DP[i][j]+1)
        DP[i+1][j+1] = max(DP[i+1][j+1],DP[i+1][j])
        DP[i+1][j+1] = max(DP[i+1][j+1],DP[i][j+1])
           
ans = ""
i = len(s)
j = len(t)
while i > 0 and j > 0 :
    if DP[i][j] == DP[i-1][j]:
        i -= 1
    elif DP[i][j] == DP[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] +ans
        i -= 1
        j -= 1
print(ans)

Measured memory_bytes: 113884
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

type Graph = Array Int [Int]

buildGraph :: (Int,Int) -> [(Int,Int)] -> Graph
buildGraph bound dat = runST $ do
  graph <- newArray bound [] :: ST s (STArray s Int [Int])
  forM_ dat $ \(s,e) -> do
    modifyArray graph s (e:)
    modifyArray graph e (s:)
  freeze graph



main :: IO ()
main = do
  n <- readLn :: IO Int
  graph <- buildGraph (1,n) . map (listToTuple2 . map readIntBS . BS.words) . BS.lines <$> BS.getContents :: IO Graph

  let
    dfs :: Int -> Int -> Graph -> Maybe [Int]
    dfs cur par tree
      | cur == n = Just [n]
      | otherwise = if next == [] then Nothing else Just (cur : head next)
        where
          next = catMaybes $ map (\i -> dfs i cur tree) (delete par $ tree!cur)

    (Just chain) = dfs 1 0 graph

    count :: Int -> Int -> Graph -> Int
    count cur par tree = 1 + (sum $ [count i cur tree | i <- tree!cur, i /= par])

    branch [] _ = []
    branch (x:xs) prev = 1 + sum [count i x graph | i <- graph!x, i /= prev, i /= next] : branch xs x
      where next = if null xs then 0 else head xs
    
    (fennec, snuke) = splitAt (ceiling $ (length chain) % 2) $ branch chain 0

  putStrLn $ if sum fennec > sum snuke then "Fennec" else "Snuke"
  


Measured memory_bytes: 68988
#include<math.h>
#include<stdio.h>
void twin_prime(int n) {
	int prime1[10001], prime2[10001];
	int i, j, k = 0, flag, b;

	for (i = 0; i <= n; i++)prime1[i] = 1;
	for (i = 4; i <= n; i += 2)prime1[i] = 0;

	b = sqrt(n);
	for (i = 3; i <= b; i += 2) {
		if (prime1[i]) {
			for (j = 2 * i; j <=n; j += i)prime1[j] = 0;
		}
	}
	for (i = 2; i <= n; i++) 
		if (prime1[i]) prime2[k++] = i;
	
	for (i = k; i >= 0; i--) {
		flag = 0;
		for (j = k - 1; j >= 0; j--) {
			if (prime2[i] - prime2[j] == 2) {
				flag = 1;
				break;
			}
		}
		if (flag)break;
	}
	printf("%d %d\n", prime2[j], prime2[i]);
	return;
}

int main(void) {
	int n,i;

	   while(1){
		scanf("%d", &n);
		if (n == 0)break;
		twin_prime(n);
}

	return 0;
}

Measured memory_bytes: 644
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int N,Q,K;
ll c[100001];
bool v[100001];
deque<pair<int,ll>> n[100001];
void dfs(int node,ll d){
      while(n[node].size()){
            pair<int,ll> next_p;
            next_p=n[node].front();
            n[node].pop_front();
            int next_n=next_p.first;
            ll next_d=next_p.second;
            if(!v[next_n]){
                  v[next_n]=true;
                  c[next_n]=d+next_d;
                  dfs(next_n,c[next_n]);
            }
      }
}

int main (){
      cin.tie(0);
      ios::sync_with_stdio(false);
      cin>>N;
      rep0(i,N-1){
            int a,b,c;
            cin>>a>>b>>c;
            n[a].push_back({b,c});
            n[b].push_back({a,c});
      }
      fill(v+1,v+N+1,false);
      cin>>Q>>K;
      v[K]=true;
      dfs(K,0);
      rep0(i,Q){
            int x,y;
            cin>>x>>y;
            cout<<c[x]+c[y]<<"\n";
      }
      
      return 0;
}


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

using namespace std;

typedef long long ll;

const int MX = 3003;
const ll MOD = 1000000007;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll qpow(ll x, ll t)
{
	ll ans = 1;
	while(t)
	{
		if(t & 1) ans = ans * x % MOD;
		x = x * x % MOD;
		t >>= 1;
	}
	return ans;
}

ll inv(ll x)
{
	return qpow(x, MOD-2);
}

ll f[MX][MX], seq[MX], rak[MX];

int main()
{
	int n, q;
	read(n), read(q);
	for(int i=1; i<=n; i++) read(seq[i]);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(seq[j] > seq[i])
				f[i][j] = 1;
	ll iv2 = inv(2);
	for(int i=1; i<=q; i++)
	{
		int x, y;
		read(x), read(y);
		if(x > y) swap(x, y);
		for(int j=1; j<=n; j++)
			if(j!=x && j!=y)
			{
				ll tmp = (f[j][x] + f[j][y]) * iv2 % MOD;
				f[j][x] = f[j][y] = tmp;
				tmp = (f[x][j] + f[y][j]) * iv2 % MOD;
				f[x][j] = f[y][j] = tmp;
			}
		ll tmp = (f[x][y] + f[y][x]) * iv2 % MOD;
		f[x][y] = f[y][x] = tmp;
	}
	ll ans = 0;
	for(int i=1; i<=n; i++)
		for(int j=1; j<i; j++)
			ans = (ans + f[i][j]) % MOD;
	printf("%lld\n", ans * qpow(2, q) % MOD);
	return 0;
}


Measured memory_bytes: 70656
def get_items(arr,idx_arr):
    return [arr[i] for i in range(len(arr)) if i in idx_arr]

def to_binaly_arr(val,digit_num):
    return list(bin(val)[2:].zfill(digit_num))

def get_one_idx(binaly_arr):
    return [idx for idx in range(len(binaly_arr)) if binaly_arr[idx] == "1"]

def get_arr_sum(mat):
    if len(mat) == 0:
        return []
    else:
        sum_arr = []
        for j in range(len(mat[0])):
            sum_val = 0
            for i in range(len(mat)):
                sum_val += mat[i][j]
            sum_arr.append(sum_val)
        return sum_arr
def is_all_item_over_X(arr,X):
    return (not (False in [item>=X for item in arr])) and len(arr) > 0

if __name__ == "__main__":
    N,M,X = map(int,input().split())
    C,A = [],[]
    for i in range(N):
        input_val = list(map(int,input().split()))
        C.append(input_val[0])
        A.append(input_val[1:])
    min_price = float("inf")
    for i in range(0,2**N):
        idx_arr = get_one_idx(to_binaly_arr(i,N))
        arr_sum = (get_arr_sum(get_items(A,idx_arr)))
        if is_all_item_over_X(arr_sum,X) == True:
            min_price = min(min_price,sum(get_items(C,idx_arr)))
    if min_price == float("inf"):
        print(-1)
    else:
        print(min_price)

Measured memory_bytes: 9224
import math
def prime(num):
    judge = True
    for i in range(2, int(math.sqrt(num)+1)):
        if num % i == 0:
            judge = False
    return judge
    
n = int(input())
cnt = 0
a =[]
for i in range(n):
    num = int(input())
    if prime(num):
        cnt += 1
print(cnt)


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

using namespace std;

int main(){
    char c[3]; cin >> c;
    char c1 = c[0];
    char c2 = c[1];
    char c3 = c[2];
    
    int cc1 = c1 - '0';
    int cc2 = c2 - '0';
    int cc3 = c3 - '0';
    
    cout << cc1+cc2+cc3 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int  p, q, r;
    cin >> p >> q >> r;
    if (p<=q&&q<=r)
    {
        cout << p+q << endl;
    }
    else if (p<=r&&r<=q)
    {
        cout << p+r << endl;
    }
    else if (q<=p&&p<=r)
    {
        cout << q+p << endl;
    }
    else if (q<=r&&r<=p)
    {
        cout << q+r << endl;
    }
    else if (r<=q&&q<=p)
    {
        cout << r+q << endl;
    }
    else
    {
        cout << p+r << endl;
    }

  return 0;
}

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

int main() {
    vector<char> C(6);
    for (int i = 0; i < 6; i++) {
        cin >> C[i];
    }

    if (C[0] == C[5] && C[1] == C[4] && C[2] == C[3]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256