akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static List<PriorityQueue<Integer>> list;
    static int[] start;
    static int[] finish;
    static int time;

    private static void dfs(int i) {
        if(start[i] > 0) return;
        time++;
        start[i] = time;
        while(!list.get(i).isEmpty()) {
            dfs(list.get(i).poll());
        }
        time++;
        finish[i] = time;
    }

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

        int n = sc.nextInt();
        list = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            PriorityQueue<Integer> set = new PriorityQueue<>();
            list.add(set);
        }

        for(int i = 0; i < n; i++) {
            int u = sc.nextInt() - 1;
            int k = sc.nextInt();
            for(int j = 0; j < k; j++) {
                list.get(u).add(sc.nextInt() - 1);
            }
        }

        start = new int[n];
        finish = new int[n];
        time = 0;
        for(int i = 0; i < n; i++) {
            dfs(i);
        }

        for(int i = 0; i < n; i++) {
            System.out.printf("%d %d %d\n", i + 1, start[i], finish[i]);
        }

        sc.close();
    }
}



Measured memory_bytes: 29780
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

int ans[200005]={};
set<int> line[200005];

void DFS(int x){
  if(line[x].empty()) return;
  while(!line[x].empty()){
    int y=*line[x].begin();
    line[x].erase(y);
    line[y].erase(x);
    ans[y]+=ans[x];
    DFS(y);
  }
  return;
}
 
int main(void){
  int N,Q;
  cin >> N >> Q;
  rep(i,N-1){
    int a,b;
    cin >> a >> b;
    line[a-1].insert(b-1);
    line[b-1].insert(a-1);
  }
  rep(i,Q){
    int a,b;
    cin >> a >> b;
    ans[a-1]+=b;
  }
  DFS(0);
  rep(i,N){
    cout << ans[i] << " ";
  }
}

Measured memory_bytes: 33792
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int gets(LL N) {
  int res = 0;
  while (N) {
    res += N % 10;
    N /= 10;
  }
  return res;
}

int main() {
  // ios_base::sync_with_stdio(0);

  LL N;
  scanf("%lld", &N);

  LL best = gets(N);
  LL p10 = 1;
  REP(i,16) {
    p10 *= 10;
    if (N < p10) break;
    LL N2 = N - N%p10 - 1;
    best = max(best, (LL)gets(N2));
  }
  printf("%lld\n", best);
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

int main(){
  char vec[101];
  while(cin >> n,n){
    rep(i,0,n)cin >> vec[i];
    int p = 0;
    bool f = true;
    clr(d,0);
    rep(p,0,n){
      d[vec[p] - 'A']++;
      rep(i,0,26){
        bool win = true;
        rep(j,0,26){
          if(i == j)continue;
          if(d[j] + (n-1 - p) >= d[i])win = false;
        }
        if(win){
          cout << char(i+'A') << " " << p + 1 << endl;
          f = false;
          break;
        }
      }
      if(!f)break;
    }
    if(f)puts("TIE");
  }
  return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
#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 H, W, K;
  cin >> H >> W >> K;
  vector<string> s(H);
  rep(i, H) cin >> s[i];
  
  vector<vector<int>> ans(H, vector<int>(W,0));
  int strawberry = 0;
  int one = -1;;
  for(int i = 0; i < H; i++) {
    vector<int> f;
    for(int j = 0; j < W; j++) {
      if (s[i][j] == '#') f.push_back(j);
    }

    if (f.size() > 0) {
      if (one == -1) one = i;
      int now = 0;
      for (int j = 0; j < f.size(); j++) {
        strawberry++;
        while (now <= f[j]) {
          ans[i][now] = strawberry;
          now++;
        }
        if (j == f.size() - 1) {
          while (now < W) {
            ans[i][now] = strawberry;
            now++;
          }
        }
      }
    } else {
      if (i == 0) continue;
      for (int j = 0; j < W; j++) {
        if (ans[i-1][j]== 0) break;
        ans[i][j] = ans[i-1][j];
      }
    }
  }
  if (ans[0][0] == 0) {
    for (int i = one-1; i >= 0; i--) {
      for (int j = 0; j < W; j++) {
        ans[i][j] = ans[i+1][j];
      }
    }
  }

  rep(i, H) rep(j, W) {
    cout << ans[i][j];
    if (j != W-1) cout << " ";
    else cout << endl;
  }
  return 0;
}


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

int main(){
	char S[100000];
	scanf("%s",S);
	int n=1,i,a=0,b=0;
	for(int j=0;j<2;j++){
		for(i=0;i<100001;i++){
			if(S[i]=='\0')break;
			if(j==0){
				if(i%2==0){
					if(S[i]!='0')a++;
				}
				else{
					if(S[i]!='1')a++;
				}
			}
			else{
				if(i%2==0){
					if(S[i]!='1')b++;
				}
				else{
					if(S[i]!='0')b++;
				}
			}
		}
	}
	if(a>=b){
		printf("%d\n",b);
	}
	else{
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int s,k;
	int x,y,z;
	cin >> k >> s;
	ll c = 0;
	for(int x = 0; x <= k; x++) {
		for(int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (z >= 0 && z <= k){
				c++;
			}
		}			
	}
	cout << c << endl;
	return 0;
}

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

int main(){

    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int> > A(H, vector<int>(W));
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) cin >> A[i][j];
    int Q;
    cin >> Q;
    vector<int> L(Q), R(Q);
    for(int i = 0; i < Q; i++) cin >> L[i] >> R[i];

    vector<int> px(1e6), py(1e6);
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) px[A[i][j]] = i, py[A[i][j]] = j;
    
    vector<int> d(1e6, 0);
    for(int i = D + 1; i <= H * W; i++){
        d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D]);
    }

    for(int i = 0; i < Q; i++){
        cout << d[R[i]] - d[L[i]] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 13952
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n;
  string s;
  cin >> n >> s;

  int b_num = 0;
  vec r,g;
  REP(i,n) {
    if(s[i] == 'R') r.push_back(i);
    else if(s[i] == 'G')g.push_back(i);
    else b_num++;
  }

  int ans = 0;
  REP(i, r.size())REP(j,g.size()){
    int ma = max(r[i], g[j]);
    int mi = min(r[i], g[j]);
    int sub = 0;
    if(2 * ma - mi < s.length() && s[2 * ma - mi] == 'B'){
      sub++;
    }
    if(2 * mi - ma >= 0 && s[2 * mi - ma] == 'B'){
      sub++;
    }
    if((ma - mi) % 2 == 0 && s[mi + (ma - mi) / 2] == 'B'){
      sub++;
    }
    ans += b_num - sub;
  }

  cout << ans << endl;

  return 0;
}

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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd<<1|1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 998244353;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

