akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,p;
int ans=1,x=1;
signed main(){
    cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    for(int i=2;x<=p;i++){
        x=1;
        for(int j=0;j<n;j++){
            x*=i;
            if(x>p){
                cout<<ans<<endl;
                return 0;
            }
        }
        if(p%x==0)ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
const int N=2e3+10;

int h, w;
char a[N][N];
int up[N][N], down[N][N], L[N][N], R[N][N];

int main() {
	cin>>h>>w;
	
	for(int i=0; i<=h+1; i++) {
		for(int j=0; j<=w+1; j++) {
			a[i][j]='#';
		}
	}

	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			cin>>a[i][j];
		}
	}
	

	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			if (a[i][j]=='#') continue;
			if (a[i-1][j]=='.') up[i][j]=up[i-1][j]+1;
			if (a[i][j-1]=='.') L[i][j]=L[i][j-1]+1;
		}
	}
	for(int i=h; i>=1; i--) {
		for(int j=w; j>=1; j--) {
			if (a[i][j]=='#') continue;
			if (a[i+1][j]=='.') down[i][j]=down[i+1][j]+1;
			if (a[i][j+1]=='.') R[i][j]=R[i][j+1]+1;
		}
	}
	int ans=0;
	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			if (a[i][j]=='#') continue;
			ans=max(ans, up[i][j]+down[i][j]+L[i][j]+R[i][j]+1);
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 67328
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <map>
#include <time.h>
#include <cstdlib>
#include <iomanip>
#include <array>

#pragma warning(disable:4996)

using namespace std;

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



int main(void) {
	int n,*a,*b,ans=0;
	cin >> n;
	a = new int[n], b = new int[n];
	FOR(i, 0, n) {
		cin >> a[i];
		b[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		if (b[i]!=1 && b[a[i]-1] != 1) {
			if (i == a[a[i]-1]-1) {
				ans++;
				b[i] = 1, b[a[i]-1] = 1;
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import math
N=int(input())
for i in range(N):
    a,b,c=map(int, input().split())
    if c==math.sqrt(a**2+b**2) or b==math.sqrt(a**2+c**2) or a==math.sqrt(c**2+b**2):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5660
#95c
A,B,C,X,Y = map(int, input().split())

#1≤A,B,C≤5000
#1≤X,Y≤10**5

#愚直解　TLEする。
#minimum_cost = 5000*A + 5000*B +5000*C
#
#for i in range(0,X+1):
#    for j in range(0,Y+1):
#        #残りの必要枚数は?
#        remain = max(X-i,Y-j) 
#        cost = A*i + B*j + C*(remain*2) #残り枚数が多い方の2倍の枚数、ABを買う
#        if minimum_cost > cost:
#            minimum_cost = cost
#
#print(minimum_cost)

minimum_cost = X*A + Y*B + (X+Y)*C

if X>Y:
    for A_pizza in range(0,X+1):
        AB_pizza = (X-A_pizza)*2 #Aピザの残りの必要枚数からABピザの購入枚数が求まる

        if Y - AB_pizza//2 > 0:
            B_pizza = Y - AB_pizza//2 #ABピザの購入枚数からBピザの購入枚数が求まる。ただしマイナスになるなら足りてるので買わない
        else:
            B_pizza = 0

        cost = A*A_pizza + B*B_pizza + C*AB_pizza #残り枚数が多い方の2倍の枚数、ABを買う

        #print(A_pizza,B_pizza,AB_pizza,cost)

        if minimum_cost > cost:
            minimum_cost = cost
            
else:
    for B_pizza in range(0,Y+1):
        AB_pizza = (Y-B_pizza)*2 #Aピザの残りの必要枚数からABピザの購入枚数が求まる

        if X - AB_pizza//2 > 0:
            A_pizza = X - AB_pizza//2 #ABピザの購入枚数からBピザの購入枚数が求まる。ただしマイナスになるなら足りてるので買わない
        else:
            A_pizza = 0

        cost = A*A_pizza + B*B_pizza + C*AB_pizza #残り枚数が多い方の2倍の枚数、ABを買う

        #print(A_pizza,B_pizza,AB_pizza,cost)

        if minimum_cost > cost:
            minimum_cost = cost
            
print(minimum_cost)

#入力の大小関係が異なるパターンに注意

Measured memory_bytes: 3064
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	int dp[n+1],h[n+1];
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for(int i=3;i<=n;i++){
		dp[i] = 1e18;
		for(int j = 1;j <= k && (i-j) >= 1;j++){
			dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]));
		}
	}
	cout<<dp[n];
	return 0;
}
//.........

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    static int[][] dp;
    static int mod  = 1000000007;

    static int max(int a, int b){
        if( a > b )
            return a;
        return b;
    }

    static int calculate(String[] arr, int i, int j){

        if(i < 0 || j < 0)
            return 0;

        if(dp[i][j] != -1){
            return dp[i][j];
        }

        if(arr[i].charAt(j) == '#'){
            dp[i][j] =  0;
            return dp[i][j];
        }

        if(i == 0 && j == 0){
            dp[i][j] = 1;
            return dp[i][j];
        }

        dp[i][j] = (calculate(arr,i-1,j)+calculate(arr,i,j-1))%mod;
        return dp[i][j];
    }

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

        String[] arr = new String[h];
        dp = new int[h][w];

        for(int i = 0; i < h; i++){
           arr[i] = sc.next();
        }

        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                dp[i][j] = -1;
            }
        }

        System.out.println(calculate(arr,h-1,w-1));
    }
}


