akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    int la = a.length(), lb = b.length();
    vector< vector< int > > dp(la + 1, vector< int > (lb + 1));
    for (int i = 1; i <= la; i++) {
        for (int j = 1; j <= lb; j++) {
            if (a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
        }
    }
    //cout << dp[la][lb] << "\n";
    int i = la, j = lb;
    string ans = "";
    while (i >= 1 && j >= 1) {
        if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
            ans = a[i - 1] + ans;
            i--;
            j--;
        }
        else if (dp[i][j] == dp[i - 1][j]) i--;
        else j--;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 38824
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <limits>
using i64 = long long;

int main() {
    constexpr int inf = std::numeric_limits<int>::max() / 2;
    int h, w, sx, sy, tx, ty;
    std::cin >> h >> w >> sx >> sy >> tx >> ty;
    std::vector<std::string> s(h);
    for (auto &e : s) std::cin >> e;

    std::deque<std::pair<int, int>> q { { sx - 1, sy - 1 } };
    std::vector dist(h, std::vector<int>(w, inf));
    dist[sx - 1][sy - 1] = 0;
    while (!q.empty()) {
        const auto [x, y] = q.front();
        q.pop_front();
        for (int i = -2; i <= 2; i++) for (int j = -2; j <= 2; j++) {
            if (i == 0 && j == 0) continue;
            const int nx = x + i, ny = y + j;
            if (nx < 0 || h <= nx || ny < 0 || w <= ny || s[nx][ny] == '#') continue;
            const int c = abs(i) + abs(j) != 1, d = dist[x][y] + c;
            if (dist[nx][ny] <= d) continue;
            dist[nx][ny] = d;
            if (c) q.emplace_back(nx, ny);
            else q.emplace_front(nx, ny);
        }
    }

    const int ret = dist[tx - 1][ty - 1];
    std::cout << (ret == inf ? -1 : ret) << std::endl;

    return 0;
}


Measured memory_bytes: 9552
#include <cmath>
#include <iostream>
#include <map>

using namespace std;
using ll = long long;

void solve(ll N) {
  if (N==1) {
    cout << 0 << endl;
    return;
  }
  map<ll, int> m{};
  for (ll i = 2, n = sqrt(N+1); i <= n; ++i) {
    while (N % i == 0) {
      m[i]++;
      N /= i;
    }
    if (N == 1) break;
  }
  if (N != 1) m[N] += 1;
  
  int ans{};
  for (const auto& [k,v]: m) {
    auto V = v;
    for(int j = 1; V>=0; ++j) {
      V -= j;
      if (V<0) break;
      ++ans;
    }
  }

  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


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

int main()
{
  int a,b,c,d,e,f;
 cin >>a;
  cin >>b;
  cin >>c;
  cin >>d;
  e=(a+b);
  f=(c+d);
  
  if (e>f)
  {
    cout << "Left"<< endl;
  }
  if (f>e)
  {
    cout << "Right"<< endl;
  }
  if (e==f)
  {
    cout << "Balanced"<< endl;
  }
  return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>
using namespace std;
  
int main(){
    int r, c;
    scanf("%d %d", &r, &c);
    int a[r + 1][c + 1] ;
    fill(a[0], a[r + 1], 0);
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c; ++j){
            scanf("%d", &a[i][j]);
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
            a[r][c] += a[i][j];
            printf("%d ", a[i][j]);
        }
        printf("%d\n", a[i][c]);
    }
    for(int i = 0; i < c; ++i){
        printf("%d ", a[r][i]);
    }
    printf("%d\n", a[r][c]);
  
    return 0;
}

Measured memory_bytes: 1068
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<string>
using namespace std;



int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A')s[i] = 'X';
		else if (s[i] == 'B')s[i] = 'Y';
		else if (s[i] == 'C')s[i] = 'Z';
		else	
	
		s[i] -= 3;
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1176
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int S[][]=new int[N][2];
		long sum=0;
		boolean fin=false;
		int z=0;
		while(z<N){
			S[z][1]=stdIn.nextInt();
			S[z][0]=stdIn.nextInt();
			z++;
		}z=0;
		Arrays.sort(S, (a, b) -> Integer.compare(a[0], b[0]));
		while(z<N){
			sum+=S[z][1];
			if(sum>S[z][0]){
				fin=true;
				break;
			}
			z++;
		}
		if(fin)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}

Measured memory_bytes: 108556
#include <iostream>
using namespace std;
inline bool IsAddable(int iNum,int iLBound,int iUBound)
{
    int iSum=0;
    while(iNum)
    {
        iSum+=iNum % 10;
        iNum/=10;
    }
    return (iLBound<=iSum&&iSum<=iUBound);
}
int main()
{
    ios::sync_with_stdio(false);
    int iEnd,iLB,iUB;
    cin>>iEnd>>iLB>>iUB;
    register int i;
    register long long iSum=0;
    for (i=1;i<=iEnd;++i)
    {
        if(IsAddable(i,iLB,iUB))
            iSum+=i;
    }
    cout<<iSum<<endl;
    return 0;
}

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

