akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}

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

int main(){
    ll A, B, C, K;
    cin >> A>>B>>C>>K;
    if(abs(A-B) > 1000000000000000000){
        cout << "Unfair" << endl;
    }
    else{
        if(K%2 == 0){
            cout << A - B << endl;
        }
        else{
            cout << B - A << endl;
        }
    }
}


Measured memory_bytes: 256
import sys
def calc(a,b,c,d):
    return a*b + c*d
N, M, K = map(int, sys.stdin.readline().strip().split())
if N*M / 2 < K:
    K = N*M -K
for n in xrange(N+1):
    for m in xrange(M+1):
        if calc(n,m,N-n,M-m) == K:
            print 'Yes'
            exit(0)
print 'No'

Measured memory_bytes: 2568
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from itertools import accumulate

def circle_sum_max(circle,num):
    n = len(circle)
    s = sum(circle)
    if num == 0:
        ans = 0
    elif num == 1:
        ans = max(circle)
    else:
        ac = list(accumulate([0]+circle))

        l = 0
        r = 1
        ans = ac[r]-ac[l]
        i = 0
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+num+1].index(max(ac[r+1:l+num+1])) + r+1
            else:
                l = ac[l+1:r].index(min(ac[l+1:r])) + l+1
            i+=1
            ans = max(ans,ac[r]-ac[l])
 
        num = n-num
        l = 0
        r = num
        i = 0
        ans = max(ans,s-ac[r]+ac[l])
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+n].index(min(ac[r+1:l+n])) + r+1
            else:
                l = ac[l+1:r-num+1].index(max(ac[l+1:r-num+1])) + l+1
            i+=1
            ans = max(ans,s-ac[r]+ac[l])
    return ans
 

n,k = readints()
p = [x-1 for x in readints()]
c = readints()

circles = []
used = [0]*n

for i in range(n):
    if not used[i]:
        circles.append([c[i]])
        used[i] = 1
        j = p[i]
        while not used[j]:
            circles[-1].append(c[j])
            used[j] = 1
            j = p[j]

score = -10**20

