akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAXH = 51;
const int MAXW = 51;
const int INF = 1<<28;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};

int H, W;
char C[MAXH][MAXW];
vector<pair<int, int> > to[MAXH][MAXW];
int mem[MAXH][MAXW][MAXH][MAXW];

bool ok(int i, int j) {
  if(i < 0 || i >= H) return false;
  if(j < 0 || j >= W) return false;
  if(C[i][j] == '#') return false;
  return true;
}

int dist(int a, int b, int c, int d) {
  return abs(c - a) + abs(d - b);
}

int rec(int a, int b, int c, int d) {
  int &res = mem[a][b][c][d];
  if(res != -1) return res;
  if(a == c && b == d) return res = 0;
  res = -INF;

  for(int i = 0; i < 2; ++i) {
    int na = a + di[i];
    int nb = b + dj[i];
    if(!ok(na, nb)) continue;
    if(na > c || nb > d) continue;
    res = max(res, rec(na, nb, c, d));
  }

  for(int k = 0; k < to[a][b].size(); ++k) {
    const int p = to[a][b][k].first;
    const int q = to[a][b][k].second;
    if(p > c || q > d) continue;
    for(int i = 0; i < 2; ++i) {
      for(int j = 2; j < 4; ++j) {
        int na = a + di[i];
        int nb = b + dj[i];
        int nc = p + di[j];
        int nd = q + dj[j];
        if(!ok(na, nb) || !ok(nc, nd)) continue;
        int A, B;
        if(dist(a, b, p, q) <= 2) A = 0;
        else A = rec(na, nb, nc, nd);
        B = rec(p, q, c, d);
        if(A == -INF || B == -INF) continue;
        res = max(res, 1 + A + B);
      }
    }
  }

  return res;
}

int main() {
  while(cin >> H >> W && (H|W)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> C[i][j];
      }
    }

    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        to[i][j].clear();
        if(islower(C[i][j])) {
          for(int ni = i; ni < H; ++ni) {
            for(int nj = j; nj < W; ++nj) {
              if(toupper(C[i][j]) == C[ni][nj]) {
                to[i][j].push_back(make_pair(ni, nj));
              }
            }
          }
        }
      }
    }

    memset(mem, -1, sizeof(mem));
    int res = rec(0, 0, H-1, W-1);
    if(res == -INF) res = -1;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 27724
