akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        aa: [u32;n]
    }
    println!("{}",
        aa.iter().max().unwrap() - aa.iter().min().unwrap());
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
	int h,w,i,k,j;
	char a[1000][1000];
	
	while(scanf("%d%d",&h,&w)!=EOF)
{
	
		for(i=0;i<h;i++)
		{
			scanf("%s",a[i]);
		}
	for(i=0;i<w+2;i++)
		printf("#");
		printf("\n");
			for(i=0;i<h;i++)
			{	printf("#");
				printf("%s",a[i]);
				printf("#\n");
			}
		for(i=0;i<w+2;i++)
		printf("#");
		printf("\n");
}
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    def trial_division():
        divs = []
        for i in range(1,int(N**0.5)+1):
            if N % i == 0:
                divs.append(i)
                if i != N//i:
                    divs.append(N//i)
        return divs

    divs = trial_division()
    ans = 10**10 + 7
    for d in divs:
        d_other = N // d
        F = max(len(str(d)),len(str(d_other)))
        ans = min(ans,F)
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}


void count(int p, VVI &l, VI &c, vector<bool> &used) {
  for(auto v : l[p]) {
    if(used[v]) continue;
    used[v] = true;
    c[v] += c[p];
    count(v, l, c, used);
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  VVI l(n);
  VI c(n, 0);
  vector<bool> used(n, false);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    l[a].push_back(b);
    l[b].push_back(a);
  }
  VI p(q), x(q);
  rep(i, q) {
    cin >> p[i] >> x[i];
    p[i]--;
  }

  rep(i, q) {
    c[p[i]] += x[i];
  }
  used[0] = true;
  count(0, l, c, used);

  rep(i, n) cout << c[i] << ' ';
  cout << endl;

  return 0;
}


Measured memory_bytes: 31360
import sys
from bisect import bisect_left, bisect_right

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

W, H = lr()
P = [ir() for _ in range(W)]
Q = [ir() for _ in range(H)]
P.sort()
Q.sort()
answer = 0
for p in P:
    i = bisect_left(Q, p)
    answer += (H - i + 1) * p

for q in Q:
    i = bisect_right(P, q)
    answer += (W - i + 1) * q

print(answer)
# 19

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{0};
    for(unsigned long i{0}, a; i < N; ++i){
        cin >> a;
        ans += ~i & a & 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n,x;
    cin>>n>>x;
    int a[n];
    lp(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    int res=0;
    lp(i,0,n)
        if(a[i]<=x)
            x-=a[i],res++;
    if(res==n&&x>0)
        res--;
    cout<<res;
}

Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			string s = cin.Next();
			string t = cin.Next();

			int offset = n;
			for (int i = 0; i < n; i++) {
				bool ok = true;
				for (int j = 0; j < n - i; j++) {
					if (s[i + j] != t[j]) {
						ok = false;
						break;
					}
				}

				if (ok) {
					offset = i;
					break;
				}
			}

			Console.WriteLine(n + offset);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(998244353)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    ll MAX_SUM = 90005;
    vector<vector<ll>> dp(n+1,vector<ll>(MAX_SUM,0));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < MAX_SUM; j++){
            dp[i+1][j] += dp[i][j]*2;
            dp[i+1][j] %= MOD;
            if(j+a[i]<MAX_SUM){
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= MOD;
            }

        }
    }
    ll over_half = 0;
    ll start = s/2;
    if(s%2==1){start++;}
    for(int i = start; i < MAX_SUM; i++){
        over_half += dp[n][i];
        over_half %= MOD;
    }


    vector<vector<ll>> dp2(n+1,vector<ll>(MAX_SUM,0));
    dp2[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < MAX_SUM; j++){
            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= MOD;
            if(j+a[i]<MAX_SUM){
                dp2[i+1][j+a[i]] += dp2[i][j];
                dp2[i+1][j+a[i]] %= MOD;
            }

        }
    }
    ll overall = 1;
    for(int i = 0; i < n; i++){
        overall *= 3;
        overall %= MOD;
    }
    ll half = (s%2==0) ? dp2[n][s/2] : 0;
    ll ans = overall - over_half*3 + half*3 +10*MOD;
    cout << ans%MOD << endl;

    return 0;
}


Measured memory_bytes: 424512
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod 1000000007
#define P(a,b) pair<a,b>
#define CIN(V,s,n) for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}

