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

bool exp(int num) {
  int l = 1;
  for (int k = 2; k <= sqrt(num); k++) {
    while (1) {
      l *= k;
      if (l == num) return true;
      if (l > num) break;
    }
    l = 1;
  }
  return false;
}

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

  for (int k = x; k > 0; k--) {
    if (exp(k)) {
      cout << k << endl;
      return 0;
    }
  }

  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int B= sc.nextInt();
		int data[] =new int[3];
		data[0]=N-B;
		data[1]=N*B;
		data[2]=N+B;
		int max=-100;
		for(int i=0;i<3;i++) {
			if(max<data[i]) {
				max=data[i];
			}
			
		}
				
		
		
		
		System.out.println(max);
		
	}

}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ran 111111
int n;
vector<int> e[ran];
bool f[ran];
int p1[ran],lp1;
int p2[ran],lp2;
void expand(int*p,int&l){
	while(true){
		int x = p[l-1];
		bool flag = true;
		for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){
			int y = *it;
			if(f[y])continue;
			p[l++] = y;
			f[y] = true;
			flag = false;
			break;
		}
		if(flag)break;
	}
}
int main(){
	int x,y,m;
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	p1[lp1++] = x;
	p2[lp2++] = y;
	f[x] = f[y] = true;
	expand(p1, lp1);
	expand(p2, lp2);
	printf("%d\n",lp1+lp2);
	for(int i=lp1-1; i>=0; i--)
		printf("%d ",p1[i]);
	for(int i=0; i<lp2; i++)
		printf("%d%c",p2[i],i<lp2-1?' ':'\n');
	return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ll N,Y;
  cin >> N >> Y;
  REP(i,N+1){
    REP(j,N+1){
      if(N - i - j < 0) continue;
      if(10000*i + 5000*j + 1000*(N-i-j) == Y){
	cout << i << " " << j << " " << N-i-j << endl;
	exit(0);
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
//D - Selection Sort Aizu - ALDS1_2_B 
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, i, j, minIndex;
	int count = 0;
	cin >> n;
	int a[n];
	for(i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	for(i = 0 ; i < (n -1) ; i++) //¸øµÚ0~n-2¸öÎ»ÖÃÕÒ×îÐ¡Öµ
	{
		minIndex = i;
		for(j = i + 1 ; j < n ; j++){
			if(a[j] < a[minIndex]){
				minIndex = j;
			}
		} 
		if(i != minIndex){
			swap(a[i], a[minIndex]);
			count++;
		}
	} 
	cout << a[0];
	for(i = 1; i < n ; i++)
	{
		cout << " " << a[i];
	}
	cout << endl << count << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll H,W;
    cin >> H >> W;
    vector<vector<ll>>c(10,vector<ll>(10));
    for(ll i=0;i<10;i++){
        for(ll j=0;j<10;j++){
            cin >> c[i][j];
        }
    }
    vector<vector<ll>>dp=c;
    for(ll i=0;i<10;i++){
        for(ll j=0;j<10;j++){
            for(ll k=0;k<10;k++){
                dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++){
            ll a;
            cin >> a;
            if(a>=0) ans+=dp[a][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "Hello World";
        return 0;
    }
    else
    {
        int a, b;
        cin >> a >> b;

        cout << a + b;
    }
}

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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    rep(i,10)rep(j,10)rep(k,10){
        int num = 0;
        rep(l,n){
            if(num == 0 && s[l] == '0'+i) num = 1;
            else if(num == 1 && s[l] == '0'+j) num = 2;
            else if(num == 2 && s[l] == '0'+k){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

void queen(int);
void print(void);

#define N 8
#define NOT_FREE 1
#define FREE 0

int col[N],dpos[2*N],dneg[2*N],row[N];
int board[N][N];

int main(){
  int i,num,j;
  int a,b;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      col[i] = dpos[i] = dneg[i]= row[i] = 0;
      board[i][j] = FREE;
    }
  }

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d%d",&a,&b);
    board[a][b] = NOT_FREE;
  }


  queen(0);

  // print();
      
  return 0;

}


void queen (int i){
  int j;
  
  if( i == N ){
    print();
    return;
  }

  for(j=0;j<=N-1;j++){
    if(col[j] == NOT_FREE ||
       dpos[i+j] == NOT_FREE ||
       dneg[i-j+N-1] == NOT_FREE){
      continue;
    }

    //put a queen at(i,j)
    //board[i][j] = NOT_FREE;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;

    /*for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	printf("%d ",board[i][j]);
      }
      printf("\n");
    }
    */
    //try the next row
    
    queen(i+1);

    //remove the queen at(i,j) for backtracking

    //printf("2\n");
    //board[i][j] == FREE;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;

  }
}
    

    
void print(void){
  int i,j;

  //満していないものを弾く
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(board[i][j] == NOT_FREE){
	if(row[i] != j) return;
      }
    }
  }
      
  
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}



Measured memory_bytes: 2692
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    string S;
    int Q;
    cin >> S >> Q;

    ll flag = 0;
    int t,f;
    string c;
    string left = "";
    string right = "";
    for (int i=0; i<Q; ++i)
    {
        cin >> t;
        if(t==1)
        {
            ++flag;
        }
        else
        {
           cin >> f >> c;
           if((f==1 && flag%2==0) || (f==2 && flag%2!=0))
           {
            //    S = c + S;   //遅い！！！
               left += c;
           }
           else if((f==2 && flag%2==0) || (f==1 && flag%2!=0))
           {
               S += c;
           }
        }
    }

    
    if(flag%2==0) 
    {
        reverse(left.begin(),left.end());
        cout << left+S << endl;
    }
    else
    {
        reverse(S.begin(), S.end());
        cout << S + left << endl;
    }

    return 0;
}

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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (B == C) {
		cout << A << endl;
	}
	else if (A == C) {
		cout << B << endl;
	}
	else if (A == B) {
		cout << C << endl;
	}

}





Measured memory_bytes: 3592
from sys import stdin

def get_result(data):
  N = data[0]
  # n円の場合、n+1円の場合
  dp = 0, 1
  for n in N:
      n = int(n)
      # N=123の1を考える
      # 100円を払うケース (1枚)
      # or 1000円払っていて + お釣り分の900円を払うケース (9枚)
      a = min(dp[0] + n, dp[1] + 10 - n)
      # 200円を払うケース (2枚) 
      # or 1000円払っていて + お釣り分の800円を払うケース (8枚, 下の桁によって減るケース)
      b = min(dp[0] + n + 1, dp[1] + 10 - (n + 1))
      dp = a, b
  return dp[0]

if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip('\n').split(' ')))
    result = get_result(data)
    print(result)


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


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

  int N, L;
  cin >> N >> L;
  int A[N];
  rep(i, N) cin >> A[i];
  {
    bool ok = false;
    for(int i=0; i<N-1; i++){
      if(A[i]+A[i+1] >= L){
        ok = true;
      }
    }
    if(!ok){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
  vector<int> ans;
  for(int i=0; i<N-1; i++){
      if(A[i]+A[i+1] >= L){
        ans.push_back(i);
        break;
      }
  }
  for(int i=ans[0]+1; i<N-1; i++){
    ans.push_back(i);
  }
  for(int i=ans[0]-1; i>=0; i--){
    ans.push_back(i);
  }
  reverse(ans.begin(), ans.end());
  for(int i=0; i<len(ans); i++){
    cout << ans[i]+1 << endl;
  }
}


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 5e5 + 1e3;

char str[N]; int fail[N], len;

void Get_Fail(char *str, bool *Pass) {
	For (i, 2, len) {
		static int j;
		for (j = fail[i - 1]; j && str[j + 1] != str[i]; j = fail[j]);
		fail[i] = j + (str[j + 1] == str[i]);
	}
	For (i, 1, len)
		if (!fail[i] || i % (i - fail[i])) Pass[i] = true;
}

bool f[N], g[N];

int main () {

	scanf ("%s", str + 1);

	len = strlen(str + 1);
	Get_Fail(str, f);
	reverse(str + 1, str + len + 1);
	Get_Fail(str, g);
	reverse(g + 1, g + len + 1);

	if (f[len])
		return puts("1\n1"), 0;

	int ans = 0;
	For (i, 1, len - 1)
		if (f[i] && g[i + 1]) ++ ans;
	if (ans) printf ("2\n%d\n", ans);
	else printf ("%d\n1", len);

	return 0;

}


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

using namespace std;

string s;
typedef unsigned long long ull;

ull sum;

int main()
{
    cin>>s;
    ull ls = s.length();
    sum = 0;

    for(ull i = 0; i<ls; i++){
        
        if(s[i] == '0'){
        	sum+=0;
        }
        if(s[i] == '1'){
        	sum+=1;
        }
        if(s[i] == '2'){
        	sum+=2;
        }
        if(s[i] == '3'){
        	sum+=3;
        }
        if(s[i] == '4'){
        	sum+=4;
        }
        if(s[i] == '5'){
        	sum+=5;
        }
        if(s[i] == '6'){
        	sum+=6;
        }
        if(s[i] == '7'){
        	sum+=7;
        }
        if(s[i] == '8'){
        	sum+=8;
        }
        if(s[i] == '9'){
        	sum+=9;
        }
    }

    if(sum % 9 == 0 || sum == 0){
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3708
s = input()

sLst = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',\
        'o','p','q','l','s','t','u','v','w','x', 'y', 'z']
ansLst = []

for i in sLst:
    if s.count(i) == 0:
        ansLst.append(i)

if len(ansLst) == 0:
    print('None')
else:
    ansLst.sort()
    print(ansLst[0])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define sfi(a) scanf("%d",&a)
#define m_p make_pair
#define inf 1e9
#define ff first
#define ss second
#define pi(x) pair<x,x>
#define mem(x) memset(x,-1,sizeof(x))
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int sz = 20;
const ld pi = acos(-1);
int arr[10];

bool check(int n){
    bool flag = true;
    while(n!=0){
        int d = n%10;
        if(arr[d]==1){flag = false;break;}
        n -= d;
        n /= 10;
    }
    return flag;
}

int fun(int val,int n){
    int ret = val - n;
    if(check(ret) && check(n)) return n;
    else return -1;
}

int main()
{
    int n,k;
    cin >> n >> k;
    while(k--){
        int x; cin >> x;
        arr[x] = 1;
    }
    int val = n;
    while(fun(val,n)==-1) n++;
    int ans = n;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int INF=(int)1e9;
const int MOD=(int)1e9+7;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    s=s[s.size()-1]+s;
    s.pop_back();
    if(s==t){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int d[101];
int a[101][101];
bool flag[101];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d",&d[i]);
		for(int j=0;j<d[i];j++){
			scanf("%d",&a[i][j]);
			a[i][j]--;
			flag[a[i][j]]=true;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(!flag[i]){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3836
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b<c)swap(b,c);
  if(a<b)swap(a,b);
  if(a==7&&b==5&&c==5){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;

int main(){
        ll n;
        scanf("%lld", &n);
        std::vector<ll> a(n);
        for(ll i=0; i<n; i++) scanf("%lld", &a[i]);
        std::vector<ll> b(a);
        std::sort(b.begin(), b.end());

        int med = (b[n/2-1]+b[n/2])/2;
        for(ll i: a) printf("%lld\n", b[n/2-(i>med)]);
        return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  long int n;
  long int a[200000]={};
  int i,j;

  scanf("%ld",&n);
  for(i=1;i<n;i++)
  {
    scanf("%d",&j);
    a[j]++;
  }

  for(i=1;i<n;i++)
  {
    printf("%ld\n",a[i]);
  }
  printf("0\n");

  return 0;
}


Measured memory_bytes: 3284
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    t = list(input())

    flg = False
    for i in range(len(s) - len(t), -1, -1):
        tmp_flg = True
        for j in range(len(t)):
            if not (s[i + j] == t[j] or s[i + j] == "?"):
                tmp_flg = False
                break
        if tmp_flg:
            s = s[:i] + t + s[i + len(t):]
            flg = True
            break

    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"

    if flg:
        print(*s, sep="")
    else:
        print("UNRESTORABLE")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
int n,ans;
set<int> S;
int main()
{
	scanf("%d",&n);
	for(int i=1,a;i<=n;++i)
	{
		scanf("%d",&a);
		if(S.find(a)!=S.end())--ans,S.erase(a);
		else ++ans,S.insert(a);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4864
n ,m = map(int, input().split())
a = [[int(j) for j in input().split()] for i in range(n)]
need = []
for i in range(n):
    need.append(a[i][1:])
ans = set(need[0])
for i in range(n):
    d = set(need[i])
    ans = ans & d
print(len(ans))

Measured memory_bytes: 3064
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    h = list(map(int, input().split()))
    ans = 0
    move = 0
    for i in range(1, n):
        if h[i] <= h[i - 1]:
            move += 1
            ans = max(ans, move)
        else:
            move = 0
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19124
package main
import (
  "fmt"
  "container/list"
)
const INF = 1<<30
func main() {
  var n int
  var s string
  fmt.Scan(&n)
  g := make([][]int,n)
  d := make([][]int,n)
  for i:=0;i<n;i++ {
    d[i] = make([]int,n)
    fmt.Scan(&s)
    for j,r := range s {
      if j != i { d[i][j] = INF }
      if r == '1' {
        g[i] = append(g[i],j)
        g[j] = append(g[j],i)
        d[i][j] = 1
      }
    }
  }
  c := make([]int,n)
  q := list.New()
  c[0] = 1
  q.PushBack(0)
  for q.Len() > 0 {
    i,_ := q.Remove(q.Front()).(int)
    for _,j := range g[i] {
      if c[j] == c[i] { fmt.Println(-1);return }
      if c[j] == 0 {
        c[j] = -c[i]
        q.PushBack(j)
      }
    }
  }
  for k:=0;k<n;k++ {
    for i:=0;i<n;i++ {
      for j:=0;j<n;j++ {
        if d[i][j] > d[i][k]+d[k][j] { d[i][j] = d[i][k]+d[k][j] }
      }
    }
  }
  m := 0
  for i:=0;i<n;i++ {
    for j:=0;j<n;j++ {
      if m < d[i][j] { m = d[i][j] }
    }
  }
  fmt.Println(m+1)
}

Measured memory_bytes: 2688
#include<iostream>
using namespace std;
int main() {
  int n,d,x; cin >> n >> d >> x;
  int count=0;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    int t=1;
    while(t<=d){
      count++;
      t += a;
    }
  }
  cout << count + x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int debt = 100000;

int main() {
    int n;

    cin >> n;

    while (n--) {
        debt = ceil(debt * 1.05 / 1000) * 1000;
    }

    cout << debt << endl;

    return 0;
}

Measured memory_bytes: 1164
# -*- coding: utf-8 -*-
###########　入力
K, N = map(int, input().split())
A = list(map(int, input().split()))

minDistance = K

for i in range(1, N-1):
    next_left = i - 1
    next_right = i + 1
    #前隣に遠回り
    d1 = A[i] - A[next_left]
    if d1 > K/2:
        d1 = K - d1
    d1 = K - d1
    #次隣に遠回り
    d2 = A[next_right] - A[i]
    if d2 > K/2:
        d2 = K - d2
    d2 = K - d2
    if d1 < minDistance:
        minDistance = d1
    if d2 < minDistance:
        minDistance = d2

#A0とAnの距離
d = abs(A[N-1] - A[0])
if d > K/2:
    d = K - d

if K-d < minDistance:
    minDistance = K-d

###########　出力
print(minDistance)

Measured memory_bytes: 26444
#!/usr/bin/env python3
#B
import numpy as np
import math
import re

n = int(input())

x = input()
y = input()
x = re.split(" ",x)
y = re.split(" ",y)
sum = 0
for i in range(n):
    if(( int(x[i]) - int(y[i]) )> 0):
        sum +=  int(x[i]) - int(y[i])
print(sum)


Measured memory_bytes: 21916
N = int(input())
length = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if length[i]<length[j]+length[k] and length[j] < length[i] + length[k] and length[k] < length[j] + length[i]:
                if length[i]!=length[j] and length[i]!= length[k] and length[j]!=length[k]:
                    ans += 1
print(ans//6)

Measured memory_bytes: 68296
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

#include <map>
using namespace std;
const int MAXN = 2e5;
map <int, int> cnt;
int a[MAXN];
int main() {
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];

    }
    int cnt = 0;
    for (int i = 1; i <= n + 1; i++) {
        if (a[i] == i) {
            cnt++;      
        } else {
            ans += (cnt + 1 ) / 2;
            cnt = 0;
        }
    }
    cout << ans;
    return 0;
}


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

int main(){
  int n = 0, m = 0, c = 0,count=0,total=0;
  cin >> n >> m >> c;
  int b[m] = {0};
  int a[n][m] = {(0,0)};
  for(int i=0;i<m;i++){
    cin >> b[i];     
  }  

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  } 
  for(int i=0;i<n;i++){  
    total = 0;
    for(int j=0;j<m;j++){
    total+=a[i][j]*b[j];  
    }
    if(total+c > 0) count++;
  } 
  cout << count << endl;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

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

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vector<vector<int>> f(n, vector<int>(10));
	vector<vector<int>> p(n, vector<int>(11));
	
	rep(i, n) {
		rep(j, 10) cin >> f[i][j];
	}
	rep(i, n) {
		rep(j, 11) cin >> p[i][j];
	}
	
	ll ans = -INF;

	for (int i = 1; i < (1 << 10); ++i) {
		int cnts[10] = { 0 };
		rep(j, 10)
			if ((i >> j) & 1) cnts[j] = 1;

		vector<int> scores(n);
		rep(j, n) {
			rep(k, 10) {
				if (cnts[k] && f[j][k]) scores[j]++;
			}
		}

		ll tmp = 0;
		rep(j, n) {
			tmp += p[j][scores[j]];
		}

		ans = max(ans, tmp);
		// cout << tmp << endl;

	}
	cout << ans << endl;
}

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

minus_num = [i for i in A if i < 0]
abs_num = map(abs, A)
min_num = min(abs_num)

for i in range(N):
    if A[i] < 0:
        A[i] = -A[i]

if len(minus_num) % 2 != 0:
    A.append(min_num * -2)

print(sum(A))


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
int arr[105];
int main() {
	int n ;cin>>n;
	for(int i = 0; i < n; i++)
		cin>>arr[i+1];
	for(int i = 1 ; i<= n ;i++)
		arr[i]+=arr[i-1];
	int ans = 1e6;
	for(int i = 1 ; i< n; i++){
		ans = min(ans , (int)abs(arr[i] -(arr[n] - arr[i])));
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll L;
ll A[MAX_N];

void solve() {
	cin >> N >> L;
	rep(i, 0, N) cin >> A[i];
	int at = -1;
	rep(i, 0, N - 1) {
		if(A[i] + A[i + 1] >= L) {
			at = i;
			break;
		}
	}
	if(at == -1) {
		cout << "Impossible\n";
	}
	else {
		cout << "Possible\n";
		rep(i, 0, at) cout << i + 1 << "\n";
		rer(i, N - 1, at + 1) cout << i + 1 << "\n";
		cout << at + 1 << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1664
import sys
h1a,m1a,s1a,h2a,m2a,s2a=map(int,input().split())
h1b,m1b,s1b,h2b,m2b,s2b=map(int,input().split())
h1c,m1c,s1c,h2c,m2c,s2c=map(int,input().split())
if(s2a<s1a):
    sa=(60+s2a)-s1a
    m2a=m2a-1
else:
    sa=s2a-s1a
if(m2a<m1a):
    ma=(60+m2a)-m1a
    h2a=h2a-1
else:
    ma=m2a-m1a
ha=h2a-h1a
if(s2b<s1b):
    sb=(60+s2b)-s1b
    m2b=m2b-1
else:
    sb=s2b-s1b
if(m2b<m1b):
    mb=(60+m2b)-m1b
    h2b=h2b-1
else:
    mb=m2b-m1b
hb=h2b-h1b
if(s2c<s1c):
    sc=(60+s2c)-s1c
    m2c=m2c-1
else:
    sc=s2c-s1c
if(m2c<m1c):
    mc=(60+m2c)-m1c
    h2c=h2c-1
else:
    mc=m2c-m1c
hc=h2c-h1c
print(str(ha)+' '+str(ma)+' '+str(sa))
print(str(hb)+' '+str(mb)+' '+str(sb))
print(str(hc)+' '+str(mc)+' '+str(sc))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> L) {
  ll ans(0);
  REP(k, N) {
    REP(j, k) {
      REP(i, j) {
	if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i])
	  continue;
	if (L[i] + L[j] <= L[k] || L[j] + L[k] <= L[i] || L[k] + L[i] <= L[j])
	  continue;
	ans++;
      }
    }
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> L(N);
  REP(i, N) {
    cin >> L[i];
  }

  solve(N, move(L));

  return 0;
}


Measured memory_bytes: 3652
import Data.List
import Data.Char
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS8
import qualified Data.Vector as Vector
import Data.Vector ((!))

main :: IO ()
main = do
  [n, d] <- unfoldr (BS8.readInt . BS8.dropWhile isSpace) <$> BS8.getLine
  p <- replicateM n $ unfoldr (BS8.readInt . BS8.dropWhile isSpace) <$> BS8.getLine

  print $ length $ filter (\a -> a <= fromIntegral d) $ map (\[x, y] -> fromIntegral(x^2+y^2) ** 0.5) p


Measured memory_bytes: 56492
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,k;
    cin>n>k;
    //int s=0,a=0;
    double s=0;
    REP(i,1,n+1){
        int a=i,b=1;
        while(a<k){b<<=1;a<<=1;}
        //cerr<b<endl;
        s+=1.0/b;
    }
    //cout<<s/n<<endl;
    printf("%.16f\n",s/n);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int t;
	int a,b,c;
	scanf("%d",&t);
	a=t/3600;
	b=(t-a*3600)/60;
	c=t-a*3600-60*b;
	printf("%d:%d:%d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
int n,a,b,c;
char ga[100005][5],ans[100005];
 
signed main()
{
	cin>>n>>a>>b>>c;
	for (int i=1;i<=n;i++)  cin>>ga[i][1]>>ga[i][2];
	
	for (int i=1;i<=n;i++)
	{
		if (ga[i][1]=='A'&&ga[i][2]=='B')
		{
			if (a<b)
			{
				a++,b--;
				ans[i]='A';
			}
			else if (a>b)
			{
				a--,b++;
				ans[i]='B';
			}
			else if (a==b)
			{
				if (ga[i+1][1]=='A'||ga[i+1][2]=='A')
				{
					a++,b--;
					ans[i]='A';
				}
				else
				{
					a--,b++;
					ans[i]='B';
				}
			}
		}
		if (ga[i][1]=='A'&&ga[i][2]=='C')
		{
			if (a<c)
			{
				a++,c--;
				ans[i]='A';
			}
			else if (a>c)
			{
				a--,c++;
				ans[i]='C';
			}
			else if (a==c)
			{
				if (ga[i+1][1]=='A'||ga[i+1][2]=='A')
				{
					a++,c--;
					ans[i]='A';
				}
				else
				{
					a--,c++;
					ans[i]='C';
				}
			}
		}
		if (ga[i][1]=='B'&&ga[i][2]=='C')
		{
			if (b<c)
			{
				b++,c--;
				ans[i]='B';
			}
			else if (b>c)
			{
				b--,c++;
				ans[i]='C';
			}
			else if (b==c)
			{
				if (ga[i+1][1]=='B'||ga[i+1][2]=='B')
				{
					b++,c--;
					ans[i]='B';
				}
				else
				{
					b--,c++;
					ans[i]='C';
				}
			}
		}
		if (a<0||b<0||c<0)  return cout<<"No"<<endl,0;
	}
	cout<<"Yes"<<endl;
	for (int i=1;i<=n;i++)  cout<<ans[i]<<endl;

	return 0;
}

Measured memory_bytes: 4228
// https://atcoder.jp/contests/abc143/tasks/abc143_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    sort(ALL(v));
    REP(i, n) FOR(j, i + 1, n) FOR(k, j + 1, n) {
        if (v[i] + v[j] > v[k])
            sum++;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
	int x,y;

	cin >> x >> y;

	if (x > y){
		cout << "a > b" << "\n";
	}
	else if (x < y){
		cout << "a < b" <<"\n";
	}
	else if(x == y){
		cout << "a == b" <<"\n";
	}

}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int A[5];

int main(void) {
    scanf("%d %d %d", &A[0], &A[1], &A[2]);
    sort(A, A+3);
    REP(i, 0, 2) {
    	ans += (A[i+1] - A[i]);
    }
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

template <class T>
class cumulativeSum
{
private:
    int ny, nx;
    vector<vector<T> > sum;
public:
    cumulativeSum(const vector<vector<T> >& a)
    {
        ny = a.size();
        nx = a[0].size();
        sum.assign(ny+1, vector<T>(nx+1, 0));
        for(int i=0; i<ny; ++i){
            for(int j=0; j<nx; ++j){
                sum[i+1][j+1] = a[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
            }
        }
    }
    T getSum(int y1, int x1, int y2, int x2)
    {
        y1 = max(y1, 0);
        x1 = max(x1, 0);
        y2 = min(y2, ny);
        x2 = min(x2, nx);
        if(y1 >= y2 || x1 >= x2)
            return 0;
        return sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];
    }
};

bool solve(const vector<vector<int> >& cnt, int len)
{
    int d = cnt.size();
    int a = len / d;
    int b = len % d;

    vector<vector<int> > v1(2*d, vector<int>(2*d, 0));
    vector<vector<int> > v2(2*d, vector<int>(2*d, 0));
    for(int i=0; i<2*d; ++i){
        for(int j=0; j<2*d; ++j){
            int y = i % d;
            int x = j % d;
            if((a + 1) * (a + 1) < cnt[y][x])
                return false;

            if(a * a < cnt[y][x]){
                ++ v1[i][j];
                if(a * (a + 1) < cnt[y][x])
                    ++ v2[i][j];
            }
        }
    }

    cumulativeSum<int> cs1(v1), cs2(v2);
    for(int y=0; y<d; ++y){
        for(int x=0; x<d; ++x){
            if(cs1.getSum(y+b, x+b, y+d, x+d) == 0 && cs2.getSum(y+b, x, y+d, x+b) == 0 && cs2.getSum(y, x+b, y+b, x+d) == 0)
                return true;
        }
    }
    return false;
}

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

    vector<vector<int> > cnt(d, vector<int>(d, 0));
    for(int i=0; i<n; ++i){
        int x, y;
        cin >> x >> y;
        y %= d;
        x %= d;
        ++ cnt[y][x];
    }

    int left = 1;
    int right = 1000 * d;
    while(left < right){
        int mid = (left + right) / 2;
        if(solve(cnt, mid))
            right = mid;
        else
            left = mid + 1;
    }
    cout << (left - 1) << endl;

    return 0;
}


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



int main() {
    string s;
    cin >> s;
    
    rep(i,s.size()) {
        if((i % 2 == 0 && s[i] == 'L') ||
           (i % 2 == 1 && s[i] == 'R')) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>

int main()
{
    char S[10];

    gets(S);

    if(strcmp(S, "Sunny")==0)printf("Cloudy");
    if(strcmp(S, "Cloudy")==0)printf("Rainy");
    if(strcmp(S, "Rainy")==0)printf("Sunny");

    return 0;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;



int main() {
	int N;
	cin >> N;
	vector<int> v(N + 1, 0);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int s = (x * x + y * y + z * z + x * y + y * z + z * x);
				if (s <= N) {
					v[s]++;
				}
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		cout << v[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  long long n,k,i,j=1,a,b,c=0,d[40],r=1,sum[40]={};
  scanf("%lld %lld",&n,&k);
  d[0]=k;
  for(i=k;i;i/=2){
    if(k&j)d[r++]=(k-j)|(j-1);
    j*=2;
  }
  //for(i=0;i<r;i++)printf("%lld\n",d[i]);
  //printf("%lld\n",j);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&a,&b);
    for(j=0;j<r;j++){
      if((d[j]|a)==d[j])sum[j]+=b;
    }
  }
  //for(i=0;i<r;i++)printf("%lld\n",sum[i]);
  for(i=0;i<r;i++)sum[0]=sum[0]<sum[i]?sum[i]:sum[0];
  printf("%lld\n",sum[0]);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 2e5 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int arr[maxn], N, left[maxn], right[maxn], stk[maxn], top;
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    N = read();
    for (ri i = 1; i <= N; ++i)
        arr[i] = read();
    for (ri i = 1; i <= N; ++i) {
        while (top && arr[stk[top]] >= arr[i]) {
            --top;
        }
        left[i] = stk[top] + 1;
        stk[++top] = i;
    }
    stk[0] = N + 1, top = 0;
    for (ri i = N; i >= 1; --i) {
        while (top && arr[stk[top]] >= arr[i]) {
            --top;
        }
        right[i] = stk[top] - 1;
        stk[++top] = i;
    }
    int ans = 0;
    for (ri i = 1; i <= N; ++i) {
        ans += (i - left[i] + 1) * arr[i] * (right[i] - i + 1);
    }
    writeln(ans);
    return 0;
}

Measured memory_bytes: 6528
from itertools import permutations

n = int(input())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
p = tuple(p_list)
q = tuple(q_list)
l = list(range(1,n+1))
s = list(permutations(l))
ans = abs(s.index(p)-s.index(q))
print(ans)

Measured memory_bytes: 8052
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int n,m;
  scanf("%d%d",&n,&m);

  int ans=-1;
  int ok=1;
  int a[4];
  for(int i=0;i<4;i++) a[i]=-1;
  int s,c;
  //矛盾ないかチェック
  for(int i=0;i<m;i++){
    scanf("%d%d",&s,&c);
    if(a[s-1]>-1 && a[s-1]!=c) ok=0;
    //printf("%d\n",a[i]);
    a[s-1]=c;}
  //先頭の桁
  if(n>1 && a[0]==0) ok=0;
  if(ok){
    if(n==1 && a[0]==-1){
      ans=0;
      printf("%d\n",ans);
      return 0;}
    ans=0;
    for(int i=0;i<n;i++){
      ans*=10;
      if(a[i]==-1){
	if(i==0) ans+=1;}
      else{
	ans+=a[i];}}
  }
  else ans=-1;
  printf("%d\n",ans);

  return 0;
  
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int k = Integer.parseInt(br.readLine());
        
        String sub;
        Set<String> subs = new HashSet(); 
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j <= s.length() && j <= i+5; j++) {
                if (j == s.length()) {
                    sub = s.substring(i);
                }
                else {
                    sub = s.substring(i, j);
                }
                
                subs.add(sub);
            }
        }
        
        List<String> list = new ArrayList<>(subs);
        Collections.sort(list);
        
        
        System.out.println(list.get(k-1));
    }
}


Measured memory_bytes: 24500
s = list(input().rstrip())
t = list(input().rstrip())

alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
            "q","r","s","t","u","v","w","x","y","z"]
for i in range(len(s)):
    s[i] = alphabet.index(s[i])
for i in range(len(t)):
    t[i] = alphabet.index(t[i])
s.sort()
t.sort()
t.reverse()
flg = "Yes"
check = 0
for j in range(min(len(s),len(t))):
    if t[j] > s[j]:
        check = 1
        break
    elif t[j] < s[j]:
        flg = "No"
        check = 1
        break
if check == 0:
    if len(s) >= len(t):
        flg = "No"
print(flg)

Measured memory_bytes: 62048
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int N, M; cin >> N >> M;
    vec A(N), B(N);
    pairs p(N);
    REP(i, N){
        cin >> A[i] >> B[i];
        p[i] = Pii(A[i], B[i]);
    }
    Sort(p);
    int ans = 0;
    REP(i, N){
        int t = min(p[i].second, M);
        ans += p[i].first * t;
        M -= t;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<functional>
#include<limits.h>
#include<numeric>

using namespace std;
int main()
{
	long long int l,n,sum=0,pos;
	cin>>n>>l;
	long long int *a=new long long int[n];
	long long int *b=new long long int[n];
    long long int min=INT_MAX;
    for(long long int i=0;i<n;i++)
	{
		a[i]=std::abs(l+(i+1)-1);
		b[i]=l+(i+1)-1;
		//cout<<a[i]<<endl;
	}
	for(long long int i=0;i<n;i++)
	{
		if(    (std::abs(a[i]))    <     min  )
		{
			pos=i;
			min=a[i];
		}

	sum+=b[i];
	}
	cout<<sum-b[pos]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
	string S;
	cin>>S;
	LL ans=0;
	LL now=0;
	REP(i,S.size()){
		if(S[i]=='B'){
			now++;
		}else{
			ans+=now;
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int N, K; cin >> N >> K;

  vector <bool> dig(10);
  
  for (int i = 0; i < K; i++){
    int D; cin >> D;
    dig[D] = true;
  }
  
  int ans = N;
  while (ans < 1000000){
    bool flag = true;

    int num = ans;
    while (num > 0){
      int D = num % 10;
      if (dig[D] == true){
        flag = false;
        break;
      }
      num = num / 10;
    }
    
    if (flag == true){
      break;
    }else{
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N = 2*1e5+5;

int vis[N];
vector<int> g[N];

int cmp = 0;
void DFS(int u){

    vis[u] = 1;
    cmp++;
    int cmp = 1;
    for(int i = 0; i<g[u].size(); i++){
        int v = g[u][i];
        if(!vis[v]) DFS(v);
    }
    return;
}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m, u, v; cin >>n >>m;
    for(int i = 0; i<m; i++){
        cin >>u >>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int ans = 1;
    for(int i = 1; i<=n; i++){
        if(!vis[i]){
            cmp = 0;
            DFS(i);
            ans = max(ans, cmp);
        }
    }

    cout <<ans <<endl;

    return 0;
}


Measured memory_bytes: 21600
#include <stdio.h>

int main(void) {
	int a, b, t;
	scanf("%d %d %d", &a, &b, &t);
	int i;
	int count = 0;
	int base = a;
	for (i = 1; i <= t; i++) {
		a = base * i;
		if (a <= t) {
			count++;
		} else {
			break;
		}
	}
	printf("%d\n", b * count);
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    int p[N];
    REP(i, N) cin >> p[i];
    bool tmp[N];
    REP(i, N){
        tmp[i] = (i+1==p[i]?true:false);
    }
    int res = 0;
    REP(i, N){
        if(tmp[i]){
            res++;
            if(i<N-1){
                tmp[i+1] = false;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 768
n=int(input())
s=input()

num_w=0
num_e=s[1:].count('E')
ans=num_e
for i in range(n):
	if i == 0:
		continue
	if s[i]=='E':
		num_e-=1
	if s[i-1]=='W':
		num_w+=1
	ans=min(ans, num_w+num_e)
print(ans)

Measured memory_bytes: 3740