fun main(args: Array<String>) {
    val H = readInputLine().toInt()
    val W = readInputLine().toInt()
    val N = readInputLine().toInt()

    if (H > W) {
        println(N / H + if (N % H == 0) 0 else 1)
    } else {
        println(N / W + if (N % W == 0) 0 else 1)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 29740
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

bool add_queue(const int s1, queue<P>& q, vector<int>& s) {
    auto it = lower_bound(s.begin(), s.end(), s1);
    if (it == s.begin()) return false;
    it--;
    // cout << s1 << " " << *it << endl;
    q.push(P(s1, *it));
    s.erase(it);
    return true;
}

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

    int ns = pow(2, n);
    vector<int> s(ns);
    for (int i=0; i<ns; i++) scanf("%d",&s[i]);
    sort(s.begin(), s.end());

    int s1, s2;
    s2 = s.back();
    s.pop_back();
    s1 = s.back();
    s.pop_back();
    
    bool ans = true;
    queue<P> q;
    if (s1 < s2) q.push(P(s1, s2));
    else ans = false;

    int day = 0;
    while (true) {
        if (q.empty()) break;
        queue<P> next_q;
        day++;
        while (!q.empty()) {
            P p = q.front();
            q.pop();
            s1 = p.first;
            s2 = p.second;

            // if (!add_queue(s1, q, s) && !add_queue(s2, q, s)) break;
            add_queue(s1, next_q, s);
            add_queue(s2, next_q, s);
        }
        q = next_q;
    }

    ans = ans && q.empty() && s.size()<=0 && day <= n;
    cout << (ans?"Yes":"No") << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <int> a(n);
    rep(i,n) cin>>a[i];
    vector <int> place(n+100, INF); 
    rep(i,n) place[a[i]] = i;
    int cnt = 1;
    int ma = -1;
    for(int i=0;i<n;i++){
        if(place[i]<place[i+1]) cnt++;
        else {ma = max(ma, cnt); cnt = 1;}
    }
    ma = max(cnt,ma);
    cout<<n-ma<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   long long int s;
  cin>>s;
    //cin>>n>>x;

    int mod = 1e9+7;
	ll n=s-3+1;
    vector<long long int> coins;

    for(int i=3;i<=s;i++)
    {
        //cin>>c;
        coins.push_back(i);
    }

    vector<long long int> dp(s+1,0);
    dp[0]=1;

    for(long long int i=1;i<=s;i++)
    {
        //dp[i]=INT_MAX;
        for(long long int j=0;j<n;j++)
        {
            if(i-coins[j] >= 0)
            dp[i] += dp[i-coins[j]];
            dp[i] %= mod;
        }
    }

    cout << dp[s] << endl;

    return 0;
} 

Measured memory_bytes: 3660
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

n=gets.to_i

if n.odd?
    puts 0
    exit
end
n/=10
ans=0
while n>0
    ans+=n
    n/=5
end
puts ans

Measured memory_bytes: 3836
#include<iostream>
using namespace std;
#include<vector>
#define int long long int
#define mod 1000000007
vector<int> vec;
bool prime[100001]={false};
void function()
{
	int j;
	for(j=2;j<=100000;j++)
	{
		prime[j]=true;
	}
	for(j=2;j<=1000;j++)
	{
		if(prime[j])
		{
			for(int k=2;j*k<=100000;k++)
			{
				prime[j*k]=false;
			}
		}
	}
	for(j=1;j<=100000;j++)
	{
		if(prime[j])
		{
			vec.push_back(j);
		}
	}
}
int power(int a,int b)
{
	if(b==0)
	  return 1;
	if(b==1)
	  return a%mod;
	else
	{
		int r=power(a,b/2);
		if(b%2==0)
		{
			return (r*r)%mod;
		}
		else
		{
			int x=(r*r)%mod;
			return (a*x)%mod;
		}
	}
}
int32_t main()
{
	function();
    int n,k;
    cin>>n>>k;
    int arr[k+2]={0};
    int j;
    for(j=k;j>=1;j--)
    {
		int div=k/j;
		int val=power(div,n);
		int i;
		for(i=2;i<=k;i++)
		{
			int p=j*i;
			if(p<=k)
			{
                val-=arr[p];
                val=val%mod;
			}
			else
			{
				break;
			}
		}
		arr[j]=val%mod;
	}
    int answer=0;
    for(j=1;j<=k;j++)
    {
		int val=(j*(arr[j]%mod))%mod;
		answer+=val;
		answer=answer%mod;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 4632
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;



int main(int argc, const char* argv[]){
    string s;

    cin >> s;
    if(s[s.size() - 1] == 's'){
        cout << s << "es" << endl;
    } else{
        cout << s << "s" << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
package main

import (
	"fmt"
	"strconv"
	"unicode/utf8"
)

func main() {
	var n, a, b, count int
	fmt.Scan(&n, &a, &b)

	for i := 1; i <= n; i++ {
		switch utf8.RuneCountInString(strconv.Itoa(i)) {
		case 1:
			if i >= a && i <= b {
				count += i
			}
		case 2:
			if num := i%10 + i/10; num >= a && num <= b {
				count += i
			}
		case 3:
			if num := i%10 + i/10%10 + i/100; num >= a && num <= b {
				count += i
			}
		case 4:
			if num := i%10 + i/10%10 + i/100%10 + i/1000; num >= a && num <= b {
				count += i
			}
		case 5:
			if num := i%10 + i/10%10 + i/100%10 + i/1000%10 + i/10000; num >= a && num <= b {
				count += i
			}
		}
	}
	fmt.Println(count)
}



Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>0){
        cout<<"Positive"<<endl;
    }else{
        if(b>=0){
            cout<<"Zero"<<endl;
        }else{
            if((b-a+1)%2==0){
                cout<<"Positive"<<endl;
            }else{
                cout<<"Negative"<<endl;
            }
        }
    }
}



Measured memory_bytes: 256
import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
F = [1 for i in range(H + W + 1)]
for i in range(1, H + W + 1):
  F[i] = F[i - 1] * i % p
def fac(a, b):
  a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p)
  return a % p
ans = 0
for h in range(H - A):
  ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
print(ans % p)

Measured memory_bytes: 12952
#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e6 + 1;

void solve(){
    char a;
    cin >> a;
    if(a >= 'a' && a <= 'z' ) cout <<"a\n";
    else cout<<"A\n";
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC=1;
    // cin>>NTC;
    ll PTC=0;
    while(PTC++<NTC){
        // cout<<"Case #"<<PTC<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3788
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int x, y, s;
	while (cin >> x >> y >> s, x, y, s) {
		int ans = -1;
		for (double i = 1; i < s; i++) 
			for (double j = 1; j < s; j++) 
				if ((int)(i*(100 + x) / 100) + (int)(j*(100 + x) / 100) == s)ans = max(ans, (int)(i*(100 + y) / 100) + (int)(j*(100 + y) / 100));
		cout << ans << endl;
	}
}

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

const long NMOD= (long) 1e9+7;

int main(){
    int N,M;
    cin >> N >> M;
    bool a[N+1];
    long dp[N+1];
    for(int i=0; i<N+1; i++){
        a[i]=0;
        dp[i]=0;
    }
    for(int i=0; i<M; i++){
        int atmp;
        cin >> atmp;
        a[atmp]=true;
    }
    dp[0]=1;
    for(int i=1; i<=N; i++){
        if(a[i]){
            dp[i]=0;
            continue;
        }else{
            if(i>1){
                dp[i]+=dp[i-2];
                dp[i] %= NMOD;
            }
            dp[i]+=dp[i-1];
            dp[i] %= NMOD;
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1152
import java.util.Arrays;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] dat = scan.nextLine().split(" ");
        scan.close();
        int[] intdat = new int[3];
        for (int i = 0; i < 3; i++)
            intdat[i] = Integer.parseInt(dat[i]);
        Arrays.sort(intdat);
        System.out.println(intdat[0] + intdat[1]);
    }
}


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

int main() {
	int a,b,k;
	cin >> a >> b >> k;
	k -= 1;
	for (int i=a;i<=b;i++){
	    if (i<=a+k || i>=b-k)
	        cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
f = list(map(int, input().split()))
m = input()
p = [0, 1, 2]
for i in range(len(m)):
	t = p[0]
	if m[i] == "N":
		p[0] = p[1]
		p[1] = 5 - t
	elif m[i] == "W":
		p[0] = p[2]
		p[2] = 5 - t
	elif m[i] == "S":
		p[0] = 5 - p[1]
		p[1] = t
	elif m[i] == "E":
		p[0] = 5 - p[2]
		p[2] = t
print(f[p[0]])


Measured memory_bytes: 5600
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int x,y,z;
    x=y=z=0;
    while(1){
        int v[3];
        rep(i,0,3)cin>>v[i];
        sort(v,v+3);
        if(v[0]+v[1]<=v[2])break;
        if(v[0]*v[0]+v[1]*v[1]==v[2]*v[2])x++;
        else if(v[0]*v[0]+v[1]*v[1]<v[2]*v[2])y++;
        else z++;
    }
    cout<<x+y+z<<" "<<x<<" "<<z<<" "<<y<<endl;
}


/*
14
1 0
1 1
1 2
2 1
0 0
0 1
0 2
0 3
3 3
4
5
6
7
8
*/



Measured memory_bytes: 3116
#include<cstdio>
#include<cstdlib>
#include<algorithm>

using namespace std;

char date[1000005];
int N;

int main()
{
	fill(date,date+1000005,0);
	scanf("%s",date);
	for(int i=0;i<1000005;i++)
	{
		if(date[i]==0)
		{
			N=i;
			break;
		}																																																																					
	}
	int J=0,O=0,I=0;
	int ans=0;
	for(int j=0;j<N;j++)
	{
		if(date[j]=='J')
		{
			if(O==0&&I==0)
			{
				J++;
			}
			else
			{
				O=0;I=0;J=1;
			}
		}
		if(date[j]=='O')
		{
			if(J>=O&&I==0)O++;
			else J=O=I=0;
		}
		if(date[j]=='I')
		{
			if(J>=O&&O>I)I++;
			else J=O=I=0;
			if(J>=O&&O==I){if(ans<I)ans=I;J=O=I=0;}
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 1944
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,n,m,i,j;
	scanf("%d %d",&a,&b);
	if(b==100)
	{
		b++;
	}
	if(a==0)
	{
		printf("%d",b);
	}
	else if(a==1)
	{
		printf("%d",b*100);
	}
	else if(a==2)
	{
		printf("%d",b*10000);
	}
	return 0;
}

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

int main(void){
    int n;
    while(cin >> n, n){
        int cnt = 0;
        while(n != 1){
            if(n % 2 == 0){
                n /= 2;
            }else{
                n = n*3 +1;
            }
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
#define mxsize (int)1e6
ll fastexp(ll a,ll n){
    ll nod=(ll)1e18;
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%nod;
        a=(a*a)%nod;
        n>>=1;
    }
    return ans;
}
void fun(){
    ll a[4];
    fi(0,4) cin>>a[i];
    ll ans=-1e18;
    for(int i=0;i<2;i++){
        for(int j=2;j<4;j++){
            ans=max(ans,a[i]*a[j]);
        }
    }
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/ATOM/input.txt", "r", stdin);
        freopen("/ATOM/output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        fun();
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,ans=0,x;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x<=k/2)
            ans+=x*2;
        else
            ans+=(k-x)*2;
    }
    cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    srand((unsigned int)time(NULL));
    
    ll a=rand(),c=rand();
    
    int N;cin>>N;
    string S;cin>>S;
    vector<vector<ll>> A(N,vector<ll>(N,-1));
    
    for(int i=0;i<N;i++){
        ll nowa=0;
        for(int j=i;j<min(N,i+N/2);j++){
            nowa*=a;
            nowa+=S[j]-'a';
            nowa%=c;
            
            A[i][j]=nowa;
        }
    }
    
    int ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(S[i]!=S[j]) continue;
            int a=j-i,b=N-j;
            a=min(a,b);
            if(A[i][i+a-1]==A[j][j+a-1]&&A[i][i+a-1]>=0&&A[j][j+a-1]>=0){
                ans=max(ans,a);
                continue;
            }
            int left=1,right=min(a,N/2+1);
            while(right-left>1){
                int mid=(left+right)/2;
                if(A[i][i+mid-1]==A[j][j+mid-1]&&A[i][i+mid-1]>=0&&A[j][j+mid-1]>=0) left=mid;
                else right=mid;
            }
            ans=max(ans,left);
        }
    }
    
    cout<<ans<<endl;
    
    //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}



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

int main() {
    int N, M, now = 0;
    cin >> N >> M;
    int64_t ans = 1;
    vector<int64_t> S(N + 1);

    for (int i = 0; i < N + 1; i++) {    
        if (i == 0) {
            S.at(0) = 1;
        }
        else if (i == 1){
            S.at(1) = 1;
        }
        else {
            S.at(i) = (S.at(i - 1) + S.at(i - 2)) % 1000000007;
        }
    }
    for (int i = 0; i < M; i++){
        int a;
        cin >> a;
        int b = a - now;
        if (b == 0) {
            cout << 0 << endl;
            return 0;
        }
        now = a + 1;
        ans = ans * S.at(b - 1) % 1000000007;
    }
    ans = ans * S.at(N - now) % 1000000007;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int a, b, c;
  int counter = 0;

  scanf("%d %d %d", &a, &b, &c);

  for(int i = a; i <= b; i++){
        if(c % i == 0){counter++;}
  }

  printf("%d\n", counter);

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const vector<string> tile3 = {
  "aa.",
  "..a",
  "..a"
};

const vector<string> tile4 = {
  "aabc",
  "ddbc",
  "efgg",
  "efhh"
};

const vector<string> tile5 = {
  "aabba",
  "bcc.a",
  "b..cb",
  "a..cb",
  "abbaa"
};

const vector<string> tile6 = {
  "aabc..",
  "ddbc..",
  "..aabc",
  "..ddbc",
  "bc..aa",
  "bc..dd"
};

const vector<string> tile7 = {
  "aabbcc.",
  "dd.dd.a",
  "..d..da",
  "..d..db",
  "dd.dd.b",
  "..d..dc",
  "..d..dc"
};

vector<string> tile[8];

const int N = 1005;
char ans[N][N];

void apply(const vector<string>& tiling, int i, int j) {
  const int n = tiling.size();
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < n; ++y) {
      ans[i+x][j+y] = tiling[x][y];
    }
  }
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  tile[3] = tile3;
  tile[4] = tile4;
  tile[5] = tile5;
  tile[6] = tile6;
  tile[7] = tile7;
  int n; cin >> n;
  if (n < 3) {
    cout << -1 << nl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ans[i][j] = '.';
    }
  }
  {
    int left = n;
    int i = 0;
    while (left >= 8) {
      apply(tile[4], i, i);
      i += 4;
      left -= 4;
    }
    apply(tile[left], i, i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << ans[i][j];
    }
    cout << nl;
  }
  return 0;
}



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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int n, k, d;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, k) {
        int tmp, tmp2;
        cin >> tmp;
        rep(j, tmp) {
            cin >> tmp2;
            a[tmp2-1]++;
        }
    }
    
    int cnt = 0;
    rep(i, n) {
        if(a[i] == 0) cnt++;
    }
    
    cout << cnt;
    
    return 0;
}


Measured memory_bytes: 3656
nd = list(map(int,input().split()))
n = nd[0]
d = nd[1]
point = []
for i in range(n):
  point.append(list(map(int, input().split())))

def dis(y,z,dim):
  sum = 0
  for i in range(dim):
    sum += (y[i] - z[i])**2

  return sum**(1/2)

count = 0

for i in range(n-1):
  for j in range(i+1, n):
      distance = dis(point[i], point[j], d)
      if distance == int(distance):
          count += 1

print(count)


Measured memory_bytes: 3064
#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);
  }
  int ans=0;
  int MIN=1000000;
  for(int i=0; i<n; i++){
    if(MIN>vec.at(i)){
      ans++;
      MIN = vec.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    r = 0
    x = 1
    while x != 2:
        r += 1
        x = a[x - 1]
        if x == 1 or r >= n:
            r = -1
            break
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20452
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//以下、素集合と木は同じものを表す
class UnionFind {
public:
    vector<ll> parent; //parent[i]はiの親
    vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
    map<ll,vector<ll>> group;//素集合ごとに管理する連想配列(keyはそれぞれの素集合の親、valueはその素集合の要素の配列)

    //コンストラクタ
    UnionFind(ll n):parent(n),siz(n,1){ 
        //全ての要素の根が自身であるとして初期化
        for(ll i=0;i<n;i++){parent[i]=i;}
    }

    //データxの属する木の根を取得(経路圧縮も行う)
    ll root(ll x){
        if(parent[x]==x) return x;
        return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
    }

    //xとyの木を併合
    void unite(ll x,ll y){
        ll rx=root(x);//xの根
        ll ry=root(y);//yの根
        if(rx==ry) return;//同じ木にある時
        //小さい集合を大きい集合へと併合(ry→rxへ併合)
        if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
    }

    //xとyが属する木が同じかを判定
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }

    //xの素集合のサイズを取得
    ll size(ll x){
        return siz[root(x)];
    }

    //素集合をそれぞれグループ化
    void grouping(ll n){
        //経路圧縮を先に行う
        REP(i,n)root(i);
        //mapで管理する(デフォルト構築を利用)
        REP(i,n)group[parent[i]].PB(i);
    }
};

signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,m;cin>>n>>m;
    UnionFind uf(n);
    REP(i,m){
        ll a,b;cin>>a>>b;
        uf.unite(a-1,b-1);
    }
    uf.grouping(n);
    ll ans=0;
    FORA(i,uf.group){
        ans=max(ans,SIZE(i.S));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 28208
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using ll = long long;
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto& e : A) cin >> e, --e;
  vector<bool> visited(N, false);
  vector<int> path = {0};
  while (!visited[A[path.back()]]) {
    visited[path.back()] = true;
    path.push_back(A[path.back()]);
  }
  int rem = 0;
  while (path[rem] != A[path.back()]) ++rem;
  cout << ((K <= rem ? path[K] : path[(K - rem) % (path.size() - rem) + rem]) +
           1)
       << endl;
}


Measured memory_bytes: 5056
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int N;

void func(string S0) {
	char Smax = '!';
	int n = S0.size();
	if (n == N) {
		cout << S0 << endl;
		return;
	}
	rep(i, n)
		Smax = (char)max((int)Smax, (int)S0[i]);
	rep(i, Smax - 'a' + 2) {
		char c = 'a' + i;
		string S1 = S0 + c;
		func(S1);
	}
	return;
}

int main() {
	cin >> N;
	string Sini = "a";
	func(Sini);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int parent[100001];
int p[100001];
int findparent(int x)
{
	if(parent[x]!=x)
		parent[x]=findparent(parent[x]);
	return parent[x];
}
void unionset(int a,int b)
{
	if((a=findparent(a))==(b=findparent(b)))
		return;
	parent[a]=b;
}
int main()
{
	int n,m,i,x,y,count=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		parent[i]=i;	
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		unionset(x,y);
	}
	for(i=1;i<=n;i++)
	{
		if(findparent(p[i])==findparent(i))
			count++;
	}
	printf("%d",count);
	return 0;
}

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

# N個の区間のうち通らないものは高々1つ
# N個の区間のうち最も長い区間を通らず、それ以外の区間を1度だけ通る経路が最短距離を与える
# よって、Kから最も長い区間を引いた長さが最短距離

# 実装では、北端をまたいだ区間の扱いに気を付ける
A.append(A[0]+K)
l = 0
for i in range(N):
  l = max(l, A[i+1]-A[i])

ans = K -l
print(ans)

Measured memory_bytes: 32228
#include <stdio.h>

int main(void){
	int kosu = 0;
	int a = 0 ,b = 0 ,c = 0;
	
	scanf("%d" ,&kosu);
	
	for( ;kosu > 0 ;--kosu){
		scanf("%d%d%d" ,&a ,&b ,&c);
		if(a*a==b*b+c*c || b*b==a*a+c*c ||c*c==a*a+b*b)
			puts("YES");
		else
			puts("NO");
		a = 0; b = 0; c = 0;
	}
	
	return (0);
}

Measured memory_bytes: 576
var
  h,w,i,j,t,q:longint;
  ch:char;
  a:array['a'..'z']of longint;
begin
  readln(h,w);
  for i:=1 to h do
    begin
      for j:=1 to w do begin read(ch); inc(a[ch]); end;
      readln;
    end;
  if (h mod 2=0)and(w mod 2=0) then
    begin
      for ch:='a' to 'z' do
        if a[ch] mod 4<>0 then begin writeln('No'); halt; end;
      writeln('Yes'); halt;
    end;
  if ((h mod 2=1)and(w mod 2=0))or((h mod 2=0)and(w mod 2=1)) then
    begin
      if w mod 2=0 then begin h:=h xor w; w:=h xor w; h:=h xor w; end;
      for ch:='a' to 'z' do
        begin
          if a[ch] mod 2<>0 then begin writeln('No'); halt; end;
          if a[ch] mod 4=2 then
            begin
              inc(t); if t>h div 2 then begin writeln('No'); halt; end;
            end;
        end;
      writeln('Yes'); halt;
    end;
  for ch:='a' to 'z' do
    begin
      if a[ch]mod 4=1 then
        begin
          inc(t); if t>1 then begin writeln('No'); halt; end;
        end;
      if a[ch] mod 4=2 then
        begin
          inc(q); if q>h div 2+w div 2 then begin writeln('No'); halt; end;
        end;
      if a[ch] mod 4=3 then
        begin
          inc(t); inc(q);
          if t>1 then begin writeln('No'); halt; end;
          if q>h div 2+w div 2 then begin writeln('No'); halt; end;
        end;
    end;
  writeln('Yes');
end.

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

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

    for (int i = 0; i <= n.length(); i++) {
        if (n.substr(i,1) == "1") {
            cout << "9" ;
        } else if (n.substr(i,1) == "9") {
            cout << "1" ;
        }
    }
    cout <<  endl;
    
}


