akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
while(true){
   var n=arr.shift();
   if(n==0)break;
   var k=arr.shift();
   var card=[];
   for(var i=0;i<n;i++)card.push(arr.shift());
   var all=[];
   var loop=function(ary){
      if(ary.length==k)all.push(ary);
      else{
         for(var i=0;i<n;i++){
            if(ary.indexOf(i)==-1)loop(ary.concat(i));
         }
      }
   };
   loop([]);
   var obj={};
   all.forEach(function(v){
      var str="";
      v.forEach(function(value){
         str+=card[value];
      });
      obj[str]=true;
   });
   console.log(Object.keys(obj).length);
}

Measured memory_bytes: 21340
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n - 2):
  if p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
    ans += 1
  elif p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3060
N,W = map(int, input().split())

import numpy as np
dp = np.full(1000*N+1, W+1, dtype=int)
dp[0]=0

for n in range(N):
  w,v = map(int, input().split())
  dp[v:] = np.minimum(dp[:-v]+w, dp[v:])

print(np.max(np.where(dp <= W)))

Measured memory_bytes: 21252
import java.util.*;
public class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		int k=s.nextInt(),SUM=s.nextInt(),sum=0;
		for(int a=0;a<=k;a++)if(a<=SUM)
				for(int b=0;b<=k;b++)
					if(SUM-a-b>=0 && SUM-a-b<=k)
						sum++;
		System.out.println(sum);
	}
}

Measured memory_bytes: 9684
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    double ans=0;
    for(int i=0;i<n;i++)
        ans+=(1.0/a[i]);
    ans=1.0/ans;
    cout<<setprecision(6)<<fixed<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int h,r;
	scanf("%d%d",&h,&r);
	if(h>-r){
		printf("1\n");
	}else if(h==-r){
		printf("0\n");
	}else{
		printf("-1\n");
	}
	return 0;
}

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


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

    int N,L;
    cin >> N >> L;
    string S[N];
    rep(i,N) cin >> S[i];

    sort(S,S+N);
    rep(i,N) cout << S[i];
    cout<< endl;


}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES    
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define quickIO()   {cin.tie(0);    cout.sync_with_stdio(false);}
#define rep(i,n)    for(ll i=0; i<(ll)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define fcout cout << fixed << setprecision(10) 
const ll inf = 1e18;
const ll mod = 1e9 +7;
     
ld sqrtld(ld x){
    ld left = 0, right = x;
    rep(i, 100){
        ld mid = (left + right)/2;
        if (mid*mid <= x)   left =mid;
        else    right = mid;
    }
    return left;
}

ll gcd(ll a, ll b){
    if(b>a){
        ll c =b; b=a;   a=c;
    }
    ll d = a%b;
    if(d==0){
        return b;
    }else if(d==1){
        return 1;
    }else{
        gcd(b,d);
    }
}


ll cul(ll n){
    return (n-1)*n/2;
}