int mx[MAXN<<2];

void update(int nd, int l, int r, int pos, int val){
    if(l==r){
        mx[nd]=max(mx[nd],val);
        return;
    }

    if(pos<=mid)update(lson,l,mid,pos,val);
    else update(rson,mid+1,r,pos,val);

    mx[nd]=max(mx[lson],mx[rson]);
}

int query(int nd, int l, int r, int L, int R){
    if(L<=l&&r<=R){
        return mx[nd];
    }

    int res=0;
    if(mid>=L)res=max(res,query(lson,l,mid,L,R));
    if(mid+1<=R)res=max(res,query(rson,mid+1,r,L,R));

    return res;
}

PII info[MAXN];

int n;

int Next[MAXN], dp[MAXN][2];

int main(){
    n=read();
    for(int i=1;i<=n;++i){
        info[i].fi=read();
        info[i].sd=read();
    }

    sort(info+1,info+n+1);

    for(int i=1;i<=n;++i)Next[i]=i;
    update(1,1,n,n,n);
    for(int i=n-1;i>=1;--i){
        int pos=lower_bound(info+1,info+1+n,MP(info[i].fi+info[i].sd,-1))-info-1;
        if(pos!=i){
            Next[i]=max(Next[i],query(1,1,n,i,pos));
        }
        update(1,1,n,i,Next[i]);
    }

    dp[n][0]=dp[n][1]=1;
    for(int i=n-1;i>=1;--i){
        dp[i][0]=(dp[i+1][0]+dp[i+1][1])%MOD;
        int t=Next[i];
        if(t!=n)dp[i][1]=(dp[t+1][0]+dp[t+1][1])%MOD;
        else dp[i][1]=dp[n][1];
    }

    cout<<(dp[1][0]+dp[1][1])%MOD;

    return 0;
}