Measured memory_bytes: 33680
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoderSolve.Tool;

namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            string s = Console.ReadLine();
            bool ok = true;
            for (var i=0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (s[i] == 'L')
                    {
                        ok = false;
                        break;
                    }
                }
                else
                {
                    if (s[i] == 'R')
                    {
                        ok = false;
                        break;
                    }
                }
            }

            Console.WriteLine(ok ? "Yes" : "No");

            //Console.Out.Flush();
        }

    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for(var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public long ModuloP(long value,long mod)
        {
            long r = value % mod;
            
            if (r * mod < 0)
            {
                r += mod;
            }
            return r;
        }

    }

    struct Pair<T> : IComparable<Pair<T>> where T : IComparable<T>
    {
        public T variable;
        public int index;

        public Pair(T val, int i)
        {
            variable = val;
            index = i;
        }

        public int CompareTo(Pair<T> otherPair)
        {
            return variable.CompareTo(otherPair.variable);
        }

        public int CompareIndex(Pair<T> otherPair)
        {
            return index.CompareTo(otherPair.index);
        }
    }



}






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

int main(){
	int n;
	int ans=0;
	std::vector<long long> aList;
	std::vector<long long> bList;
	std::vector<long long> delta;
	long long minusSum=0;
	std::vector<long long> plusList;

	std::cin>>n;
	aList.resize(n);
	bList.resize(n);
	delta.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	for(int i=0; i<n; i++)
		std::cin>>bList[i];

	for(int i=0; i<n; i++)
		delta[i]= aList[i]-bList[i];

	for(int i=0; i<n; i++){
		if(delta[i]<0){
			minusSum+= delta[i];
			ans++;
		}
		else
			plusList.push_back(delta[i]);
	}

	std::sort(plusList.begin(), plusList.end(), [](long long x, long long y){return x>y;});

	for(int i=0; i<plusList.size(); i++){
		if(minusSum>=0)
			break;

		minusSum+= plusList[i];
		ans++;
	}

	if(minusSum<0){
		std::cout<<-1<<std::endl;
		return 0;
	}
	else{
		std::cout<<ans<<std::endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 3576
#include <cstdio>

using namespace std;

typedef long long ll;

int n;
int a[1 << 20];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[a[i]] == i) {
      ans++;
    }
  }
  printf("%d\n", ans / 2);
}


Measured memory_bytes: 512
# coding: utf-8