int x[100010];
int main (){
    int n,k;    cin >> n >> k;
    rep(i,n){
        cin >> x[i];
    }

    ll ans=inf;
    for(int i=0; i+k<=n; i++){
        ll a;
        if(x[i]<0 && x[i+k-1]<0){
            a = -1 * x[i];
        }else if(x[i]>0 && x[i+k-1]>0){
            a = x[i+k-1];
        }else{
            ll b;
            a = -2 * x[i] + x[i+k-1];
            b = -1 * x[i] + 2 * x[i+k-1];
            a = min(a,b);
        }
        ans = min(ans, a);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int N;
  int64_t K, countB = 0;
  cin >> N >> K;
  vector<vector<int>> x(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> x.at(i).at(0) >> x.at(i).at(1);
  }
  sort(x.begin(), x.end());
  int ans;
  for (int i = 0; i < N ;i++) {
    countB += x.at(i).at(1);
    if (countB >= K) {
      ans = x.at(i).at(0);
      break;
    }
    else {
      continue;
    }
    
  }
  
  cout << ans << endl;
}

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

const int inf = 1e9 + 7;
const int mnx = 1e6 + 9;

ll n, p;
ll a[mnx];
ll b[mnx];
ll pos[mnx];

int main(){

cin >> n;

for(int i = 1; i <= n; i++){
    cin >> p; pos[p] = i;
}

for(int i = 1; i <= n; i++){
    a[i] = i * 30000;
    b[i] = (n - i) * 30000 + pos[i];
}

for(int i = 1; i <= n; i++){
    cout << a[i] << ' ';
} cout << '\n';
for(int i = 1; i <= n; i++){
    cout << b[i] << ' ';
}

return 0;

}


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

int main()
{
    int k, a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; i++)
    {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;

}

Measured memory_bytes: 3624
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  //vector<ll>to[1000005];
  // ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,ans=0;cin>>a;
  vector<vector<ll>>b(3,vector<ll>(a));
  rep(i,3){
    rep(o,a)cin>>b[i][o];
    sort(b[i].begin(),b[i].end());
  }
  rep(i,a){
    ll x=lower_bound(b[0].begin(),b[0].end(),b[1][i])-b[0].begin();
    ll y=a-(upper_bound(b[2].begin(),b[2].end(),b[1][i])-b[2].begin());
    ans+=x*y;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;

void solve()
  {
    int x;
   cin>>x;
   x /= 200;
   cout<<(10-x);
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 

   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3608
#include<stdio.h>

int main(){
	int x,y;
	int ii = 0;
	while(1){
		ii++;
		scanf("%d%d",&x,&y);
		if(y == 0 && x == 0)break;
		if(x > y){
			
			printf("%d %d\n",y,x);
		}
		else if(x < y){
			
			printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",x,y);
		}
		
		
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdlib.h>
#include <stdio.h>
int MAX(int a,int b){
    return a>b?a:b;
}

int main()
{   int n,a,b,c,d,flag=0;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    char s[n+1];
    scanf("%s",s);
    for(int i=a-1;i<MAX(c,d);i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            printf("No");
            return 0;
        }
    }
    if(c>d){
        for(int i=b-2;i<d-1;i++){
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
                flag=1;
            }
        }
        if(flag==0){
            printf("No");
            return 0;
        }
    }
    
    printf("Yes");

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int arrys[] = new int[5];
		// sc.close();

		for(int i = 0; i<arrys.length; i++){
			arrys[i] = sc.nextInt();
		}
		for(int j = 0; j<arrys.length; j++){
			if(0==arrys[j]){
				System.out.println(j+1);
			}
		}
	}
}

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

using namespace std;

int a[100010];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	int i=1;
	int numb=0;
	int k=0;
	int ans=0;
	for(i=1;i<=n;i++){
		if(a[i]!=k){
			if(numb%2)
				ans++;
			numb=1;
			k=a[i];
		}
		else{
			numb++;
		}
	}
	if(numb%2)
		ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
import itertools
n = int(input())
dic = {"M":0, "A":0, "R":0, "C":0, "H":0, "Z":0}
for i in range(n):
    s = input()
    if s[0] not in dic:
        dic["Z"] += 1
    else:
        dic[s[0]] += 1
ans = 0
for i in itertools.combinations(["M", "A", "R", "C", "H"], 3):
    ans += dic[i[0]]*dic[i[1]]*dic[i[2]]
print(ans)

Measured memory_bytes: 46552
n=int(input())
a=list(map(int,input().split()))
s=[0]
ans=0
for i in range(n):
    S=s[i]+a[i]
    s.append(S)
s.sort()
cnt=1
for i in range(n):
    if s[i]==s[i+1]:
        cnt+=1
    else:
        ans+=cnt*(cnt-1)//2
        cnt=1
ans+=cnt*(cnt-1)//2
print(ans)

Measured memory_bytes: 27132
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi;
#define second se;
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    while(cin >> n, n){
        vector<char> c(n);
        rep(i, 0, n) cin >> c[i];
        int d[26] = {};
        int MAX = 0, id = -1;
        int sMAX = 0, sid = -1;
        bool f = false;
        rep(i, 0, n){
            int now = c[i] - 'A';
            d[now]++;
            if(MAX < d[now]){
                if(id != now){
                    sMAX = MAX;
                    sid = id;
                }   
                MAX = d[now];
                id = now;
            }else if(sMAX < d[now] && d[now] <= MAX && id != now){
                sMAX = d[now];
                sid = now;
            }
            //else if(sMAX < d[now]){
            //     sMAX = d[now];
            //     sid = now;
            // }
            // cout << i << " " << MAX << " " << sMAX << endl;
            if(MAX > sMAX + n - 1 - i){
                f = true;
                cout << (char)('A' + id) << " " << i + 1 << endl;
                break;
            }
        }
        if(!f) cout << "TIE" << endl;
    }
}

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

struct pla{
	int rank, score;
} a[100000];

bool c8763(pla a, pla b){
	return a.rank > b.rank;
}

int main() {
	int n, i;
	while(cin >> n){
		for(i = 0; i < n; i++){
			cin >> a[i].rank >> a[i].score;
		}
		sort(a, a + n, c8763);
		cout << a[0].rank + a[0].score << "\n";
	}
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,temp;
	std::vector<int> v;
	std::cin >> n;
	for (size_t i = 0; i < n; i++) {
		std::cin >> temp;
		v.push_back(temp);
	}
	sort(v.begin(),v.end());
	int now = v[0];
	int counter = 1;
	for (size_t i = 0; i < v.size(); i++) {
		if (now != v[i]) {
			now = v[i];
			counter++;
		}
	}
	std::cout << counter << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n == 25){
            System.out.println("Christmas");
        }else if (n == 24){
            System.out.println("Christmas Eve");
        }else if (n == 23){
            System.out.println("Christmas Eve Eve");
        }else {
            System.out.println("Christmas Eve Eve Eve");
        }

    }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
