akhauriyash/Code-Regression huggingface dataset:
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())

dp = [10**9] * (N+1)
dp[1] = 1
# dp[6] = 1
# dp[9] = 1
i = 6
while i <= N:
    dp[i] = 1
    i *= 6
i = 9
while i <= N:
    dp[i] = 1
    i *= 9

for i in range(1, N):
    if dp[i] != 10**9:
        dp[i+1] = min(dp[i+1], dp[i]+1)
        j = 6
        while i+j <= N:
            dp[i+j] = min(dp[i+j], dp[i]+1)
            j *= 6
        j = 9
        while i+j <= N:
            dp[i+j] = min(dp[i+j], dp[i]+1)
            j *= 9
print(dp[N])


    


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

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()

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

	map<char, int> pos;
	map<char, int> maxlength;

	//同じ文字間の長さ
	rep(i, s.size())
	{
		if (pos.count(s[i]) == 0)
		{
			maxlength[s[i]] = i;
		}
		else
		{
			maxlength[s[i]] = max(maxlength[s[i]], i - pos[s[i]] - 1);
		}

		pos[s[i]] = i;
	}

	//右端までの長さ
	for (auto p : pos)
	{
		maxlength[p.first] = max(maxlength[p.first], (int)s.size() - 1 - p.second);
	}

	int ans = 1000000000;

	for (auto l : maxlength)
	{
		ans = min(ans, l.second);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	c := sc.ReadString()

	redCount := 0
	for i := 0; i < n; i++ {
		if c[i] == 'R' {
			redCount++
		}
	}

	leftRedCount := 0
	leftWhiteCount := 0
	minTryCount := redCount
	for leftEnd := 0; leftEnd < n; leftEnd++ {
		if c[leftEnd] == 'R' {
			leftRedCount++
		} else {
			leftWhiteCount++
		}
		rightRedCount := redCount - leftRedCount
		tryCount := Max(leftWhiteCount, rightRedCount)
		if tryCount < minTryCount {
			minTryCount = tryCount
		}
	}

	fmt.Println(minTryCount)
}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 2440
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int x;
int y;
int main()
{
  int total = 0;
  for(int i = 0;i < 4;i++){
    cin >>x;
    total +=x;
  }
  cout <<total/60<<endl;
  cout <<total%60<<endl;
  return 0;
}

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

