akhauriyash/Code-Regression huggingface dataset:
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define MAX 305

ld dp[MAX][MAX][MAX];
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;

    dp[0][0][0] = 0;

    for (int k = 0; k <= n; k++) {
        for (int j = 0; j <= n; j++) {
            for (int i = 0; i + j + k <= n; i++) {
                if (i + j + k == 0) {
                    continue;
                }

                ld sum1 = (ld)n / (ld)(i + j + k);
                ld sum2 = 0;
                if (i != 0) {
                    sum2 += dp[i - 1][j][k] * i;
                }

                if (j != 0) {
                    sum2 += dp[i + 1][j - 1][k] * j;
                }

                if (k != 0) {
                    sum2 += dp[i][j + 1][k - 1] * k;
                }

                sum2 /= (i + j + k);

                dp[i][j][k] = sum1 + sum2;
            }
        }
    }

    ll a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        if (x == 1) {
            a++;
        } else if (x == 2) {
            b++;
        } else {
            c++;
        }
    }

    cout << fixed << setprecision(9) << dp[a][b][c] << "\n";
}


Measured memory_bytes: 436480
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fl first
#define fr second
using namespace std;
  
typedef long long LL;
typedef pair<int, int> pii;
const int N = 20000 + 5;

int n, a[N], b[N], p[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
    for (int i = 1; i <= n; i++)
    {
        a[i] = 30000 * i;
        b[i] = 30000 * (n - i + 1);
    }
    for (int i = 1; i <= n; i++) a[p[i]] -= n - i + 1;
    for (int i = 1; i <= n; i++) printf("%d ", a[i]);
    printf("\n");
    for (int i = 1; i <= n; i++) printf("%d ", b[i]);
    return 0;
}


Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

int i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
 int n,k; cin>>n>>k; string s;
 cin>>s;
  s[k-1]=s[k-1]-'A'+'a';
  cout<<"\n"<<s;	
}

Measured memory_bytes: 256
n, l = input().split()

def apple_aji(i):
  return int(l) + int(i) - 1

def remove_min(p):
  minimun = min(list(map(abs, p)))
  if minimun not in p:
    minimun = minimun * -1
  p.remove(minimun)
  return p

def apple_pie(n):
  ajis = [apple_aji(x) for x in n]
  return sum(remove_min(ajis))