struct strongly_connected_components{
	int V;
	vector<vector<int>> E1;
	vector<vector<int>> E2;
	vector<int> t;
	vector<bool> used;
	vector<int> scc;
	strongly_connected_components(vector<vector<int>> &G){
		V = G.size();
		E1 = vector<vector<int>>(V);
		E2 = vector<vector<int>>(V);
		used = vector<bool>(V, false);
		scc = vector<int>(V, -1);
		for (int i = 0; i < V; i++){
			for (int j : G[i]){
				E1[i].push_back(j);
				E2[j].push_back(i);
			}
		}
	}
	void dfs1(int v){
		for (int w : E1[v]){
			if (!used[w]){
				used[w] = true;
				dfs1(w);
			}
		}
		t.push_back(v);
	}
	void dfs2(int v, int k){
		for (int w : E2[v]){
			if (scc[w] == -1){
				scc[w] = k;
				dfs2(w, k);
			}
		}
	}
	void decomp(){
		for (int i = 0; i < V; i++){
			if (!used[i]){
				used[i] = true;
				dfs1(i);
			}
		}
		reverse(t.begin(), t.end());
		int count = 0;
		for (int i = 0; i < V; i++){
			if (scc[t[i]] == -1){
				scc[t[i]] = count;
				dfs2(t[i], count);
				count++;
			}
		}
	}
	int operator [](int k){
		return scc[k];
	}
};
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
  }
  strongly_connected_components SCC(E);
  SCC.decomp();
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int u, v;
    cin >> u >> v;
    if (SCC[u] == SCC[v]){
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B;
  cin >> A >> B;
  if(A==B){
    cout << "Draw" << endl;
  }
  else if(A==1){
    cout << "Alice" << endl;
  }
  else if(B==1){
    cout << "Bob" << endl;
  }
  else if(A>B){
    cout << "Alice" << endl;
  }
  else{
    cout << "Bob" << endl;
  }
}
     


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