int main() {
  ll n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long double ld;

const int MAX = 501,IINF = INT_MAX;
const ld LDINF = 1e100;
int H,W,sx,sy,gx,gy;
ld mincost[MAX][MAX][2]; // mincost[][][0] => from start, [1] = > from star
char c[MAX][MAX];
bool ban[MAX][MAX];
vector<int> star,plane;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y) { return 0 <= x && x < W && 0 <= y && y < H; }

inline void bfs(vector<int> sp,vector<int> Forbidden,int type){
  rep(i,H)rep(j,W) mincost[i][j][type] = LDINF, ban[i][j] = false;
  queue<int> que;
  rep(i,(int)sp.size()) que.push(sp[i]), mincost[sp[i]/W][sp[i]%W][type] = 0;
  rep(i,(int)Forbidden.size()) ban[Forbidden[i]/W][Forbidden[i]%W] = true;

  while(!que.empty()){
    int cur = que.front(); que.pop();
    rep(i,4){
      int nx = cur % W + dx[i], ny = cur / W + dy[i];
      if( c[ny][nx] == '#' ) continue;
      if( ban[ny][nx] ) continue;
      if( mincost[ny][nx][type] == LDINF ) {
        mincost[ny][nx][type] = mincost[cur/W][cur%W][type] + 1;
        que.push(nx+ny*W);
      }
    }
  }
}

bool check(ld E){
  ld T = 0;

  rep(i,(int)plane.size()){
    int x = plane[i] % W, y = plane[i] / W;
    T += min(mincost[y][x][0],mincost[y][x][1]+E);
  }

  ld len = plane.size();
  return len * E > T;
}

int main(){
  cin >> W >> H;
  rep(i,H)rep(j,W){
    cin >> c[i][j];
    if( c[i][j] == 's' ) sx = j, sy = i, c[i][j] = '.';
    if( c[i][j] == 'g' ) gx = j, gy = i;
    if( c[i][j] == '*' ) star.push_back(j+i*W);
    if( c[i][j] == '.' ) plane.push_back(j+i*W);
  }

  vector<int> sp,forbidden;
  sp.push_back(gx+gy*W);
  forbidden = star;
  forbidden.push_back(gx+gy*W);
  bfs(sp,forbidden,0);

  sp = star;
  forbidden.push_back(gx+gy*W);
  //forbidden.clear();
  bfs(sp,forbidden,1);

  ld L = 0, R = 1e10, M = 0;
  rep(i,60){
    M = ( L + R ) * (ld)0.5;
    if( check(M) ) R = M;
    else           L = M;
  }

  cout << setiosflags(ios::fixed) << setprecision(20) << min((ld)mincost[sy][sx][0],(ld)mincost[sy][sx][1]+L) << endl;

  return 0;
}

Measured memory_bytes: 10456
H,W,D=map(int, input().split())

pos=[0]*(H*W)
for h in range(H):
    a=list(map(int, input().split()))
    for w in range(W):
        pos[a[w]-1]=(h,w)

for i in range(D):
    nowx,nowy=pos[i]
    idx=i
    rui=0
    pos[i]=rui
    while idx+D<H*W:
        idx+=D
        x,y=pos[idx]
        rui=rui+abs(x-nowx)+ abs(y-nowy)
        pos[idx]=rui
        nowx=x
        nowy=y

Q=int(input())
for i in range(Q):
    L,R=map(int, input().split())
    print(pos[R-1]-pos[L-1])
#print(pos)


Measured memory_bytes: 13032
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 	    make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod        1000000007
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
vector<int>adj[100001];
bool mark[100001];
int height[100001];
int maxi=0;
void dfs(int s){
	mark[s]=1;
	int maxtemp=0;
	for(int i=0;i<(int)adj[s].size();i++){
		if(!mark[adj[s][i]]){
			dfs(adj[s][i]);
			maxtemp=max(maxtemp,height[adj[s][i]]);
		}
		else {
			maxtemp=max(maxtemp,height[adj[s][i]]);
		}
	}
	height[s]=maxtemp+1;
	maxi=max(maxi,height[s]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
	//cin>>t;
	while(t--)
	{
	int n,m;
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
	}
	for(int i=1;i<=n;i++){
		if(!mark[i])
		dfs(i);
	}
	cout<<maxi-1;
	}
return 0;
}