main()
{
  int N, K;
  cin >> N >> K;
  int i = 0;
  int x = K;
  
  for (; i < 100; i++)
  {
    if (x > N)
    {
      break;
    }
    x *= K;
  }
  
  i += 1;
  cout << i << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
string S[200000];
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(S,S+N);
    int ans=1;
    for(int i=1;i<N;i++){
        if(S[i]!=S[i-1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9856
h, w = map(int, input().split())
field = [[*input()] for _ in range(h)]

dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, -1, -1, -1]

for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            continue

        cnt = 0
        for d in range(8):
            xi = i + dx[d]
            yj = j + dy[d]

            if xi < 0 or xi > h-1 or yj < 0 or yj > w-1:
                continue

            if field[xi][yj] == '#':
                cnt += 1
        
        field[i][j] = cnt

for i in range(h):
    print(*field[i], sep='')


Measured memory_bytes: 9224
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
void pyes() { cout << "Yay!" << endl; }
void pno() { cout << ":(" << endl; }
struct edge { ll to, cost; };
ll n, l = 0, memo, ans = 0, r = 0;
ll a[224224];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	ll p = 0;
	rep(i, n)p += a[i];
	p /= 2;
	rep(i, n) {
		l += a[i];
		if (l >= p) {
			ans += l - p;
			memo = i;
			break;
		}
	}
	for (int i = memo + 1; i < n; i++)r += a[i];
	ll le = 0, lr = 0, lans = 0;
	rep(i, n) {
		le += a[i];
		if (le >= p) {
			lans += p - (le - a[i]);
			memo = i - 1;
			break;
		}
	}
	for (int i = memo + 1; i < n; i++)lr += a[i];
	cout << min(ans + abs(r - p), lans + abs(lr - p)) << endl;
	ggr
}

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

int main(){
	
	int o,n, max=0,maxi=0,sum=0;
	cin >> o >> n;
	vector<int> h(n);
	for (int i=0; i < n; i++){
		cin >> h[i];
		if (i) {
			sum += h[i]-h[i-1];
			if (h[i]-h[i-1] > max){
				max = h[i]-h[i-1];
				maxi = i;
				}
			}
		}
	sum += o-h[n-1]+h[0];
	if (o-h[n-1]+h[1] > max){
		max = o-h[n-1]+h[0];
		maxi = n;
		}
	cout << sum - max;
}


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

class dice {
  
  public:int l[6];

    void in() {
        for(int i = 0; i < 6; i++) cin >> l[i];
    }

    void roll(char c) {
        if(c=='N') {
            int tmp;
            tmp = l[0];
            l[0] = l[1];
            l[1] = l[5];
            l[5] = l[4];
            l[4] = tmp;
        }
        else if(c=='E') {
            int tmp;
            tmp = l[0];
            l[0] = l[3];
            l[3] = l[5];
            l[5] = l[2];
            l[2] = tmp;
        }
        else if(c=='W') {
            int tmp;
            tmp = l[0];
            l[0] = l[2];
            l[2] = l[5];
            l[5] = l[3];
            l[3] = tmp;
        }
        else if(c=='S') {
            int tmp;
            tmp = l[0];
            l[0] = l[4];
            l[4] = l[5];
            l[5] = l[1];
            l[1] = tmp;
        }
        else if(c=='R') {
            roll('S'), roll('W'), roll('N');
        }
        else if(c=='L') {
            roll('S'), roll('E'), roll('N');
        }
    }

    void rot(int a, int b) {
        int i;

        for(i = 0; i < 6; i++) if(l[i] == a) break;
        if(i==1) roll('N');
        else if(i==2) roll('W');
        else if(i==3) roll('E');
        else if(i==4) roll('S');
        else if(i==5) roll('N'), roll('N');

        for(i = 1; i < 5; i++) if(l[i] == b) break;
        if(i==2) roll('L');
        else if(i==3) roll('R');
        else if(i==4) roll('R'), roll('R');
    }

};

int main() {
    dice d[2];  d[0].in();d[1].in();
  	int i;
  
    bool flag = true;
  
    for(i = 0; i < 4; i++) {
        if(d[0].l[0]==d[0].l[1]) d[0].roll('R');
    }
  
  	d[1].rot(d[0].l[0], d[0].l[1]);

    for(i = 0; i < 6; i++) {
        if(d[0].l[i] != d[1].l[i]) flag = false;
        if(flag == false) break;
    }
  
  	if(flag==false) {
      	flag=true;
    	d[1].roll('E');
      	for(i = 0; i < 6; i++) {
          if(d[0].l[i] != d[1].l[i]) flag = false;
          if(flag == false) break;
        }
      	d[1].roll('W');
    }
  	if(flag==false) {
      	flag=true;
    	d[1].roll('S');
      	for(i = 0; i < 6; i++) {
          if(d[0].l[i] != d[1].l[i]) flag = false;
          if(flag == false) break;
        }
      	d[1].roll('N');
    }
  	if(flag==false) {
      	flag=true;
    	d[1].roll('W');
      	for(i = 0; i < 6; i++) {
          if(d[0].l[i] != d[1].l[i]) flag = false;
          if(flag == false) break;
        }
      	d[1].roll('E');
    }
  	if(flag==false) {
      	flag=true;
    	d[1].roll('N');
      	for(i = 0; i < 6; i++) {
          if(d[0].l[i] != d[1].l[i]) flag = false;
          if(flag == false) break;
        }
      	d[1].roll('S');
    }
  	

    if(flag==true) cout << "Yes" << endl;
    else cout << "No" << endl;
           
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

bool mp[11];

int main(){
	
	int n, k;cin >> n >> k;
	REP(i, k){
		int a;cin >> a;
		mp[a] = true;
	}
	
	for(int i = n;;i++){
		bool flag = true;
		int now = i;
		while(now){
			if(mp[now % 10])flag = false;
			now /= 10;
		}
		
		if(flag){
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll x;
  cin>>x;
  ll amari=x%500;
  ll amari2=amari%5;
  cout<<(x-amari)*2+(amari-amari2);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
struct node {
    int x, y;
}red[105], blue[105], temp[105];
int cmd(node &a, node &b) {
    if(a.x < b.x)
        return true;
    if(a.x == b.x && a.y < b.y)
        return true;
    return false;
}
int cmd2(node &a, node &b) {
    if(a.y > b.y)
        return true;
    if(a.y == b.y && a.x > b.x)
        return true;
    return false;
}
int main() {
    int n, pos = 1, bj = 1, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> red[i].x >> red[i].y;
    for(int i = 1; i <= n; i++)
        cin >> blue[i].x >> blue[i].y;
    sort(red + 1, red + n + 1, cmd);
    sort(blue + 1, blue + n + 1, cmd);
    for(int i = 1; i <= n; i++) {
        while(pos <= n && red[pos].x < blue[i].x) temp[bj].x = red[pos].x, temp[bj++].y = red[pos++].y;
    //    cout << bj << endl;
    //    for(int j = 1; j < bj; j++)
     //       cout << temp[j].x << " " << temp[j].y << endl;
      //  cout << endl;
       // cout << blue[i].x << " " << blue[i].y << endl;
       // system("pause");
        sort(temp + 1, temp + bj, cmd2);
        if(bj == 1 || temp[bj - 1].y >= blue[i].y)
            continue;
        int now;
        for(now = bj - 1; temp[now].y < blue[i].y; now--) ;
        now++, ans++;
        for(int j = now; j < bj - 1; j++)
            temp[j] = temp[j + 1];
        bj--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] argv) throws IOException {
        //*
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            String s = in.readLine();
            if (s == null) {
                break;
            }
            f(s);
        }
        //*/
    }

    public static void f(String s) {
        int[] p = new int[1000000];
        Arrays.fill(p, 1);
        p[0] = 0;
        p[1] = 0;
        int count = 0;
        for (int i = 2; i < 1000000; i++) {
            if (p[i] != 0) {
                count++;
                p[i] = count;
                for (int j = i * 2; j < 1000000; j+=i) {
                    p[j] = 0;
                }
            }
        }
        for (int i = Integer.parseInt(s); i >= 0; i--) {
            if (p[i] != 0) {
                System.out.println(p[i]);
                return;
            }
        }
        System.out.println(0);
    }
}

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

#define ll long long
int n, a[100005];
bool vis[100005];

int main()
{    
    ll ans=0;
    memset (vis, false, sizeof (vis));
    scanf ("%d", &n);
    
    for (int i=0; i<n; i++){
        scanf ("%d", &a[i]);
        
		if (a[i])
			vis[i] = true;
			
        ans += a[i] / 2;
        a[i] %= 2;
    }
    
    for (int i=1; i<n; i++){
        if (a[i] && a[i-1]){
            a[i] = 0;
            a[i-1] = 0;
            ans++;
        }
        else if (a[i] == 0 && a[i-1])
            if (vis[i]){
            	a[i]++; 
				a[i-1]--;
            }
    }                   			
    
    printf ("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 768
abc = list(map(int, input().split()))

abc.sort()
dif1 = abc[2] - abc[1]
dif2 = abc[1] - abc[0]
if dif2 % 2 == 0:
    print(dif1 + dif2//2)
else:
    print(dif1 + (dif2+1)//2 + 1)


Measured memory_bytes: 2940
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a=new long[3*n]; 
		for(int i=0;i<a.length;i++) a[i]=sc.nextLong();
		
		long score=0;
		PriorityQueue<Long> leftQueue=new PriorityQueue<>();
		PriorityQueue<Long> rightQueue=new PriorityQueue<>(Collections.reverseOrder());		
		for(int i=0;i<n;i++){
			leftQueue.add(a[i]);
			score+=a[i];
			rightQueue.add(a[2*n+i]);
			score-=a[2*n+i];
		}
		
		long[] ds=new long[n+1];
		long d=0;
		for(int i=1;i<=n;i++){
			leftQueue.add(a[n+i-1]);
			d+=a[n+i-1]-leftQueue.poll();
			ds[i]+=d;
		}
		d=0;
		for(int i=1;i<=n;i++){
			rightQueue.add(a[2*n-i]);
			d+=rightQueue.poll()-a[2*n-i];
			ds[n-i]+=d;
		}

		long maxds=ds[0];
		for(int i=1;i<=n;i++) maxds=Math.max(maxds, ds[i]);
		
		System.out.println(score+maxds);
	}
}


Measured memory_bytes: 97996
N,K=map(int,input().split())
X=list(map(int,input().split()))

def culclen(l,r):
  return abs(X[r]-X[l])+min(abs(X[l]),abs(X[r]))

ans=10**9
for x in range(len(X)-K+1):
  ans=min(ans,culclen(x,x+K-1))
print(ans)


Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define ll long long
#define fo(i,n) for(int i=0;i<n;i++)
#define rfo(i,n) for(int i=n-1;i>=0;i--)
#define Fo(i,q,n) for(int i=q;i<n;i++)
#define rFo(i,q,n) for(int i=n-1;i>=q;i--)
#define fO(i,n,k) for(int i=0;i<n;i+=k)
#define FO(i,q,n,k) for(int i=q;i<n;i+=k)
#define zero(a,n) memset(a,0,sizeof(a[0])*n)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
using namespace std;
const int MOD=1000000007;
void print(){cout <<endl;}
template <typename T, typename... Types> 
void print(T var1, Types... var2){cout << var1 << " " ;print(var2...) ;}
//ceil of a/b
template <typename T>
T fceil(T a,T b){return (T)(a+b-1)/b;}
//const int N=2e5;
//int arr[N+1];

bool legal(int x,int y,int h,int w,char mat[][1000]){
	if(x>=h || x<0 || y>=w || y<0 || mat[x][y]=='#'){
		return false;	
	}
	return true;	
} 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h,w;
	cin>>h>>w;
	int sx,sy,ex,ey;
	cin>>sx>>sy>>ex>>ey;
	sx--;sy--;ex--;ey--;
	char mat[1000][1000];
	fo(i,h){
		fo(j,w){
			cin>>mat[i][j];	
		}	
	}
	int dist[h][w];
	fo(i,h){
		fo(j,w){
			dist[i][j]=INT_MAX-1;	
		}	
	}
	dist[sx][sy]=0;
	deque< pair<int,int> > dq;
	dq.push_front(mp(sx,sy));
	int dx[4] = {-1,1,0,0};
	int dy[4] = {0,0,-1,1};
	while(!dq.empty()){
		int currx = dq.front().F;
		int curry = dq.front().S;
		dq.pop_front();
		for(int d=0;d<4;d++){
			int nx = currx+dx[d];
			int ny = curry+dy[d];
			if(!legal(nx,ny,h,w,mat)){continue;}
			if(dist[nx][ny]>dist[currx][curry]){
				dist[nx][ny] = dist[currx][curry];
				dq.push_front(mp(nx,ny));	
			}	
		}
		for(int x=currx-2;x<=currx+2;x++){
			for(int y=curry-2;y<=curry+2;y++){
				if(!legal(x,y,h,w,mat)){continue;}
				if(dist[x][y]>dist[currx][curry]+1){
				dist[x][y] = dist[currx][curry]+1;
				dq.push_back(mp(x,y));	
				}		
			}	
		}	
	}
	cout<<((dist[ex][ey]==INT_MAX-1)?-1:dist[ex][ey])<<endl;
	return 0;
}


Measured memory_bytes: 8604
def main():
    n, m = map(int, input().split())
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        for i in range(m):
            total = 0
            flag = 1
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if not total%2 == p[i]:
                flag = 0
                break
        if flag:
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	private static Scanner sc;

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

		Integer result = a - 2 * b > 0 ? a - 2 * b : 0;

		System.out.println(result);
	}



}


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

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

  if (x%10==2||x%10==4||x%10==5||x%10==7||x%10==9) {
    cout << "hon" << endl;
  }
  else if (x%10==0||x%10==1||x%10==6||x%10==8) {
  cout << "pon" << endl;
  }
  else if (x % 10 == 3) {
  cout << "bon" << endl;
  }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 500005
#define MOD 1000000007
int gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    int K,a,b,c,temp;
    long long ans=0;
    scanf("%d",&K);
    for(a=1;a<=K;a++)
    {
        for(b=1;b<=K;b++)
        {
            temp=gcd(a,b);
            for(c=1;c<=K;c++)
            {
                ans=ans+gcd(temp,c);
            }
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3824
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum=0;
    for(int i=1;i<=n;i++){
      if(i%3!=0&&i%5!=0){
        sum+=i;
      }
    }
    pl(sum+"");
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


Measured memory_bytes: 38912
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  map<int,int> mp;
  int ans = 0;
  rep(i,n) {
    if (!mp.count(a[i])) {
      ans++;
      mp[a[i]];
    }
    else {
      ans--;
      mp.erase(a[i]);
    }
  }

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

Measured memory_bytes: 5376
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] n_m_l = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            long[][] a = new long[n_m_l[0]][n_m_l[1]];
            long[][] b = new long[n_m_l[1]][n_m_l[2]];
            for (int i = 0; i < n_m_l[0]; i++) {
                long[] al = Stream.of(sc.nextLine().split(" "))
                    .mapToLong(Long::parseLong)
                    .toArray();
                if (al.length != n_m_l[1]) {
                    System.out.println("Condition is invalid,");
                }
                a[i] = al;
            }
            for (int i = 0; i < n_m_l[1]; i++) {
                long[] bl = Stream.of(sc.nextLine().split(" "))
                        .mapToLong(Long::parseLong)
                        .toArray();
                if (bl.length != n_m_l[2]) {
                    System.out.println("Condition is invalid,");
                }
                b[i] = bl;
            }
            long[][] c = new long[n_m_l[0]][n_m_l[2]];
            for (int i = 0; i < n_m_l[0]; i++) {
                for (int j = 0; j < n_m_l[2]; j++) {
                    for (int k = 0; k < n_m_l[1]; k++) {
                        c[i][j] += a[i][k] * b[k][j];
                    }
                }
                System.out.println(LongStream.of(c[i])
                        .boxed()
                        .map(Object::toString)
                        .collect(Collectors.joining(" ")));
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 41136
package main

import (
	"fmt"
	"sort"
)

type item struct {
	i int
	s string
	p int
}

type items []item

func (is items) Len() int {
	return len(is)
}

func (is items) Less(i, j int) bool {
	if is[i].s == is[j].s {
		return is[i].p > is[j].p
	}
	return is[i].s < is[j].s
}

func (is items) Swap(i, j int) {
	is[i], is[j] = is[j], is[i]
}

func main() {
	var n int
	fmt.Scan(&n)

	a := make(items, n)
	for i := range a {
		a[i].i = i + 1
		fmt.Scan(&a[i].s, &a[i].p)
	}
	sort.Sort(a)
	for _, e := range a {
		fmt.Println(e.i)
	}
}


Measured memory_bytes: 512
#1行目
hoge = gets.chomp.to_i - 1

#2行目読み込み
a = gets.chomp.split(" ").map!{|i| i.to_i}
b= gets.chomp.split(" ").map!{|i| i.to_i}
c = gets.chomp.split(" ").map!{|i| i.to_i}

unchi = b[a[0]-1]

for i in 1..hoge do
 unchi = unchi + b[a[i]-1]
 if a[i] == a[i-1] + 1
   unchi = unchi + c[a[i]-2]
 end
end

print unchi

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    vector<int> q(N);
    for(int i=0;i<N;i++){
        cin >> p[i] ;
    }
    for(int i=0;i<N;i++){
        cin >> q[i] ;
    }
    //
    vector<int> Num(N);
    for(int i=0;i<N;i++){
        Num[i]= i+1;
    }
    //
    map<vector<int>,int>permutation;
    int cnt =0;
    while(next_permutation(Num.begin(), Num.end())){
        cnt++;
        permutation[Num] = cnt;   // map[vector] = int;
    }
    cout << abs(permutation[p] - permutation[q]) << endl;
}

Measured memory_bytes: 8516
N = int(input())
A = list(map(lambda x: int(x),input().split()))
flag = 0
cnt = 0
for i in A:
    if i < 0:
        cnt += 1
    elif i == 0:
        flag = 1
cnt %= 2
A = list(map(lambda x: abs(x), A))
if flag or cnt == 0:
    print(sum(A))
else:
    print(sum(A)-2*min(A))

Measured memory_bytes: 65568
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    int n,k;
    cin>>n>>k;
    int ans=0;
    rep(i,n)
    {
        int h;
        cin>>h;
        if(h>=k)ans++;
    }
    cout<<ans;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector <ll> arr(n+1);
	for (int z=0;z<=n;z++){
		cin >> arr[z];
	}
	ll i = 1;
	vector <ll> maxi(n+1);
	for (int z=0;z<=n;z++){
		maxi[z] = i;
		i -= arr[z];
		if (i <= ll(1e17)){
			i *= 2;
		}
		if (z == n){
			if (i < 0){
				cout << -1 << endl;
				return 0;
			}
		} else {
			if (i <= 0){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	ll ans = 0;
	ll cul = 0;
	for (int z=n;z>=0;z--){
		cul += arr[z];
		cul = min(cul,maxi[z]);
		ans += cul;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4812
S = input()
count1 = 0
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "1":
      count1 += 1
  else:
    if S[i] == "0":
      count1 += 1
count2 = 0
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "0":
      count2 += 1
  else:
    if S[i] == "1":
      count2 += 1
print(min(count1, count2))

Measured memory_bytes: 3188
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int n,a[1000000],tot=0;
scanf("%d",&n);
for(int i=0;i<2*n;i++){
scanf("%d",&a[i]);
}
sort(a,a+2*n);
for(int i=0;i<2*n;i+=2){
tot+=a[i];
}
printf("%d\n",tot);
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;
typedef int64_t Weight;
Weight INF = INT64_C(1000000000000000);
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> h(n);
  REP(i,n)cin>>h[i];
  vector<vector<int>> p(n);
  Graph g(n);
  p[0].push_back(x);
  REP(i,m){
    int a,b,t;
    cin>>a>>b>>t;
    --a;--b;
    g[a].push_back((Edge){a,b,t});
    g[b].push_back((Edge){b,a,t});
  }
  Array d(n,INF);
  Array hg(n);
  d[0] = 0;
  hg[0] = x;
  typedef tuple<Weight,int,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, 0, x));
  while (!que.empty()) {
    Weight dist;
    int v; int hq;
    tie(dist, v, hq) = que.top();
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (h[e.src] < e.weight) continue;
      int cst = 0;
      int nh = hq - e.weight;
      if (hq < e.weight) {
        cst = e.weight - hq;
        nh = 0;
      }
      if (hq > e.weight + h[e.dest]) {
        cst = hq - (e.weight + h[e.dest]);
        nh = h[e.dest];
      }
      if (d[e.dest] > d[v] + cst + e.weight) {
        d[e.dest] = d[v] + cst + e.weight;
        hg[e.dest] = nh;
        que.push(P(d[e.dest], e.dest, nh));
      }
    }
  }
  int64_t mn = d[n-1] + (h[n-1] - hg[n-1]);
  if (mn < INF)
    cout << mn << endl;
  else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 24100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

ll C[102][102];

int main(){
    int N;
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> C[i][j];
        }
    }
    ll ans = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            ans += min(C[i][j], C[j][i]);
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

//#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
ll mod=1e16+7;
ll suma(ll a,ll b){
	if(a==0)
		return 0;
	if(a%2==0){
		ll val=(2*suma(a/2,b))%mod;
		return val;
	}
	else{
		ll val=(2*suma((a-1)/2,b)+b)%mod;
		return val;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll x,k,d;
	cin>>x>>k>>d;
    x=abs(x);
	ll val=x/d;
	val=abs(val);
	ll dis1=(k*d);
	if(k<val){
		ll ans=x;;
		if(x<0){
			ans=x+dis1;
		}
		else{
			ans=x-dis1;
		}
		cout<<abs(ans)<<endl;
		return 0;
	}
	k-=val;
	ll v1,v2;
	if(x>0){
		v1=x%d;
		v2=v1-d;
	}
	else{
		v1=-1*(x%d);
		v2=v1+d;
	}
	if(k%2==0)
		cout<<abs(v1)<<endl;
	else
		cout<<abs(v2)<<endl;
	return 0;
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
S=input().strip()
M=[input().split() for i in range(Q)]

PLACE=-1

for i in range(Q-1,-1,-1):

    if PLACE+1<N and M[i][0]==S[PLACE+1] and M[i][1]=="L":
        PLACE+=1

    elif PLACE>=0 and M[i][0]==S[PLACE] and M[i][1]=="R":
        PLACE-=1

    if PLACE==N:
        print(0)
        sys.exit()

PLACE2=N

for i in range(Q-1,-1,-1):

    if PLACE2-1>=0 and M[i][0]==S[PLACE2-1] and M[i][1]=="R":
        PLACE2-=1

    elif PLACE2<=N-1 and M[i][0]==S[PLACE2] and M[i][1]=="L":
        PLACE2+=1

    if PLACE==-1:
        print(0)
        sys.exit()

print(max(0,N-(PLACE+1+(N-PLACE2))))
    

Measured memory_bytes: 81700
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]; n);

    let mut flag = vec![vec![1;n];n];
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                if a[i][j] > a[i][k] + a[k][j] {
                    println!("-1");
                    return;
                }
                if i==j || j==k || k==i {
                    continue;
                }
                if a[i][j] == a[i][k]+a[k][j] {
                    flag[i][j] = 0;
                }
            }
        }
    }

    let mut sum = 0;
    for i in 0..n {
        for j in 0..n {
            sum += a[i][j]*flag[i][j];
        }
    }
    println!("{}", sum/2);
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int x[52],y[52];
pii p[52];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d%d",x+i,y+i);
    REP(i,n)p[i] = pii(x[i],y[i]);
    sort(p,p+n);
    REP(i,n)x[i]=p[i].first, y[i]=p[i].second;
    int ans = n;
    REP(i,n)REP(j,i){
        int dx = x[i]-x[j];
        int dy = y[i]-y[j];
        vector<bool> used(n,false);
        int tmp = 0;
        REP(k,n){
            if(!used[k])tmp++;
            FOR(l,k+1,n)if(x[l]==x[k]+dx && y[l]==y[k]+dy){
                used[l] = true;
            }
        }
        CHMIN(ans, tmp);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main (){
  char S[255] = {"\0"};
  bool odd = true;

  scanf("%s",S);

  char* sp = S;

  while(*sp){
    if(odd == true && sp[0] == 'L'){
      puts("No");
      return 0;
    }

    if(odd == false && sp[0] == 'R'){
      puts("No");
      return 0;
    }

    odd = !odd;
    sp++;
  }

  puts("Yes");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    //入力
    long a,b,x;
    cin>>a>>b>>x;
    
    //計算
    long ans=(b/x)-(a/x);
    if(a%x==0) ans++;
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 892
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N+1];
		for( int i=0; i<N; i++ ){
			A[i] = sc.nextLong();
		}
		A[N] = 1000000001L;
		Arrays.sort(A);
		int ans = 0;
		int count = 1;
		for( int i=1; i<=N; i++ ){
			if( A[i]==A[i-1] ){
				count++;
			}
			if( A[i]!=A[i-1] || i==N ){
				if( count%2!=0 ){
					ans++;
				}
				count = 1;
			}
		}
		System.out.println(ans);
	}
}


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