for cir in circles:
    m = len(cir)
    a = sum(cir)
    if k>m:
        if a>0:
            score = max(score, (k//m)*a + circle_sum_max(cir,k%m), (k//m-1)*a + circle_sum_max(cir,m))
        else:
            score = max(score,circle_sum_max(cir,m))
    else:
        score = max(score,circle_sum_max(cir,k))

print(score)










Measured memory_bytes: 10020
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    a, b, c, d = ril()
    x = [a, b]
    y = [c, d]
    if a <= 0 and 0 <= b:
        x.append(0)
    if c <= 0 and 0 <= d:
        y.append(0)
    ans = max([i * j for i in x for j in y])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
S = [0]*4

for i in range(N):
  s = str(input())
  if(s=="AC"):
    S[0]+= 1
  elif(s=="WA"):
    S[1]+= 1
  elif(s=="TLE"):
    S[2]+= 1
  else:
    S[3] += 1

print("AC x "+ str(S[0]))
print("WA x "+ str(S[1]))
print("TLE x "+ str(S[2]))
print("RE x "+ str(S[3]))

#print(S)



Measured memory_bytes: 72072
# coding=utf-8

c = []

for _ in range(3):
    line = list(map(lambda x:int(x), input().split(" ")))
    c.append(line)

if not (c[0][0]-c[1][0] == c[0][1]-c[1][1] == c[0][2]-c[1][2]):
    print("No")
    exit()

if not (c[1][0]-c[2][0] == c[1][1]-c[2][1] == c[1][2]-c[2][2]):
    print("No")
    exit()

if not (c[2][0]-c[0][0] == c[2][1]-c[0][1] == c[2][2]-c[0][2]):
    print("No")
    exit()

if not (c[0][0]-c[0][1] == c[1][0]-c[1][1] == c[2][0]-c[2][1]):
    print("No")
    exit()

if not (c[0][1]-c[0][2] == c[1][1]-c[1][2] == c[2][1]-c[2][2]):
    print("No")
    exit()

if not (c[0][2]-c[0][0] == c[1][2]-c[1][0] == c[2][2]-c[2][0]):
    print("No")
    exit()

print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

string s;

int main() {
cin>>s;
for(int i=0;i<s.length()-8;i++)
cout<<s[i];
cout<<endl;


    return 0;
           }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=100000000000000000;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF = 0x3f3f3f3f ;
#define PII pair<int,int>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
vi v;

int main() 
{
    int n,x;
    si(n);
    
    for(int i=0;i<n;i++){
        si(x);
        v.pb(x);
    }
    
    sort(all(v));
    
    int N = v[n-1];
    double val = (N*1.0000)/2.0;
    int mn=INT_MAX,ans;
    
    for(int i=0;i<n;i++){
        if(abs(val - v[i]) < mn){
            mn=abs(val - v[i]);
            ans=v[i];
        }
    }
    
    cout<<N<<" "<<ans<<endl;
    return 0;
}

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

int main() {
  long long a,b,k;
  cin>>a>>b>>k;
  if(a>=k)cout<<a-k<<" "<<b<<endl;
  else if(a+b>k)cout<<0<<" "<<a+b-k<<endl;
  else cout<<0<<" "<<0<<endl;
}

Measured memory_bytes: 256
result = input()
n = int(result)
input_list = [input() for i in range(n)]

answer_dict = {}

answer_list = ['AC', 'WA', 'TLE', 'RE']

for i in answer_list:
    answer_dict[i] = 0

for i in input_list:
    answer_dict[i] += 1
        
for key in answer_list:
    item_num = answer_dict[key]
    print(f"{key} x {item_num}")

Measured memory_bytes: 16284
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

void Solve() {
  lint N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  
  map<lint, lint> memo;
  priority_queue<pair<lint, lint>, vector<pair<lint, lint>>, greater<pair<lint, lint>>> pq;

  pq.emplace(0, N);
  memo[N] = 0;

  auto Relax = [&](lint n, lint cost) {
    if (n < 0) return;
    if (n <= 100 && memo.count(n) == 0 || memo[n] > cost) {
      memo[n] = cost;
      pq.emplace(memo[n], n);
    }
    if (n == 0) return;
    if (n % 2 == 0) {
      lint c = min(A, lint((1ll * n / 2) <= (1e18 / D) ? (1ll * n / 2) * D : 1e18));
      if (memo.count(n / 2) == 0 || memo[n / 2] > cost + c) {
        memo[n / 2] = cost + c;
        pq.emplace(memo[n / 2], n / 2);
      }
    }
    if (n % 3 == 0) {
      lint c = min(B, lint((2ll * n / 3) <= (1e18 / D) ? (2ll * n / 3) * D : 1e18));
      if (memo.count(n / 3) == 0 || memo[n / 3] > cost + c) {
        memo[n / 3] = cost + c;
        pq.emplace(memo[n / 3], n / 3);
      }
    }
    if (n % 5 == 0) {
      lint c = min(C, lint((4ll * n / 5) <= (1e18 / D) ? (4ll * n / 5) * D : 1e18));
      if (memo.count(n / 5) == 0 || memo[n / 5] > cost + c) {
        memo[n / 5] = cost + c;
        pq.emplace(memo[n / 5], n / 5);
      }
    }
  };

  while (!pq.empty()) {
    lint n = pq.top().second;
    lint cost = pq.top().first;
    pq.pop();
    if (n == 0) {
      cout << cost << "\n";
      return;
    }
    if (cost > 1e18) continue;
    if (memo[n] != cost) continue;

    bool split = 0;
    Relax(n, cost);
    for (lint i = 1; i <= 5; i++) {
      Relax(n + i, cost + i * D);
      Relax(n - i, cost + i * D);
    }
  }
}

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

  int T;
  cin >> T;
  while (T--) {
    Solve();
  }
}

Measured memory_bytes: 8928
import itertools

#a=itertools.product([0,1],repeat=N)

N = int(input())
AAA = [[] for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        AAA[i].append([int(k) for k in input().split()])


for ifkind in itertools.product([1,0],repeat=N):
    consistent = True
    for i,A in enumerate(AAA):
        if ifkind[i]==1:
            for x,y in A:
                x=x-1
                if ifkind[x]!=y:
                    consistent = False
    if consistent==True:
        print(sum(ifkind))
        break


Measured memory_bytes: 9152
#include<bits/stdc++.h>
//#include<cstdio>
#define ll long long
using namespace std;
int main()
{
   long long  n;
    cin>>n;
    string a;
    long long x1=0,x2=0,x3=0,x4=0,x5=0;
    long long ans=0;
    for(int i=1;i<=n;++i)
    {

        cin>>a;
        if(a[0]=='M')x1++;
        if(a[0]=='A')x2++;
        if(a[0]=='R')x3++;
        if(a[0]=='C')x4++;
        if(a[0]=='H')x5++;
    }
    if(x1==0&&x2==0&&x3==0&&x4==0&&x5==0){
            cout<<0;return 0;}
    else{
        long long k=(x1+x2+x3+x4+x5);
        if(k<=2){
                cout<<0;return 0;}
 if(k>=3){
        ans=(k*(k-1)*(k-2))/6;
       // cout<<ans<<"sdsa"<<endl;
        if(x1>=2){
            if(x1==2)ans-=(k-x1);
                if(x1>2){
                    ans-=(x1*(x1-1)*(x1-2))/6;
                    ans-=( (x1*(x1-1))/2  )*(k-x1);
                }
        }
         if(x2>=2){
            if(x2==2)ans-=(k-x2);
                if(x2>2){
                    ans-=(x2*(x2-1)*(x2-2))/6;
                    ans-=( (x2*(x2-1))/2  )*(k-x2);
                }
        }
         if(x3>=2){
            if(x3==2)ans-=(k-x3);
                if(x3>2){
                    ans-=(x3*(x3-1)*(x3-2))/6;
                    ans-=( (x3*(x3-1))/2  )*(k-x3);
                }
        }
         if(x4>=2){
            if(x4==2)ans-=(k-x4);
                if(x4>2){
                    ans-=(x4*(x4-1)*(x4-2))/6;
                    ans-=( (x4*(x4-1))/2  )*(k-x4);
                }
        }
         if(x5>=2){
            if(x5==2)ans-=(k-x5);
                if(x5>2){
                    ans-=(x5*(x5-1)*(x5-2))/6;
                    ans-=( (x5*(x5-1))/2  )*(k-x5);
                }
        }

      }
    }
    if(ans<=0)cout<<0<<endl;
    else cout<<ans<<endl;
}


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

namespace AtCoder
{
	public class Program
	{
		static long mod = 1000000007;

		static int n;
		static int k;
		static int[] a;

		static bool[] dp;

		static void Main(string[] args)
		{
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			n = vs[0];
			k = vs[1];
			a = Console.ReadLine().Split().Select(int.Parse).ToArray();

			dp = new bool[k + 1];
			for (int i = 1; i <= k; i++) {
				for (int j = 0; j < a.Length; j++) {
					if (i - a[j] >= 0) {
						dp[i] |= !dp[i - a[j]];
					}
				}
			}
			Console.WriteLine(dp[k] ? "First" : "Second");
		}
	}
}

Measured memory_bytes: 13396
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
N = int(input())

def solve(s = "", used = 0, depth = 0):
  if len(s) == N:
    print(s)
    return
  
  for i in range(min(used + 2, depth + 1)):
    #if used + 1 < i:
    #  break
    solve(s + chars[i], max(used, i), depth + 1)

solve()


Measured memory_bytes: 4340
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	ll flag = 1;
	ll index = 0;
	rep(i,0,a){
		if(s[index]<'0'||s[index]>'9'){
			flag = 0;
		}
		index++;
	}
	if(s[index]!='-')flag = 0;
	index++;
	rep(i,0,b){
		if(s[index]<'0'||s[index]>'9'){
			flag = 0;
		}
		index++;
	}
	if(flag==1){
	    cout << "Yes" << endl;
	}
	else{
	    cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
    a:isize,
    b:isize,
    }
    let mut z=0;
    for i in 0..=a {
        for j in 0..=a {
            if b-i-j<=a&&0<=b-i-j{z+=1}
        }
    }
    println!("{}",z)
}

Measured memory_bytes: 2128
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int n;
	scanf("%i",&n);
	int a[n+1],b[n+1];
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&b[i]);
	}
	int c[n+1];
	for(int i=1;i<=n;i++)
	{
		c[i]=i;
	}
	int ac=1,bc=1,r1,r2;
	bool bul=false;
	do
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=c[i])
			{
				bul=true;
				break;
			}
		}
		if(bul==false)
		{
			r1=ac;
		}
		else
		{
			ac++;
		}
		bul=false;
		for(int i=1;i<=n;i++)
		{
			if(b[i]!=c[i])
			{
				bul=true;
				break;
			}
		}
		if(bul==false)
		{
			r2=bc;
		}
		else
		{
			bc++;
		}
		bul=false;
	}while(next_permutation(c+1,c+n+1));
	printf("%i",abs(r1-r2));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