Measured memory_bytes: 12116
#include<stdio.h>
int main(void){
    int a,b,c;
    int t;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        t=a;
        a=b;
        b=t;
    }if(b>c){
        t=c;
        c=b;
        b=t;
    }if(a>b){
        t=a;
        a=b;
        b=t;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2048
n=int(input())
h=list(map(int,input().split()))
m=max(h)
ans=0
for i in range(m):
    k=m-i
    for j in range(n):
        if j!=n-1:
            if h[j]==k and h[j]==h[j+1]:
                ans-=1
        if h[j]==k:
            ans+=1
            h[j]-=1        
print(ans)

Measured memory_bytes: 3064
// Date: 2020-03-19

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int r[N][30], x[N], n, L, Q, dep;

void init() {
    rep(i, 1, n) r[i][0] = upper_bound(x+i, x+n+1, x[i]+L)-x-1;
    rep(d, 1, 20) {
        rep(i, 1, n) {
            r[i][d] = r[r[i][d-1]][d-1];
        }
    }
}

int main() {
    FIO;
    cin >> n;
    rep(i, 1, n) cin >> x[i];
    cin >> L >> Q;
    init();
    while(Q--) {
        int u, v;
        cin >> u >> v;
        if(u > v) swap(u, v);
        int ans = 0;
        for(int i = 20; i >= 0; --i) {
            if(r[u][i] < v) {
                ans += (1 << i);
                u = r[u][i];
            }
        }
        cout << ans+1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 12928
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

ll N;

const ll MAXN = 2 * 100000;
ll A[MAXN];
ll B[MAXN];
ll C[MAXN];

int main()
{
    cin >> N;

    rep (i, N)
    {
        cin >> A[i];
        --A[i];
        ++B[A[i]];
    }

    ll sum = 0;

    rep (i, N) if (!C[A[i]])
    {
        const ll b = B[A[i]];
        sum += b * (b - 1) / 2;
        C[A[i]] = 1;
    }

    rep (i, N)
    {
        const ll b = B[A[i]];

        const ll prev = b >= 2 ? (b * (b - 1)) / 2 : 0;
        const ll next = b >= 2 ? ((b - 1) * (b - 2)) / 2 : 0;

        const ll ans = sum - prev + next;
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N,X; cin>>N>>X;
	ll miN=10000000000,sum=0;
	rep(i,N){
		ll tmp; cin>>tmp;
		miN=min(miN,tmp);
		sum+=tmp; 
	}
	cout<<N+(X-sum)/miN;	
}

Measured memory_bytes: 256
function main(input) {
  let [a, b] = input[0].trim().split(" ").map(i => i);
  a = BigInt(parseInt(a));
  b = parseInt(b.split(".").join(""));
  ans = 0n;

  for(let i=0;i<b;i++){
    ans += a;
  }
  ans = ans + "";

  if(ans.length<=2){
    console.log(0);
  }else{
    const ans1 = ans.slice(0,ans.length-2);
    console.log(ans1);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 29656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,c; cin>>n>>c;
    vector <vector<int>> data(30,vector <int>(100050));
    rep(i,n){
        int a,b,s; cin>>a>>b>>s; s--;
        for(int i = a;i<=b;i++){
            data[s][i]++;
        }
    }
    int ans = 1;
    rep(j, 100050){
        int cnt = 0;
        rep(i, 30){
            if(data[i][j] == 1) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a+b+1)/2<<endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ");
        int rows = Integer.parseInt(line[0]);
        int cols = Integer.parseInt(line[1]);

        char[][] matrix = new char[rows][cols];

        for (int r = 0; r < rows; r++) {
            matrix[r] = scanner.nextLine().toCharArray();
        }

        long[][] dp = new long[rows][cols];
        dp[0][0] = 1;
        int c = 0;
        while (c < cols && matrix[0][c] != '#') {
            dp[0][c] = 1;
            c++;
        }

        int r = 0;
        while (r < rows && matrix[r][0] != '#') {
            dp[r][0] = 1;
            r++;
        }

        for (r = 1; r < rows; r++) {
            for (c = 1; c < cols; c++) {
                if (matrix[r][c] != '#') {
                    dp[r][c] = (dp[r - 1][c] + dp[r][c - 1]) % 1000000007 ;
                }
            }
        }
        System.out.println((dp[rows - 1][cols - 1]));
    }
}


Measured memory_bytes: 62272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
 
int main() {
  int n,m;
  cin>>n>>m;
  int a[n];
  double sum=0;
  rep(i,n){
       cin>>a[i];
       sum+=a[i];
  }
 
  sum/=(4*m);
  int ans=0;
  rep(i,n){
      if(sum<=a[i]) ans++;
  }
 
  if(ans>=m) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 
 
}

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

using namespace std;

void ShowString(string str);
int main(){
	string str;
	while(cin>>str){
		ShowString(str);
	}
	return 0;
}

void ShowString(string str){
	for( unsigned int i=0;i<str.length();i++ ){
		if( str[i]!='@' ){
			cout<<str[i];
		}else{
			for( int j=0;j<str[i+1]-48;j++ ){
				cout<<str[i+2];
			}
			i+=2;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 1180
function main(input) {
  lines = input.split('\n')
  v = lines[0].split(' ').map((n) => parseInt(n));
  h = v[0];
  w = v[1];
  s = [];
  for (i = 1; i < h + 1; i++) {
    s.push(lines[i]);
  }
  dw = [];
  dh = [];
  for (i = 0; i < h; i++) {
    cw = [];
    count = 0;
    for (j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cw.push(0);
      } else if (j == 0 || s[i][j - 1] == '#') {
        count = 0;
        for (k = j; k < w; k++) {
          if (s[i][k] == '.') {
            count ++;
          } else {
            break;
          }
        }
        cw.push(count);
      } else {
        cw.push(count);
      }
    }
    dw.push(cw);
  }
  for (j = 0; j < w ; j++) {
   ch = [];
   count = 0;
   for (i = 0 ; i < h ; i++) {
     if (s[i][j] == '#') {
       ch.push(0);
     } else if (i == 0 || s[i - 1][j] == '#') {
       count = 0;
       for (k = i; k < h; k++) {
         if (s[k][j] == '.') {
           count += 1;
         } else {
           break;
         }
       }
       ch.push(count);
     } else {
       ch.push(count);
     }
   }
   dh.push(ch);
  }
  max = 0;
  for (i = 0; i< h; i++) {
    for (j = 0; j < w; j++) {
      sum = dw[i][j] + dh[j][i];
      if (max < sum) {
        max = sum;
      }
    }
  }
  console.log( max - 1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 126336
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 1e4 + 10;
ll a[maxn];
void solve(){
    ll n, m; cin >> n >> m;
    for(int i = 0; i < m; i++) cin >> a[i];
    ll sum = 0;
    for(int i = 0; i < m; i++) sum += a[i];

    if(sum <= n)  cout << n - sum << endl;
    else cout << -1 << endl;
}
int main(){
    IOS; int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3708
from collections import deque
n=int(input())
a=deque()
a=list(map(int,input().split()))
s=0
if a.count(0) == 0:
  s=1
  for i in range(n):
    l=a.pop()
    s=s*l      
  
    if len(str(s)) >= 19:
      if s == 10**18 and i==n-1:
        break
      s=-1
      break

    
print(s)

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

int main()
{
    int n,d,x;
    cin>>n>>d>>x;
    int arr,sum=0;
    for(int i=0;i<n;i++)
    {
        int ans=0;
        cin>>arr;
        for(int j=0;1;j++)
        {
           if(arr*j+1>d)
            break;
            ans++;
        }
        //cout<<ans<<endl;
        sum=sum+ans;
    }
    cout<<sum+x<<endl;

    
    
}

Measured memory_bytes: 256
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
d = {}
dd = set()
for i in l:
    if i in d:
        d[i] += 1
        dd.add(i)
    else:
        d[i] = 1
r = list(d.keys())
m = len(set(l))
c = 0
x = 0
for i in range(m):
    for j in range(i + 1, m):
        for k in range(j + 1, m):
            x = 0
            if r[i] + r[j] > r[k]:
                x = 1
            if r[i] in dd:
                x *= d[r[i]]
            if r[j] in dd:
                x *= d[r[j]]
            if r[k] in dd:
                x *= d[r[k]]
            c += x
print(c)

Measured memory_bytes: 8960
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	n := nextInt()
	x := nextInt()
	a := nextInts(n)
	sort.Ints(a)
	ans := 0
	for i := 0; i < n-1; i++ {
		if x >= a[i] {
			x -= a[i]
			ans++
		} else {
			break
		}
	}
	if x == a[len(a)-1] {
		ans++
	}
	fmt.Println(ans)
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[i].b
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int g = __gcd(i, j);
      for (int k = 1; k <= n; k++) {
        sum += __gcd(g, k);
      }
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n;
    cin >> n;
    for(int i = 0; i < s.size(); ){
       cout << s[i];
       i += n;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=1<<30;
int dp[1<<15][15];
vector<pair<int,int>> ls[15];
int main(){
	int v,e;	cin>>v>>e;
	for(int i=0;i<e;i++){
		int s,t,d;	cin>>s>>t>>d;
		ls[s].push_back(make_pair(t,d));
	}
	for(int i=0;i<15;i++){
		for(int j=0;j<1<<15;j++)	dp[j][i]=inf;
	}
	dp[0][0]=0;
	for(int i=0;i<(int)ls[0].size();i++){
		int to=ls[0][i].first,cost=ls[0][i].second;
		dp[1<<to][to]=cost;
	}
	for(int i=1;i<(1<<v);i++){
		for(int j=0;j<v;j++){
			if(dp[i][j]==inf)	continue;
			for(int k=0;k<(int)ls[j].size();k++){
				int to=ls[j][k].first,cost=ls[j][k].second;
				if(i&(1<<to))	continue;
				dp[i|(1<<to)][to]=min(dp[i|(1<<to)][to],dp[i][j]+cost);
			}
		}
	}
	if(dp[(1<<v)-1][0]==inf)	cout<<-1<<endl;
	else 	cout<<dp[(1<<v)-1][0]<<endl;
	return 0;
}

Measured memory_bytes: 5000
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int F(int x){
    int L = 1 , R = 1e7 ; 
    int ans = -1 ;
    while(L <= R){
        int mid = L + (R - L) / 2 ;
        if ( mid * (mid + 1) / 2 <= x ){
            ans = mid ; 
            L = mid + 1 ;
        }
        else R = mid - 1;
    }
    assert(ans != -1) ; 
    return ans ; 
}
signed main(){
    fastio
    int n ;
    cin >> n ;
    if ( n == 1 ) {
        cout << 0 << endl ; 
        return 0 ; 
    }
    map<int,int> mp ;
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            mp[i]++; 
            n /= i ; 
        }
    }
    if ( n > 1 ) mp[n]++ ;
    int ans = 0 ;
    for(auto &p : mp){
        ans += F(p.second) ; 
    }
    cout << ans << endl ;
    return 0; 
}

Measured memory_bytes: 3600
//
//  main.cpp
//  042
//
//  Created by Coma on 2020/05/12.
//  Copyright © 2020 Coma. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int N, L;
    
    cin >> N >> L;
    vector<string> vs;
    string stmp;
    
    for(int i = 0; i < N; i++)
    {
        cin >> stmp;
        vs.push_back(stmp);
    }
    
    sort(vs.begin(), vs.end());
    
    for_each(vs.begin(), vs.end(), [](string str)
             {
        cout << str;
    });
    cout << endl;
    
    return 0;
    
    /*
    string stmp;
    
    vector<int> vi(N);
    for(int i = 0; i < N; i++)
    {
        vi[i] = 0;
        
        cin >> stmp;
        vs.push_back(stmp);
        
        char* chr1 = new char[vs[i].size()+1];
        strcpy(chr1, vs[i].c_str());
        
        int itmp = 0;
        for(int j = 0; j < vs[i].size(); j++)
        {
            //cout << hex << int(chr1[j]) << endl;
            //cout << hex << int(chr1[j]<<8*j) << endl;
            itmp += int(chr1[j]<<8*j);
        }
        
        vi[i] = itmp;
        
        //cout << vi[i] << endl;
    }
    
    sort(vi.begin(), vi.end());

    for(int i = 0; i < N; i++)
    {
        int x = vi[i];
        for(int j = 0; j < L; j++)
        {
            cout << char((x>>(8*j))&0xFF);
        }
    }

    return 0;
     */
}


Measured memory_bytes: 256
/*
Keep clam  Believe youself
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<cmath>
#define Xiaobo main
using namespace std;
const int maxn=2e5+7;
const int mod=1e9+7;
const double eps=1e-15;
const double pi=acos(-1);
const int INF=0x3f3f3f3f;
typedef long long ll;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
//别急 dp找状态 问题看看本身的规律 贪心找方法
ll a[maxn];
ll n,k;
bool ok(ll x) 
{
	ll sum=0;
	for(int i=0;i<n;i++) {
		if(a[i]*a[i]<=x) sum--;
		if(a[i]<0) {
			ll mx=x/a[i]-1;
			while(mx*a[i]>x) mx++;
			int id=lower_bound(a,a+n,mx)-(a);
			sum+=n-id;
		}
		else if(a[i]>0) {
			ll mx=x/a[i]+1;
			while(mx*a[i]>x) mx--;
			int id=upper_bound(a,a+n,mx)-(a);
			sum+=id;
		}
		else {
			if(x>=0) sum+=n;
		}
	}	
	return sum/2>=k;
} 
int Xiaobo()
{
	
	cin>>n>>k;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a,a+n);
	ll l=-1e18,r=1e18,ans=0;
	while(l<=r) {
		ll mid=(l+r)/2;
		if(ok(mid)) {
			r=mid-1;
			ans=mid;
		}
		else l=mid+1;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // get value from StandardIn
    int n = Integer.parseInt(sc.next());
    int r = Integer.parseInt(sc.next());
    if(n>=10){
      System.out.println(r);
    }else{
      System.out.println(r+100*(10-n));
    }
    // System.out.println(n);
  }
}


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

#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define all(vec) vec.begin(), vec.end()

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

int h, w, n, a, b, cnt, x, y, nx, ny, nnx, nny, sum;
vector<int>v;
unordered_map<int, bool>mp;
int ans[10];
signed main() {
	scanf("%lld %lld %lld", &h, &w, &n);
	rep(i, n) {
		scanf("%lld %lld", &a, &b);
		--a; --b;
		v.emplace_back(w * a + b);
	}
	sort(all(v));
	for (int i : v) {
		y = i / w, x = i % w;
		rep(j, 9) {
			nx = x + dx[j], ny = y + dy[j];
			if (1 <= nx && nx < w - 1 && 1 <= ny && ny < h - 1) {
				if (!mp[w * ny + nx]) {
					mp[w * ny + nx] = true;
					rep(k, 9) {
						nnx = nx + dx[k], nny = ny + dy[k];
						if (binary_search(all(v), w * nny + nnx)) {
							++cnt;
						}
					}
					++ans[cnt];
					++sum;
					cnt = 0;
				}
			}
		}
	}
	ans[0] += (h - 2) * (w - 2) - sum;
	for (int i : ans) {
		printf("%lld\n", i);
	}
}


Measured memory_bytes: 37472
#include<iostream>
using namespace std;
int main(void)
{
    int k, n, a1, an, am, max = 0;
    cin >> k >> n;
    
    cin >> a1;
    an = a1;
    for(int i=1; i<n; i++)
    {
        am = an;
        cin >> an;
        if (max < an - am)
          max = an - am;
    }
    if (max < (k - an + a1))
      max = k - an + a1;
    cout << k - max << endl;
  
    return 0;
}

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

int main(int argc, char const *argv[])
{
    int a;
    int b;
    int c;
    cin >> a >> b >> c;

    if (b - a == c - b)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }

    return 0;
}

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

using namespace std;


int main(){
    long long int a,b,x,ans;

    cin >> a >> b >> x;
    ans = 0;

    for(long long int i=a/x * x;i<=b;i+=x){


        if(i%x == 0 && i>=a){
            ans++;
            ans += (b-i)/x;
            break;
        }

    }

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


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

ll powmod(ll n, ll k) {
  ll ret = 1;
  while (k) {
    if (k & 1) ret = ret * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return ret;
}

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  ll cnt = 0;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') continue;
    ans += powmod(2, cnt) * powmod(3, n - i - 1) % MOD;
    cnt++;
  }
  ans += powmod(2, cnt);
  cout << ans % MOD << endl;
  return 0;
}


Measured memory_bytes: 512
#D - Grid Repainting
#最短距離のルートを記録してあとはすべて黒く塗る
import copy
import sys
from collections import deque
#幅優先のロジックを作成する
H,W = (int(i) for i in input().split())
s_tmp = []
for _ in range(H):
    s_tmp.append(list(input()))
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
q = deque()
s = copy.deepcopy(s_tmp)
q.append([0,0,0])
s[H-1][W-1] = 'g'
s[0][0] = 's'
flg = False

def result():
    cnt = 0
    for j in range(W):
        for i in range(H):
            if s_tmp[i][j] =='.':
                cnt += 1
    if flg == False:
        print(-1)
    else :
        print(cnt-z-2)
        
while len(q) > 0:
    #print(q)
    node = q.popleft()#qから左端を取り出す(幅優先)
    if node is not None:
        y = node[0]
        x = node[1]
        z = node[2]
        s[y][x] = '#'
        #上下を探索して移動できるところをスタックする
        for dx, dy in d:
            nx, ny = x + dx, y + dy
            if not (0 <= nx < W and 0 <= ny < H) or s[ny][nx] == '#':
                continue
            else:
                tmp = [ny,nx,z+1]
                if s[ny][nx] != 'y':
                    q.append(tmp)
                if s[ny][nx] == 'g' and flg == False:
                    #print(z+1)
                    flg = True
                    result()
                    sys.exit()
                s[ny][nx] = 'y'
if flg == False:
        print(-1)

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

int main(){
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string s;
        cin >> s;
        cout << s << endl << s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

get_ints = lambda: [int(st) for st in input().split()]
N=int(input())
inarr=get_ints()
sorted_in = sorted(inarr)
comb = N*(N+1) // 2

bit = Bit(2*N+1)
def binsearch(lft, rgt):
    half = (lft + rgt) // 2
    if lft >= half:
        return half
    summed = 0
    res = 0
    bit.reset()
    bit.add(N, 1)
    for x in inarr:
        value = 1 if x >= sorted_in[half] else -1
        summed += value
        count = bit.sum(N + summed)
        bit.add(N + summed, 1)
        res += count
    return binsearch(half, rgt) if res >= math.ceil(comb/2) else binsearch(lft, half)

res = binsearch(0, N)
print(sorted_in[res])


Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,sum=0;
  string s;
  cin>>a>>b;
  if(a>=13) cout<<b<<'\n';
  else if(a>=6) cout<<b/2<<'\n';
  else cout<<0<<'\n';
  return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 21.12.2019 21:42:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> s;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    s.push_back(x);
    while (s.size() >= 3 && s[s.size() - 2] > s.back() && s[s.size() - 2] > s[s.size() - 3]) {
      s[s.size() - 3] = s[s.size() - 3] - s[s.size() - 2] + s.back();
      s.pop_back();
      s.pop_back();
    }
  }
  long long ans = 0;
  int i = 0, j = (int) s.size() - 1;
  int f = 1;
  while (i <= j) {
    ans += f * (s[i] > s[j] ? s[i++] : s[j--]);
    f = -f;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int h[100000];
int n;
int m[100000];
int w(int i,int j)
{
    if(h[i]>h[j])
        return h[i]-h[j];

        return h[j]-h[i];
}
int min(int i,int j)
{
    return i<j?i:j;
}
int f(int i)
{
    if(i==n)
        return 2<<25;
    if(i==n-1)
        return 0;
    if(m[i]!=-1)
        return m[i];
    m[i]=min(f(i+1)+w(i,i+1),f(i+2)+w(i,i+2));
    return m[i];
}
int main()
{
    int i,k;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&h[i]);
    for(i=0;i<n;i++)
        m[i]=-1;
    k=f(0);
    printf("%d",k);
    return 0;
}


Measured memory_bytes: 5556
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l = 0;
  for (int i = 0; i < s.size(); i++){
    if (s.at(i) == 'x')
      l++;
  }
  if (l >= 8)
    cout << "NO" << endl;
  else cout << "YES" << endl;
}


Measured memory_bytes: 256
n, k = input().split()
n = int(n)
k = int(k)
p = list(map(int, input().split()))
if n==k:
	print((sum(p)+n)/2)
else:
	q = [p[0]]
	for i in range(n-1):
		q.append(q[i]+p[i+1])
	r = []
	for i in range(n-k):
		r.append(q[i+k]-q[i])
	r.sort(reverse=True)
	print((r[0]+k)/2)

Measured memory_bytes: 25928
#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))
const int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#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>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

set<int> edge[10];

int main(void){
    int N,M;
    cin >> N >> M;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        edge[a].insert(b);
        edge[b].insert(a);
    }
    int A[N];
    int ans=0;
    rep(i,N) A[i]=i;
    do{
        if(A[0]!=0) break;
        bool reach[N]={};
        bool che=true;
        rep(i,N-1){
            if(!edge[A[i]].count(A[i+1])) che=false;
        }
        if(che) ans++;
    }while(next_permutation(A,A+N));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long a,  long long b) {
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long c_num = b / c - (a - 1) / c;
	long long d_num = b / d - (a - 1) / d;
	long long cd = lcm(c, d);
	long long cd_num = b / cd - (a - 1) / cd;

	long long ans = (b - a + 1) - (c_num + d_num - cd_num);
	cout << ans << endl;
}

Measured memory_bytes: 256
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# a, b
# s = input()

N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += d[i] * d[j]
print(ans)


Measured memory_bytes: 3060
S = input()
K = int(input())

left = S[0]
right = S[-1]

inside = []
tmp = 1
bef = ""
for idx, val in enumerate(S):
    if idx == 0:
        bef = val
        continue
    if val == bef:
        tmp += 1
    else:
        inside.append(tmp)
        tmp = 1
    bef = val
else:
    inside.append(tmp)

ans = 0
if left == right:
    if len(inside) == 1:
        print((len(S) * K )// 2)
    elif len(S) > 2:
        head = inside[0]
        tail = inside[-1]
        center = inside[1:-1]
        init = inside[:-1]
        last = inside[1:]
        joint = head + tail

        init_op = 0
        last_op = 0
        for i in init:
            if i != 1:
                init_op += i //2
        for i in last:
            if i != 1:
                last_op += i //2
        joint_op = joint // 2
        center_op = 0
        for i in center:
            if i != 1:
                center_op += i //2

        if K == 1:
            ans = init_op + tail // 2
        else:
            ans += init_op
            ans += last_op
            ans += joint_op * (K - 1)
            ans += center_op * (K - 2)
        print(ans)
    elif len(S) == 1:
        print(K // 2)
    elif len(S) == 2:
        print(K)
else:
    for i in inside:
        if i != 1:
            ans += i //2
    print(ans * K)


Measured memory_bytes: 3064
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = next()
    val sum = n.map { it.toString().toInt() }.sum()
    println(if (n.toInt() % sum == 0) "Yes" else "No")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31892
#include<stdio.h>
int main(void)
{
	long long a,b,c,d,x[4],y,i;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	x[0]=a*d;
	x[1]=a*c;
	x[2]=b*c;
	x[3]=b*d;
	y=x[0];
	for(i=0;i<4;i++){
		if(y<x[i]) y=x[i];
	}
	printf("%lld\n",y);
	return 0;
}


Measured memory_bytes: 1736
from collections import defaultdict

n = int(input())
data_1 = defaultdict(int)
data_2 = defaultdict(int)
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
for i in range(n):
    if i % 2 == 0:
        data_1[v[i]] += 1
    else:
        data_2[v[i]] += 1
data_1 = sorted(data_1.items(), key = lambda x: x[1],reverse = True)
data_2 = sorted(data_2.items(), key = lambda x: x[1],reverse = True)

ans = n - data_1[0][1] - data_2[0][1]
if data_1[0][0] == data_2[0][0]:
    ans = n - max(data_1[0][1] + data_2[1][1], data_1[1][1] + data_2[0][1])
print(ans)


Measured memory_bytes: 22492
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 2e5 + 5;
int tree[4*N] , a[N], h[N], dp[N];  

void update(int node, int start, int end,int idx, int val) {
	if(start == end) {
		tree[node] = val ;
		return ;
	}
	int mid = (start + end) >> 1 ;
	
	if(start <= idx and idx <= mid) update(2*node, start, mid, idx, val) ;
	else update(2*node+1, mid+1, end, idx, val) ;
	tree[node] = max(tree[2*node], tree[2*node+1]);
}

int query(int node, int start,int end,int l, int r) {
	if(r < start or l > end ) return 0 ;
	if(l <= start and end <= r) return tree[node] ;
	int mid = (start + end) >> 1 ;
	return max(query(2*node,start, mid, l,r), query(2*node+1,mid+1,end,l,r));
}

void solve(int test) {
	int n; cin >> n ;
	rep(i,1,n+1) cin >> h[i] ;
	rep(i,1,n+1) cin >> a[i] ;

	rep(i,1,n+1) {
		dp[h[i]] = a[i] + query(1,1,n,0,h[i]-1) ;
		update(1,1,n,h[i], dp[h[i]]) ;
	}

	cout << *max_element(dp+1, dp+n+1 ) ; 
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif   

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int>A(N);
 
for(int i=0;i<N;i++){
  cin>>A.at(i);
}
  
sort(A.begin(),A.end());
reverse (A.begin(),A.end());
  
int count=0;
for(int i=0;i<N;i++){
  count+=A.at(i);
}

if(A.at(M-1)<(double)count/(M*4)){
  cout<<"No"<<endl;
}
else{
  cout<<"Yes"<<endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    vector<ll> a(5);
    rep(i,5) cin>>a[i];
    ll res=0, tmp=100;
    rep(i,5){
        if(a[i]%10==0) res+=a[i]/10;
        else {
            res+=a[i]/10+1;
            chmin(tmp, a[i]%10);
        }
    }
    if(tmp==100) cout<<res*10<<endl;
    else cout<<(res-1)*10+tmp<<endl;
    return 0;
}

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

using namespace std;

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

    sort(X.begin(), X.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if(i & 1) ans -= X[i];
        else ans += X[i];
    }
    cout << ans << endl;
}

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

int L[100005];
int main() {
	int n, a;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a);
		L[a] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (i == n) {
			printf("%d\n", L[i]);
		}
		else printf("%d ", L[i]);
	}

	return 0;
}


Measured memory_bytes: 4100
from bisect import bisect_right
s = input()
t = input()
alpha = [[] for _ in range(26)]
def f(c): return ord(c)-ord("a")

for i,c in enumerate(s): alpha[f(c)].append(i)
idx = -1
loop = 0
for c in t:
    lst = alpha[f(c)]
    if not lst:
        ans = -1
        break
    i = bisect_right(lst,idx)
    if i == len(lst):
        loop += 1
        idx = lst[0]
    else:
        idx = lst[i]
else:
    ans = len(s)*loop+idx+1
print(ans)

Measured memory_bytes: 7668
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        Map<String, Map<Integer, Integer>> gidebook = new TreeMap<>();

        for (int i = 1; i <= num; i++) {
            String inCity = sc.next();
            if (!gidebook.containsKey(inCity)) {
                gidebook.put(inCity, new TreeMap<Integer, Integer>(Comparator.reverseOrder()));
            }
            gidebook.get(inCity).put(sc.nextInt(), i);
        }

        for (String city : gidebook.keySet()) {
            for (Integer score : gidebook.get(city).values()) {
                System.out.println(score);
            }
        }

    }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int firstNumber = scan.nextInt();
		int i[] = new int[3];
		for (int k = 0; k < firstNumber; k++) {
			for (int j = 0; j < i.length; j++) {
				i[j] = scan.nextInt();
			}
			Arrays.sort(i);
			if ((i[2] * i[2]) == (i[1] * i[1]) + (i[0] * i[0])) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

	}
}

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

using namespace std;
int main(){
    long long int X, temp1, temp2;
    bool find = false;

    cin>>X;

    for(long long int i=-5000; i<50000; i++){
        for(long long int j=-5000; j<50000; j++){
            if(i*i*i*i*i - j*j*j*j*j == X){
                temp1 = i;
                temp2 = j;
                find = true;
                break;
            }
        }
        if(find){
            break;
        }
    }

    cout<<temp1<<" "<<temp2<<"\n";

    return 0;
}



Measured memory_bytes: 3640