N = int(input())
L = []
p1 = 0
p2 = float('inf')
r1 = float('inf')
r2 = 0
for i in range(N):
    a, b = map(int,input().split())
    L.append([a, b])
    r1 = min(a, r1)
    p1 = max(b, p1)
    r2 = max(a, r2)
    p2 = min(b, p2)

ans = r2
for i in range(N):
    if L[i][0] == r2:
        ans += L[i][1]
print(ans)

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

int main(){
  int n,m;
  cin >> n>>m;
  vector<int> broken(m);
  vector<int> dp(n);
  rep(i,n) cin>> broken[i];
  int bindex = -1;
  int b=-1;
  for(int i=0;i<n;i++){
    while(b<i+1){
      bindex++;
      if (bindex >= m) break;
      b = broken[bindex];
    }
    if(i==0){
      dp[0] = b == 1 ? 0 : 1;
    }
    else if(i==1){
      dp[1] = b == 2 ? 0 : dp[0] + 1;
    }
    else
      dp[i] = b == i+1 ? 0 : (dp[i-1] + dp[i-2]) % MOD;
  }
  cout << dp[n-1] << endl;
}



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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n, ans = 0;
    cin >> n;
    n++;
    ans = n / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
sss = input()

now = 1
cnt = 0
x = []

for i in range(n):
    if sss[i] == str(now):
        cnt += 1
    else:
        x.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    x.append(cnt)
if sss[-1] == 0:
    x.append(0)

Add = 2 * k + 1
ans = 0

y = [0]
for i in range(len(x)):
    y.append(y[i] + x[i])

for i in range(len(x))[::2]:
    left = i
    right = min(i + Add, len(x))
    tmp = y[right] - y[left]
    
    ans = max(tmp, ans)

print(ans)


Measured memory_bytes: 7932
using System;

namespace A
{
    class Node
    {
        public int key = -1;
        public int id;
        public int left = -1;
        public int right = -1;
        public void node()
        {
            key = -1;
        }
    }

    class Tree
    {
        public Node[] node = new Node[500001];
    }

    class Output
    {
        public void insert(ref Tree tree, int key, int nowid)
        {
            if (tree.node[0].key == -1)
            {
                tree.node[0].key = key;
            }
            else
            {
                int x = 0, parent=0;
                while (x!= -1)
                {
                    parent = tree.node[x].id;
                    if (key < tree.node[x].key)
                    {
                        x = tree.node[x].left;
                    }
                    else
                    {
                        x = tree.node[x].right;
                    }
                }

                if (key < tree.node[parent].key)
                {
                    tree.node[parent].left = nowid;
                }
                else
                {
                    tree.node[parent].right = nowid;
                }
                tree.node[nowid].key = key;
            }
        }

        public void inorder(Tree tree, int key)
        {
            if (tree.node[key].left != -1)
            {
                inorder(tree, tree.node[key].left);
            }
            Console.Write(" " + tree.node[key].key);
            if (tree.node[key].right != -1)
            {
                inorder(tree, tree.node[key].right);
            }
        }

        public void preorder(Tree tree, int key)
        {
            Console.Write(" " + tree.node[key].key);
            if (tree.node[key].left != -1)
            {
                preorder(tree, tree.node[key].left);
            }
            if (tree.node[key].right != -1)
            {
                preorder(tree, tree.node[key].right);
            }
        }
    }

    class A
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int n = int.Parse(input1), i;
            string[] input2 = new string[2];
            Output output = new Output();
            Tree tree = new Tree();
            int count = 0;
            for (i = 0; i < tree.node.Length; i++)
            {
                tree.node[i] = new Node();
                tree.node[i].id = i;
            }
            for (i = 0; i < n; i++)
            {
                input2 = Console.ReadLine().Split(' ');
                if (input2[0] =="print")
                {
                    output.inorder(tree, 0);
                    Console.WriteLine();
                    output.preorder(tree, 0);
                    Console.WriteLine();
                }
                else
                {
                    output.insert(ref tree, int.Parse(input2[1]), count);
                    count++;
                }
            }
        }
    }
}