// lld A[lim],B[lim],C[lim];

int main(){
    lld a = sc(), b = sc(), n = sc();
    lld x = min(b - 1, n);
    double num = x;
    num = num / b;
    lld diff = num * a;
    prL(diff);
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n, k;
  cin >> n >> k;
  vt<int> a(n);
  rep(i, 0, n) cin >> a[i];

  vvt<int> dp(n + 1, vt<int>(k + 1, 0));
  vt<int> sum(k + 2);
  sum[0] = 0;
  dp[0][k] = 1;
  rep(i, 0, n) {
    rep(j, 0, k + 1) (sum[j + 1] = sum[j] + dp[i][j]) %= mod;

    rep(j, 0, k + 1) {
      (dp[i + 1][j] = sum[min(k + 1, j + a[i] + 1)] - sum[j]) %= mod;
      if(dp[i + 1][j] < 0) dp[i + 1][j] += mod;
    }
  }

  cout << dp[n][0] << endl;
}

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

int main(){
	
	int a,b,k;
	cin>>k;
	cin>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			flag=1;
			break;	
		}	
	} 
	if(flag)
	{
		cout<<"OK";
		return 0;
	}
	cout<<"NG";
	
	return 0;
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[]A = new int[N];

		for (int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		int[] ASort = Arrays.copyOf(A, N);
		Arrays.sort(ASort);
		int max = ASort[N-1];
		int max2 = ASort[N-2];

		for (int i=0; i<N; i++){
			if (A[i] == max){
				System.out.println(max2);
			} else {
				System.out.println(max);
			}
		}
	}


}

