akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
#define pb push_back
using namespace std;
vector <int> adj[100001];
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int root_find()
{
    ll x;
    for(int i=1;i<100001;i++)
    {
        if(adj[i].size()==1)
        {
            x = i;
            break;
        }
    }
    return x;
}
void dfs(int s,int y)
{
    for(int i=0;i<adj[s].size();i++)
    {
        if(adj[s][i]==y)
        continue;
        dfs(adj[s][i],s);
    }
}
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
ll smallestDivisor(ll n) 
{ 
    // if divisible by 2 
    if (n % 2 == 0) 
        return n/2; 
  
    // iterate from 3 to sqrt(n) 
    for (int i = 3; i * i <= n; i += 2) { 
        if (n % i == 0) 
            return n/i; 
    } 
  
    return n; 
}  
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int l,r,d;
    cin>>l>>r>>d;
    ll ans = (r/d)-(l/d);
    if(l%d==0)
    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5948
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<long long> x(n), y(n), z(n); REP(i, n) cin >> x[i] >> y[i] >> z[i];
  long long ans = 0;
  // x:+ y:+ z:+
  vector<vector<long long> > dp(n+1, vector<long long>(m+1, -LINF));
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:- y:+ z:+
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) x[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:- y:- z:+
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) y[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:- y:- z:-
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) z[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:+ y:- z:-
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) x[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:+ y:+ z:-
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) y[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:- y:+ z:-
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) x[i] *= -1;
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  // x:+ y:- z:+
  dp.resize(n+1, vector<long long>(m+1, -LINF));
  REP(i, n) {
    x[i] *= -1;
    y[i] *= -1;
    z[i] *= -1;
  }
  REP(i, n+1) dp[i][0] = 0;
  REP(i, n) REP(j, m) dp[i+1][j+1] = max(dp[i][j+1], dp[i][j] + x[i] + y[i] + z[i]);
  ans = max(ans, dp[n][m]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8192
package main
import "fmt"
import "math"
func main(){
    var N, keta, ans int

    fmt.Scanf("%d", &N)
    
    for i := 1; i <= N; i++ {
        keta = int(math.Trunc(math.Log10(float64(i))) + 1)
        if keta % 2 == 1 {
            ans++
        }
    }
    fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 5;

int n, a[4][N];

int inv[2], flip[2];
int label[N];

void add_col(vector <int> v, int id)
{
    if(abs(v[2] - v[0]) != 2 || abs(v[1] - v[0]) != 1 || v[1] % 3 < 2)
    {
        cout << "No" << endl;
        exit(0);
    }

    int parity = !(v[1] & 1);
    if(v[0] > v[2])
        flip[parity]++;

    label[(v[1] + 1) / 3] = id;
    if(id & 1 != parity)
    {
        cout << "No" << endl;
        exit(0);
    }
}

bool vis[N];
int comp_sz;
void DFS(int v)
{
    vis[v] = true;
    comp_sz++;
    if(!vis[label[v]])
        DFS(label[v]);
}


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

    int n;
    cin >> n;
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= n; j++)
            cin >> a[i][j];

    for(int j = 1; j <= n; j++)
    {
        vector <int> v = {a[1][j], a[2][j], a[3][j]};
        add_col(v, j);
    }

    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            comp_sz = 0;
            DFS(i);
            inv[i & 1] += (comp_sz - 1);
        }
    }

    inv[0] &= 1;
    inv[1] &= 1;
    flip[0] &= 1;
    flip[1] &= 1;
    if(inv[0] != flip[1] || inv[1] != flip[0])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1920
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n, k;
main() {
  file("threesum");
  ios;
  cin >> n >> k;
  cout << min(n % k, k - (n % k));
  return 0;
}
/**

*/