Measured memory_bytes: 41592
n = int(input())
A = list(map(int,input().split()))
Can = [0]*n
ans = 0
can = 1
for i,a in enumerate(A):
    if can < a:
        print(-1)
        exit(0)
    elif i < n:
        can -= a
        can *= 2
        Can[i] = can
real = A[-1]
for i in range(n-1,-1,-1):
    ans += real
    real = min(real,Can[i]//2)
    real += A[i]
print(ans + 1)


Measured memory_bytes: 706308
N,Q = list(map(int,input().split()))
S = input()
S = S + "#"
sum = [0]
for i in range(1,N+1):
  sum.append(sum[i-1] + (S[i-2:i] == "AC"))
for i in range(Q):
  l,r = list(map(int,input().split()))
  res = sum[r]-sum[l-1]
  print(res-1 if S[l-2:l] == "AC" else res)

Measured memory_bytes: 7796
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

template<class Abel> struct WeightedUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<map<int, ll>> a(n);
  REP(i, n) a[i][i] = 0;
  WeightedUnionFind<ll> tree(n);
  REP(i, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    l--;r--;
    if(tree.same(l, r)) {
      ll diff = tree.diff(l, r);
      if(diff != d) {
        cout << "No" << endl;
        return 0;
      }
      continue;
    }
    tree.merge(l, r, d);
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 12928
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;



int main(void) {

    int X; cin>>X;
    int ans = 1;
    for (int i = 2; i <= X; ++i) {
        for (int j= i*i; j <= X; j*=i) {
            ans = max(ans, j);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int x,y;
for(;;)
  {
scanf("%d",&x);
 scanf("%d",&y);
 if(!(x==0 && y==0))
   {
     if(x>y)
       {printf("%d %d\n",y,x);}
     else{printf("%d %d\n",x,y);}
   }
 else{break;}
   }
  
    return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.buffer.readline

def main():
    K,N = map(int,input().split())
    a = list(map(int,input().split()))
    
    a = [a[-1]-K] + a + [a[0]+K]
    
    ans = K
    
    for i in range(N):
        use = max(a[i+1]-a[i],a[i+2]-a[i+1])
        ans = min(ans,K-use)
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};


lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

lli n, k;

bool check(const lli a[], lli x) {
    vlli rems;

    for (int i = 0; i < n; ++i) {
        rems.push_back(a[i] % x);
    }

    sort(all(rems));

    lli l = 0, r = n - 1;
    lli rem = 0, required = 0;

    while (l <= r) {
        if (rem <= 0) {
            rem += rems[l];
            required += rems[l];
            l++;
        } else {
            rem -= (x - rems[r]);
            required += (x - rems[r]);
            r--;
        }
    }

    if (rem) return false;
    return (required <= 2 * k);

}

void solve() {
    cin >> n >> k;
    lli a[n], sum = 0, ans = 0;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    for (lli i = 1; i * i <= sum; ++i) {
        if (sum % i) continue;

        if (check(a, i)) ans = max(ans, i);
        if (check(a, sum / i)) ans = max(ans, sum / i);
    }

    cout << ans << endl;
}


int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
A=int(input())
B = [input() for _ in range(A)]
count = 0
if len(set(B)) != len(B):
  print('No')
else:
  for b in B:
    if count == 0:
      k = b[-1]
      count += 1
    else:
      if k == b[0]:
        k = b[-1]
      else:
        print('No')
        exit()
  print('Yes')
      

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
const int MAX = 3000;
const int MOD = 998244353;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

int main() {
	int n, s;
	cin >> n >> s;
	long long dp[MAX+1] = {};
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		for (int j = s; j >= 0; j--) {
			dp[j] = mod(dp[j] * 2);
			if (j - a >= 0) dp[j] = mod(dp[j] + dp[j-a]);
		}
	}
	long long ans = dp[s];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main()
  

{
  string s;
  cin>>s;
  long int sum=0;
  for(int i=0;i<s.size();i++)
  {
    int x=s[i]-'0';
    sum=sum+x;
    
    
    
  }
  if(sum%9==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    

  
  
  
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define debb(x) cout << (x) << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=2e5+10;

ll par[mxn];
ll sz[mxn];

ll find(ll x){
	if(par[x]==x) return x;
	else return par[x]=find(par[x]);
}

void join(ll a,ll b){
	a=find(a);
	b=find(b);
	if(a == b){
		return;
	}
	par[a]=b;
	sz[b]+=sz[a];
}



void init(){

	ll i,j;
	for(i=0;i<mxn;i++){
		par[i]=i;
		sz[i]=1;
	}
    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    // iota(itf,its) ;
    // n=unique(a+1,a+1+n,n)-(a+1);


    ll n,m;
    cin >> n >> m;
    ll x,y;
    for(i=0;i<m;i++){
    	cin >> x >> y;
    	join(x,y);
    }
    ll mx=0;
    for(i=1;i<=n;i++){
    	mx=max(mx,sz[find(i)]);
    }
    debb(mx);



    return 0;
}


Measured memory_bytes: 12848
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
int main() {
    // freopen("in.txt", "r", stdin);
    int N;
    long long K;
    cin >> N >> K;
    vector<bool> vis(N+1,false);
    vector<int> t(N+1);
    for(int i=1;i<=N;i++) cin >> t[i];
    int cur = 1, cnt = 0;
    while(vis[cur]==false) {
        vis[cur] = true;
        cur = t[cur];
        cnt++;
    }
    int target = cur, cnt2 = 0;
    cur = 1;
    while(cur!=target && K>0) {
        cur = t[cur];
        cnt2++;
        K--;
    }
    K %= (cnt - cnt2);
    // cout << cnt << " " <<cnt2 << endl;
  	if(cur == target) {
      while(K--) {
          cur = t[cur];
      }
    }
    cout << cur << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;

    if (S[2] == S[3] & S[4] == S[5]){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define MN 1001000

using namespace std;
typedef long long ll;

ll n, k, ans;

int main() {
    scanf("%lld %lld", &n, &k);

    ans += (n / k) * (n / k) * (n / k);

    if(k % 2 == 0) {
        n -= k / 2;
        if(n >= 0) {
            ans += (n / k + 1) * (n / k + 1) * (n / k + 1);
        }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
n,k = gets.chomp.split.map(&:to_i)
@R,@S,@P = gets.chomp.split.map(&:to_i)
T = gets.chomp
ans = 0
def score(c)
  if c == "r"
    @P
  elsif c == "s"
    @R
  elsif c == "p"
    @S
  end
end
(0..k-1).each do |i|
  current = T[i]
  flag = true
  ans += score(T[i])
  loop do
    i += k
    break if i >= n
    if T[i] == current
      if flag
        flag = false
      else
        ans += score(T[i])
        flag = true
      end
    else
      ans += score(T[i])
      flag = true
    end
  current = T[i]
  end
end
puts ans



Measured memory_bytes: 3964
s = str(input())[::-1]

while(len(s) >= 5):
    if s[:5] == 'maerd':
        s = s.replace('maerd', '', 1)
    elif s[:7] == 'remaerd':
        s = s.replace('remaerd', '', 1)
    elif s[:5] == 'esare':
        s = s.replace('esare', '', 1)
    elif s[:6] == 'resare':
        s = s.replace('resare', '', 1)
    else:
        print('NO')
        exit()

else:
    print('YES')


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
 
using namespace std;
using namespace __gnu_pbds;
 
// template<typename T>
using o_set=tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define M 1000010


int main(){
	IOS;
	ll a,b;cin>>a>>b;
	if(a==b)cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

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

vector<int> Input(const int n)
{
	vector<int> W;
	for(int i = 0; i < n; i++){
		int w;
		cin >> w;
		W.push_back(w);
	}
	return W;
}

bool IsAllLoaded(int P, vector<int>& W, int k)
{
	int TrackIndex = 0;
	int CurrentSum = 0;
	int i = 0;
	for(i = 0; i < W.size(); i++){
		if(W[i] > P){
			return false;
		}
		if(CurrentSum + W[i] > P){
			TrackIndex++;
			if(TrackIndex == k){
				return false;
			}
			CurrentSum = 0;
		}
		CurrentSum += W[i];
	}
	return true;
}

int Calc(vector<int> W, int k)
{
	int Sum = accumulate(W.begin(), W.end(), 0 );
	int Ave = Sum / W.size();
	int e = Sum;
	int s = Ave;
	int m = (e + s) / 2;
//	cout << s << ' ' << m << ' ' << e << endl;
	
	while(IsAllLoaded(m, W, k) || !IsAllLoaded(m+1, W, k)){
		if(IsAllLoaded(m, W, k) && IsAllLoaded(m+1, W, k)){
			e = m;
			m = (s + m) / 2;
			if(s == e) return m;
		}else{
			s = m;
			m = (e + m) / 2;
		}
//		cout << s << ' ' << m << ' ' << e << endl;
	}
	return m+1;
}

int main()
{
	int n, k; //n:???????????° k:?????????????????°  
	cin >> n >> k;
	vector<int> W = Input(n);
	int P = Calc(W, k); //P:??????????????????????????????????????????????????§????????????????°????
	cout << P << endl;
	return 0;
}

Measured memory_bytes: 3660
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi l(n);
	int sum = 0;
	rep(i, n) cin >> l[i], sum += l[i];
	rep(i, n){
		if(l[i] >= (sum - l[i])){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
def main():
    a,b = map(int,input().split())
    a_c = ord(str(a))
    b_c = ord(str(b))
    a_s = str(a) * b
    b_s = str(b) * a
    if a_c < b_c:
        answer = a_s
    elif a_c > b_c:
        answer = b_s
    else:
        answer = a_s if len(a_s) <= len(b_s) else b_s
    print(answer)


if __name__ == '__main__':
    main()


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

int main(){
    ll n, p; cin >> n >> p;
    if(p == 1){
        cout << 1 << endl;
        return 0;
    }
    if(n == 1){
        cout << p << endl;
        return 0;
    }
    vector<int> factors;
    // 素因数の表を作る
    for(ll i=2; i<=sqrt(p); i++){
        while(p%i == 0){
            factors.push_back(i);
            p /= i;
        }
        if(p == 1) break;
    }
    if(p != 1){
        factors.push_back(p);
    }
    
    ll tmp = factors[0];
    ll cnt = 1;
    ll ans = 1;
    if(n==1) ans = factors[0];
    for(ll i= 1; i<factors.size(); i++){
        if(tmp == factors[i]){
            cnt++;
        }else{
            tmp = factors[i];
            cnt=1;
        }
        if(cnt%n == 0){
            ans = ans*tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int a, b;

    cin >> a >> b;

    if (a + b == 15) {
        cout << "+";
    } else if (a * b == 15) {
        cout << "*";
    } else {
        cout << "x";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  vector<ll> a(3); cin >> a[0] >> a[1] >> a[2];
  for (int i = 0; i < 3; ++i) {
    if (a[i]%2==0) {
      cout << 0 << endl;
      return 0;
    }
  }

  sort(ALL(a));

  cout << abs((a[2]/2)*a[0]*a[1] - (a[2]+2-1)/2*a[0]*a[1]) << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let l = parse_line!(f64);

    println!("{}", l / 3.0 * l / 3.0 * l / 3.0);
}


Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        double total = (list.get(0) + list.get(1)) / 2.0;
        for(int i=2; i<n; i++) {
            total = (list.get(i) + total) / 2.0;
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 35924
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort;
ans = 0

while n > 1 do
  kougeki = a[0]
  if kougeki == 1
    ans = 1
    break
  else
    (n - 1).times do |i|
      a[i + 1] = a[i + 1] % kougeki
    end
    a.delete(0)
    a = a.sort
    n = a.count
  end
end

if ans != 1
  ans = a[0]
end
puts ans

Measured memory_bytes: 11760
#include <iostream>
int main()
{
	using namespace std;
	int a, b;
	cin >> a >>b;
	if (a > b)
		cout << "a > b" << endl;
    else if (a < b)
    	cout << "a < b" << endl;
    else  
    	cout << "a == b" << endl;
    return 0;
 } 


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std; 
int main()  
{ 
    int n;
    long long a,ans=1,m=(long long)1e18; 
    cin >> n;
    bool f=false;
    for(int i=0;i<n;i++){
    	cin >> a;
    	if(a==0){
    		ans=0;
    		f=false;
			break;
		}	
    	if(!f){
    		if(m/ans<a) {
	    		f=true;
			}
	    	ans*=a;
		}
	}
	if(f) ans=-1;
	
	cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 3616
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

//nCr mod m
#define MOD 998244353
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin>>s;
	int n=s.size();
	vi co(n+1);
	rep(i,n)co[i+1]=co[i]+s[i]-'0';
	vi dp(n+1);
	dp[0]=1;
	rep(i,n){
		vi ndp(n+1);
		rep(j,n)if(dp[j]){
			if(j+1<=co[i+1])(ndp[j+1]+=dp[j])%=MOD;
			if(i+1-j<=2*i+2-co[i+1])(ndp[j]+=dp[j])%=MOD;
		}
		dp=ndp;
	}
	int out=0;
	rep(i,n+1)(out+=dp[i]*nCr(n,co[n]-i)%MOD)%=MOD;
	cout<<out<<endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 211;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, a[N], zero;
	

main () {
	cin >> n;
	int ans = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (!a[i]) {
			cout << 0;
			return 0;
		}

	}

	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (ans > INF / a[i]) {
			cout << -1;
			return 0;
		}			
		ans *= a[i];
	}

	if (ans > INF)
		ans = -1;

	cout << ans << endl;
}





Measured memory_bytes: 4416
#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;

long long power(int a, int b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%MOD;
    long long res=power(a,b/2)%MOD;
    if(b%2)
        return (((res*res)%MOD)*a)%MOD;
    return (res*res)%MOD;
}

int main() {
	long long n;
	cin>>n;
	if(n<3)
	{
	    cout<<0;
	    return 0;
	}
	long long ans=0;
	vector<long long> dp(n+1,0);
	for(int i=3;i<=n;i++)
	{
	    long long ad=1;
	    for(int j=3;j<=i-3;j++)
	    {
	        ad=(ad+(1*dp[i-j])%MOD)%MOD;
	    }
	    dp[i]=ad;
	    //cout<<i<<"="<<dp[i]<<endl;
	}
	
	cout<<dp[n];
	
	return 0;
}


Measured memory_bytes: 3580
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
t=[[] for i in range(200001)]
y=[[] for i in range(200001)]
pl=[[] for i in range(400001)]
ml=[[] for i in range(400001)]
pr=[[] for i in range(400001)]
mr=[[] for i in range(400001)]
for i in range(N):
    X,Y,U=input().split()
    X=int(X)
    Y=int(Y)
    if U=="U":
        t[X].append((Y,1))
        pl[X-Y].append((X,1))
        mr[X+Y].append((X,0))
    elif U=="D":
        t[X].append((Y,0))
        pr[X-Y].append((X,0))
        ml[X+Y].append((X,1))
    elif U=="L":
        y[Y].append((X,0))
        pl[X-Y].append((X,0))
        ml[X+Y].append((X,0))
    else:
        y[Y].append((X,1))
        pr[X-Y].append((X,1))
        mr[X+Y].append((X,1))
a=3000000
for i in t:
    if not i:
        continue
    i.sort()
    c=-1000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*5
            if p<a:
                a=p
for i in y:
    if not i:
        continue
    i.sort()
    c=-1000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*5
            if p<a:
                a=p
for i in pl:
    if not i:
        continue
    i.sort()
    c=-2000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*10
            if p<a:
                a=p
for i in pr:
    if not i:
        continue
    i.sort()
    c=-2000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*10
            if p<a:
                a=p
for i in mr:
    if not i:
        continue
    i.sort()
    c=-2000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*10
            if p<a:
                a=p
for i in ml:
    if not i:
        continue
    i.sort()
    c=-2000001
    for j in i:
        if j[1]:
            c=j[0]
        else:
            p=(j[0]-c)*10
            if p<a:
                a=p
if a==3000000:
    print("SAFE")
else:
    print(a)


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

#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
//typedef 1000000007 mod

#define mp map<ll,ll>
#define vc vector<ll>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..

#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)

#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)

#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define mod 1000000007

bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}

int main(){ 
	ll n;
	cin>>n;
	ll dp[n][3];
	ll a,b,c;
	rep(i,n){
		cin>>a>>b>>c;
		if(i==0){
			dp[i][0]=a;dp[i][1]=b;dp[i][2]=c;
		}
		else{
			dp[i][0]=  a+max(dp[i-1][1],dp[i-1][2]);
			dp[i][1] = b+max(dp[i-1][0],dp[i-1][2]);
			dp[i][2] = c+max(dp[i-1][0],dp[i-1][1]);
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 2560
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int H = sc.nextInt();
       int W = sc.nextInt();
       int N = sc.nextInt();
       
       long[] a = new long[(int)N];
       long[] m= new long[H*W];
       int mcnt=0;
       for (int i=0 ; i<N; i++) {
           a[i] = sc.nextLong();
           for(int j=0;j<a[i];j++) {
        	   m[mcnt]=i+1;
        	   mcnt++;
           }
       }
 
//       String S = sc.next();
//       String T = sc.next();
//       char[] s = S.toCharArray();
//       char[] t = T.toCharArray();
       int[][] am=new int[H][W];
       int cnt=0;
       for(int i=0;i<H;i++) {
    	   if(i%2==0) {
    		   for(int j=W-1;j>=0;j--) {
    			   am[i][j]=(int) m[cnt];
    			   cnt++;
    		   }
    	   } else {
    		   for(int j=0;j<W;j++) {
    			   am[i][j]=(int) m[cnt];
    			   cnt++;
    		   }    		   
    	   }
    	   for(int j=0;j<W;j++) {
    		   System.out.print(am[i][j]);
    		   if(j!=W-1) {
    			   System.out.print(" ");
    		   }
    	   }
    	   System.out.println("");
       }
       
   }


}

Measured memory_bytes: 31124
def b754(s):

    ans = 10**7

    for i in range(len(s) - 2):
        ans = min(ans , abs(int(s[i:i+3]) - 753))

    return ans

def main():
    s = str(input())
    print(b754(s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------
// Mr.HITMAN/hblord787
// Solution for Problem Code : C -  Caracal vs Monster
// Contest : Beginner 153 
//-------------------------------------------- 
int main() {
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////    
	ios_base::sync_with_stdio(false); // fast io
	cin.tie(NULL);
	cout.tie(NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    long long int h;
    cin >> h;
    long long int i,j,k = 1;
    i = log2(h) + 1;
    for(j = 1; j <= i; j++)
    {
        k = k * 2;
    }
    
    cout << (k - 1);
    
  	
}


Measured memory_bytes: 256
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
      
  else:
    dfs(i+1, f + '-' + n[i+1], sum-int(n[i+1]))
    dfs(i+1, f + '+' + n[i+1], sum+int(n[i+1]))
    
n = input()
dfs(0, n[0], int(n[0]))

Measured memory_bytes: 9128
n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

sm = 0
li = [[0, 0]]
for i, e in enumerate(a, 1):
    sm += e
    li.append([sm - k * i, i])

li.sort()
for i in range(n + 1):
    li[i][0] = i + 1

li.sort(key=lambda x: x[1])

bit = [0] * (n + 2)


def update(x):
    while x <= n + 1:
        bit[x] += 1
        x += x & (-x)


def sm(x):
    ret = 0
    while x:
        ret += bit[x]
        x -= x & (-x)

    return ret


ans = 0
for e, _ in li:
    ans += sm(e)
    update(e)

print(ans)


Measured memory_bytes: 47936
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int num=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=0; i<n; i++)
    {
        if(a[i]==a[i+1])
        {
            a[i]=a[i+1]=0;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(a[i]!=0)
        {
            num++;
        }
    }
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 640