int main(){
	long long int a,b,c;
	long long int k;
	cin>>a>>b>>c>>k;
	while(k--){
		if(a>=b){
		
			b*=2;
		}
		else if(b>=c){
		
			c*=2;
		}
		
	}
		 if(a<b&&b<c){
			cout<<"Yes"<<endl;
			return 0;
		}
		cout<<"No"<<endl;
		return 0;
}


Measured memory_bytes: 3608
use std::cmp;
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ').map(|s| s.trim().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {
    let order = read_one::<String>();
    let mut ans = 700;
    for c in order.chars().collect::<Vec<char>>() {
        if c == 'o' {
            ans += 100;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    int[] ruig1 = new int[n + 1];
    int[] ruig2 = new int[n + 1];
    for(int i = 1; i <= n; i++) {
      ruig1[i] = gcd(ruig1[i - 1], a[i - 1]);
    }
    for(int i = 1; i <= n; i++) {
      ruig2[i] = gcd(ruig2[i - 1], a[n - i]);
    }
    int ans = 1;
    for(int i = 0; i < n; i++) {
      ans = Math.max(ans, gcd(ruig1[i], ruig2[n - 1 - i]));
    }
    System.out.println(ans);
  }

  public static int gcd(int x, int y) {
    if(x == 0) return y;
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
}

Measured memory_bytes: 50780
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  int sum=0;
  rep(i,0,N){
    cin>>A[i];
    sum+=A[i];
  }
  sort(ALL(A));
  string ans="No";
  if(sum-A[N-1]>A[N-1]) ans="Yes";
  cout<<ans<<endl;
  }


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 1001001001;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