Measured memory_bytes: 6400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  string s;
  cin >> n >>s;
  int ans = 0;
  for(int i = 1; i < n; ++i){
    int count = 0;
    vector<int> a(26), b(26);
    for(int l = 0; l < i; ++l){
      a[s[l] - 'a']++;
    }
    for(int r = i; r < n; ++r){
      b[s[r] - 'a']++;
    }
    rep(j, 26){
      if(a[j] > 0 && b[j] > 0)  count++;
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def conv(a): #convert the num to character
  a += 97
  return chr(a)

# 整数の入力
n = int(input())
name = ''

while n>0:
  n -= 1
  name += conv(n%26)
  n //= 26

# 出力
print(name[::-1])

Measured memory_bytes: 9092
n = int(input()) #整数
h = [int(i) for i in input().split() ]

i = 0
l = [0 for i in range(n)]
ans = 0
while h != l:
    ans += 1
    start = False
    for i in range(n):
        if start == False:
            if h[i] > 0:
                start = True
                h[i] -= 1
        else:
            if h[i] > 0:
                h[i] -= 1
            elif h[i]== 0:
                break
print(ans)

Measured memory_bytes: 3064
from fractions import gcd
from functools import reduce

N, X = map(int, input().split())

x_lis = list(map(int, input().split())) + [X]

x_lis = sorted(x_lis)

x_diff = [0] * (N)

for i in range(N):
    x_diff[i] = x_lis[i + 1] - x_lis[i]

def gcd_list(x_diff):
    return reduce(gcd, x_diff)

print(gcd_list(x_diff))

Measured memory_bytes: 16308
#include <bits/stdc++.h>
using namespace std;
int main(){
  double n,m,d,ans; cin>>n>>m>>d;
  if(d==0) ans=(m-1)/n;
  else ans=(n-d)*2*(m-1)/n/n;
  cout<<setprecision(9)<<ans<<endl;
}

Measured memory_bytes: 256
from heapq import*
def m():
 n=int(input())
 A=[[]for _ in[0]*n]
 for _ in[0]*n:
  e=list(map(int,input().split()))
  for i in range(e[1]):k=2*-~i;A[e[0]]+=[(e[k],e[k+1])]
 H=[[0,0]]
 d=[0]+[1e6]*n
 c=[1]*n
 while H:
  f=heappop(H)
  u=f[1]
  c[u]=0
  if d[u]>=f[0]:
   for s in A[u]:
    v=s[0]
    if c[v]and d[v]>d[u]+s[1]:
     d[v]=d[u]+s[1]
     heappush(H,[d[v],v])
 for i in range(n):print(i,d[i])
m()


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

int main(void) {
    int N,X,g,tmp;
    cin >> N >> X;

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

    if(N == 1) {
        cout << abs(x[0]-X) << endl;
        return 0;
    }

    sort(x.begin(), x.end());
    g = X - x[0];
    for(int i=1;i<N;i++) {
        g=__gcd(g,x[i]-x[0]);
    }
    cout << g << endl;
    
    return 0;
}


Measured memory_bytes: 640
/**
*    created: 12.05.2020 00:35:15
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
    }
    int cnt = 0;
    rep2(i,1,n-1) {
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
ss = [input() for _ in range(n)]
m = int(input())
ts = [input() for _ in range(m)]

scores = defaultdict(int)
for s in ss:
    scores[s] += 1
for t in ts:
    scores[t] -= 1

ans = max(max(scores.values()), 0)
print(ans)

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

int main()
{
    int t,rem;
    cin>>t;
    rem=t%10;
    if(rem==2 || rem==4 ||
    rem==5 || rem==7 ||
    rem==9)
    cout<<"hon\n";
    else if(rem==0 || rem==1 ||
    rem==6 || rem==8)
    cout<<"pon\n";
    else cout<<"bon\n";
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int N = S.length();
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == 'o')cnt++;
  }
  int win = 15 - N + cnt;
  cout << ((win >= 8) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		// (AGC を含む) or (どこかを入れ替えると AGC を含む)
		// .* (AGC | ACG | GAC | A.GC | AG.C) .*
		const int M = 10;
		var dfa = new int[M, 4] {
			{ 3, 4, 1, 1 },
			{ 2, 2, 2, 2 },
			{ 3, 5, 6, 7 },
			{ 8, 4, 1, 1 },
			{ 8, 9, 2, 10 },
			{ 3, 2, 1, 1 },
			{ 3, 9, 1, 1 },
			{ 3, 5, 2, 7 },
			{ 8, 4, 2, 1 },
			{ 3, 4, 2, 1 } };
		for (var i = 0; i < M; i++) for (var j = 0; j < 4; j++) dfa[i, j]--;
		var N = F;
		var dp = new long[N + 1, M];
		dp[0, 0] = 1;
		for (var i = 0; i < N; i++)
			for (var s = 0; s < M; s++)
				for (var c = 0; c < 4; c++)
				{
					var t = dfa[s, c];
					dp[i + 1, t] = (dp[i + 1, t] + dp[i, s]) % MOD;
				}
		WriteLine((Pow(4, N, MOD) - dp[N, 1] + MOD) % MOD);
	}
	public static long Pow(long a, long b, long mod)
	{
		var p = 1L;
		var x = a;
		while (b > 0)
		{
			if ((b & 1) == 1) p = (p * x) % mod;
			b >>= 1;
			x = (x * x) % mod;
		}
		return p;
	}
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    string s; cin >> s;
    int left = 0, right = 0;
    for (char c: s) {
        if (c == 'E') right++;
    }
    int ans = n+5;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') right--;
        ans = min(ans,left+right);
        if (s[i] == 'W') left++;
    }
    cout << ans << '\n';
}



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

const int mod = 1e9 + 7;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int n;
char s[2003];
mint dp[2003][2003];
int succ[2003][26];
int pred[2003][26];

int main() {
  scanf("%s", s + 1);
  s[0] = 'a';
  n = strlen(s) + 2;
  s[n - 1] = 'a';
  for (int j = 0; j < 26; j++) {
    succ[n - 1][j] = n;
    pred[0][j] = -1;
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      succ[i][j] = s[i + 1] == j + 'a' ? i + 1 : succ[i + 1][j];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      pred[i][j] = s[i - 1] == j + 'a' ? i - 1 : pred[i - 1][j];
    }
  }
  for (int i = 0; i < n; i++) {
    dp[i][i] = 1;
  }
  for (int d = 1; d <= n - 1; d++) {
    for (int l = 0; l + d < n; l++) {
      int r = l + d;
      if (s[l] != s[r]) continue;
      dp[l][r] += 1;
      for (int k = 0; k < 26; k++) {
        int ll = succ[l][k];
        int rr = pred[r][k];
        if (ll <= rr) {
          dp[l][r] += dp[ll][rr];
        }
        if (ll < rr) {
          dp[l][r] += 1;
        }
      }
    }
  }
  dp[0][n - 1] -= 1;
  printf("%d\n", dp[0][n - 1].n);
}



Measured memory_bytes: 18836
h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

mat_map = [()]*(h*w+1)

for i in range(h):
    for j in range(w):
        mat_map[a[i][j]] = (i, j)

dp = [0]*(h*w+1)

for i in range(h*w-1, 0, -1):
    if i+d > h*w:
        continue
    current = mat_map[i]
    nex = mat_map[i+d]
    dist = abs(current[0]-nex[0]) + abs(current[1]-nex[1])
    dp[i] = dp[i+d] + dist

q = int(input())
ans= []
for _ in range(q):
    l, r = map(int, input().split())
    ans.append(dp[l]-dp[r])

print(*ans, sep='\n')

Measured memory_bytes: 23716
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

	string s;
	cin >> s;
	int n = s.length();
	vector<int> mark, ans(n);
	for (int i = 1; i < n; i++) if (s[i-1] == 'R' && s[i] == 'L') mark.push_back(i);
	// for (int x : mark) printf("%d ", x); printf("\n");

	for (int i = 0; i < n; i++) {
		int j;
		if (s[i] == 'R') {
			auto ptr = upper_bound(mark.begin(), mark.end(), i);
			j = *ptr;
			if ((j-i)%2) j--;
		}
		else {
			auto ptr = lower_bound(mark.begin(), mark.end(), i);
			if (ptr == mark.end() || *ptr > i) ptr--;
			j = *ptr;
			if ((i-j)%2) j--;
		}
		// printf("%d %c %d\n", i, s[i], j);
		ans[j]++;
	}
	for (int x : ans) printf("%d ", x);
	printf("\n");
}


Measured memory_bytes: 1280
c=[0]*3
c_max=0
for i in range(3):
    c[i]=list(map(int,input().split()))
    c_max=max(c_max,max(c[i]))
c_max+=1
for a1 in range(c_max):
    b1 = c[0][0] - a1
    b2 = c[0][1] - a1
    b3 = c[0][2] - a1
    a2 = c[1][0] - b1
    a3 = c[2][0] - b1
    if a1+b1==c[0][0] and a1+b2==c[0][1] and a1+b3==c[0][2] and a2+b1==c[1][0] and a2+b2==c[1][1] and a2+b3==c[1][2] and a3+b1==c[2][0] and a3+b2==c[2][1] and a3+b3==c[2][2]:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 9228
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;
//#include <boost/multiprecision/cpp_int.hpp>
//using bint = boost::multiprecision::cpp_int;
const int mod = 1000000007;

struct group{
    int people = -1;
    int friends = 0;
    int blocks = 0;
};

vector<group> uf;
void init(){
    rep(i,100001){
        group g;
        uf.pb(g);
    }
}

int parent(int v){
    if (uf[v].people < 0) return v;
    return uf[v].people = parent(uf[v].people);
}


void add(int v,int w, bool f){
    int pv = parent(v);
    int pw = parent(w);
    bool same = (pw==pv);
    if (f){
        if (pv!= pw){
            uf[pw].people += uf[pv].people;
            uf[pv].people = pw;
        }
    }
    if (f) {
        uf[v].friends++;
        uf[w].friends++;
    }
    else{
        if (same){
            uf[v].blocks++;
            uf[w].blocks++;
        }
    }
    
}

int main(){
    init();
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> A(m),B(m);
    vector<int> C(k),D(k);
    rep(i,m) {
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
        add(A[i],B[i],1);
    }
    rep(i,k) {
        cin >> C[i] >> D[i];
        C[i]--;D[i]--;
        add(C[i],D[i],0);
    }
    

    
    rep(i,n){
        int p = parent(i);
        cout << -uf[p].people - 1 - uf[i].friends - uf[i].blocks << " ";
        
    }

    
}


Measured memory_bytes: 4212
/*
ÂmÂ[ÂhÂÃ° n/2 ÂÃÂÃ2ÂÃÂÃÂOÂÂÂ[ÂvÂÃÂÂªÂÂ¯ÂÃ©

  ÂOÂÂÂ[Âv1   ÂOÂÂÂ[Âv2
  ---------   ---------
          1           0
          2           5
          3           4

ÂÂ±ÂÃ2ÂÃÂÃÂOÂÂÂ[ÂvÂÃ°ÂÃÂÂºÂÃÂÂÂÃÂÃÂMÂUÂMÂUÂÃÂÃÂÃÂÂ°ÂÃ©ÂÃ1ÂpÂ^Â[ÂÂÂÃÂÂ«ÂÂ ÂÂªÂÃ©.
  0 -> 1 -> 5 -> 2 -> 4 -> 3

ÂÂ³ÂÃ§ÂÃ, ÂÂ±ÂÃÂpÂ^Â[ÂÂÂÃ°ÂÂ½ÂÂÂvÂÃ±ÂÃ¨ÂÃÂÂÂÃÂÃÂÃ±Â]ÂÂ³ÂÂ¹ÂÃÂÂ¢ÂÂ­ÂÃ,
  0 -> 1 -> 5 -> 2 -> 4 -> 3
  1 -> 2 -> 0 -> 3 -> 5 -> 4
  2 -> 3 -> 1 -> 4 -> 0 -> 5
ÂÃÂÃ°ÂÂ¤ÂLÂÂµÂÃÂÂ¢(n / 2)ÂÃÂÃÂSÂÃ¦ÂÃÂÃ°ÂÂ¾ÂÃ©ÂÂ±ÂÃÂÂªÂÃÂÂ«ÂÃ©.

n=ÂÃ´ÂÂÂÃÂÂ ÂÃ©ÂÃÂÂ«, ÂÂ±ÂÃÂ@ÂÂ¥ÂÃÂÂµÂÂ½ÂÂªÂÃÂÃÂSÂÃ¦ÂÃÂÃ°ÂgÂÃÂÃÂÂ¢ÂÃÂÂ½ÂÃªÂÂ,
ÂSÂÃ¦ÂÃÂÃÂgÂÃ­ÂÃÂÂ¢ÂÃ¦ÂÂ¤ÂÃÂÂ³ÂÃÂÃÂGÂbÂWÂÂª1ÂÃÂÃ ÂÂ­ÂÂ¶ÂÂµÂÃÂÂ¢.

ÂÂ±ÂÃÂÂ±ÂÃÂÂ©ÂÃ§, ÂÂ±ÂÃÂÃ»Â@ÂÂªÂÃªÂÃÂÂ½ÂÂ­ÂÂ³ÂÃ±ÂSÂÃ¦ÂÃÂÃ°ÂÃ¬ÂÃ©ÂÂ±ÂÃÂÂªÂÃÂÂ«ÂÃ©.


ÂÂÂÂ½ÂÃÂÂ
  ÂoÂÃÂÂªÂÂ½ÂÂ·ÂÂ¬ÂÃ©ÂÃÂ\ÂzÂÃÂÂ«ÂÃ©ÂÃªÂÂÂÃ, printfÂÃ°ÂgÂÂ¤

 */

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

int main(){
  int n, k;

  while(cin >> n >> k){
    if(n / 2 < k){
      printf("-1\n");
      //cout << "-1\n";
      continue;
    }

    int p[n + 2];
    p[0] = 0;

    for(int i = 1; i < n; i += 2){
      p[i] = i / 2 + 1;
      p[i + 1] = n - p[i];
    }

    for(int i = 0; i < k; i++){
      if(i != 0) printf("\n");

      for(int j = 0; j < n - 1; j++){
        int a = (p[j] + i) % n + 1;
        int b = (p[j + 1] + i) % n + 1;
        printf("%d %d\n", a, b);
        //cout << a << " " << b << endl;
      }
    }
  }
}

Measured memory_bytes: 916
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int D;
	scanf("%d", &D);
	int c[26], s[D][26], last[26], ans[D];
	for (int i = 0; i < 26; ++i) scanf("%d", &c[i]);
	for (int i = 0; i < D; ++i) {
		for (int j = 0; j < 26; ++j) scanf("%d", &s[i][j]);
	}
	fill_n(last, 26, -1);
	for (int i = 0; i < D; ++i) {
		int x = -1000000000, opt = 0;
		for (int j = 0; j < 26; ++j) {
			if (c[j] * (i - last[j] + 6) + s[i][j] > x) x = c[j] * (i - last[j] + 6) + s[i][j], opt = j;
		}
		last[opt] = i;
		ans[i] = opt;
	}
	for (int i = 0; i < D; ++i) printf("%d\n", ans[i] + 1);
	return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */

int main() {
    int n;cin >> n;
    vi s(n);
    int sum = 0;
    rep(i, n) {
        cin >> s[i];
        sum += s[i];
    }
    sort(all(s));
    int i = 0;
    while(sum%10==0) {
        if(s[i]%10!=0) sum-=s[i];
        else i++;
        if(i==n) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<pair<char, int> > A(N), B;
    for(auto it=A.begin(); it!=A.end(); it++){
        char suit;
        int value;
        cin >> suit >> value;
        *it=make_pair(suit, value);
    }
    copy(A.begin(), A.end(), back_inserter(B));

    auto print=[](vector<pair<char, int> > &A){
        for(auto it=A.begin(); it!=A.end(); it++){
            if(it!=A.begin()){
                printf(" ");
            }
            printf("%c%d", (*it).first, (*it).second);
        }
        printf("\n");
    };

    [&A, N]{
        for(int i=0; i<N; i++){
            for(int j=N-1; j>=i; j--){
                if(A[j].second < A[j-1].second){
                    swap(A[j], A[j-1]);
                }
            }
        }
    }();

    print(A);
    printf("Stable\n");

    [&B, N]{
        for(int i=0; i<N; i++){
            int minj=i;
            for(int j=i; j<N; j++){
                if(B[j].second < B[minj].second){
                    minj=j;
                }
            }
            swap(B[i], B[minj]);
        }
    }();

    print(B);
    if(A==B){
        printf("Stable\n");
    } else{
        printf("Not stable\n");
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << endl;

int main() {
  ll N;

  CIN(N);

  ll H, last;
  CIN(last);

  ll c = 0;
  ll m = 0;
  for (ll i = 1; i < N; i++) {
    CIN(H);

    if (last >= H) {
      c++;
    } else {
      m = max(m, c);
      c = 0;
    }
    last = H;
  }

  m = max(m, c);


  COUT(m);

  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
X=[int(i) for i in input().split()]
ans=1000000000000000
for n,x in enumerate(X):
    if n+K>N:break
    y=X[n+K-1]
    if x*y>=0:#同符号orどっちか０
        move=max(abs(x),abs(y))
    else:#異符号
        move=max(abs(x),abs(y))+min(abs(x),abs(y))*2
    ans=min(move,ans)
print(ans)

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

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, m, dp[100005], pre[100005];
vector<int> g[100005];

void dfs(int u) {
    dp[u] = 1;
    for (int v : g[u]) {
        if (dp[v] == -1) {
            dfs(v);
        }
        if (dp[u] < dp[v] + 1) {
            dp[u] = dp[v] + 1;
            pre[u] = v;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cont (i, n + m - 1) {
        int u, v;
        cin >> u >> v;
        g[v].push_back(u);
    }
    memset(dp, -1, sizeof(dp));
    cont (i, n) {
        if (dp[i] == -1) {
            dfs(i);
        }
        cout << pre[i] << endl;
    }
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

int n;
map <string, int> mp;
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int ans = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string x; cin >> x;
		sort(all(x));
		ans += mp[x];
		++mp[x];
	}
	cout << ans;
	time;
}

Measured memory_bytes: 11632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, a[10020];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int Ans = 0;
    for (int i = 0; i < k; i++)
        Ans += a[i];
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c=0;
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                for(int k=0;k<j;k++)
                {
                    if(a[k]!=a[j] && a[i]!=a[j] && a[k]+a[j]>a[i])
                     c+=1;
                }
            }
        }
        System.out.println(c);
 
        
    }
}

Measured memory_bytes: 36512
/*input
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=305;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n,m;

int a[maxn][maxn];
int ans=INF;
int cnt[maxn];
bool val[maxn];
int main()
{
	cin>>n>>m;
	REP(i,n) REP(j,m) cin>>a[i][j];
	REP(i,n) REP(j,m) a[i][j]--;
	REP(I,m){
		REP(i,m) cnt[i]=0;
		REP(i,n){
			int tmp=0;
			while(val[a[i][tmp]]) tmp++;
			cnt[a[i][tmp]]++;
		}
		int id=0;
		REP(i,m) if(cnt[id]<cnt[i]) id=i;
		ans=min(ans,cnt[id]);
		val[id]=1;
	}
	cout<<ans<<'\n';

	return 0;
}



Measured memory_bytes: 640
K, S = map(int, input().split())
count = 0
if K*3 < S:
    print(count)
else:
    for i in range(K, -1, -1):
        X = i
        YZ = S - X
        for j in range(K, -1, -1):
            Y = j
            Z = YZ - Y
            if Z > K:
                continue
            elif Z < 0:
                continue
            else:
                count += 1
                #print(X,Y,Z)
print(count)

Measured memory_bytes: 3064
n=int(input())
d={}
for i in range(1,n+1):
  f=i//(10**(len(str(i))-1))
  l=i-(i//10)*10
  if l!=0: 
    c=f*10+l
    if c in d:
      d[c]+=1
    else:
      d[c]=1
ans=0
for i in d:
  if int(str(i)[::-1]) in d:
    ans+=d[i]*d[int(str(i)[::-1])]
print(ans)

Measured memory_bytes: 9204
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

f s = f' 0 0 s
  where
    f' _ _ [] = True
    f' l r (a:as)
      | min l r > a = False
      | max l r < a = f' a (min l r) as
      | otherwise = f' a (max l r) as

main = getInt >>= flip replicateM getInts >>= mapM_ (putStrLn . cond "YES" "NO" . f)

Measured memory_bytes: 4112
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
ll n,k;
ll vet[maxn];
bool check(int mid){
    ll cont=0;
    rep(i,0,n){
        cont+=(vet[i]+mid-1)/mid-1;
    }
    return cont<=k;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    rep(i,0,n){
        cin>>vet[i];
    }
    ll ini=1,mid,fim=1e9;
    ll ans=-1;
    while(ini<=fim){
        mid = (ini+fim)>>1;
        if(check(mid)){
            ans=mid;
            fim=mid-1;
        }
        else ini=mid+1;
    }
    cout<<ans<<'\n';
    return 0;  
}   

Measured memory_bytes: 5144
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	h := scanInt()

	ans := int64(0)

	c := int64(1)

	for h != 0 {
		ans+=c
		h /= 2
		c *= 2
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int x,y;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> x >> y;
}

int solve(){
    cout << x + y/2 << endl;
    return 0;
}   

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


Measured memory_bytes: 256
def solve(N):
    s = 1
    e = int(pow(N, 0.5)) + 1
    ds = []
    for i in range(s, e):
        if N % i == 0:
            m = (N // i) - 1
            if m and N // m == N % m:
                ds.append(N // i)
                # print(f"{N} = {m} * {N // m} + {N % m}")

    return sum([i - 1 for i in ds])


assert (solve(8) == 3 + 7)
assert (solve(10) == 4 + 9)
assert (solve(1000000000000) == 2499686339916)
if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int a,b;
	cin>>a>>b;
	
	cout<<a*b<<endl;
}

Measured memory_bytes: 3636
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]

def main():

    n,m = tuple([int(t)for t in input().split()])
    p = tuple([int(t)-1 for t in input().split()])

    uf = UnionFind(n)
    for _ in [0]*m:
        uf.unite(*[int(t)-1 for t in input().split()])

    ans = 0
    for i in range(n):
        if uf.isSame(i,p[i]):
            ans += 1

    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int a, b;
    cin >> a >> b;
    
    if (a != 1 && b != 1) cout << 1 << endl;
    if (a != 2 && b != 2) cout << 2 << endl;
    if (a != 3 && b != 3) cout << 3 << endl;
     


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

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

vector<int> IntegerToVector(int bit, int n) {
  vector<int> S;
  for(int i = 0; i< n; i++) {
    if(bit & (1 << i)) {
      S.push_back(i);
    }
  }
  return S;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> light(m, vector<bool>(n, false));
  for(int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      light[i][s-1] = true;
    }
  }
  //for(int i = 0; i < m; i++) {
  //  for(int j = 0; j < n; j++) {
  //    cout << light[i][j] << " ";
  //  }
  //  cout << endl;
  //}
  vector<int> remain(m);
  for(int i = 0; i < m; i++) {
    cin >> remain[i];
  }

  int output = 0;
  for(int bit = 0; bit < (1 << n); bit++) {
    int count = 0;
    vector<int> s = IntegerToVector(bit, n);
    //for(int i = 0; i < s.size(); i++) {
    //  cout << s[i];
    //}
    //cout << endl;
    for(int i = 0; i < m; i++) {
      int tmp = 0;
      for(int p : s) {
        //cout << p;
        if(light[i][p]) tmp++;
      }
      //cout << " " << tmp << endl;
      if(tmp % 2 == remain[i]) count++;
    }
    //cout << "count : " << count << endl;
    if(count == m) output++;
  }
  cout << output << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


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

// matrix
template<int MOD> struct Matrix {
    vector<vector<long long> > val;
    Matrix(int n, int m, long long x = 0) : val(n, vector<long long>(m, x)) {}
    void init(int n, int m, long long x = 0) {val.assign(n, vector<long long>(m, x));}
    size_t size() const {return val.size();}
    inline vector<long long>& operator [] (int i) {return val[i];}
};

template<int MOD> ostream& operator << (ostream& s, Matrix<MOD> A) {
    s << endl; 
    for (int i = 0; i < A.size(); ++i) {
        for (int j = 0; j < A[i].size(); ++j) {
            s << A[i][j] << ", ";
        }
        s << endl;
    }
    return s;
}

template<int MOD> Matrix<MOD> operator * (Matrix<MOD> A, Matrix<MOD> B) {
    Matrix<MOD> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i) 
        for (int j = 0; j < B[0].size(); ++j)
            for (int k = 0; k < B.size(); ++k) 
                R[i][j] = (R[i][j] + A[i][k] * B[k][j] % MOD) % MOD; 
    return R;
}

template<int MOD> Matrix<MOD> pow(Matrix<MOD> A, long long n) {
    Matrix<MOD> R(A.size(), A.size());
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) {
        if (n & 1) R = R * A;
        A = A * A;
        n >>= 1;
    }
    return R;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
     int n; ll k;    cin >>n >> k;
     Matrix<MOD> mat{n, n};
     
     for(int i = 0; i < n; ++i){
         for(int j = 0; j < n; ++j){
              cin >> mat[i][j];
         }
     }
    
    mat = pow(mat, k);
    
    ll ans = 0;
    for(int i = 0; i < n; ++i){
         for(int j = 0; j < n; ++j){
              ans += mat[i][j];
              ans %= MOD;
         }
     }
     cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>


const int kN = 100000 + 5;
int n, a[kN];


int main()
{
    int result = 0;
    int last = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        int b = 0;
        while (a[i] >> b + 1) ++ b;
        int c = a[i] != (1 << b);
        b += c;
        if (last >= b) {
            last = b - c;
        } else {
            result += b - last;
            last = b;
        }
        // printf("(%d, %d %d %d)\n", a[i], b, c, result);
    }
    printf("%d\n", result);

}


Measured memory_bytes: 512
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [5e9] * (n + 2)
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        if not i + j < n:
            break
        dp[i + j] = min([dp[i + j], dp[i] + abs(h[i] - h[i + j])])

print(dp[n - 1])


Measured memory_bytes: 56288