Measured memory_bytes: 256
void main(){
	int n = _scan();
	writefln(n%1000==n? "ABC": "ABD");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2864
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();

    int input = scan.nextInt();

    int cases = 1;

    while(input>0) {
      int[][] arr = new int[input][input];
      int x=0,y=0;
      int count = 1;
      boolean mode = false;
      while(x<input&&y<input) {
        arr[x][y] = count;

        if(mode) {
          x--;  y++;
        }else {
          y--;  x++;
        }

        if(x>=input) {
          x--;  y++;  y++;
          mode = !mode;
        }else if(y>=input) {
          y--;  x++;  x++;
          mode = !mode;
        }

        if(x<0) {
          x++;
          mode = !mode;
        }else if(y<0) {
          y++;
          mode = !mode;
        }

        count++;
      }

      sb.append("Case "+cases+":\n");

      for(int i = 0; i < input; i++) {
        for(int j = 0; j < input; j++) {
          sb.append(String.format("%3d",arr[j][i]));
        }
        sb.append("\n");
      }

      input = scan.nextInt();
      cases++;
    }

    System.out.print(sb.toString());
  }
}

Measured memory_bytes: 26280
#include <iostream>

using namespace std;

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

	long long n, d;
	cin >> n >> d;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		long long x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d)
			cnt++;
	}
	cout << cnt << "\n";

	return 0;
}


Measured memory_bytes: 3640
let s = read_line ()
let n = String.length s
let _ = for i = 0 to n - 1 do let k = min (n - 1) @@ n + i - 8 in
  if String.(sub s 0 i ^ sub s (k + 1) (n - 1 - k)) = "keyence" then (print_endline "YES"; exit 0) done; print_endline "NO"

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
{
  LL n, m;
  cin >> n >> m;
  if(n == 1 || m == 1)
    {
    cout << 1 << endl;
    return 0;
    }

  LL res = 0;
  res += ((m + 1) / 2) * ((n + 1) / 2);
  res += (m / 2) * (n / 2);
  cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,pair<int,int> >edge[60000];
int h[210];
pair<int,int> ev[210];
int UF[210];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;
	UF[a]+=UF[b];UF[b]=a;
}
int v[210];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%d",h+i);
		for(int i=0;i<a;i++)ev[i]=make_pair(-h[i],i);
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<a;i++)v[i]=0;
		for(int i=0;i<b;i++){
			int p,q,r;scanf("%d%d%d",&p,&q,&r);
			p--;q--;
			edge[i]=make_pair(r,make_pair(p,q));
		}
		int ret=0;
		std::sort(ev,ev+a);std::sort(edge,edge+b);
		int cnt=0;
		for(int i=0;i<a;i++){
			int at=ev[i].second;
			v[at]=1;
			if(i==a-1||ev[i].first!=ev[i+1].first){
				for(int j=0;j<b;j++){
					int l=edge[j].second.first;
					int r=edge[j].second.second;
					if(v[l]&&v[r]&&FIND(l)!=FIND(r)){
						ret+=edge[j].first;
						UNION(l,r);
						cnt++;
					}
				}
				if(cnt!=i){
					cnt=0;
					ret=0;
					for(int j=0;j<a;j++)UF[j]=-1;
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1736
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long N=stdIn.nextLong();
		long K=stdIn.nextLong();
		long A=N%K;
		long B=K-A;
		System.out.println(Math.min(A,B));
	}
}


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

int main() {
	int N; cin >> N;
	vector<string> A(N);
	rep(i, N) cin >> A[i];

	int a = 0, ab = 0, b = 0, ba = 0;
	rep(i, N) {
		if (A[i].front() == 'B') b++;
		rep(j, A[i].size()) {
			if (A[i][j]=='A' && A[i][j+1]=='B') ab++;
		}
		if (A[i].back() == 'A') a++;
		if (A[i].front()=='B' && A[i].back()=='A') ba++;
	}
	int con = min(a, b);
	if (ba>0 && a==ba && b==ba) con--;
	cout << ab + con << endl;
}

Measured memory_bytes: 768
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 
def main():
    S = list(getS())
    tgt5 = [list(s) for s in ["dream", "erase"]]
    tgt6 = [list(s) for s in ["eraser"]]
    tgt7 = [list(s) for s in ["dreamer"]]
    dp = [0 for i in range(len(S)+1)]
    dp[0] = 1
    for i, c in enumerate(S):
        if dp[i] == 1:
            for tg in tgt5:
                if S[i: i+5] == tg and i+5 <= len(S):
                    dp[i+5] = 1
            for tg in tgt6:
                if S[i: i+6] == tg and i+6 <= len(S):
                    dp[i+6] = 1
            for tg in tgt7:
                if S[i: i+7] == tg and i+7 <= len(S):
                    dp[i+7] = 1

    # print(dp)
    if dp[-1] == 1:
        print("YES")
    else: 
        print("NO")

    return


 
if __name__ == "__main__":
    main()
   

Measured memory_bytes: 83800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhijeetkns
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenApple solver = new BGoldenApple();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenApple {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            double n = in.nextDouble();
            double d = in.nextDouble();
            d = 2 * d + 1;
            out.println((int) Math.ceil(n / d));
        }

    }
}