Measured memory_bytes: 256
from itertools import chain

N, M = map(int, input().split())
l = [list(map(int, input().split()))[1:] for i in range(N)]
l = list(chain.from_iterable(l))

food_counts = 0
for i in range(1, M+1):
    if l.count(i) == N:
        food_counts += 1
print(food_counts)


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

int main(){
    int n;
    cin >> n;
    vector<pii> s(n),l(n);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        s[i] = make_pair(b,a);
    }
    rep(i,n){
        int c,d;
        cin >> c >> d;
        l[i] = make_pair(c,d);
    }
    sort(l.begin(),l.end());
    int ans = 0;
    rep(i,n){
        sort(s.begin(),s.end(),greater<pii>());
        rep(j,s.size()){
            if(s[j].second < l[i].first && s[j].first < l[i].second){
                ans++;
                s.erase(s.begin() + j);
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
A, B, C =[input() for _ in range(3)]
T = {"a":A, "b":B, "c":C}
player = "a"
card = "a"
while len(T[player])>0:
  card = T[player][0]
  T[player] = T[player][1:]
  player = card
else:
  print(player.upper())

Measured memory_bytes: 8864
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
ll i,j;

ll r,c,k,n;
ll a,b,ans=0;
P aka[105],ao[105];
bool used[105];
ll num=-1;

int main(){
	cin>>n;
	fill(used,used+n,false);
	for(i=1;i<=n;i++){
		cin>>aka[i].first>>aka[i].second;
	}
	for(i=1;i<=n;i++){
		cin>>ao[i].first>>ao[i].second;
	}
	sort(aka,aka+n+1);
	sort(ao,ao+n+1);

	for(i=n;i>=1;i--){
		//iは赤
		num = -1;
		for(j=1;j<=n;j++){
			if(aka[i].first<ao[j].first && aka[i].second<ao[j].second && !used[j]){
				if(num==-1)num=j;
				if(ao[num].second>ao[j].second){
					num=j;
				}
			}
		}
		if(num!=-1){
			used[num]=true;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    b=Vector{Int}()
    for i in 1:n
        if i%2==n%2
            unshift!(b,a[i])
        else
            push!(b,a[i])
        end
    end
    println(join(b," "))
end
main()

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

const ll INF = ll(1e18)+1;

int main(void){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll l = -INF,r = INF;
    //二分探索
    while(l+1<r){
        ll x = (l+r)/2;
        bool ok = [&]{
            ll tot = 0;
            rep(i,n){
                if (a[i]<0){
                    int l = -1,r = n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i] < x) r=c; else l=c;
                    }
                    tot += n-r;
                }else{
                    int l = -1,r = n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i] < x) l=c; else r=c;
                    }
                    tot += r;
                }
                if (a[i]*a[i] < x) tot --;
            }
            tot /= 2;
            return tot < k;
        }();
        if(ok) l=x;else r=x;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    cin >>n;
    vector<vector<int>> h(n, vector<int>(3));
    rep(i,n)rep(j,3) cin >>h[i][j];

    vector<vector<int>> dp(n,vector<int>(3));
    rep(i,3) dp[0][i] = h[0][i];

    for(int i=1; i<n; ++i){
        rep(j,3){
            rep(pre,3)if(j != pre){
                dp[i][j] = max(dp[i][j], dp[i-1][pre]+h[i][j]);
            }
        }
    }

    int ans = 0;
    rep(i,3) ans = max(ans, dp[n-1][i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010, INF = 0x3f3f3f3f;
int n,a[N],cur,ans[N],rec[N],cnt;
struct node {
  int mx,semx,num,sum,tag;
} t[N << 2];
void puttag(int x,int v) {
  if (v >= t[x].mx) return;
  if (v <= t[x].semx) assert(0);
  t[x].sum -= t[x].num * (t[x].mx - v);
  t[x].mx = v;
  t[x].tag = min(t[x].tag,v);
}
void push_down(int x) {
  puttag(x<<1,t[x].tag);
  puttag(x<<1|1,t[x].tag);
  t[x].tag = INF;
}
void push_up(int x) {
  if (t[x].tag != INF) push_down(x);
  if (t[x<<1].mx > t[x<<1|1].mx) {
    t[x].mx = t[x<<1].mx;
    t[x].num = t[x<<1].num;
    t[x].semx = max(t[x<<1].semx,t[x<<1|1].mx);
  } else if (t[x<<1].mx < t[x<<1|1].mx) {
    t[x].mx = t[x<<1|1].mx;
    t[x].num = t[x<<1|1].num;
    t[x].semx = max(t[x<<1|1].semx,t[x<<1].mx);
  } else {
    t[x].mx = t[x<<1].mx;
    t[x].num = t[x<<1].num + t[x<<1|1].num;
    t[x].semx = max(t[x<<1].semx,t[x<<1|1].semx);
  }
  t[x].sum = t[x<<1].sum + t[x<<1|1].sum;
}
void modify(int l,int r,int v,int x=1,int lp=1,int rp=n) {
  if (l > rp || r < lp) return;
  if (lp >= l && rp <= r && v > t[x].semx)
      return (void)(puttag(x,v));
  push_down(x);
  int mid = (lp + rp) >> 1;
  modify(l,r,v,x<<1,lp,mid);
  modify(l,r,v,x<<1|1,mid+1,rp);
  push_up(x);
}
int query(int l,int r,int x=1,int lp=1,int rp=n) {
  if (l > rp || r < lp) return 0;
  if (lp >= l && rp <= r)
    return t[x].sum;
  push_down(x);
  int mid = (lp + rp) >> 1;
  return query(l,r,x<<1,lp,mid) + query(l,r,x<<1|1,mid+1,rp);
}
void build(int x=1,int lp=1,int rp=n) {
  t[x].tag = INF;
  if (lp == rp) {
    t[x].mx = t[x].sum = a[lp];
    t[x].num = 1;
    t[x].semx = -INF;
    return;
  }
  int mid = (lp + rp) >> 1;
  build(x<<1,lp,mid);
  build(x<<1|1,mid+1,rp);
  push_up(x);
}
signed main() {
  scanf("%lld",&n);
  for (int i = 1 ; i <= n ; ++ i) {
    scanf("%lld",&a[i]);
    if (a[i] > cur) {
      cur = a[i];
      rec[++cnt] = i;
    }
  }
  build();
  for (int i = cnt ; i >= 1 ; -- i) {
    ans[rec[i]] = query(rec[i],n);
    modify(rec[i],n,a[rec[i-1]]);
    ans[rec[i]] -= query(rec[i],n);
  }
  for (int i = 1 ; i <= n ; ++ i)
    printf("%lld\n",ans[i]);
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && a[i] == c[i] && b[i] == c[i]) {
			continue;
		} else if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) {
			ans += 2;
			continue;
		}

		map<char, int> mp;
		mp[a[i]]++;
		mp[b[i]]++;
		mp[c[i]]++;

		int score = INT_MAX;
		for (auto v : mp) {
			score = min(score, v.second);
		}

		ans += score;
	}

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


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

char s[303];
int dp[2][303][303],now;
int main(){
    //freopen("atlarge.in","r",stdin);
    //freopen("atlarge.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    int T,j,i,k,ca=0,K,m=0,n;
    scanf("%s%d",s,&K);n=strlen(s);
    int ans=0;
    rep(i,0,n){
        per(j,i,n){
            rep(k,0,K+1){
                int &w=dp[now][j][k];
                if(i==j){
                    Max(ans,w+1);
                }
                else if(s[i]==s[j]){
                    if(i+1==j)Max(ans,w+2);
                    else Max(dp[1-now][j-1][k],w+2);
                }
                else{
                    if(k+1<=K){
                        if(i+1==j)Max(ans,w+2);
                        else Max(dp[1-now][j-1][k+1],w+2);
                    }
                    Max(dp[now][j-1][k],w);
                    Max(dp[1-now][j][k],w);
                }
            }
        }
        now=1-now;
    }
    printf("%d\n",ans);
    //cerr<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
    return 0;
}   

Measured memory_bytes: 1024
import java.util.Scanner;
import java.lang.Integer;
import java.lang.Math;

class Main {
  private static int[][] dp;

  private static int calc(int N, int M, int[] c) {
    if (N <= 0) {
      return 1;
    }

    for (int i = 1; i < M + 1; i++) {
      for (int j = 0; j < N + 1; j++)  {
        int candidate1 = dp[i - 1][j];
        int candidate2 = ((j - c[i] >= 0) && (c[i] <= N)) ? dp[i][j - c[i]] + 1 : Integer.MAX_VALUE;

        dp[i][j] = Math.min(candidate1, candidate2);
        //System.out.println(((j - c[i] >= 0) && (c[i] <= N)) + " candidate2 " + candidate2);
        //System.out.println("dp[" + i + "]" + "[" + j + "], " + dp[i][j]);
      }
    }

    return dp[M][N];
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] c = new int[M+1];
    c[0] = 0;
    for (int i = 1; i < M + 1; i++) {
      c[i] = sc.nextInt();
    }
    dp = new int[M + 1][N + 1];

    // init kind of coin(i) == 0;
    int i = 0;
    for (int j = 0; j < N + 1; j++) {
      if (j == 0) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = Integer.MAX_VALUE;
      }
    }

    int result = calc(N, M, c);

    System.out.println(result);
  }
}

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