Measured memory_bytes: 84704
inputs = gets.chomp.split.map!(&:to_i)
a = 0
if inputs[0] > inputs[3] then
  a += inputs[3]
elsif inputs[0] <= inputs[3] && inputs[1] > (inputs[3] - inputs[0]) then
  a += inputs[0]
else inputs[0] <= inputs[3] && inputs[1] <= (inputs[3] - inputs[0]) && inputs[2] <= (inputs[3] - inputs[0] - inputs[1])
  a += (inputs[0] - (inputs[3] - inputs[0] - inputs[1]))
end

puts a

Measured memory_bytes: 14380
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

dp = [None for _ in range(H*W)]
for i, l in enumerate(A) :
    for j, v in enumerate(l) :
        dp[v-1] = (i, j)

def f(p, q) :
    x, y = dp[p]
    i, j = dp[q]
    return abs(x-i)+abs(y-j)

distance = [0 for _ in range(H*W)]
for i in range(H*W) :
    if i<D :
        pass
    else :
        distance[i] = f(i-D, i) + distance[i-D]

for l, r in LR :
    print(distance[r-1]-distance[l-1])

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;


int main(){
    
    int N;
    cin>>N;
    int p[N];
    rep(i,N)cin>>p[i];

    //rep(i,N)cout<<p[i]<<endl;


    int q[N];
    rep(i,N)cin>>q[i];

    //rep(i,N)cout<<q[i]<<endl;

    long long cnt[N+1];
    cnt[0]=1;

    rep2(u,N)cnt[u]=u*cnt[u-1];


    //rep2(i,N)cout<<cnt[i]<<" ";
    bool used[N+1]={};
    long long A=0;

    rep(i,N-1){
        rep2(j,N){
            if(used[j])continue;

            if(p[i]!=j){
                A+=cnt[N-1-i];
            }
            else{
                used[j]=true;
                break;
            }
        }
    }
    //cout<<A<<endl;

    rep2(i,N)used[i]=false;

    long long B=0;

    rep(i,N-1){
        rep2(j,N){
            if(used[j])continue;
            if(q[i]!=j){
                B+=cnt[N-1-i];
            }
            else{
                used[j]=true;
                break;
            }
        }
    }
    //cout<<B<<endl;

    cout<<abs(A-B)<<endl;

return 0;

}
/*


*/


Measured memory_bytes: 256
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int D, T, S;
    cin >> D >> T >> S;
    if (T * S >= D)
    {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll qsum[300010],a[300010];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        qsum[i]=qsum[i-1]+a[i];
    }
    ll mi =1e18;
    for(int i=1;i<=n-1;i++){
        if(abs(qsum[i]-(qsum[n]-qsum[i]))<mi) {
            mi = abs(qsum[i] - (qsum[n] - qsum[i]));
        }
    }
    cout<<mi;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int a, b;
    cin >> a >> b;
    int diff = b -  a;

    int B=0;
    for (int i=1; i<=diff; i++){
        B += i;
    }
    out(B-b);
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1), b(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  b[0] = a[0];
  for (int i = 1; i < n - 1; i++) {
    b[i] = min(a[i], a[i - 1]);
  }
  b[n - 1] = a[n - 2];
  cout << accumulate(b.begin(), b.end(), 0) << '\n';
  return 0;
}


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