print(apple_pie(range(1, int(n)+1)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
// -----------------------------------------------

class DSU{    
public:
	vector<int> id, sz;
    DSU(int n) {
        id = vector<int> (n+5);
        sz = vector<int> (n+5);
        for (int i = 0; i < n+5; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    int find_root(int x) {
        while (id[x] != x) {
            id[x] = id[id[x]];
            x = id[x];
        }
        return x;
    }
    void Union(int v, int u) {
        int root_v = find_root(v);
        int root_u = find_root(u);
        if (sz[root_v] > sz[root_u]) {
            sz[root_v] += sz[root_u];
            id[root_u] = id[root_v];
        }else {
            sz[root_u] += sz[root_v];
            id[root_v] = id[root_u];
        }
    }
    bool connected(int u, int v){
        return (find_root(u) == find_root(v));
    }
};

signed main(){

    fastIO

    int t = 1;
    // cin >> t;
    while (t--){
   		int n, m;
   		cin >> n >> m;
   		DSU dsu(n + 10);
   		vector<pair<int, int>> p;
   		for (int i = 0, a, b; i < m; i++) {
   			cin >> a >> b;
   			p.emplace_back(a, b);
   			if (dsu.find_root(a) != dsu.find_root(b)) {
   				dsu.Union(a, b);
   			}
   		}
   		int ans = 1;
   		for (auto it : p) {
   			int a = it.ff;
   			int rt = dsu.find_root(a);
   			ans = max(ans, dsu.sz[rt]);
   		}
   		cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10520
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
const ll mod=1e9+7;
inline void adjust(ll &x)
{
	if(x>=mod)
	{
		x-=mod;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int a[m+1];
	bool cnt[n+1];
	memset(cnt,false,sizeof(cnt));
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		cnt[a[i]]=true;
	}
	ll dp[n+1];
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(cnt[i])
		{
			dp[i]=0;
		}
		else
		{
			if(i>=1)
			{
				dp[i]+=dp[i-1];
			}
			if(i>=2)
			{
				dp[i]+=dp[i-2];
			}
			adjust(dp[i]);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int main(void)
{
    int n, m;
    string x;
    int data[4][14];

    rep(i, 4)
        rep(j, 14)
            data[i][j] = 0;

    cin >> n;
    rep(i, n) {
        cin >> x >> m;
        if (x == "S") {
            ++data[0][m];
        }
        else if (x == "H") {
            ++data[1][m];
        }
        else if (x == "C") {
            ++data[2][m];
        }
        else if (x == "D") {
            ++data[3][m];
        }
    }

    for (int i = 0;i < 4;++i) {
        switch (i) {
        case 0:x = "S"; break;
        case 1:x = "H"; break;
        case 2:x = "C"; break;
        case 3:x = "D"; break;
        }
        for (int j = 1;j <= 13;++j) {
            if (data[i][j] == 0)
                cout << x << " " << j << endl;
        }
    }
}



Measured memory_bytes: 3148
# Vacation
dp=[0,0,0]
n=int(input())
for i in range(n):
    a,b,c=map(int,input().split())
    #ｘに進める大きい方を採用しておけばいい
    dp = [max(dp[1],dp[2])+a, #aに進める選択肢のうち大きい方
          max(dp[0],dp[2])+b,
          max(dp[1],dp[0])+c]
print(max(dp))
"""
i 日目にとりうる選択肢が何通りかあって、
愚直に全探索すると O(2n)O(2n) とか O(3n)O(3n) とか O(Kn)O(Kn) とかになる場面では
「dp[ i ] := 最初の i 日間での最適解」の形の DPの検討はアリ。
"""

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int N,M,p[101][101],K,l[101],a[101][101];
//double dx,dy,dz,sx,sy,sz,a,b,c,p,q,r;
//long long int l[51],sum;
//double t,lt;
int main(){
    while(1){
        cin >>N ;
        if (N == 0)break;

        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                a[i][j] = 0;
            }
        }

        for(int i=1;i<=N;i++){
            cin >> M;
            for (int j=1;j<=M;j++){
            cin >>p[i][j];
            a[i][p[i][j]] = 1;
            }
        }
        cin >> K ;
        for (int i=1;i<=K;i++){
            cin >> l[i];
        }
        int cnt = 0;
        int ans = -1;
        for (int i=1;i<=N;i++){
            int know = 1;
            for (int j=1;j<=K;j++){
                know = know *  a[i][l[j]];
            }
            if (know ==  1){
                cnt++;
                ans = i;
            }

        }
        if(cnt >1)ans = -1;
        cout <<ans <<endl;
    }

}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
 
void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<pii >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

const int maxn = 302;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int f[maxn][maxn][maxn],n,m;
vec s[maxn];

void add(int &x,int y) {x+=y;if(x>mod) x-=mod;}

int check(int r,int g,int b) {
    int now=max(r,max(g,b));
    for(int i=0,L=s[now].size()-1;i<=L;i++) {
        int l=s[now][i].fr,x=s[now][i].sc;
        int p=(r>=l)+(g>=l)+(b>=l);
        if(p!=x) return 1;
    }return 0;
}

int main() {
    read(n),read(m);
    for(int i=1,l,r,x;i<=m;i++) read(l),read(r),read(x),s[r].pb(mp(l,x));
    f[0][0][0]=1;int ans=0;
    for(int r=0;r<=n;r++)
        for(int g=0;g<=n;g++)
            for(int b=0;b<=n;b++) {
                if((r==g||r==b||g==b)&&((!r)+(!g)+(!b))<2) continue;
                if(check(r,g,b)) continue;
                int k=max(r,max(g,b))+1;
                add(f[k][g][b],f[r][g][b]);
                add(f[r][k][b],f[r][g][b]);
                add(f[r][g][k],f[r][g][b]);
                if(k==n+1) add(ans,f[r][g][b]);
            }write(ans);
    return 0;
}


Measured memory_bytes: 107904
import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
// ?¨??????\???????????????????????????????????????
Scanner sc = new Scanner(System.in); int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++)
{
values[i] = i + 1;
}
for (int i = 0; i < n; i++)
{
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1;
int b = Integer.parseInt(ab[1]) - 1;

int c = values[a];
values[a] = values[b];
values[b] = c;
}
for(int i = 0;i < values.length;i++)
{
System.out.println(values[i]);
}
}
}

Measured memory_bytes: 26212
#include<stdio.h>

int main(){
  int W,H,x,y,r,A,B;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  A = W-r;
  B = H-r;
  if(r <= x){
    if(x <= A){
      if(r <= y){
        if(y <= B){
          printf("Yes\n");}
        else{
          printf("No\n");}}
      else{
        printf("No\n");}}
     else{
       printf("No\n");}}
  else{
    printf("No\n");}
  return 0;}

Measured memory_bytes: 584
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int n = int.Parse(Console.ReadLine());
		var h = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		
		int counter = 0;
		int highest = 0;
		
		for(int a=0; a!=n; a++){
			if(h[a] >= highest){
				counter++;
				highest = h[a];
			}
		}
		
		Console.WriteLine(counter);
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
}

Measured memory_bytes: 13396
#include<stdio.h>
int main(void){
int a,b,k;
scanf("%d%d%d",&k,&a,&b);
  for(int i=a;i<=b;i++){
	if(i%k==0)
    {
      printf("OK");
               return 0;
              }
  }
printf("NG");
  return 0;
}

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

int main(){
    int N,K;

    cin >> N >> K;

    int B[N] = {};//0で初期化できるらしい

    for(int i=0;i<K;i++){
        int d;
        cin >> d;

        int A[d];
        for(int r=0;r<d;r++){
            cin >> A[r];

            B[A[r]-1] = 1;
        }
    }

    int sum =0;

    for(int i=0;i<N;i++){
        if(B[i] == 0){
            sum++;
        }
    }

    cout << sum << endl;
}

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

using namespace std;

const double EPS = 1e-6;

int main() {
	double a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f) {
		double det = a * e - d * b;
		double x = (c * e - b * f) / det, y = (a * f - d * c) / det;
		x = round(x * 1000) / 1000;
		y = round(y * 1000) / 1000;
		if(signbit(x) && abs(x - 0) < EPS) x *= -1;
		if(signbit(y) && abs(y - 0) < EPS) y *= -1;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0;
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    int kai=0;
    n=n%12;
    rep(i,n){
        if(kai==0){
            a=a-b;
            kai=1;
        }
        else{
            b=a+b;
            kai=0;
        }
    }
    cout<<a<<" "<<b<<endl;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int t[N<<1],nxt[N<<1],lst[N],l;
void add(int x,int y) {t[++l]=y;nxt[l]=lst[x];lst[x]=l;}

int n,deg[N],q[N],val[N],mx[N],ans,dis;
bool ban[N];
char c[N];

void dfs(int x,int y) {
	val[x]=c[x]=='W';
	rep(i,x)
		if (t[i]!=y&&!ban[t[i]]) {
			dfs(t[i],x);
			val[x]^=1;ans+=2;
		}
	if (y) val[x]^=1;
	ans+=val[x];val[x]=val[x]==1?2:0;
	int m=0,sm=0;
	rep(i,x)
		if (t[i]!=y&&!ban[t[i]]) {
			if (mx[t[i]]>=m) sm=m,m=mx[t[i]];
			else sm=max(sm,mx[t[i]]);
		}
	mx[x]=m+val[x];
	dis=max(dis,m+sm+val[x]);
}

int main() {
	n=read();
	fo(i,1,n-1) {
		int x=read(),y=read();
		add(x,y);add(y,x);
		deg[x]++;deg[y]++;
	}
	scanf("%s",c+1);
	int hd=0,tl=0;
	fo(i,1,n) if (c[i]=='B'&&deg[i]==1) q[++tl]=i;
	while (hd<tl) rep(k,q[++hd]) if ((--deg[t[k]])==1&&c[t[k]]=='B') q[++tl]=t[k];
	if (tl==n) {puts("0");return 0;}
	fo(i,1,tl) ban[q[i]]=1;
	int rt=0;
	fo(i,1,n) if (!ban[i]) {rt=i;break;}
	if (tl==n-1) {
		puts(c[rt]=='W'?"1":"0");
		return 0;
	}
	dfs(rt,0);
	printf("%d\n",ans-dis);
	return 0;
}

Measured memory_bytes: 7552
from collections import Counter
import string


def main():
    """
    各文字列の共通文字とその最大文字数を求め
    並べてsort
    """
    n = int(input())

    inf = float("inf")
    d = {k: inf for k in string.ascii_lowercase}
    for i in range(n):
        S = input()
        c = Counter(S)
        for char, n_char in d.items():
            d[char] = min(d[char], c.get(char, 0))

    ans = ""
    for k, v in d.items():
        if v == inf:
            continue
        ans += k * v
    ans = "".join(sorted(ans))

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

string add(string s, string direction, int k)
{
  for (int i = 0; i < k; i++)
  {
    s += direction;
  }

  return s;
}

int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans = "";
  if (sx <= tx && sy <= ty)
  {
    ans = add(ans, "R", tx - sx);
    ans = add(ans, "U", ty - sy);
    ans = add(ans, "L", tx - sx);
    ans = add(ans, "D", ty - sy);

    ans = add(ans, "D", 1);
    ans = add(ans, "R", tx - sx + 1);
    ans = add(ans, "U", ty - sy + 1);
    ans = add(ans, "L", 1);
    ans = add(ans, "U", 1);
    ans = add(ans, "L", tx - sx + 1);
    ans = add(ans, "D", ty - sy + 1);
    ans = add(ans, "R", 1);
  }
  else if (sx <= tx && sy > ty)
  {
    ans = add(ans, "R", tx - sx);
    ans = add(ans, "D", abs(ty - sy));
    ans = add(ans, "L", tx - sx);
    ans = add(ans, "U", abs(ty - sy));

    ans = add(ans, "U", 1);
    ans = add(ans, "R", tx - sx + 1);
    ans = add(ans, "D", abs(ty - sy) + 1);
    ans = add(ans, "L", 1);
    ans = add(ans, "D", 1);
    ans = add(ans, "L", tx - sx + 1);
    ans = add(ans, "U", abs(ty - sy) + 1);
    ans = add(ans, "R", 1);
  }
  else if (sx > tx && sy <= ty)
  {
    ans = add(ans, "L", abs(tx - sx));
    ans = add(ans, "U", ty - sy);
    ans = add(ans, "R", abs(tx - sx));
    ans = add(ans, "D", ty - sy);

    ans = add(ans, "D", 1);
    ans = add(ans, "L", abs(tx - sx) + 1);
    ans = add(ans, "U", ty - sy + 1);
    ans = add(ans, "R", 1);
    ans = add(ans, "U", 1);
    ans = add(ans, "R", abs(tx - sx) + 1);
    ans = add(ans, "D", ty - sy + 1);
    ans = add(ans, "L", 1);
  }
  else if (sx > tx && sy > ty)
  {
    ans = add(ans, "L", abs(tx - sx));
    ans = add(ans, "D", abs(ty - sy));
    ans = add(ans, "R", abs(tx - sx));
    ans = add(ans, "U", abs(ty - sy));

    ans = add(ans, "U", 1);
    ans = add(ans, "L", abs(tx - sx) + 1);
    ans = add(ans, "D", abs(ty - sy) + 1);
    ans = add(ans, "R", 1);
    ans = add(ans, "D", 1);
    ans = add(ans, "R", abs(tx - sx) + 1);
    ans = add(ans, "U", abs(ty - sy) + 1);
    ans = add(ans, "L", 1);
  }

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll n,K;
  cin>>n>>K;
  vector<ll> data(n);
  ll m_index=0,p_index=0;
  rep(i,n){
    cin>>data[i];
    if(data[i]>=0&&!m_index){
      m_index=i-1;
      p_index=i;
    }
    
  }
  
  ll k=K-1;
  ll ans=INF;
  for(int i=0;i<n-k;i++){
    if(0<=data[i])ans=min(ans,data[i+k]);
    else if(data[i+k]<0)ans=min(ans,abs(data[i]));
    else if((data[i]<=0&&data[i+k]<=0)||(data[i]>=0&&data[i+k]>=0))ans=min(ans,abs(data[i]-data[i+k]));
    else ans=min(ans,min(abs(data[i]*2)+abs(data[i+k]), abs(data[i])+abs(data[i+k]*2)));
    //cout<<i<<" "<<ans<<endl;
  }
  
  if(ans==INF)cout<<0<<endl;
  else cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1152
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>  //setprecision(桁)
using namespace std;
#define pb push_back
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 1e+9
const ll MOD = 1000000007;

struct edge {
    int to;
    double cost;
};

// <最短距離, 頂点の番号>
using P = pair<double, int>;

int V;
const int ci = 2e5+ 5;
vector<edge> G[ci];
double d[ci];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) { //cout << "On" << endl;
        P p = que.top();
        que.pop();
        int v = p.second; //cout << "v=" << v << endl;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            edge e = G[v][i]; //cout << "koo" << endl;
            if (d[e.to] > d[v] + e.cost) { //cout << e.cost << endl;
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
ll modPow(ll a, ll n, ll p) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}
//ll dp[200005];

int main(){
    string s; cin >> s;
    int n = s.size();
    map<int,int> mp;
    int d = 1,num = 0;
    ll ans = 0;
    mp[0]++;
    for(int i = n-1; i >= 0; i--){
        int c = s[i] - '0';
        c *= d;
        c %= 2019;
        d *= 10;
        d %= 2019;
        num += c;
        num %= 2019;
        ans += mp[num];
        mp[num]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8428
import sys
input = sys.stdin.readline
S = list(input())[: -1]
N = len(S)
if S[: : -1] != S:
  print("No")
  exit(0)
if S[: N // 2][: : -1] != S[: N // 2]:
  print("No")
  exit(0)
S.reverse()
if S[: N // 2][: : -1] != S[: N // 2]:
  print("No")
  exit(0)
print("Yes")

Measured memory_bytes: 38384
import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))

c=[]
for i in range(n):
    c.append(a[i] - b[i])

c.sort(reverse=True)
d=np.array(c)
z=np.sum(d < 0)

x=np.sum(d[ d < 0])
y=np.sum(d[ d > 0])

if x == 0:
    print("0")
    exit()

if x + y < 0:
    print("-1")
    exit()    

for i,num in enumerate(c):
    x += num
    if x >= 0:
        print(z+i+1)
        exit()

Measured memory_bytes: 23940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  ll A,B;
  cin >> A >> B;
  ll Xa,Xb;// 
  double K,L;
  K = (double)A/0.08;
  L = (double)B/0.1;
  Xa = ceil(K);
  Xb = ceil(L);
  if( Xa > Xb )
  {
    if( Xa >= L+10)
    {
      cout << -1;
    }else{
      cout << Xa;
    }
  }else{
    if( Xb >= K+12.5 )
    {
      cout << -1;
    }else{
      cout << Xb;
    }
  }
  
  return 0;
} 

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ABs = []
for _ in range(N):
    A,B = inpl()
    ABs.append([A+B,A,B])

ABs.sort(reverse=True)
t = a = 0

for i,[AB,A,B] in enumerate(ABs):
    if i%2 == 0:
        t += A
    else:
        a += B

print(t-a)


Measured memory_bytes: 58200
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
int pa[111111],id[111111],cnt,rk[111111];
bool used[111111];
int n,m,x,y,z;
vector<pair<int,int> > g[1111111];
vector<int> gra[1111111];
void Init(int i)
{
	pa[i]=i;
	used[i]=0;
	id[i]=-1;	
	rk[i]=1;
}
int root(int x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
void Union(int x,int y)
{
	int rx=root(x),ry=root(y);
	if (rx==ry) return;
	if (rk[rx]>rk[ry]) 
	{
		pa[ry]=rx;
		rk[rx]+=rk[ry];
	}
	else 
	{
		pa[rx]=ry;
		rk[ry]+=rk[rx];
	}
}
queue<int> q;
int dist[1111111];
void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int main()
{
	while(scanf("%d%d",&n,&m)!=-1)
	{
		for (int i=1;i<=n;i++) g[i].clear();
		for (int i=1;i<=1000000;i++) gra[i].clear();
		for (int i=1;i<=m;i++)
		{
			scanf("%d%d%d",&x,&y,&z);
			g[z].push_back(make_pair(x,y)); 
		}
		cnt=n;
		for (int i=1;i<=1000000;i++)
		{
			for (int j=0;j<g[i].size();j++)
			{
				Init(g[i][j].first);
				Init(g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				Union(g[i][j].first,g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				x=g[i][j].first;y=g[i][j].second;
				if (!used[x])
				{
					int r=root(x);
					if (!~id[r]) id[r]=++cnt;
					used[x]=1;
					gra[x].push_back(id[r]);
					gra[id[r]].push_back(x); 
				}
				if (!used[y])
				{
					int r=root(y);
					if (!~id[r]) id[r]=++cnt;
					used[y]=1;
					gra[y].push_back(id[r]);
					gra[id[r]].push_back(y);  
				}
			}
		}
		memset(dist,-1,sizeof(dist));
		q.push(1);dist[1]=0;
		while(!q.empty())
		{
			x=q.front();q.pop();
			for (int i=0;i<gra[x].size();i++)
			{
				int to=gra[x][i];
				if (!~dist[to])
				{
					dist[to]=dist[x]+1;
					q.push(to); 
				}
			}
		}
		if (!~dist[n]) printf("-1\n");
		else printf("%d\n",dist[n]/2);
	}
	return 0;
}

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

#define ll long long 
 
using namespace std ;
 
ll z , ans , o ;

ll mod = 1e9 + 7 ;
ll N = 1e5 + 7 ;


int main( ){

	ll x ;

	cin >> x ;

	ll u = 100 ;

	while( u < x ){

		u += ( u ) / 100 ;

		ans ++ ;

	}

	cout << ans ;

}	



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <list>
#include <queue>

#define LL long long
#define rep(i, n) for (LL i = 0; i < (LL)(n); i++)

using namespace std;

LL dan[50];

LL func(LL level, LL x)
{
    if (level == 0) {
        return 1;
    }

    if (x == 1) {
        return 0;
    } else if (x == dan[level - 1] + 2) {
        return func(level - 1, x - 1) + 1;
    } else if (x == dan[level]) {
        return func(level - 1, dan[level - 1]) * 2 + 1;
    } else if (x > dan[level - 1] + 1) {
        return func(level - 1, dan[level - 1]) +
            func(level - 1, x - (dan[level - 1] + 2)) + 1;
    } else { 
        return func(level - 1, x - 1);
    }
}

int main()
{
    LL n,x;
    cin >> n >> x;

    /* level0 は一段 */
    dan[0] = 1;
    for (int i = 1; i < n; i++) {
        /* 3はパティとバーガーが増えるの意味 */
        dan[i] = dan[i - 1] * 2 + 3;
    }

    cout << func(n, x) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  vector<ll> A(n);
  for (auto& _a : A) cin >> _a;
  int j = 0;
  for (int i = 0; i < n; ++i) {
    if (A[i] == j+1) {
      ++j;
    }
  }
  int n_remain = j;
  int n_break = n - j;
  if (n_break == n) {
    cout << -1 << endl;
  } else {
    cout << n_break << endl;
  }

}


Measured memory_bytes: 4784
import java.util.Scanner;

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

    //input
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < a.length; i++){
      a[i] = sc.nextInt();
    }

    //output
    int count = 0;
    for(int i = 0; i < a.length; i++){
      if( (i+1)%2 == 1 ){ //if the location is odd
        //System.out.println("test");
        if( a[i]%2 == 1 ){ //if num is odd
          count++;
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 27036
//#define LOCAL

#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	#ifdef LOCAL
		freopen("E:\\Temp\\input.txt", "r", stdin);
		freopen("E:\\Temp\\output.txt", "w", stdout);
	#endif

	int minv, maxv = -2e9, a, n;
	scanf("%d %d", &n, &minv);
	for(int i=1; i<n; ++i) {
		scanf("%d", &a);
		maxv = max(maxv, a-minv);
		minv = min(minv, a);
	}

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

	return 0;
}

Measured memory_bytes: 2756
import static java.util.Arrays.*;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int[][] on = new int[2][1024];
		for (;;) {
			String line = sc.nextLine();
			if (line.length() == 0) break;
			String[] ss = line.split(",");
			int num = Integer.parseInt(ss[0]);
			int day = Integer.parseInt(ss[1]);

			on[0][num]++;

		}
		for (;sc.hasNextLine();) {
			String line = sc.nextLine();
			String[] ss = line.split(",");
			int num = Integer.parseInt(ss[0]);
			int day = Integer.parseInt(ss[1]);
			on[1][num]++;
		}
		for (int i = 0; i < 1024; i++) {
			if (on[0][i] > 0 && on[1][i] > 0) {
				out.println(i + " " + (on[0][i] + on[1][i]));
			}
		}
	}

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

	Scanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();
	}

}

Measured memory_bytes: 17204
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int x;
	scanf("%d",&x);
	if(x>=30){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1640
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;

int main(){
  ll a,b,x;
  cin>>a>>b>>x;
  ll af = a/x;
  ll bf = b/x;
  if(bf==af){
    if(a%x==0){
      cout<<1<<endl;

    }
    else
    {
      cout<<0<<endl;
    }

    return 0;
    

  }

ll oo=0;
  if(a%x==0){
    oo++;
  }

  cout<<bf-af+oo<<endl;
}


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

typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


void solve(ll N, vector<long double> p){
    ld dp[N+1][N+1];
    fill(dp[0], dp[N+1], 0);
    dp[0][0] = 1;
    FOR(i, 1, N+1) {
        rep(j, i+1) {
            if (j > 0) dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1 - p[i-1]);
            else dp[i][j] = dp[i-1][j] * (1-p[i-1]);
        }
    }
    ld ans;
    ans = 0;
    FOR(i, (N+1)/2, N+1) {
        ans += dp[N][i];
    }
    cout << setprecision(10) << ans << endl;
}

int main() {
  ll N;
    scanf("%lld",&N);
    vector<long double> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&p[i]);
    }
  solve(N, move(p));
  return 0;
}


Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rpv(v,n) rep(i,n)scanf("%d",&v[i]);sort(v.begin(),v.end());
int main() {
  int n;
  cin >> n;
  vector<int> va(n), vb(n), vc(n);
  rpv(va, n)
  rpv(vb, n)
  rpv(vc, n)

  long long sum = 0;
  rep(i, n) {
    sum += (lower_bound(va.begin(), va.end(), vb[i]) - va.begin())
        * (vc.end() - upper_bound(vc.begin(), vc.end(), vb[i]));
  }
  cout << sum;
  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 998244353;
vector<int> graph[100100];
bool seen[100100];
const ll mod = 1e9+7;

int main()
{
	int n, k;
	cin >> n >> k;
	rep(i,n-1){
		int x, y;
		cin >> x >> y;
		--x,--y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}

	queue<P> q;
	q.push({0,-1});
	ll ans = k;
	seen[0] = true;
	while(!q.empty()){
		int v = q.front().first;
		int p = q.front().second; q.pop();
		ll color = k-1;
		if(p == -1) color = k-1;
		else {
			// 親の繋がってるところで色塗り済みを数える
			for(auto x:graph[v]){
				if(seen[x]){
					color --;
				}
			}
		}
		for(auto x: graph[v]){
			// いけるのはx.first
			if(seen[x])continue;
			ans *= color;
			ans %= mod;
			color--;
			q.push({x,v});
			seen[x] = true;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 10072
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  map<ll,ll> a;
  rep(i,n){
    ll ai;
    cin >> ai;
    a[ai]++;
  }
  rep(i,m){
    ll b,c;
    cin >> b >> c;
    vector<ll> rem;
    for(auto e:a){
      if(b==0) break;
      if(e.first>=c) break;
      if(e.second<b) {
        a[c] += e.second;
        b -= e.second;
        a[e.first] = 0;
      }else{
        a[e.first] -= b;
        a[c] += b;
        b = 0;
      }
      if(a[e.first]==0) rem.emplace_back(e.first);
    }
    for(ll r:rem) a.erase(r);
  }
  ll ans = 0;
  for(auto e:a){
    ans += e.first * e.second;
  }
  cout << ans << endl;
}

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

#define ll long long int
#define LD long double

const int N = 1000010;

int inf = 1e9;
ll mod = 998244353;

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= mod;
  if (a < 0) a += mod;
  int b = mod, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += mod;
  return u;
}

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

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

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

    vector<int> sum(N, 0);
    vector<int> sqsum(N, 0);

    for(int i = 1; i < N; i++) {
        for(int j = i; j < N; j += i) {
            add(sum[i], mul(cnt[j], j));
            add(sqsum[i], mul(mul(j, j), cnt[j]));
        }
    }

    vector<int> ans(N, 0);

    for(int i = N - 1; i > 0; i--) {
        int temp = mul(sum[i], sum[i]);
        sub(temp, sqsum[i]);

        for(int j = i + i; j < N; j += i) {
            sub(temp, ans[j]);
        }

        ans[i] = temp;
    }

    int bit = 0;

    for(int i = 1; i < N; i++) {
        add(bit, mul(ans[i], inv(i)));
    }

    cout << mul(bit, inv(2)) << "\n";
    return 0;
}


Measured memory_bytes: 15872
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
struct A{
int x,y;
bool operator <(A z)
{
    return y<z.y;
}
}s[200005];
int main()
{

int t;
int n,m;
cin>>t;
 for(int i=1;i<=t;i++)
    scanf("%d%d",&s[i].x,&s[i].y);
 sort(s+1,s+1+t);
 int q=0;
 int time=0;
 for(int i=1;i<=t;i++)
 if(time+s[i].x>s[i].y){q=1;break;}
 else {
    time+=s[i].x;
 }
 if(q)cout<<"No\n";
 else cout<<"Yes\n";
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    string sd, t;
    cin >> sd >> t;

    for (int i = sd.size() - t.size(); i >= 0; i--) {
        bool ok = true;
        string cpSD = sd;
        for (int j = 0; j < t.size(); j++) {
            if (cpSD[i + j] == '?' || cpSD[i + j] == t[j]) {
                cpSD[i + j] = t[j];
                continue;
            }
            else {
                ok = false;
            }
        }
        if (ok) {
            rep (j, cpSD.size()) {
                if (cpSD[j] == '?') cpSD[j] = 'a';
            }
            cout << cpSD << endl;
            return 0;
        }
    }
    
    cout << "UNRESTORABLE" << endl;
    return 0;
}


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

class sample
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		List<int> num = new List<int>();

		for(int i=0;i<input.Length;i++)
		{
			num.Add(Convert.ToInt32(input[i]));
		}

		num=num.Distinct().ToList();

		if(num.Count==2)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}


	}
}



Measured memory_bytes: 11348
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int ans=0;
	if(n>=2)
	  ans+=((n-1)*(n-1)+(n-1))/2;
    if(m>=2)
	  ans+=((m-1)*(m-1)+(m-1))/2;
	cout<<ans<<endl;
	//system("pause");
	return 0;  
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    int a[n + 1], b[n + 1];
    rep2(i, n) a[i] = i * 40000;
    rep2(i, n) b[i] = a[n + 1 - i];

    rep(i, n) {
        a[p[i]] -= n - (i + 1);
    }

    rep2(i, n) cout << a[i] << (i == n ? "\n" : " ");
    rep2(i, n) cout << b[i] << (i == n ? "\n" : " ");

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


vector<long long> v(0);
void ret(long long N, long long a){
    long long tmp = a*10 + 3;
    if (tmp <= N){
        v.push_back(tmp);
        ret(N,tmp);
    }
    tmp = a*10 + 5;
    if (tmp <= N){
        v.push_back(tmp);
        ret(N,tmp);
    }
    tmp = a*10 + 7;
    if (tmp <= N){
        v.push_back(tmp);
        ret(N,tmp);
    }
}

int main(){
    long long N; cin >> N;
    v.push_back(3),v.push_back(5),v.push_back(7);
    
    //cout << "checker-1" << endl;

    ret(N,3);
    ret(N,5);
    ret(N,7);
    long long ans = 0;

    //cout << "checher-2" << endl;

    for (int i = 0; i < v.size(); i++){
        bool thr = false,fiv = false, sev = false;
        long long tmp = v[i];
        while (tmp > 0){
            long long t = tmp % 10;
            if (t == 3) thr = true;
            if (t == 5) fiv = true;
            if (t == 7) sev = true;
            tmp /= 10;
        }

        if (thr && fiv && sev && v[i] <= N) {
            ans++;
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>

using namespace std;

#define LL long long

int n,las_min=1000000007,ans=-1000000000;

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		int r;
		cin>>r;
		if(i)ans=max(ans,r-las_min);
		las_min=min(las_min,r);
	}
	cout<<ans<<endl;
	return 0;
}

//14:07

/*
各Rに対してそれまでの最小値を持つ



*/


Measured memory_bytes: 3112
#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*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B;
    cin >> A >> B;

    A--;
    B--;

    cout << 98 << " " << 99 << endl;
    REP(i, 49){
        REP(j, 99){
            if(i==0){
                cout << '#';
                continue;
            }
            if(i==48){
                cout << '#';
                continue;
            }
            if(i%2==1 && j%2==1){
                if(A>0){
                    cout << ".";
                    A--;
                    continue;
                }
            }
            cout << '#';
        }
        cout << endl;
    }

    REP(i, 49){
        REP(j, 99){
            if(i==0){
                cout << '.';
                continue;
            }
            if(i==48){
                cout << '.';
                continue;
            }
            if(i%2==1 && j%2==1){
                if(B>0){
                    cout << "#";
                    B--;
                    continue;
                }
            }
            cout << '.';
        }
        cout << endl;
    }
    return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int n;
    cin>>n;
    int arr[n+1];
    map<int,int> m1, m2;
    for(int i=1;i<=n;i++) {
        cin>>arr[i]; 
        m1[arr[i]+i]++;
        m2[i-arr[i]]++;
    }   
    int ans = 0;
    for(auto it: m1) {
        ans += it.second*m2[it.first];
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 39328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(S == U) --A;
    if(T == U) --B;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n, x, y, ans = 0;
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x >> y;
		ans += y - x + 1;
	}
	cout << ans << endl;
	return 0;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> t(n);
    ll sum=0;
    rep(i,n){
        cin>>t[i];
        sum+=t[i];
    }
    ll m; cin>>m;
    rep(i,m){
        ll p,x; cin>>p>>x;
        p--;
        cout<<sum-t[p]+x<<endl;
    }
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    SORT(A);
    cout << A[N-1]-A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define M 1002

void printline(int n,int a[]){
	int i;
	printf("%d",a[0]);
	for(i=1;i<n;i++){
		printf(" %d",a[i]);
	}
	printf("\n");
	return;
}

void insertsort(int p, int a[]){

	int pp=p,dum_a,dum_b,i;

	for(i=0;i<p;i++){
		if(a[p]<a[i]){
		 pp=i;
		 dum_a=a[p];
		 break;
		}
	}

	if(i==p) return;

	for(i=pp;i<p+1;i++){
		dum_b=a[i];
		a[i]=dum_a;
		dum_a=dum_b;
	}

	return;

}

int main(void){
	int i,n,a[M];
	scanf("%d",&n);

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

	for(i=0;i<n;i++){
		insertsort(i,a);
		printline(n,a);
	}

	return 0;

}

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

int main(){
    int A,B,K;
    scanf("%d %d %d",&A,&B,&K);
    int i;
    for(i=100;1<=i;i--){
        if(A%i==0 && B%i==0){
            K -= 1;
            if(K==0){
                printf("%d",i);
                i=0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
while True:
	a,op,b=input().split()
	a,b=map(int,[a,b])
	if op=='+':
		print(a+b)
	elif op=='-':
		print(a-b)
	elif op=='*':
		print(a*b)
	elif op=='/':
		print(a//b)
	else:
		break
		

Measured memory_bytes: 7660