//< ave , a(time), b(manzoku) >
typedef tuple<double, int, int> A;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

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

    vector<int> list(n);
    rep(i, n) {
        int a;
        cin >> a;
        list[i] = a;
    }

    // 0~iまでの最大公約数
    vector<int> lgcds(n);
    lgcds[0] = list[0];
    // n~iまでの最大公約数
    vector<int> rgcds(n);
    rgcds[n - 1] = list[n - 1];


    rep(i, n) {
        if (n == 0) continue;
        lgcds[i] = gcd(lgcds[i - 1], list[i]);
    }
    for (int i = n - 2; i >= 0; i--) {
        rgcds[i] = gcd(rgcds[i + 1], list[i]);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            int r = rgcds[1];
            ans = max(ans, r);
        } else if (i == n - 1) {
            int l = lgcds[n - 2];
            ans = max(ans, l);
        } else {
            int l = lgcds[i - 1];
            int r = rgcds[i + 1];
            ans = max(ans, gcd(l, r));
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 1408
#include <iostream>
#include <cmath>

#define I using
#define can namespace
#define AK std
#define NOI ;

I can AK NOI

long long n, a[300001];

int main()
{
	cin >> n;
	for (long long i = 1; i <= n; ++i)
		cin >> a[i];
	long long maxn = -2147483647, minn = a[1];
	for (long long i = 2; i <= n; ++i)
	{
		maxn = max(maxn, a[i] - minn);
		minn = min(minn, a[i]);
	}
	cout << maxn << endl;
  //  system("pause");
    return 0;
}


Measured memory_bytes: 4668
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    
    int N,R;cin>>N>>R;
    
    cout<<floor((log(N)/log(R))+1)<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n, m, x;
  while (scanf("%d %d %d", &n, &m, &x) != EOF)
  {
    int c[n], a[n][m];
    for (int i = 0; i < n; i++)
    {
      scanf("%d", &c[i]);
      for (int j = 0; j < m; j++)
        scanf("%d", &a[i][j]);
    }
    int ans = 1e9;
    for (int bit = 0, end = 1 << n; bit < end; bit++)
    {
      int cost = 0, level[m]; memset(level, 0, sizeof(level));
      for (int i = 0; i < n; i++)
        if (bit & (1 << i))
        {
          cost += c[i];
          for (int j = 0; j < m; j++)
            level[j] += a[i][j];
        }
      bool can = true;
      for (int j = 0; j < m; j++)
        if (level[j] < x)
          can = false;
      if (can)
        ans = min(ans, cost);
    }
    if (ans == 1e9) ans = -1;
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3828
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL calc(pair<int, int> p, pair<int, int> q) {
	return abs(p.first - q.first) + abs(p.second - q.second);
}

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> students(n);
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		students[i] = { a,b };
	}

	vector<pair<int, int>> checkpoint(m);
	for (int i = 0; i < m; i++) {
		int c, d; cin >> c >> d;
		checkpoint[i] = { c,d };
	}

	for (int i = 0; i < n; i++) {
		LL l = INF2;
		LL id = 0;
		for (int j = 0; j < m; j++) {
			LL v = calc(students[i], checkpoint[j]);
			if (l > v) {
				id = j;
				l = v;
			}
		}
		cout << id+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256