Measured memory_bytes: 24404
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int64_t N = 0;
	int64_t len = 0;
	int64_t res = 0;
	int M;
	in >> M;
	for (size_t i = 0; i < M; i++)
	{
		int64_t d, num;
		in >> d>> num;

		N += d* num;
		len += num;
	}


	res = (len - 1);
	while (N>=10) {
		res += N / 10;
		N = (N % 10) + N / 10;
	}
	out << res << endl;



	return 0;
}
#endif


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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define sz(a) ((int)a.size())

ll mod=1e9+7;
const int nax=2e5+5; 

void self_mul(int &a, int b){
  a=(ll)a*b%mod; 
}
int add(int a, int b){
  return (a+b)%mod; 
}
ll tree[nax*4]; 
void update(int i, ll val, int p=1, int l=1, int r=nax){
  if(l>i || r<i) return; 
  else if(l==r){
    tree[p]=max(tree[p],val); 
  }
  else {
    int m=(l+r)>>1; 
    int c1=p<<1, c2=p<<1|1; 
    update(i,val,c1,l,m); 
    update(i,val,c2,m+1,r); 
    tree[p]=max(tree[c1],tree[c2]); 
  }
}
ll maxx(int i, int j, int p=1, int l=1, int r=nax){
  if(r<i || l>j) return 0; 
  else if(i<=l && r<=j) return tree[p]; 
  else {
    int m=(l+r)>>1; 
    int c1=p<<1, c2=p<<1|1; 
    ll a=maxx(i,j,c1,l,m); 
    ll b=maxx(i,j,c2,m+1,r); 
    return max(a,b); 
  }
}

void solve(){
  int n; cin>>n; 
  vector<int> h(n), a(n); 
  for(int &i:h){
    cin>>i; 
  }
  for(int &i:a){
    cin>>i; 
  }
  ll ans=0; 
  for(int i=0;i<n;i++){
    ll to=maxx(1,h[i]-1)+a[i]; 
    update(h[i],to); 
    ans=max(ans,to); 
  }
  cout<<ans<<endl; 
}

int main(){
	fast_io;
	clock_t beg=clock();
  int t;
  t=1;
  while(t--){
	  solve();
  }
	clock_t end=clock();
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC);
	return 0;
}

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