int main() {
  int N;
  cin >> N;
  if(to_string(N).find("7") != string::npos){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3768
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define repi(i,a,b) for(lint i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif

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

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

    vector<lint> a(3);
    cin>>a[0]>>a[1]>>a[2];
    tsort(a);
    co(a[0]+a[1]);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Dmondai {
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var M = line[1];
        //使える数字
        var A= Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).OrderByDescending(x=>x).ToArray();
        //それぞれの数字で使用するマッチの本数（index+1=数字）
        var cost = new int[] { 2,5,5,4,5,6,3,7,6};
        //dp用の配列
        var dp = new int[N+1];
        //マッチ棒を0本使用してできる桁はないので、0を入れる
        dp[0] = 0;
        //dpの配列にintの最小の数を入れる（inde=0以外）
        for (int i = 1; i <= N; ++i) dp[i] = int.MinValue;
        //動的計画法
        //マッチ棒をdpのindexぶん、使ったときにできる最大桁数を求める
        for (int i=0;i<=N;++i)
        {
            if (i != 0 && dp[i] == int.MinValue) continue;
            for (int j=0;j<M;++j)
            {
                if (N < i + cost[A[j] - 1]) continue;
                dp[i+cost[A[j] - 1]] = dp[i]+1;
            }
        }
        //答えを格納する文字列を用意
        var ans = string.Empty;
        //数字の文字列を作成する
        var index = N;
        while (0<index)
        {
            for (int j=0;j<M;++j)
            {
                if (index - cost[A[j] - 1] < 0) continue;
                if (dp[index - cost[A[j] - 1]] == dp[index] -1) {
                    ans += A[j];
                    index -= cost[A[j] - 1];
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27220
import sys
inf = float('inf')
N = int(input())
d = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
    d[i][i] = 0
ans=0
for a in range(N):
    for b in range(N):
        flag = True
        for i in range(N):
            if i == a or i == b:
                continue
            if d[a][i]+d[i][b]<d[a][b]:
                print(-1)
                sys.exit()
            if d[a][i]+d[i][b]==d[a][b]:
                flag = False
                break
        if flag:
            ans+=d[a][b]
            
print(ans//2)
    






Measured memory_bytes: 43996
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;


int main() {
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 + y1 - y2 << " " << y2 + x2 - x1 << " " << x1 + y1 - y2 << " " << y1 + x2 - x1 << endl;
	return 0;
}

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

using namespace std;

const int N = 2e5 + 100;

int Ans[N];

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

    vector <pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        int x;  cin >> x;
        v.push_back({x, i});
    }

    sort(v.begin(), v.end());

    for (int i = 0; i < n; i++) {
        if (i + 1 < n) {
            Ans[v[i].second] = v.back().first;
        } else Ans[v[i].second] = v[v.size() - 2].first;
    }

    for (int i = 0; i < n; i++)
        cout << Ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 4080
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	ll N; cin >> N;
	vector<int>C(N);
	REP(i, N) {
		int A; cin >> A;
		C[i] = A - i - 1;
	}
	sort(C.begin(), C.end());

	ll med = C[N / 2];
	ll out = 0;
	REP(i, N) {
		out += abs(C[i] - med);
	}
	print(out);


	return 0;
}


Measured memory_bytes: 1024
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int h,w;
vector<vector<int>> li = {{1,0}, {0,1}, {-1,0}, {0, -1}};

void bfs(vector<string> &da, vector<vector<int>> &co, int s, int t){
	if(da[s][t] == '#') return;
	queue<P> q;
	q.push(mpa(s,t));
	co[s][t] = 1;
	while(!q.empty()){
		P now = q.front();
		q.pop();
		rip(i,4,0){
			if(0 <= now.first + li[i][0] && now.first + li[i][0] < h && now.second + li[i][1] >= 0 && now.second + li[i][1] < w && co[now.first + li[i][0]][now.second + li[i][1]] == 0 && da[now.first + li[i][0]][now.second + li[i][1]] == '.'){
				q.push(mpa(now.first + li[i][0], now.second + li[i][1]));
				co[now.first + li[i][0]][now.second + li[i][1]] = co[now.first][now.second] + 1;
			}
		}
	}
	//vvdeb(co);
	return;
}

int MM(vector<vector<int>> &co){
	int s=0, t = 0;
	rip(i,h,0){
		rip(j,w,0){
			if(co[i][j] > co[s][t]){
				s=i;t=j;
			}
		}
	}
	return co[s][t];
}

int main(){
	cin >> h >> w;
	vector<string> da(h);
	rip(i,h,0){
		cin >> da[i];
	}
	int ans = 0;
	rip(i,h,0){
		rip(j,w,0){
			vector<vector<int>> co(h,vector<int>(w));
			bfs(da, co, i, j);
			ans = max(ans, MM(co));
		}
	}
	cout << ans-1 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
const int Nlim = 10000;
int N;
string s[Nlim];

int Ans() {
  int ab = 0;
  int last_a = 0, first_b = 0, both = 0;
  REP(i, N) {
    auto pos = s[i].find("AB");
    while (pos != string::npos) {
      ++ab;
      pos = s[i].find("AB", pos + 2);
    }
    if (s[i].back() == 'A' && s[i].front() == 'B') {
      ++both;
    } else {
      if (s[i].back() == 'A') { ++last_a; }
      if (s[i].front() == 'B') { ++first_b; }
    }
  }
  if (last_a >= 1 && first_b >= 1) {
    return ab + MIN(last_a, first_b) + both;
  } else {
    if (last_a >= 1 || first_b >= 1) {
      return ab + both;
    } else {
      return ab + MAX(both-1, 0);
    }
  }
}

signed main() {
  cin >> N;
  REP(i, N) { cin >> s[i]; }

  auto ans = Ans();

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


Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <stdio.h>
#include <vector>
#include <numeric>

using namespace std;
int main()
{
   long long int y,z,i,j,k,n,t[100],m,p,x;
   cin >> n;
   
   for(i=0;i<n;i++)
   {
       cin >> t[i];
   }
   cin >> m;
   while(m--)
   {
       cin >> p >> x;
       int s=0;
       for(i=0;i<n;i++)
       {
           if (i==p-1)
           {
               s = s+x;
           }
           
           else
           {
               s = s+t[i];
           }
       }
       
       cout << s << "\n";
   }
}


Measured memory_bytes: 3568
#include <iostream>

int main(int argc, char const *argv[]) {
    int N, K, X, Y;
    std::cin >> N >> K >> X >> Y;
    int cost;
    if (N > K) {
        cost = K * X + (N - K) * Y;
    } else {
        cost = N * X;
    }
    std::cout << cost << std::endl;
    return 0;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
#define ld long double

const int mod = 1000000007;
const ld PI = acosl(-1.0);
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int ans = 0;
    string s;
    cin>>s;
    int curr = 0;
    f1(i,0,s.size())
    {
        if(s[i] == 'R')
        curr++;
        else
        {
            curr = 0;
        }
        ans = max(ans, curr);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				begin(c), std::end(x)
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define V_TYPE				int
#define INF					1e4+1

using namespace std;
typedef long long ll;
typedef vector<V_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


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

	int ans = n - (k - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int main(int argc, char** argv){
    int n, m;
    std::cin >> n >> m;

    int mod = std::floor(m / n);
    for(int i=mod; i>0; --i){
        if(m % i == 0){
            std::cout << i << std::endl;
            return 0;
        }
    }
    
    return 0;
}

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

int main() {
  int X, Sum=0;
  cin >> X;
  int Y=X%100;
  for(int i=5; i>0; i--){
    Sum=Sum+Y/i;
    Y=Y-i*int(Y/i);
  }
  if(Sum<=X/100) cout << '1' << endl;
  else cout << '0' << endl;
}

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

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

  int a,b,c;
  cin>>a>>b>>c;
  
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c<<"\n";
  return 0;
    
}

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

int main() {
  long long H,tmp=1;
  int ans=0;
  cin >> H;
  while(H!=1){
    H = H/2;
    ans++;
  }
  ans++;
  while(ans>0){
  tmp *= 2;
  ans--;
  }
  cout << tmp-1 << endl;
}

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

int N;
vector<int> G[100100];
vector<P> edges;
map<int, int> mp;
int K = 0;

void dfs(int v, int pv, int pc) {
    int c = 1;
    rep(i, G[v].size()) {
        int nv = G[v][i];
        if (nv==pv) continue;
        if (c==pc) c++;
        mp[1000000*min(v, nv)+max(v, nv)] = c;
        K = max(c, K);
        dfs(nv, v, c);
        c++;
    }
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N-1) {
        int a, b; cin >> a >> b;
        G[a-1].pb(b-1);
        G[b-1].pb(a-1);
        edges.pb(P(a-1, b-1));
    }
    
    dfs(0, -1, -1);
    cout << K << endl;
    rep(i, N-1) {
        int a = edges[i].first, b = edges[i].second;
        cout << mp[1000000*a+b] << endl;
    }
}

Measured memory_bytes: 16372
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());
    let r: usize = sc.read();
    println!("{}", r * r);
}

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

typedef vector<vector<int>> Graph;

void warhsall_floyd(Graph& G) {
    for (int k = 0; k < G.size(); k++) {
        for (int i = 0; i < G.size(); i++) {
            if (G[i][k] == INF) {
                continue;
            }
            for (int j = 0; j < G.size(); j++) {
                if (G[k][j] == INF) {
                    continue;
                }
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
}

int main() {
    int N, M, R;
    cin >> N >> M >> R;

    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r[i];
    }

    Graph G(N, vector<int>(N, INF));
    for (int  i = 0; i < M; i++) {
        int A, B, C;
        cin >> A >> B >> C;
        --A;
        --B;
        G[A][B] = C;
        G[B][A] = C;
    }

    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }

    warhsall_floyd(G);

    long long ans = LINF;
    sort(r.begin(), r.end());
    do {
        long long dist = 0;
        for (size_t i = 1; i < r.size(); i++) {
            // cout << r[i - 1] << ", " << r[i] << endl;
            dist += G[r[i - 1] - 1][r[i] - 1];
        }
        ans = min(ans, dist);
    } while (next_permutation(r.begin(), r.end()));

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N,k;
  k=0;
  cin >> N;
  vector<long int> H(N);
  vector<long int> c(N,0);
  cin >>H.at(0);
  for(int i=1;i<N;i++){
    cin >>H.at(i);
    if(H.at(i-1)>=H.at(i)){
      c.at(k)++;
    }
    else{
      k++;
    }
  }
  cout <<*max_element(c.begin(),c.end())<<endl;

}


Measured memory_bytes: 1792
#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 = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    ll N,A,B; cin >> N >> A >> B;
    ll shou=N/(A+B);
    ll ama=N%(A+B);
    
    ll ans=0;
    ans+=shou*A;
    if (ama<=A) ans+=ama;
    else ans+=A;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int i;   
    cin >> i;
    cout << i/3 <<endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal
import java.math.MathContext

fun main(args: Array<String>) {
    fun sqrt(a: BigDecimal, scale: Int = 50): BigDecimal {
        var x = BigDecimal(
                Math.sqrt(a.toDouble()), MathContext.DECIMAL64)
        if (scale < 17) return x
        val b2 = BigDecimal(2)
        var tempScale = 16
        while (tempScale < scale) {
            x = x.subtract(
                    x.multiply(x).subtract(a).divide(
                            x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN))
            tempScale *= 2
        }
        return x
    }
    val (a, b, c) = readLine()!!.split(' ').map(String::toDouble)
    val ba = BigDecimal(a)
    val bb = BigDecimal(b)
    val bc = BigDecimal(c)
    println(if (sqrt(ba).plus(sqrt(bb)) < sqrt(bc)) "Yes" else "No")
}


Measured memory_bytes: 38276
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include <bitset>

using namespace std;

int N;
void solve(){
    cin >> N;
    cout.precision(10);
    cout << (double)(N - N / 2) / (double)N << endl;
    return;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
cas=[list(map(int,input().split())) for _ in range(n)]
ans=float('inf')
for i in range(1, 2**n):
    v=0
    us=[0]*m
    for b,ca in zip(bin(i)[2:].zfill(n), cas):
        b=int(b)
        if b==0:
            continue
        v+=ca[0]
        for j,a in enumerate(ca[1:]):
            us[j]+=a
    for u in us:
        fg=0
        if u<x:
            fg=1
            break
    if fg==0:
        ans=min(ans,v)
if i==2**n-1 and fg==1:
    print(-1)
    exit()
print(ans)


Measured memory_bytes: 9228
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<int>ans(N, 1);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--, R--;
		if (v[L] <= v[R])ans[L] = 0;
		if (v[L] >= v[R])ans[R] = 0;
	}
	cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}


Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<queue>
#include<cmath>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    vector<int64> a(N);
    int64 sum = 0;
    for (int64 i = 0; i < N; i++)
    {
        cin>>a[i];
        sum^=a[i];
    }
    for (int64 i = 0; i < N; i++)
    {
        cout<<(sum^a[i])<<" ";
    }
    
    cout<<endl;
    return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    typedef pair<long long, int> AB;
    priority_queue<AB, vector<AB>, greater<AB>> que;
    for(int i=0; i<N; i++){
        long long A;
        int B;
        cin >> A >> B;
        que.push(AB(A,B));
    }

    int count = 0;
    long long sum_cost = 0;
    while(true){
        AB vals = que.top(); que.pop();
        long long cost = vals.first;
        int max_n = vals.second;

        int buy_n = min({max_n, M-count});
        count += buy_n;
        sum_cost += (long long)buy_n*cost;

        if(count == M){
            break;
        }

    }

    cout << sum_cost <<endl;
    return 0;

}

Measured memory_bytes: 5340
n = int(input())
a = map(int, input().split())
b1, b2, b4 = 0, 0, 0

for i in a:
    if i % 4 == 0:
        b4 += 1
    elif i % 2 == 0:
        b2 += 1
    else:
        b1 += 1
if b2:
    if b1 <= b4:
        print("Yes")
    else:
        print("No")
else:
    if b1 <= b4 + 1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 11096
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
struct edge{ll to, cost;}; //edgeパラメータ
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ll> d; // dist[n] = ノードnまでのの重み
  vector<ll> parent;

  graph(ll n): N(n), G(N), d(n,INF2), parent(N) {}

  void add_edge(ll s, ll t, ll cost){
    G[s].emplace_back((edge){t, cost});
    G[t].emplace_back((edge){s, cost}); //無向ならON
  }

  void dijkstra(ll s){
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que; //ansが小さい順に出る
    que.push(P(0,s)); // P < ans , Node >
    while(!que.empty()){
      P p = que.top(); que.pop(); //pに <ans,Node> 入れる
      ll v = p.second; //vに Node 入れる
      if(d[v] < p.first) continue; //すでに良い数値が入っているならパス
      rep(i,G[v].size()){
        edge& E = G[v][i];
        if(d[E.to] > d[v] + E.cost){ //更新するなら
          d[E.to] = d[v]+ E.cost;
          parent[E.to] = v; //親を記録,goalから遡れば道順
          que.push(P(d[E.to], E.to));
        }
      }
    }
  }
};

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> p(N);
    rep(i,N) cin>>p[i];
    rep(i,N) --p[i];

    vector<ll> aplus(N,0);
    vector<ll> bplus(N,0);

    rep(i,N){
        if(p[i]+1!=N) aplus[p[i]+1]=20001-i;
        if(p[i]-1!=-1) bplus[p[i]-1]=20001-i;
    }
    reps(i,1,N){
        aplus[i]+=aplus[i-1];
        bplus[N-1-i]+=bplus[N-i];
    }
    rep(i,N){
        cout<<i+1+aplus[i]<<" ";
    }
    cout<<"\n";
    rep(i,N){
        cout<<N-i+bplus[i]<<" ";
    }
    cout<<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1152
#include<stdio.h>

int main(void)
{
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	int x;
	
	x = b / a;
	
	if(x >= c){
		printf("%d\n",c);
	}
	
	else{
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, readline().split())
if a + b > c + d:
    print('Left')
elif a + b < c + d:
    print('Right')
else:
    print('Balanced')


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
    int A, B, C; cin >> A >> B >> C;
    if(B <= C)
        cout << "NO" << endl;
    
    for(int i=1; i<=B; i++) {
        if(A*i%B == C) {cout << "YES" << endl; return 0;} 
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] A = new int[M];
        int sum = 0;
        for(int i = 0; i < M; i++) {
            A[i] = scanner.nextInt();
            sum += A[i];
        }
        if(N - sum < 0) {
            System.out.println(-1);
        }else{
            System.out.println(N - sum);
        }

        return;
    }
}

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

main(){
  string a;
  cin >> a;
  if(a.length()<4){
    cout << "No" <<endl;
  }else if(a.find("YAKI")==0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;
typedef int int32;
#define int ll

using namespace std;

typedef long long ll;

void solve() {
	int count[4][4001] = {};

	ll n;
	cin >> n;

	string s;
	cin >> s;

	map<char,int> id;
	id['R'] = 1;
	id['G'] = 2;
	id['B'] = 3;

	char rev[] = {'Q','R','G','B'};

	for (int i = n-1; i >= 0; i--) {
		count[id[s[i]]][i]++;
		if (i != 0) {
			count[1][i] += count[1][i+1];
			count[2][i] += count[2][i+1];
			count[3][i] += count[3][i+1];
		}
	}

	ll ans = 0;
	
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n-1; j++) {
			if (s[i] == s[j])	continue;
			ll third = (id[s[i]] xor id[s[j]]);
			ans += count[third][j+1];
			ll dis = j-i;
			if ((j+dis < n) && (s[j+dis] == rev[third])) {
				ans--;
			}
		}
	}
	
	cout << ans << endl;
}

int32 main() {
	int t = 1;
	//cin >> t;
	int c = 0;
	while (c < t) {
		solve();
		c++;	
	}
	return 0;
}

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

int main(){ 
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i,n) cin >> t[i];
  sort(t.begin(), t.end());
  t.emplace_back(2e9+1);
  int res = 0;
  int prev = t[0];
  int cnt = 1;
  for (int i = 1; i < n+1; i++) {
    if (t[i] <= prev + k && cnt < c) {
      cnt++;
    } else {
      cnt = 1;
      prev = t[i];
      res++;
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

void test();

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> a(n);
	int mx = 0;
	for(auto &i : a){
		cin >> i;
		mx = max(mx,i);
	}
	sort(all(a));
	int ans = 0;
	f(i,1,mx+1){
		auto k = lower_bound(all(a),i);
		int t1 = (k-a.begin());
		int t2 = n-t1;
		if(t1 == t2)
			ans ++ ;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;

void solve() {
    ll cnt[2020], n, i, j, k, ans = 0, sum = 0;
    string s;
    fo(i,2020)cnt[i]=0;
    cin>>s;
    reverse(s.begin(), s.end());
    n = s.length();
    ll arr[n+1];arr[0]=1;
    Fo(i,1,n)arr[i] = ( arr[i-1] * 10ll ) % 2019ll;
    cnt[0] = 1;
    fo(i,n) {
        sum = ( sum  + (s[i] - 48) * arr[i] ) % 2019ll;
        ans += cnt[sum];
        cnt[sum]++;
    }
    cout<<ans;
}

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}


Measured memory_bytes: 5364
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{int to,cost;};
V<edge>graph[20];
int main(){
  int n;cin>>n;
  n--;
  for(int i=0;i<19;i++)graph[i].emplace_back(edge{i+1,0});
  int ind=-1;
  for(int i=19;i>=0;i--)if(n&(1<<i)){ind=i;break;}
  for(int i=18;i>=0;i--){
      if(18-i!=ind)graph[i].emplace_back(edge{i+1,(1<<(18-i))});
      else break;
  }
  graph[0].emplace_back(edge{19,(1<<ind)});
  int x=(1<<ind);
  for(int i=ind-1;i>=0;i--){
      if(n&(1<<i)){
          graph[0].emplace_back(edge{19-i,x+1});
          x+=(1<<i);
      }
  }
  int sum=0;
  for(int i=0;i<20;i++)sum+=(int)graph[i].size();
  cout<<20<<" "<<sum<<"\n";
  for(int i=0;i<20;i++)for(int j=0;j<graph[i].size();j++)cout<<i+1<<" "<<graph[i][j].to+1<<" "<<graph[i][j].cost<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
long long int gozyo(long long int x,long long int y) {
	long long int tmp;
	long long int seki = x * y;
	if (x < y) {
		tmp = x;
		x = y;
		y = tmp;
	}
	tmp = x % y;
	while (tmp != 0) {
		x = y;
		y = tmp;
		tmp = x % y;
	}
	seki /= y;
	return seki;
}
int main() {
	long long int n, m;
	long long int a,b;
	long long int skip, skip2;
	char s[100005], s2[100005];
	scanf("%d%d", &n, &m);
	scanf("%s%s", s, s2);
	a = gozyo(n, m);
	b = n * m / a;
	skip = a / n;
	skip2 = a / m;
	for (int i = 0; i < b; i++) {
		if (s[i*skip2] != s2[i*skip]) {
			printf("-1");
			return 0;
		}
	}
	printf("%lld", a);
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void)
{
    long long n,k;

    cin >>n >>k;

    long long rem = n % k;

    printf("%lld\n", min(rem, abs(rem-k)));

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int k = sc.nextInt();
        if(k == 1){
        	System.out.println(0);
        }else{
        	System.out.println(n - k);
        }
	}
}

Measured memory_bytes: 35688
N, C = map(int, input().split())
sushi_list = []
for _ in range(N):
    sushi_list.append(tuple(map(int, input().split())))

clock = [0]
clock_double = [0]

cal = 0
for idx, sushi in enumerate(sushi_list, 1):
    cal += sushi[1]
    clock.append(max(clock[idx - 1], cal - sushi[0]))
    clock_double.append(max(clock_double[idx - 1], cal - sushi[0] * 2))

cal = 0
rev_clock = [0]
rev_clock_double = [0]
for idx, sushi in enumerate(sushi_list[::-1], 1):
    cal += sushi[1]
    rev_clock.append(max(rev_clock[idx - 1], cal - (C - sushi[0])))
    rev_clock_double.append(max(rev_clock_double[idx - 1], cal - (C - sushi[0]) * 2))

max_cal = 0
for i in range(N + 1):
    c = clock_double[i] + rev_clock[N - i]
    r_c = rev_clock_double[i] + clock[N - i]
    max_cal = max(max_cal, c, r_c)
print(max_cal)


Measured memory_bytes: 29904
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int n;
long long sum=0,min=1000000,max=-1000000;
cin >>n;
int y;
for( int I=0;I<n;I++){
	cin >> y;
	if(min>y){
		min = y;}
	if(max<y){
		max = y;}
	sum+=y;
}
cout<<min<<" "<<max<<" "<<sum<<endl;
return 0;
}


Measured memory_bytes: 3136