int main(){
  int x,ma=1,a;
  cin >> x;
  r(2,i,x){
    a=i*i;
    while(1){
      if(a>x)break;
      ma=max(ma,a);
      a*=i;
    }
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> P;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  vector<P> robots;
  int N;
  cin >> N;
  rep(i, N) {
    int x, l;
    cin >> x >> l;
    robots.push_back(P(x + l, x - l));
  }

  Sort(robots);

  int count = 0;
  int before = 0;
  rep(i, N) {
    P p = robots[i];
    if (count == 0 || before <= p.second) {
      count++;
      before = p.first;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1400
using System;


class Program
{
    public static void Main(string[] args)
    {
        int a = int.Parse(Console.ReadLine());
        string b = Console.ReadLine();
        int c = int.Parse(Console.ReadLine());

        char target = b[c -1];
        string ans = string.Empty;

        for (int i = 0; i < a;i++){
            char s = b[i];
            if (s.Equals(target)){
                ans = ans + s;  
            }else{
                ans = ans + '*';
            }
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

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

    if (a + b == c || b + c == a || c + a == b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string S;
    cin >> S;
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '0' + i % 2)
        {
            ans1++;
        }
        if (S[i] == '0' + (i + 1) % 2)
        {
            ans2++;
        }
    }

    printf("%d\n", min(S.size() - ans1, S.size() - ans2));
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> F(60010, 0);
    for(ll i=1; i<=100; i++){
        for(ll j=1; j<=100; j++){
            for(ll k=1; k<=100; k++){
                ll temp;
                temp = i*i + j*j + k*k + i*j + j*k + k*i;
                F[temp]++;
            }
        }
    }
    for(ll i=1; i<=N; i++){
        cout << F[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  int L;
  cin >> A >> B >> C; 

  L = A * B;

  if ( L < C ){
    cout << L << endl;
  } else {  
	cout << C << endl;
  } 
}

Measured memory_bytes: 3616
N, T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
  if t[i+1] > t[i] + T:
    ans += T
  else:
    ans += t[i+1] - t[i]
ans += T
print(ans)

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

int main(){
    int n;
    string s;
    string pa;
    cin>>n>>s;
    pa="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i=0;i<s.size();i++){
        for(int j=0;j<pa.size();j++){
            if(s[i]==pa[j]){
                if(j+n<pa.size()){
                    s[i]=pa[j+n];
                    break;
                }
                else{
                    s[i]=pa[j+n-26];
                    break;
                }
            }
            else{
                int unko=0;
            }

        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    b, e, t = map(int, input().split())
    s = t+e-b
    if t > b:
        a = a[:b] + a[t:s] + a[e:t] + a[b:e] + a[s:]
    else:
        a = a[:t] + a[b:e] + a[s:b] + a[t:s] + a[e:]
print(*a)


Measured memory_bytes: 5804
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
    T tmp = r;
    r = l;
    l = tmp;
}



int main() {

  string s;
  cin >> s;

  int ans = 100000;
  for(int i=2;i<s.size();i++){
    int num = (int)(s[i-2]-'0')*100 + (int)(s[i-1]-'0')*10 + (int)(s[i]-'0');
    // cerr << num << " : "<< ans << endl;

    ans = min(abs( 753 - num ),ans);
    

  }






  cout << ans;
  // cout << ((n == 3 || n==5 || n==7)? "YES" : "NO" );

  // cout <<"w:" <<w << "  h:" <<h<<endl;


}




















Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define adp(a) for(auto ii:a) cout << ii.F << " " << ii.S << endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;
#define N 200003
#define INF INTMAX_MAX

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};


ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

bool cmp(const pll &a, const pll &b)
{
    if (a.F != b.F) {
        return a.F > b.F;
    }
    else
        return a.S < b.S;
}


// bool check(ll i, ll j)
// {
//     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '#')
//         return true;
//     return false;
// }

int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        ll n, d;
        cin >> n >> d;
        ll ans = 0;
        ld b = (ld)d;
        REP(i, 0, n)
        {
            ll x, y;
            cin >> x >> y;
            ll z = x * x + y * y;
            ld a = sqrt(z);
            if (a <= b)
                ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3696
#区間スケジューリング問題

N = int(input())

robots = {}

for _ in range(N):
    X, L = list(map(int, input().split()))

    robots[X] = (X-L, X+L)

#終端が早い順にソートして、取れるものから貪欲法でとっていく

robots_sorted = sorted(robots.items(), key=lambda x:x[1][1])

ans = 1
current_robot = robots_sorted[0]

for i in range(0, N):
    if current_robot[1][1] > robots_sorted[i][1][0]:
        continue

    ans += 1
    current_robot = robots_sorted[i]


print(ans)


Measured memory_bytes: 99124
#include <iostream>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;

struct Building
{
	int index;
	int x;
	int y;

	double distanceTo(const Building& obj)
	{
		return sqrt((x-obj.x)*(x-obj.x) + (y-obj.y)*(y-obj.y));
	}
};

struct Path
{
	int connectingIndex;
	double distance;
};

struct Agent
{
	int index;
	int prev_index;
	double distance;

	bool operator<(const Agent& rhs) const
	{
		return distance > rhs.distance;
	}
};

int n, m;
Building buildings[100];
vector<vector<Path>> edges;
int prev_index[100];
priority_queue<Agent> que;
bool defined[100];

int main()
{
	while (true)
	{
		cin >> n;
		if (n == 0)
		{
			return 0;
		}

		// initialize
		edges.assign(n, vector<Path>());

		// input
		for (int i = 0; i < n; ++i)
		{
			cin >> buildings[i].index
				>> buildings[i].x
				>> buildings[i].y;
		}

		// calc distance
		for (int i = 0; i < n; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				Building A = buildings[i];
				Building B = buildings[j];
				double distance = A.distanceTo(B);
				if (distance <= 50.0)
				{
					int indexA = A.index - 1;
					int indexB = B.index - 1;
					edges[indexA].push_back(Path{ indexB, distance });
					edges[indexB].push_back(Path{ indexA, distance });
				}
			}
		}
		
		// query loop
		cin >> m;
		for (int i = 0; i < m; ++i)
		{
			int s, g;
			cin >> s >> g;

			// initialize
			que = priority_queue<Agent>();
			memset(defined, 0, sizeof defined);

			// dijkstra
			bool found_goal = false;
			que.push(Agent{ s - 1, 0 });
			while (!que.empty())
			{
				Agent agent = que.top(); que.pop();
				
				if (defined[agent.index])
				{
					continue;
				}
				defined[agent.index] = true;
				prev_index[agent.index] = agent.prev_index;

				if (agent.index == g - 1)
				{
					found_goal = true;
					break;
				}

				for (auto path : edges[agent.index])
				{
					if (!defined[path.connectingIndex])
					{
						que.push(Agent{ path.connectingIndex,
						                agent.index,
						                agent.distance + path.distance });
					}
				}
			}

			// output
			if (!found_goal)
			{
				cout << "NA" << endl;
			}
			else
			{
				vector<int> path;
				int agent = g - 1;
				while (agent != s - 1)
				{
					path.push_back(agent + 1);
					agent = prev_index[agent];
				}
				cout << s;
				for (auto itr = path.rbegin(); itr != path.rend(); ++itr)
				{
					cout << ' ' << *itr;
				}
				cout << endl;
			}
		} // end of query loop
	} // end of while
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define rg register
using namespace std;
const int MAXN=110;
int n,X[MAXN],Y[MAXN],H[MAXN];
inline int Abs(rg int A){   return A>0?A:-A;   }
inline int Max(rg int A,rg int B){   return A>B?A:B;   }
inline int Min(rg int A,rg int B){   return A<B?A:B;   }
 main()
{   scanf("%lld",&n);
	for(rg int i=1;i<=n;i++) scanf("%lld%lld%lld",&X[i],&Y[i],&H[i]);
	for(rg int Cx=0;Cx<=100;Cx++)
		for(rg int Cy=0;Cy<=100;Cy++)
		{   rg int Lim=2e9,Now=-2e9;
			for(rg int i=1;i<=n;i++)
				if(H[i]==0) Lim=Min(Lim,Abs(Cx-X[i])+Abs(Cy-Y[i]));
				else if(Now==-2e9) Now=H[i]+Abs(Cx-X[i])+Abs(Cy-Y[i]);
				else if(Now!=H[i]+Abs(Cx-X[i])+Abs(Cy-Y[i])) {   Now=-2e9;   break ;   }
			if(Now!=-2e9&&Now<=Lim&&Now>=1) printf("%lld %lld %lld\n",Cx,Cy,Now),exit(0);
		}
}


Measured memory_bytes: 256
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)なるxを返す
def modinv(a):
    (inv, q, gcd_val) = egcd(a, MOD)
    return inv % MOD

MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=1
a_m=0
a_M=0
for i in range(n-k,-1,-1):
    a_m+=a[i]*c
    a_m%=MOD
    a_M+=a[n-1-i]*c
    a_M%=MOD
    c=( c*(n-i)*modinv(n-k+1-i) )%MOD

ans=(a_M-a_m+MOD)%MOD
print(ans)

Measured memory_bytes: 14040
from itertools import combinations,permutations

N = int(input())

p_dic={}

for i in range(2,N+1):
    p=2
    while i!=1:
        c=0
        while i%p==0:
            c+=1
            i//=p
        if c>0 and p not in p_dic.keys():
            p_dic[p]=c
        elif c>0:
            p_dic[p]+=c
        p+=1

ans=0

p_keys = p_dic.keys()

for p in p_keys:
    if p_dic[p]>=74:
        ans+=1

for p,q in permutations(p_keys,2):
    i=p_dic[p]
    j=p_dic[q]
    if i>=2 and j>=24:
        ans+=1
    if i>=4 and j>=14:
        ans+=1

for p,q,r in combinations(p_keys,3):
    i,j,k = sorted([p_dic[p],p_dic[q],p_dic[r]])
    if i>=4:
        ans+=3
    elif j>=4 and i>=2:
        ans+=1
print(ans)


Measured memory_bytes: 3064
##模範を受けて自分で書いてみる
n = int(input()) 
h = list(map(int,input().split()))
cnt = 0 #移動できる分のカウンター
cnt_list =[] #移動できた分を格納しておくカウンター

for i in range(0,len(h)-1):
    if h[i] >= h[i+1]:
        cnt += 1 #移動できる場合はカウンターに＋１
    else:
        cnt_list.append(cnt) #移動できなくなったら、リストに保存。カウンターを元に戻す。
        cnt = 0
cnt_list.append(cnt)
print(max(cnt_list))

Measured memory_bytes: 14252
#include<iostream>
#include<string.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int a[55][55][70],ans[55][55],ans1[55][55],mul[70];
signed main(){
	int n,k,i,sum=0,j,l,dem;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin>>a[i][j][0];
			ans[i][j]=a[i][j][0];
		}
	}
	k--;
	mul[0]=1;
	for(l=1;l<=59;l++){
		mul[l]=mul[l-1]*2;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(dem=1;dem<=n;dem++){
					a[i][j][l]=(a[i][j][l]+a[i][dem][l-1]*a[dem][j][l-1])%mod;
				}
			}
		}
	}
	for(i=59;i>=0;i--){
		if(k>=mul[i]){
			memset(ans1,0,sizeof(ans1));
			for(j=1;j<=n;j++){
				for(l=1;l<=n;l++){
					for(dem=1;dem<=n;dem++){
						ans1[j][l]=(ans1[j][l]+ans[j][dem]*a[dem][l][i])%mod;
					}
				}
			}
			k-=mul[i];
			for(j=1;j<=n;j++){
				for(l=1;l<=n;l++){
					ans[j][l]=ans1[j][l];
				}
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			sum=(sum+ans[i][j])%mod;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 1792
def main():
    n, *a = map(int, open(0).read().split())

    sorted_a  = sorted(a)
    max_a = sorted_a[-1]
    next_max_a = sorted_a[-2]
    for cur_a in a:
        if cur_a == max_a:
            print(next_max_a)
        else:
            print(max_a)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 25036
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const map<T, S> m) { for (pair<T, S> p: m) s << p << endl; return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

int count(int a, int b) {
  if (a <= b && b < 4 * a) return 0;
  else if (a < b) {
    return -1 + count(4 * a, b);
  } else {
    return 1 + count(a, 4 * b);
  }
}
signed main() {
  int N; cin >> N;
  VI A(N);
  REP (i, N) cin >> A[i];
  VVI dp(2, VI(N));
  REP (k, 2) {
    map<int, int> mp;
    for (int i = N - 2; i >= 0; i--) {
      dp[k][i] = dp[k][i + 1];
      int dif = count(A[i], A[i + 1]);
      int pt = i;
      if (dif == 0) {
        continue;
      } else if (dif < 0) {
        mp[i] = -dif;
      } else {
        for (auto it = mp.begin(); it != mp.end(); ) {
          dp[k][i] += dif * (it->fi - pt);
          pt = it->fi;
          if (it->se <= dif) {
            dif -= it->se;
            mp.erase(it++);
          } else {
            it->se -= dif;
            dif = 0;
            break;
          }
        }
        dp[k][i] += dif * (N - 1 - pt);
      }
    }
    reverse(ALL(A));
  }
  int ans = 1e18;
  REP (i, N) {
    ans = min(ans, i + 2 * (dp[0][i] + (i == 0 ? 0 : dp[1][N - i])));
  }
  cout << ans << endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    if (x < K - x) {
      sum += 2 * x;
    }
    else {
      sum += 2 * (K - x);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int ca, cb;
int main() {
	map<char, int>  mp;
	int n;
	cin >> n;
	char a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		mp[a]++;
	}
	cout << (mp.size() == 3 ? "Three" : "Four") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int r;
	cin >> r;
	cout << 2 * r * acos(-1);
	return 0;
}

Measured memory_bytes: 3256
N = int(input())
li = list(map(int, input().split()))
ans = float('inf')
for i in li:
    cnt = 0
    if i%2==0:
        tudukeru = True
    else:
        tudukeru = False
        ans = 0
    while tudukeru:
        if i%2 == 0:
            i = i//2
            cnt += 1
        else:
            tudukeru = False
            if cnt < ans:
                ans = cnt
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;

int n;

int f(vi a, int n, int idx)
{
	vi kesu;

	for (int i = idx + 1; i < n; ++i) {
		if (a[i] != a[idx]) break;
        kesu.push_back(i);
	}
	for (int i = idx - 1; i >= 0; --i) {
		if (a[i] != a[idx]) break;
        kesu.push_back(i);
	}

    if (kesu.size() < 3) return n;

    while (!kesu.empty()) {
        a[kesu.back()] = 0;
        kesu.pop_back();
    }
    a[idx] = 0;

	vi b;

	int nextidx = -1;

	for (int i = 0; i < n; ++i) {
		if (a[i]) {
			b.push_back(a[i]);
			if (nextidx == -1 && i >= 1 && a[i - 1] == 0) {
				nextidx = b.size() - 1;
			}
		} else {
			if (nextidx == -1) {
				if (!b.empty()) {
					nextidx = i - 1;
				}
			}
		}
	}

   return f(b, b.size(), nextidx); 
}

int calc(vi a, int n, int idx)
{
	vi b = a;
	if (idx >= 3 && a[idx - 1] == a[idx - 2] && a[idx - 2] == a[idx - 3]) {
		b[idx] = b[idx - 1];
	} else if (idx <= n - 4 && a[idx + 1] == a[idx + 2] && a[idx + 2] == a[idx + 3]) {
		b[idx] = b[idx + 1];
	} else if (idx >= 2 && idx <= n - 2 && a[idx - 1] == a[idx - 2] && a[idx - 1] == a[idx + 1]) {
		b[idx] = b[idx - 1];
	} else if (idx >= 1 && idx <= n - 3 && a[idx - 1] == a[idx + 1] && a[idx - 1] == a[idx + 2]) {
		b[idx] = b[idx - 1];
	} else {
		return n;
	}

	return f(b, b.size(), idx);
}

int main()
{
	while (cin >> n, n) {
        vi arr;

        for (int i = 0; i < n; ++i) {
            int a; cin >> a;
            arr.push_back(a);
        }

        int mi = 10001;

        for (int i = 0; i < n; ++i) {
            mi = min(mi, calc(arr, arr.size(), i));
        }

        cout << mi << endl;
    }
}

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

int main() {
  char a;
  cin >> a;
  string boin = "aeiou";
  string result = "consonant";
  
  for (int i = 0; i < boin.size(); i++) {
    if (a == boin.at(i)) {
      result = "vowel";
      break;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3636
S = [int(a) for a in input()[::-1]]
m = 2019
N = len(S)
s = 0
p = 1
X = [0] * 2019
X[0] = 1
ans = 0
for a in S:
    s = (s + a * p) % m
    ans += X[s]
    X[s] += 1
    p = p * 10 % m

print(ans)

Measured memory_bytes: 10824
import sys
input = sys.stdin.buffer.readline
import itertools

def main():
    N,K = map(int,input().split())
    if K > (N-1)*(N-2)//2:
        print(-1)
    else:
        ans = [(1,i+2) for i in range(N-1)]
        rest = (N-1)*(N-2)//2-K
        l = [i+2 for i in range(N-1)]
        c = 0
        for v in itertools.combinations(l,2):
            if c == rest:
                break
            else:
                ans.append(v)
                c += 1
        print(len(ans))
        for a,b in ans:
            print(a,b)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
int dig(long long a){
  int dig = 0;
  while(a != 0){
    dig++;
    a /= 10;
  }
  return dig;
}
int main(){
  long long n;
  cin >> n;
  int mn = 11;
  for(long long i = 1; i <= sqrt(n); i++){
    if(n % i == 0){
      mn = min(mn, max(dig(n / i),dig(i)));
    } 
  }
  cout << mn << endl;
}


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

typedef long long ll;


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

ll n,k;
ll tot;
vector<ll> a;

ll f(ll m) {
  for(int i = 0; i < n; i++) {
    ll l = -1, r = n;
    if(a[i] < 0) {
      while(r - l > 1) {
	ll mid = (l + r) / 2;

      if(a[i] * a[mid] < m) r = mid; else l = mid;
      }
      tot += n - r;
      if(a[i] * a[i] < m) tot--;
    }
    else {
      while(r - l > 1) {
	ll mid = (l + r) / 2;
	if(a[i] * a[mid] < m)l = mid; else r = mid;
      }
      tot += r;
      if(a[i] * a[i] < m) tot--;
    }
  }
  tot /= 2;
}

    
int main() {
 
  cin >> n >> k;
 
  for(int i = 0; i < n; i++) {
    ll A;
    cin >> A;
    a.push_back(A);
  }

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

  ll L = -INF, R = INF;

  while(R - L > 1) {
    ll mid = (L + R) / 2;
 
    tot = 0;
    f(mid);
    if(tot < k) L = mid; else R = mid;
  }

  cout << L << endl;
}
  
  


Measured memory_bytes: 2420
//A - Not
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define INF 0x3f3f3f3f
using namespace std;

int x;

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

int main() {
    // File();
    cin>>x;
    cout<<(x ^ 1);
    // fclose(stdin);
    // fclose(stdout);
   // system("pause");
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		try (Stream<String> lines = new BufferedReader(new InputStreamReader(System.in)).lines()) {
			new Main().exec(lines.toArray(String[]::new));
		}
	}

	void exec(String[] args) {
		Map<Integer, ArrayList<Boolean>> map = new HashMap<>();
		IntStream.rangeClosed(1, Integer.parseInt(args[0].split(" ")[1]))
			.forEach(i -> {
				String[] ia = args[i].split(" ");
				map.computeIfAbsent(Integer.valueOf(ia[0]), k -> new ArrayList<>()).add("AC".equals(ia[1]));
			});
		int[] rs = map.values().stream()
			.map(l -> new int[]{l.contains(true) ? 1 : 0, Math.max(l.indexOf(true), 0)})
			.collect(() -> new int[2], (a1, a2) -> {a1[0] += a2[0]; a1[1] += a2[1];}, (a1, a2) -> {a1[0] += a2[0]; a1[1] += a2[1];});
		System.out.println(rs[0] + " " + rs[1]);	
	}

}

Measured memory_bytes: 61228
table={}
import sys
input=sys.stdin.readline
n=int(input())
ss=[]
for i in range(n):
	s=input().rstrip()
	if s in table:
		table[s]+=1
	else:
		table[s]=1
		ss.append(s)
ans=[]
saidai=max(table.values())
for i in range(len(ss)):
	if table[ss[i]]==saidai:
		ans.append(ss[i])
ans.sort()
for x in ans:
	print(x)

Measured memory_bytes: 33416