int main(){
  int M,D;
  cin >> M >> D;
  int count = 0;
  for(int m=1;m<=M;m++){
    for(int d=1;d<=D;d++){
      if((d/10)>=2&&(d%10)>=2&&(d/10)*(d%10)==m){
        count ++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
else:
    evenW = W//2 + W % 2
    oddW = W//2
    evenH = H//2 + H % 2
    oddH = H//2
    print(evenW*evenH+oddW*oddH)

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

int main() {
    Int A;
    double B;
    cin >> A >> B;
    Int C = B*100 + 0.5;
    cout << (A *C)/100 << endl;
}


Measured memory_bytes: 3680
import sys
import numpy as np


readline = sys.stdin.readline
read = sys.stdin.read

h, w, k = map(int, input().split())
a = np.array(list(read())).reshape([h,-1])[:,:-1]
b = np.where(a=='.', 0, 1)

ans = 0
for i in range(2**h):
    for j in range(2**w):
        I = np.array(list(format(i, '0'+str(h)+'b')), dtype=np.int64)
        J = np.array(list(format(j, '0'+str(w)+'b')), dtype=np.int64)
        if np.sum((b[I==1])[:,J==1]) == k:
            ans += 1
print(ans)

Measured memory_bytes: 27100
import random
import time
import numpy as np

def decrease(day, schedule, c, s, satisfy):
    ret = 0
    date = [0] * 26

    for d in range(day):
        now = schedule[d] + 1
        date[now - 1] = d + 1
        tmp = 0
        for i in range(26):
            tmp += c[i] * (now - date[i])
        ret += tmp
        satisfy.append(tmp)

    return ret

def change(_from, _to, schedule, c, s, satisfy):
    ret = 0
    date = [0] * 26

    for d in range(_to):
        if d < _from:
            ret += satisfy[d]
            continue

        now = schedule[d] + 1
        date[now - 1] = d + 1
        tmp = 0
        for i in range(26):
            tmp += c[i] * (now - date[i])
        ret += tmp
        satisfy[d] = tmp

    return ret

def Main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]
    
    dissatisfy=[]
    schedule = []
    score = 0
    start = time.time()

    #最大値を足すだけ
    for i in range(D):
        schedule.append(np.argmax(s[i]))
        score += np.max(s[i])
    
    ans = score - decrease(D, schedule, c, s, dissatisfy)
    
    while time.time() - start < 1.8:
        contest = random.randint(0, 25)
        day = random.randint(0, D - 1)
        save = dissatisfy.copy()
        dec = change(day + 1, D, schedule, c, s, dissatisfy)
        score2 = score - s[day][schedule[day]] + s[day][contest]

        if ans < score2 - dec:
            ans = score2 - dec
            score = score2
            schedule[day] = contest
        else:
            dissatisfy = save
        
    for i in range(D):
        print(schedule[i] + 1)

if __name__ == "__main__":
    Main()


Measured memory_bytes: 27412
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ");
var K = input[0]-0;
var center = input[1]-0;
var out = [];
for(var i = 0; i < K * 2 - 1; i++) {
  out.push(center - (K - 1) + i);
}
console.log(out.join(" "));


Measured memory_bytes: 7372
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int l = 0;
		int tempx = 0;
		int count = 1;
		for (int i = 0; i < n; i++) {
			l = sc.nextInt();
			tempx += l;
			if (x < tempx) {
				break;
			} else {
				count++;
			}
		}
		System.out.println(count);
		return;
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define SIZE 10
int h,w;
vector < vector < int > > inp;
void init()
{
    int i,j;
    for (i=0;i<SIZE;i++)
    {
        vector < int > tmp;
        for (j=0;j<SIZE;j++)
            if (i!=j) tmp.push_back(INF);
            else tmp.push_back(0);
        inp.push_back(tmp);
    }
}
void solve()
{
    int i,j,k,ans=0;
    for (i=0;i<SIZE;i++)
        for (j=0;j<SIZE;j++)
            cin>>inp[i][j];
    for (k=0;k<SIZE;k++)
        for (i=0;i<SIZE;i++)
            for (j=0;j<SIZE;j++)
                inp[i][j]=min(inp[i][j],inp[i][k]+inp[k][j]);
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
        {
            int x;
            cin>>x;
            if (x==1||x==-1) ;
            else ans+=inp[x][1];
        }
    }
    cout<<ans<<endl;
}
int main()
{
    init();
    while(cin>>h>>w)
        solve();
}

Measured memory_bytes: 256
import java.util.*


fun main(args : Array<String>) {

  val scanner = Scanner(System.`in`)

  val len = scanner.nextInt()

  scanner.nextLine()

  val xList = scanner.nextLine().split(" ")
  val yList = scanner.nextLine().split(" ")


  for ( p in listOf(1.0, 2.0, 3.0, -1.0) ) {

    var D = 0.0
    var sigma = 0.0

    if (p != -1.0) {

      for ( i in 0 until len) {
        sigma += Math.pow( Math.abs( xList[i].toDouble() - yList[i].toDouble() ), p )
      }

      D = Math.pow( sigma, 1.0/p )

    } else {

      for ( i in 0 until len) {
        D = Math.max(D, Math.abs( xList[i].toDouble() - yList[i].toDouble() ) )
      }

    }

    println("%.8f".format(D))

  }

}



Measured memory_bytes: 33508