using namespace std;
bool sortBylen(string &a,string &b)
{
    if(a.size()>b.size())
        return true;
    else if(a.size()==b.size())
    {
        if(a>b)
        {
            return true;
        }
        else
            false;
    }
    else
        return false;
}
int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll n,W,i,j,k=2,l1,l2,m;
    ll r,c;
    cin >> r >> c;
    vector<string> G(r);
    for(i=0;i<r;i++)
        cin >> G[i];
    vector<vector<ll> > DP(r,vector<ll>(c));

    DP[0][0]=1;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            if(G[i][j]=='.')
            {
                if(j-1>=0 and G[i][j-1]=='.')
                    DP[i][j] += DP[i][j-1];
                if(i-1>=0 and G[i-1][j]=='.')
                    DP[i][j] += DP[i-1][j];

                DP[i][j] %= mod;
            }
        }
    }

    cout << DP[r-1][c-1];

}

	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    int n;
    cin>>n;
    ll ans =0;
    rep(i,n){
        ll x=i+1;
        ll c =n/x;
        ans+=((x+(x*c))*c)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
import fractions
import math
import sys

fastinput = sys.stdin.readline
gcd = fractions.gcd
N,K=map(int,fastinput().split())
A = [int(i) for i in fastinput().split()]
S = sum(A)
yakusu = []
for i in range(1,math.floor(math.sqrt(S))+1):
    if not S%i:
        yakusu.append(i)
        yakusu.append(S//i)

yakusu.sort(reverse = True)
for kouho in yakusu:
    amaris =[a%kouho for a in A]
    amaris.sort()
    amarisum= sum(amaris)
    y=amarisum // kouho
    if y==0:
        print(kouho)
        break
    else:
        yakuwa = 0
        for i in range(N-y):
            yakuwa += amaris[i]
        if yakuwa <= K:
            print(kouho)
            break
    

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

int main(){
    ll n,k;
    cin >>n>>k;
    if(n>=k){
        n-=(n/k)*k;
    }
    if(n>abs(k-n)){
            n=abs(k-n);
        }
    cout << n;
}

Measured memory_bytes: 3624
object Main extends App {
  val seq1 = for(i<-1 to 9) yield Vector(i,i,i)
  val seq2 = for(i<-1 to 7) yield Vector(i,i+1,i+2)

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

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

Measured memory_bytes: 71860
#include <stdio.h>
void spin1(int a[]);
void spin2(int a[]);
void spin3(int a[]);
int judge(int a[],int b[]);
 
int main(void){
  int d[2][6],q,u,f=0,i,j,k;
    for(i=0;i<6;i++){
        scanf("%d",&d[0][i]);
    }
    for(i=0;i<6;i++){
        scanf("%d",&d[1][i]);
    }
    for(i=0;i<10;i++){
      spin1(d[0]);
      for(j=0;j<10;j++){
	spin2(d[0]);
	for(k=0;k<4;k++){
	  spin3(d[0]);
	  if(judge(d[0],d[1])){
	    f=1;
	    break;
	  }
	}
	if(f)
	  break;
      }
      if(f)
	break;
    }
    if(f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}
 
void spin1(int a[]){
    int t=a[0];
    a[0]=a[4];
    a[4]=a[5];
    a[5]=a[1];
    a[1]=t;
}
void spin2(int a[]){
    int t=a[1];
    a[1]=a[2];
    a[2]=a[4];
    a[4]=a[3];
    a[3]=t;
}
void spin3(int a[]){
    int t=a[0];
    a[0]=a[2];
    a[2]=a[5];
    a[5]=a[3];
    a[3]=t;
}
int judge(int a[],int b[]){
  int i;
  for(i=0;i<6;i++){
    if(a[i]!=b[i])
      return 0;
  }
  return 1;
}

Measured memory_bytes: 580
#include<iostream>
using namespace std;
int main() {
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if (c <= a && c <= b) {
        if (x >= y) {
            ans = min(x * c * 2, y * 2 * c + (x - y) * a);
        } else {
            ans = min(y * c * 2, x * 2 * c + (y - x) * b);
        }
    } else if (a <= c && b <= c) {
        ans += x * a + y * b;
    } else {
        if (b < a) {
            swap(a, b);
            swap(x, y);
        }
        //a <= c <= b
        if (x > y) {
            ans += (x - y) * a;
            double min = 5000 * 1e5;
            int key = 2 * c > b ? b : 2 * c;
            for (int i = 0; i <= y; ++i) {
                double price = i * ((double)(a + key) / 2) + (y - i) * c;
                //cout << price << endl;
                min = min > price ? price : min;
            }
            ans += 2 * min;
        } else {
            int key = 2 * c > b ? b : 2 * c;
            ans += (y - x) * key;
            //cout << ans << endl;
            double min = 5000 * 1e5;
            for (int i = 0; i <= x; ++i) {
                double price = i * ((double)(a + key) / 2) + (x - i) * c;
                //cout << price << endl;
                min = min > price ? price : min;
            }
            ans += 2 * min;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int wa[(int)1e5 + 55] = {0};
int ac[(int) 1e5 + 55] = {0};
void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int p;
        string s;
        cin >> p >> s;
        if (ac[p])
            continue;
        if (s == "AC")
            ac[p]++;
        else
            wa[p]++;
    }
    int a = 0, b = 0;
    for (int i = 0; i < (int) 1e5 + 55; ++i) {
        a += ac[i];
        if (ac[i])
            b += wa[i];
    }
    cout << a << ' ' << b;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
int main() {
  std::string s;
  std::cin>>s;
  int i,t,a=753;
  for(i=2;i<s.size();++i) {
    t = std::abs((s[i-2]-48)*100+(s[i-1]-48)*10+(s[i]-48)-753);
    a = (a>t?t:a);
  }
  std::cout<<a<<"\n";
}
    

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

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

    vector<ll> data(10000001,2);
    vector<ll> sum(10000001);
    sum.at(0) = 0;
    sum.at(1) = 1;
    sum.at(2) = 5;
    sum.at(3) = 11;
    sum.at(4) = 23;

    for(int i = 2 ; i <= n ; i++){
        int temp = i * 2;
        while(temp <= n){
            data.at(temp)++;
            temp += i;
        }
        sum.at(i) = sum.at(i - 1) + data.at(i) * i;
    }

    cout << sum.at(n) << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
ll mod=1e18;
int main(){
	startTime=clock();
	ll s;
	cin >> s;
	ll x1,y1,x2,y2,x3,y3;
	x1=0ll;
	y1=0ll;
	x2=1e9;
	y2=1;
	x3=(mod-s)%1000000000;
	y3=(s+x3)/1000000000;
	cout << x1 << " " << y1 <<" "
	<< x2 << "  " << y2 <<	" "
	<< x3 << " " << y3;
		

	return 0;
}


// x2y3-x3y2
// cy3-x3

Measured memory_bytes: 3592
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Dec  9 21:29:57 2018
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := make([]int, 3)
	fmt.Scan(&arr[0], &arr[1], &arr[2])
	sort.Ints(arr)
	fmt.Println(arr[1] - arr[0] + arr[2] - arr[1])
}


Measured memory_bytes: 512
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	
	while(1){

		int n,m,p,l,f=0,x,k;
		cin >> n;
		if(n==0) break;

		/*?????°??£?¨?*/
		VI M;
		VVI pp(n);
		VI flag(n, 0);

		/*???????????\???*/
		for(int i=0; i<n; i++){
			cin >> m;
			M.PB(m);
			for(int j=0; j<m; j++){
				cin >> p;
				pp[i].PB(p);
			}
		}

		/*?????????????????\???*/
		cin >> k;
		VI L;
		for(int i=0; i< k; i++){
			cin >> l;
			L.PB(l);
		}

		/*????????????????????°???????????¨?????§*/
		for(int i=0; i<n; i++){
			flag[i]=0;
			if(k > M[i]) continue;
			for(int j=0; j < M[i];j++){
				for(int LL=0; LL<k; LL++){
					if(pp[i][j] == L[LL]){
						flag[i]++;
					}
				}
			}
		}

		/*?????????????????¨????????????????????????*/
		for(int i=0; i<n; i++){
			if(k == flag[i]){
				f++;
				x = i + 1;
			}
		}
		if(f ==1){
			cout << x << endl;
		}
		else
			cout << -1 << endl;

	}

	return 0;

}

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

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r = 0;
	int c,s = 0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	int n = ri();
	int k = ri() - 1;
	std::string s;
	std::cin >> s;
	s[k] += 'a' - 'A';
	std::cout << s << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
def mx(mtrx):
	maxSum = -1000000
	for colStart in range(n):
		partSum = [0]*n
		for colEnd in range(colStart,n):
			for row in range(n):
				partSum[row] += mtrx[row][colEnd]
			maxSum = max(maxPart(partSum), maxSum)
	return maxSum

def maxPart(array):
	maxSum = -1000000
	calcSum = 0
	for i in range(n):
		calcSum += array[i]
		maxSum = max(calcSum,maxSum)
		if calcSum < 0:	calcSum = 0
	return maxSum
	
n = int(raw_input())
print mx([map(int, raw_input().split()) for i in range(n)])

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

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

    vector<int64_t> na(n);
    vector<int64_t> v(n+1);
    rep(i,n){
        cin >> na[i];
        v[na[i]]++;
    }
    vector<int64_t> nor(n+1);
    vector<int64_t> abn(n+1);
    rep(i, n+1){
        if(v[i] > 1){
            nor[i] = (v[i] * (v[i]-1))/2;
            abn[i] = ((v[i]-1) * (v[i]-2))/2;
        }
        else{
            nor[i] = 0;
            abn[i] = 0;
        }
    }
    int64_t alln = accumulate(all(nor), 0LL);
    rep(i, n){
        cout << alln-nor[na[i]]+abn[na[i]] << endl;
    }
      

}

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

int main() {
    int n;
    cin >> n;
    int a = 0;
    a += n / 100000000 % 10;
    a += n / 10000000 % 10;
    a += n / 1000000 % 10;
    a += n / 100000 % 10;
    a += n / 10000 % 10;
    a += n / 1000 % 10;
    a += n / 100 % 10;
    a += n / 10 % 10;
    a += n / 1 % 10;
    if (n % a == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef pair<int, int> i_i;
typedef double D;
typedef complex<D> P;
typedef long long ll;
D pi = acos(-1.0);

#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 pb push_back

const int MAX_N = 100010;
int _k, _N, _rank[MAX_N + 1], tmp[MAX_N + 1], sa[MAX_N + 1], lcp[MAX_N];

bool compare_sa(int i, int j) {
	if (_rank[i] != _rank[j]) return _rank[i] < _rank[j];
	else {
		int ri = i + _k <= _N ? _rank[i + _k] : -1;
		int rj = j + _k <= _N ? _rank[j + _k] : -1;
		return ri < rj;
	}
}

void make_sa(string s) {
	_N = s.length();
	rep(i, _N + 1) {
		sa[i] = i;
		_rank[i] = i < _N ? s[i] : -1;
	}
	for (_k = 1; _k <= _N; _k *= 2) {
		sort(sa, sa + _N + 1, compare_sa);
		tmp[sa[0]] = 0;
		rep1(i, _N)
			tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
		rep(i, _N + 1) _rank[i] = tmp[i];
	}
}

void make_lcp(string s) {
	int N = s.length();
	rep(i, N + 1) _rank[sa[i]] = i;
	int h = 0;
	lcp[0] = 0;
	rep(i, N) {
		int j = sa[_rank[i] - 1];
		if (h > 0) h--;
		for (; j + h < N && i + h < N; h++)
			if (s[j + h] != s[i + h])
				break;
		lcp[_rank[i] - 1] = h;
	}
}

char c[2000001];

struct bit {
	vector<ll> v;
	bit(int n) : v(n + 1) {}
	ll sum(int i) {
		ll res = 0;
		for (; i > 0; i -= i & -i) res += v[i];
		return res;
	}
	void add(int i, ll x) {
		for (i++; i < v.size(); i += i & -i) v[i] += x;
	}
	ll sum(int i, int j) {
		return sum(j) - sum(i);
	}
};

int main() {
	string S; cin >> S;
	int N = S.length();
	make_sa(S);
	int Q; cin >> Q;
	vector<vector<pair<int, i_i> > > v(N + 1);
	for (int k = 0; k < Q; k++) {
		int l, r; scanf("%d%d%s", &l, &r, c);
		r++;
		string s = c;
		int n = s.length();
		int lb = -1, ub = N + 1;
		while (ub - lb > 1) {
			int mid = (lb + ub) / 2, i = sa[mid];
			if (S.substr(i, min(n, N - i)) >= s) ub = mid;
			else lb = mid;
		}
		int lb2 = -1, ub2 = N + 1;
		while (ub2 - lb2 > 1) {
			int mid2 = (lb2 + ub2) / 2, i = sa[mid2];
			if (S.substr(i, min(n, N - i)) > s) ub2 = mid2;
			else lb2 = mid2;
		}
		v[l].push_back(make_pair(k, i_i(ub, ub2)));
		v[max(l, r - n + 1)].push_back(make_pair(k, i_i(ub, ub2)));

	}
	bit bt(N + 1);
	vector<vector<int> > ans(Q);
	vector<int> sai(N + 1);
	for (int x = 0; x <= N; x++)
		sai[sa[x]] = x;
	for (int i = N; i >= 0; i--) {
		bt.add(sai[i], 1);
		for (int j = 0; j < v[i].size(); j++) {
			int k = v[i][j].first;
			int l = v[i][j].second.first, r = v[i][j].second.second;
			ans[k].push_back(bt.sum(l, r));
		}
	}
	for (int k = 0; k < Q; k++)
		printf("%d\n", abs(ans[k][0] - ans[k][1]));
}

Measured memory_bytes: 17288
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		int[] a = new int[n];
		
		for(int i=0; i<n; i++)
		{
			a[i] = scanner.nextInt();
		}
		
		for(int i=0; i<n/2; i++)
		{
			int buf = a[i];
			a[i] = a[n-i-1] ;
			a[n-i-1]  = buf;
		}
		
		for(int i=0; i<n; i++)
		{
			System.out.print(a[i]+(i==n-1?"\n":" "));
		}
		
	}
}

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

int main(){
    long long b,c,n,m,k1,l,o=0,max=0;
    cin>>n>>m>>k1;
    long long a[m+1];
    
    for (int i=0; i<k1; i++) {
        cin>>b;
        a[b]=1;
    }
    for (int i=1; i<n; i++) {
        cin>>k1;
        for (int j=0; j<k1; j++) {
            cin>>b;
            a[b]+=1;
        }
    }
    for (int i=1; i<=m; i++) {
        if (a[i]==n) {
            o+=1;
        }
    }
    cout<<o<<endl;
}




Measured memory_bytes: 888
//JAI SAI RAM.//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll P=1000000007;
bool definitelyGreaterThan(long double a,long double b,long double epsilon)
{
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,s,t,a,b,c;
   long double x,y,z,xx,yy,zz;
    cin>>a>>b>>c;
    x=a*b;
    xx=sqrt(x);
    z=c;
    y=a+b+2*xx;
    if(definitelyGreaterThan(z,y,(long double )LDBL_EPSILON))
    {
        cout<<"Yes\n";
    }
    else 
    {
        cout<<"No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
#define NIL -1

using namespace std;

struct Node{
    int parent,left,right;
};

Node T[25];

void preOrder(int u){
    if (u==NIL) return;
    cout<<" "<<u;
    preOrder(T[u].left);
    preOrder(T[u].right);
}

void inOrder(int u){
    if(u==NIL) return;
    inOrder(T[u].left);
    cout<<" "<<u;
    inOrder(T[u].right);
}

void postOrder(int u){
    if(u==NIL) return;
    postOrder(T[u].left);
    postOrder(T[u].right);
    cout<<" "<<u;
}

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

    rep(i,n) T[i].parent=NIL;
    
    rep(i,n){
        cin>>u;
        cin>>T[u].left>>T[u].right;
        if(T[u].left!=NIL) T[T[u].left].parent=u;
        if(T[u].right!=NIL) T[T[u].right].parent=u;
    }

    root=0;
    while(u!=NIL){
        root=u;
        u=T[u].parent;
    }
    
    cout<<"Preorder"<<endl;
    preOrder(root);
    cout<<endl;

    cout<<"Inorder"<<endl;
    inOrder(root);
    cout<<endl;

    cout<<"Postorder"<<endl;
    postOrder(root);
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3088
//14-4
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    set<pair<int,int> > all;
    int N,M;
    cin >> N;
    for(int i=0; i<N; i++){
        int h,m;
        cin >> h >> m;
        all.insert(make_pair(h,m));
    }
    cin >> M;
    for(int i=0; i<M; i++){
        int h,m;
        cin >> h >> m;
        all.insert(make_pair(h,m));
    }

    for(auto itr=all.begin(); itr!=all.end(); itr++){
        if(itr != all.begin()) cout << " ";
        cout << (*itr).first << ":";
        if((*itr).second < 10) cout << "0";
        cout << (*itr).second;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3096
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val a = input.split(" ").head.toDouble
    val b = input.split(" ").tail.head.toDouble
    val h = input.split(" ").tail.tail.head.toInt
    val m = input.split(" ").tail.tail.tail.head.toInt
    val theta = Pi / 6.0d * (h - 11.0d * m / 60.0d)
    sqrt(a * a + b * b - 2.0d * a * b * cos(theta)).toString
  }

  val tests=List(
    """3 4 9 0""".stripMargin -> """5.00000000000000000000
                                   |
                                                                      |""".stripMargin,
    """3 4 10 40""".stripMargin -> """4.56425719433005567605
                                     |
                                     |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55320
package main

import "fmt"

func main() {
	var (
		N        int
		sum      int
		prevCost int
	)

	fmt.Scanf("%d\n", &N)
	spots := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &spots[i])
		sum += abs(spots[i] - prevCost)
		prevCost = spots[i]
	}
	sum += abs(spots[len(spots)-1])

	for i := 0; i < N; i++ {
		var prevVal, nextVal int
		if i-1 >= 0 {
			prevVal = spots[i-1]
		}
		if i+1 < N {
			nextVal = spots[i+1]
		}
		curVal := spots[i]

		res := sum - abs(curVal-prevVal) - abs(nextVal-curVal) + abs(nextVal-prevVal)
		fmt.Println(res)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
int main() {
    string s; cin >> s;
    
    ll ans = INT_MAX;
    for (char c = 'a'; c <= 'z'; c++) {
        string w = s;
        ll cnt = 0;
        while (true) {
            
            if (w.empty()) {
                break;
            }
           
            if (w == string(w.length(), c)) {
                cerr << w << endl;
                ans = min(ans, cnt);
                break;
            }
            string a = "";
           
            rep (j, w.size()-1) {
                if (w[j] == c || w[j+1] == c) {
                    a += c;
                }
                else a += w[j];
            }
            w = a;
            cnt++;
        }
    }
    cout << ans << endl;
}

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

ll p[55600];
vector<ll>pri;
void era(){
    for(ll i = 2; i < 55600; i++){
        p[i] = 1;
    }
    for(ll i = 2; i * i < 55600; i++){
        for(ll j = i * 2; j < 55600; j += i){
            p[j] = 0;
        }
    }
    for(ll i = 1; i <= 55555; i++)if(p[i])pri.push_back(i);
}
int main(){
    era();
    vector<ll>v;
    for(ll i = 0; i < pri.size(); i++)if(pri[i] % 5 == 1)v.push_back(pri[i]);
    ll N;
    cin >> N;
    for(ll i = 1; i <= N; i++){
        cout << v[i];
        if(i < N)cout << " ";
        else cout << endl;
    }


    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ma = 0, mi = 10000000000;
  REP(i, n) {
    cin >> a[i];
    ma = max(ma, a[i]);
    mi = min(mi, a[i]);
  }
  dump(ma-mi);
  return 0;
}


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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}




ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/




int main()
{ fast


ll n,k;

cin>>n>>k;

ll ans = 0;

if ( (n-k)%(k-1)==0 ) ans = (n-1) / (k-1) ;


else ans = (n + k -2 )/(k - 1) ;

cout<<ans<<"\n";




 return 0;

}


Measured memory_bytes: 256
V, E = map(int, input().split())
INF = 10**12
dp = [[INF] * V for _ in range(V)]
for i in range(V):
  dp[i][i] = 0
for _ in range(E):
  s, t, d = map(int, input().split())
  dp[s][t] = d

for k in range(V):
  for i in range(V):
    for j in range(V):
      if dp[i][k] < INF and dp[k][j] < INF:
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

# 自分自身への距離が負の時、負閉路が存在する
for i in range(V):
  if dp[i][i] < 0:
    print('NEGATIVE CYCLE')
    exit()
        
for i in range(V):
  print(*['INF' if d == INF else d for d in dp[i]])


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

//INSERT ABOVE HERE
template<typename T,typename U>
void sort_pair(vector<T> &ts, vector<U> &us){
  assert(ts.size()==us.size());
  using P = pair<T, U>;
  vector<P> vp;
  for(size_t i=0;i<ts.size();i++)
    vp.emplace_back(ts[i],us[i]);
  sort(vp.begin(),vp.end());
  for(size_t i=0;i<ts.size();i++)
    tie(ts[i],us[i])=vp[i];
}

signed main(){
  Int n;
  while(cin>>n,n){
    vector<Int> ps,ds,qs;
    for(Int i=0;i<n;i++){
      Int p,d;
      cin>>p>>d;
      if(d==1){
        qs.emplace_back(p);
        continue;
      }
      ps.emplace_back(p);
      ds.emplace_back(d);
    }
    sort(qs.begin(),qs.end());
    sort_pair(ps,ds);
    
    if(ps.empty()&&n==2){        
      cout<<qs.back()-qs.front()<<endl;    
      continue;
    }
    
    Int ans=0;    
    for(Int i=0;i+1<(Int)ps.size();i++){
      ans+=ps[i+1]-ps[i];
      ds[i]--;
      ds[i+1]--;
    }
    
    vector<Int> as;
    for(Int i=0;i<(Int)ps.size();i++)
      for(Int j=0;j<ds[i];j++)     
        as.emplace_back(ps[i]);

    assert(is_sorted(as.begin(),as.end()));
    if(as.size()<qs.size()){
      cout<<-1<<endl;
      continue;
    }
    
    const Int INF = 1e16;
    vector<Int> dp(as.size(),INF);
    vector<Int> nx(as.size(),INF);
    for(Int i=0;i<(Int)qs.size();i++){      
      Int idx=lower_bound(as.begin(),as.end(),qs[i])-as.begin();
      Int res=INF*(i!=0);       

      if(i!=0){
        Int idy=lower_bound(as.begin(),as.end(),qs[i-1])-as.begin();
        for(Int j=idy-(n+10);j<=idy+(n+10);j++){
          if(j<0||j>=(Int)as.size()) continue;
          if(j<idx-(n+10)) chmin(res,dp[j]);  
        }
      }
      {
        for(Int j=idx-(n+10);j<=idx+(n+10);j++){
          if(j<0||j>=(Int)as.size()) continue;
          chmin(nx[j],res+abs(as[j]-qs[i]));
          chmin(res,dp[j]);
        }
      }
      if(i!=0){
        Int idy=lower_bound(as.begin(),as.end(),qs[i-1])-as.begin();
        for(Int j=idy-(n+10);j<=idy+(n+10);j++){
          if(j<0||j>=(Int)as.size()) continue;
          dp[j]=INF;
        }
      }
      { 
        for(Int j=idx-(n+10);j<=idx+(n+10);j++){
          if(j<0||j>=(Int)as.size()) continue;
          dp[j]=nx[j];
          nx[j]=INF;          
        }
      }
    }
    if(!qs.empty())
      ans+=*min_element(dp.begin(),dp.end());
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 410480
n,m,c=map(int, raw_input().split())
b=list(map(int,raw_input().split()))
a=[]
for i in range(n):
    a.append(list(map(int,raw_input().split())))
counter=0
for i in range(n):
    d=0
    for k in range(m):
        d+=a[i][k]*b[k]
    if d+c>0:
        counter+=1
print counter



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


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

    string ans = "Christmas";
    for (int i = 0; i < (25-D); i++) {
        ans += " Eve";
    }
    
    cout << ans << endl;
    return 0;
}

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

void func();
int sum_digits(int n);

void foo();
#define MAX_DIGIT 20

int main(){
    //func();
    foo();
}

void foo(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    int digits[MAX_DIGIT] = {};
    int sum_digits = 0;
    for(int i = 1; i <= n ; i++)
    {
        int move_up = 0;
        for(int it = 0; it <MAX_DIGIT;it++){
            if(digits[it]!=9){
                digits[it]++;break;}
            else{
                digits[it] =0;move_up++;
            }
        }
        sum_digits = sum_digits + 1 - (9*move_up);
        //cout << i << "," << sum_digits <<"\n";
        if(a<=sum_digits && sum_digits<=b) ans+=i;
    }
    cout << ans << "\n";
}


void func(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = n; i > 0; i--)
    {
        int tmp = sum_digits(i);
        if(a<=tmp && tmp<=b) {
            //cout << i << "\n"; 
            ans+=i;}
    }
    cout << ans << "\n";
}

int sum_digits(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}



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

int main() {
  int N;
  cin >> N;
  int m=10000000, p, ans=0;
  for (int i=0; i<N; i++) {
    cin >> p;
    if (m>=p) {
      ans++;
      m=p;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;




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

	int n, i, j, k, ans, x, r, ss, ww;
	string s;
	cin >> n >> s;
	vector<int> w(n + 1);
	w[n] = 0;
	for (i = n - 1; i >= 0; i--) {
		if (s[i] == 'W') w[i] = w[i + 1] + 1;
		else w[i] = w[i + 1];
	}

	ans = w[0];
	ans = min(ans, n - w[0]);
	r = 0;
	for (i = 0; i < n; i++) {
		if (s[i] == 'R') r++;
		x = min(i + 1 - r, (n - 1 - i - w[i + 1]));
		ss = x + (i + 1 - r - x) + (n - 1 - i - w[i + 1]) - x;
		ans = min(ans, ss);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4052
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<b+c-d<<" "<<c+d-a<<" "<<a+b-d<<" "<<b+c-a<<endl;
}	

Measured memory_bytes: 256
drops = {
    1: ((0,0,0,0,0), (0,0,1,0,0), (0,1,1,1,0), (0,0,1,0,0), (0,0,0,0,0)),
    2: ((0,0,0,0,0), (0,1,1,1,0), (0,1,1,1,0), (0,1,1,1,0), (0,0,0,0,0)),
    3: ((0,0,1,0,0), (0,1,1,1,0), (1,1,1,1,1), (0,1,1,1,0), (0,0,1,0,0))}

paper = [[0] * 14 for j in xrange(14)]

def solve(x, y, size):
    for i in xrange(5):
        for j in xrange(5):
            if drops[size][i][j] == 1:
                paper[y+i][x+j] += 1

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    solve(*map(int, line.split(',')))

result = [f for i in [l[2:12] for l in paper[2:12]] for f in i]

print result.count(0)
print max(result)

Measured memory_bytes: 5016
#include <stdio.h>
#define N 10000
typedef struct {
        char name;
        int value;

}Card;
void Bubble(Card c[],int n){
        Card swap;
        int i,j;
        for(i=0; i<=n-1; i++) {
                for(j=n-1; j>=i+1; j--) {
                        if(c[j].value<c[j-1].value) {
                                swap=c[j];
                                c[j]=c[j-1];
                                c[j-1] =swap;
                        }
                }
        }
        for(i=0; i<n-1; i++) {
                printf("%c%d ",c[i].name,c[i].value);
        }
        printf("%c%d",c[i].name,c[i].value);
        printf("\n");
}
void Selection(Card c[],int n){
        Card swap;
        int i,j;
        int minj;
        for(i=0; i<n; i++) {
                minj=i;
                for(j=i+1; j<n; j++) {
                        if(c[j].value<c[minj].value) {
                                minj=j;

                        }

                }
                swap=c[i];
                c[i]=c[minj];
                c[minj] =swap;
        }
        for(i=0; i<n-1; i++) {
                printf("%c%d ",c[i].name,c[i].value);
        }
          printf("%c%d",c[i].name,c[i].value);
        printf("\n");
}
int isStable(Card A[],Card B[],int n){
        int flug=0,i;
        for(i=0; i<n; i++) {
                if(A[i].name!=B[i].name) {
                        flug++;
                }

        }
        if(flug==0) return 1;
        else return 0;
}
int main(){
        int i,n;

        Card A[N],B[N];
        scanf("%d",&n);
        for(i=0; i<n; i++) {
                scanf("%c%c%d",&A[i].name,&A[i].name,&A[i].value);
                B[i]=A[i];
        }

        Bubble(A, n);
        printf("Stable\n");
        Selection(B, n);
        if(isStable(A,B,n)) {
                printf("Stable\n");
        }
        else  {

                printf("Not stable\n");
        }
        return 0;
}

Measured memory_bytes: 624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC124b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int count = 0;
            int maxh = -1;


            for(int i = 0; i < N; i++)
            {
                if(maxh <= int.Parse(s[i]))
                {
                    maxh = int.Parse(s[i]);
                    count++;
                }
            }

            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 13140
import sys
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, q = na()
a, b = [0]*n, [0]*n
G = [[] for i in range(n)]
for i in range(n-1):
        a, b = na()
        G[a-1].append(b-1)
        G[b-1].append(a-1)

counter = [0] * n
for i in range(q):
        p, x = na()
        counter[p-1] += x

visit = [False] * n
visit[0] = True
stack = [0]

while stack:
        parent = stack.pop()
        for child in G[parent]:
                if visit[child]:
                        None
                else:
                        visit[child] = True
                        counter[child] += counter[parent]
                        stack.append(child)

print(*counter)

Measured memory_bytes: 63980