int main() {
    int c[4][4];
    for (int i=1; i<=3; i++){
        for (int j=1; j<=3; j++){
            cin >> c[i][j];
        }
    }
    bool flag = false;
    for (int i=0; i<=c[1][1]; i++){
        int a1 = i;
        int b1 = c[1][1] - a1;
        int b2 = c[1][2] - a1;
        int b3 = c[1][3] - a1;
        if (b1 >= 0 && b2 >= 0 && b3 >= 0) {
            int a2 = c[2][1] - b1;
            if (a2 == c[2][2] - b2 && a2 == c[2][3] - b3 && a2 >= 0) {
                int a3 = c[3][1] - b1;
                if (a3 == c[3][2] - b2 && a3 == c[3][3] - b3 && a3 >= 0) {
                    flag = true;
                }
            }
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける

int main(){
  int N, count;
  cin >> N;
  count = N;
  vi p(N);
  vi q(N);
  priority_queue<int> pq;

  for (int n = 0; n < N; n++) {
    cin >> p.at(n);
    pq.push(p.at(n));
  }

  for (int i = N-1; i >= 0  ; i--)
  {
    if (p.at(i) == pq.top())
    {
      count --;
    }
    pq.pop();
  }

  if (count <3)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return
    if H % 2 == 0 or W % 2 == 0:
        if W % 2 != 0:
            print(min(H // 2, W))
            return
        if H % 2 != 0:
            print(min(W // 2, H))
            return
        else:
            if H >= W:
                print(W // 2)
                return
            else:
                print(H // 2)
                return

    if H == 1:
        print(1)
        return
    if W == 1:
        print(1)
        return
    else:
        answer = float("inf")
        for i in range(1, H):
            m = W // 2
            choco = [i * W, m * (H - i), (m + 1) * (H - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans

        print(min(answer, min(H, W)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		IntStream alices = IntStream.range(sc.nextInt(), sc.nextInt());
		List<Integer> bobs = IntStream.range(sc.nextInt(), sc.nextInt()).boxed().collect(Collectors.toList());
		Long count = alices.filter(alice -> bobs.contains(alice)).count();
		System.out.println(count);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 28244
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let d = "KIHBR".chars().collect::<Vec<_>>();

    let mut na = vec![];
    for &ch in &s {
        if ch != 'A' {
            na.push(ch);
        }
    }
    if na != d {
        println!("NO");
        return;
    }

    let mut pointer = 0;
    let mut idx = 0;
    let mut count = 0;
    while pointer < s.len() {
        if s[pointer] != 'A' {
            idx += 1;
            count = 0;
        } else {
            count += 1;
        }
        if idx == 1 || idx == 2 {
            if count > 0 {
                println!("NO");
                return;
            }
        } else {
            if count > 1 {
                println!("NO");
                return;
            }
        }
        pointer += 1;
    }
    println!("YES");
    return;
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

public class Main {

	public static void main(String[] args) {
		KagamiMochi solver = new KagamiMochi();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class KagamiMochi {

		private int n;
		private int[] d;

		private Scanner scanner;
		private int output;

		public KagamiMochi() {
			scanner = new Scanner(System.in);
		}
		public void readInput() {
			n = scanner.nextInt();
			d = new int[n];
			for(int i=0; i<n; i++) {
				d[i] = scanner.nextInt();
			}
		}
		public void solve() {
			Arrays.sort(d);
			int t=0;
			for(int i :d) {
				if(t == i) {
					continue;
				}
				t = i;
				output++;

			}
		}

		public void writeOutput() {
			System.out.println(output);
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, ans;
int a[25], b[25];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n) {
		if (a[i] > b[i])ans += a[i] - b[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;	
	const int N = 1e5 + 10;
	int n, m, x[N], to[N], arr[N], id[N], ans[N];
	ll k;
	void trans(int *a, const int *b)
	{
		static int tmp[N];
		for (int i = 1; i < n; i++)
			tmp[i] = a[b[i]];
		memcpy(a + 1, tmp + 1, sizeof(int[n - 1]));
	}
	int work()
	{
		read(n);
		for (int i = 0; i < n; i++)
			read(x[i]), id[i] = to[i] = i;
		for (int i = n - 1; i > 0; i--)
			x[i] -= x[i - 1];
		read(m), read(k);
		for (int i = 1; i <= m; i++)
			read(arr[i]), --arr[i];
		for (int i = 1; i <= m; i++)
			swap(to[arr[i]], to[arr[i] + 1]);
		while (k)
		{
			if (k & 1)
				trans(id, to);
			trans(to, to);
			k >>= 1;
		}
		ll last;
		write(last = x[0]), putchar('\n');
		for (int i = 1; i < n; i++)
			write(last += x[id[i]]), putchar('\n');
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 3072
#include <stdio.h>
int main(void) {
	int n;
	int p[20];
	int cnt = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	for (int i = 0; i < n - 2; i++) {
		if ((p[i] < p[i+1] && p[i+1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
			cnt++;
		}
	}
	printf("%d", cnt);

	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N;
std::vector<int>ans;

int main()
{
	in >> N;
	ans.resize(N);
	std::string tmp;
	out << 0 << std::endl;
	in >> tmp;
	if (tmp == "Vacant") return 0;
	ans[0] = (tmp == "Male" ? 1 : 2);
	out << N - 1 << std::endl;
	in >> tmp;
	if (tmp == "Vacant") return 0;
	ans[N - 1] = (tmp == "Male" ? 1 : 2);
	int l = 0, r = N - 1;
	while (r - l > 1)
	{
		int m = (l + r) / 2;
		std::string res;
		out << m << std::endl;
		in >> res;
		if (res == "Vacant") return 0;
		auto kind = ans[m] = (res == "Male" ? 1 : 2);
		if ((m - l) % 2 == 0)
		{
			if (ans[l] != kind) r = m;
		}
		else
		{
			if (ans[l] == kind) r = m;
		}
		if ((r - m) % 2 == 0)
		{
			if (ans[r] != kind) l = m;
		}
		else
		{
			if (ans[r] == kind) l = m;
		}
	}
	out << l << std::endl;
	in >> tmp;
	if (tmp == "Vacant") return 0;
	out << r << std::endl;
	in >> tmp;
	return 0;
}


Measured memory_bytes: 1236
#include <stdio.h>

int main() {
  int n,m,i,j,cnt=0;
  scanf("%d",&n);
  int a[n];
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  scanf("%d",&m);
  for(i=0; i<m; i++) {
    int x;
    scanf("%d",&x);
    for(j=0; j<n; j++) {
      if(a[j]==x) {
	cnt++;
	break;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 636
n, a = map(int, input().split())
x = list(map(int, input().split()))
MAX = 50 * n

dp = [[[0] * (MAX + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1

for i, e in enumerate(x, 1):
    for j in range(i):
        for k in range(MAX + 1):
            dp[i][j][k] += dp[i-1][j][k]

    for j in range(i):
        for k in range(MAX - e + 1):
            dp[i][j+1][k+e] += dp[i-1][j][k]

ans = 0
for cnt in range(1, n + 1):
    sm = cnt * a
    ans += dp[n][cnt][sm]

print(ans)


Measured memory_bytes: 69136
#include<iostream>

using namespace std;
int main() {
	
	int N;
	int a[100000];
	int ans=0;

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

	for (int i = 0; i < N; i++) {
		if (i+1 == a[a[i]-1] ) {
			ans++;
		}
	}

	cout << ans/2 << endl;
}

Measured memory_bytes: 768
'''
Created on 2020/08/31

@author: harurun
'''
def main():
  from itertools import combinations
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  ans=0
  d=[0]*5
  for _ in [0]*N:
    S=pin()[:-1][0]
    if S=="M":
      d[0]+=1
    elif S=="A":
      d[1]+=1
    elif S=="R":
      d[2]+=1
    elif S=="C":
      d[3]+=1
    elif S=="H":
      d[4]+=1
  c=list(combinations([0,1,2,3,4],3))
  for i in c:
    cnt=1
    for j in list(i):
      cnt*=d[j] 
    ans+=cnt 
  print(ans)
  return 
main()
    
    
    
  

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

int main() {
    int N;
    cin >> N;
    int tmp = 0;
    int tmp2 = N;
    while (N != 0) {
        tmp += N % 10;
        N /= 10;
    }
    if (tmp2 % tmp == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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



int MOD=1000000007;
int main(void){
	long long N,cnt=0,p=1;
	cin >> N;
	long long a[N+10];
	for(long long i=0; i<N; i++){
		cin >> a[i];
	}
	for(long long i=0; i<N; i++){
		if(a[i]==p) p+=1;
		else cnt+=1;
	}
	if(p==1) cout << -1 << endl;
	else
	cout << cnt << endl;
}


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

int main() {
  int A;
  cin >> A;
  int B = A % 100;
  int C = A - B;
  if (B * 20 <= C){
    cout << "1" << endl;
  }
  else{
    cout << "0" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
        int n;
        int a[200];
        scanf("%d", &n);
        for(int i=0; i<n ;i++){
                scanf("%d", a+i);
        }
        int stop=0;
        int count=0;
        while(!stop){
                for(int i=0; i<n ;i++){
                        if(a[i] % 2) stop=1;
                }
                if(!stop){
                        count++;
                        for(int i=0; i<n ;i++){
                                a[i]/=2;
                        }
                }

                for(int i=0; i<n ;i++){
                        //printf("%d ",a[i]);
                }
        }
        printf("%d",count);

        return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  unordered_map<char, long> mp;
  for (auto it: S) mp[it]++;

  long min_num = mp['a'];
  min_num = min(min_num, mp['b']);
  min_num = min(min_num, mp['c']);

  mp['a'] -= min_num;
  mp['b'] -= min_num;
  mp['c'] -= min_num;

  vector<long> foo;
  foo.push_back(mp['a']);
  foo.push_back(mp['b']);
  foo.push_back(mp['c']);
  sort(foo.begin(), foo.end());

  bool ans = true;

  if (foo[2] >= 2) ans = false;

  cout << (ans ? "YES" : "NO") << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 512
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <cassert>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=(a%10/5)+(a%5), a/=10; return res;}

int n, me[100001], a[100];

bool dfs(int k, bool fs) {
  //cout<<k<<" "<<fs<<endl;
  if (me[k] >= 0) {
    //cout<<"  "<<k<<" "<<fs<<" "<<(me[k] ^ !fs)<<endl;
    return me[k] ^ !fs; // true ^ (!true) →true
  }
  for(int i=0;i<n;i++) {
    if (k - a[i] < 0) break;
    if (dfs(k - a[i], !fs) == fs) {
      me[k] = true;
      //cout<<"  "<<k<<" "<<fs<<" "<<(me[k] ^ !fs)<<endl;
      return me[k] ^ !fs;
    }
  }
  me[k] = false;
  //cout<<"  "<<k<<" "<<fs<<" "<<(me[k] ^ !fs)<<endl;
  return me[k] ^ !fs;
}

int main() {
  int k; cin>>n>>k;
  for(int i=0;i<n;i++) {
    cin>>a[i];
  }
  fill(me,me+100001,-1); // その人が勝つならtrue
  if (dfs(k,true)) {
    cout<<"First"<<endl;
  } else {
    cout<<"Second"<<endl;
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 11764
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	Vi a(3);
	int ans=0;
	cin >>a[0]>>a[1]>>a[2];
	sort(all(a));
	cout<<(a[0]*a[1]/2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    unsigned long long int a,b,c,d,e=100;
    scanf("%lld",&a);
    scanf("%lld.%lld",&b,&c);
    d=a*b+a*c/e;
    cout<<d<<endl;
    return 0;
}


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

int main() {
  int s;
  cin >> s;
  int a = s/100, b = s%100;
  bool yymm = false, mmyy = false;
  if (b >= 1 && b <= 12) {
    yymm = true;
  }
  if (a >= 1 && a <= 12) {
    mmyy = true;
  }
  if (yymm && mmyy) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (yymm) {
    cout << "YYMM" << endl;
  }
  else if (mmyy) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "NA" << endl;
  }
  return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int A[n];
  rep(i, n) cin >> A[i];

  vector<int> B(n+2);
  B[0] = 0;
  rep(i, n) B[i+1] = (B[i] + A[i]) % m;
  B[n+1] = m;
  sort(B.begin(), B.end());

  ll count = 0;
  int i, j;
  i = 0; j = -1;
  while (j < n) {
    while (B[++j] == B[i]) {}
    ll tmp = j-i;
    count += tmp*(tmp-1)/2;
    i = j;
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s;
    cin >> t;

    long long shead = 0;
    long long time = 0;
    for (char x : t) {
        int pos = s.find(x);
        if (pos == -1) {
            cout << -1 << endl;
            return 0;
        }
        int ppos = s.substr(shead).find(x);
        if (ppos == -1) {
            time += 1;
            shead = pos + 1;
        } else {
            shead += ppos + 1;
        }
    }
    cout << (time * s.size() + shead) << endl;
    return 0;
}

    

Measured memory_bytes: 640
class Array
  def imos
    n = size

    ret = map(&:dup)

    (n - 1).downto(0) do |i|
      (n - 2).downto(0) do |j|
        ret[i][j] += ret[i][j + 1]
      end
    end

    (n - 2).downto(0) do |i|
      (n - 1).downto(0) do |j|
        ret[i][j] += ret[i + 1][j]
      end
    end

    ret
  end
end

def f(v)
  cnt_2 = 0
  cnt_5 = 0

  while (v % 2) == 0 && cnt_2 < 18
    cnt_2 += 1
    v /= 2
  end

  while (v % 5) == 0 && cnt_5 < 18
    cnt_5 += 1
    v /= 5
  end

  cnt_2 = 18 if 18 < cnt_2
  cnt_5 = 18 if 18 < cnt_5

  [cnt_2, cnt_5]
end

M = 10 ** 9
N = gets.to_i
A = N.times.map { gets.chomp }

table = Array.new(19) { Array.new(19, 0) }

A.each do |a|
  nums = a.split('.')

  n = if nums.size == 1
        nums[0].to_i * M
      else
        l = nums[1].size
        nums[0].to_i * M + nums[1].to_i * (10 ** (9 - l))
      end
  cnt_2, cnt_5 = f(n)

  table[cnt_2][cnt_5] += 1
end

table = table.imos
ans = 0

A.each do |a|
  nums = a.split('.')

  n = if nums.size == 1
        nums[0].to_i * M
      else
        l = nums[1].size
        nums[0].to_i * M + nums[1].to_i * (10 ** (9 - l))
      end
  cnt_2, cnt_5 = f(n)

  ni = 18 - cnt_2
  nj = 18 - cnt_5

  if 9 <= cnt_2 && 9 <= cnt_5
    ans -= 1
  end

  ans += table[ni][nj]
end

puts ans / 2


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

#define M (1 << 24)

int func(int P, int n, int k, int w[]) {
    int P_tmp = 0, k_tmp = 0;
    for(int i = 0; i < n; i++) {
        if(w[i] > P) return 0;
        if(P_tmp + w[i] > P) {
            k_tmp++;
            if(k_tmp == k) return 0;
            P_tmp = w[i];
        } else {
            P_tmp += w[i];
        }
    }
    return 1;
}

int main() {
    int n, k, w[100010];
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> w[i];
    }

    int left = 1, right = 2000000000, P;

    while(left < right) {
        int mid = (left + right) / 2;

        if(func(mid, n, k, w) == 1) {
            right = mid;
        } else {
            left = mid + 1;
        }
        if(func(left, n, k, w) == 1) {
            P = left;
            break;
        }
    }
    cout << P << endl;
    return 0;
}


Measured memory_bytes: 3488
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(N);
    double ave=0;
    for(int i=0; i<N; i++){
        cin >> x.at(i);
        ave += x.at(i);
    }
    ave /= N;
    int a = round(ave);
    
    int sum=0;
    for(int i=0; i<N; i++){
        sum += pow(x.at(i)-a,2);
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] A = new int[n];
		for(int i=0;i<n;i++){
			A[i] = in.nextInt();
		}
		int q = partition(A,0,n-1);
		for(int i = 0;i<n;i++){
			if(i>0)System.out.print(" ");
			if(i==q)System.out.print("[");
			System.out.print(A[i]);
			if(i==q)System.out.print("]");
		}
		System.out.println("");
	}
	
	public static int partition(int[] A,int p,int r){
		int x = A[r];
		int i = p-1;
		for(int j=p;j<r;j++){
			if(A[j]<=x){
				i = i +1;
				int temp = A[i];
				A[i] = A[j];
				A[j] = temp;
			}
		}
		int current = A[i+1];
		A[i+1] = A[r];
		A[r] = current;
		return i+1;
	}
}

Measured memory_bytes: 71812
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n;
	cin>>n;
	vi co(3);
	rep(i,n){
		int a;cin>>a;
		co[a%3]++;
	}
	int out=1;
	if(co[1]){
		int s=co[1],t=co[2];
		s--;
		int r=min(s,t);
		int c=1+co[0]+r*2;
		c+=min(t-r,1);
		c+=min(s-r,2);
		out=max(out,c);
	}
	if(co[2]){
		int s=co[2],t=co[1];
		s--;
		int r=min(s,t);
		int c=1+co[0]+r*2;
		c+=min(t-r,1);
		c+=min(s-r,2);
		out=max(out,c);
	}
	cout<<out<<endl;
}













Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,X,Y,ans;
  cin >> A >> B >> C >> X >> Y;
  int mi = min(X,Y);
  if(A+B > 2*C){
    X -= mi;
    Y -= mi;
    ans = mi * 2 * C;
    if(X)ans = min(ans + X*A,ans + 2*C*X);
    if(Y)ans = min(ans + Y*B,ans + 2*C*Y);
  }
  else ans = A * X + B * Y;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int 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 F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int k,x;cin>>k>>x;
  for(int i=-k+1;i<=k-1;i++){
    cout<<x+i<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,cntr[4005],cntg[4005],cntb[4005];
char s[maxn];
char t[3] = {'R','G','B'};
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	scanf("%s",s+1);
	for(int i = 1;i <= n;i++){
		if(s[i] == 'R'){
			cntr[i] = cntr[i-1] + 1;
			cntg[i] = cntg[i-1];
			cntb[i] = cntb[i-1];
		}
		else if(s[i] == 'G'){
			cntr[i] = cntr[i-1];
			cntg[i] = cntg[i-1] + 1;
			cntb[i] = cntb[i-1];
		}
		else{
			cntr[i] = cntr[i-1];
			cntg[i] = cntg[i-1];
			cntb[i] = cntb[i-1] + 1;
		}
	}
	ll ans = 0;
	for(int i = 1;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			if(s[i] != s[j]){
				int d = j - i;
				char ch;
				rep(k,0,2) if(t[k] != s[i] && t[k] != s[j]) ch = t[k];
				if(ch == 'R') ans += (cntr[n] - cntr[j]);
				else if(ch == 'G') ans += (cntg[n] - cntg[j]);
				else if(ch == 'B') ans += (cntb[n] - cntb[j]);
				if(j + d <= n && s[j + d] == ch) ans -= 1;
			}
		}
	}
	cout << ans << endl;
	return 0; 
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 3736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	string s; cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i,n){
		repr(j,1,n-i+1){
			string t = s.substr(i,j);
			bool ok = true;
			rep(k,t.size()){
				if(t[k] != 'A' && t[k] != 'T' && t[k] != 'C' && t[k] != 'G') ok = false;
			}
			if(ok) ans = max(ans,j);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256