akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left
import sys
input = sys.stdin.readline

A, B, Q = map(int, input().split())

INF = 10 ** 12
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]

ret = []
for _ in range(Q) :
    x = int(input())
    spos = bisect_left(s, x)
    tpos = bisect_left(t, x)
    ls, rs = s[spos-1], s[spos]
    lt, rt = t[tpos-1], t[tpos]
    if ls < lt :
        if rs < rt :
            ret.append(min(x-ls, rt-x, min(x-lt, rs-x)+rs-lt))
        else :
            ret.append(min(x-ls, rs-x))
    else :
        if rs < rt :
            ret.append(min(x-lt, rt-x))
        else :
            ret.append(min(x-lt, rs-x, min(x-ls, rt-x)+rt-ls))
    
for r in ret :
    print(r)

Measured memory_bytes: 76764
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <set>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <map>
    #include <stack>
    #define N 1005
    using namespace std;
    typedef long long ll;
    int a[305][305];
    struct node
    {
        int x;
        int y;
    }p[90005];
    int ans[90005];
    int main()
    {
        int h,w,d,len;
        scanf("%d%d%d",&h,&w,&d);
        for(int i=1;i<=h;i++)
            for(int j=1;j<=w;j++){
              scanf("%d",&a[i][j]);
              int n=a[i][j];
               p[n].x=i;
               p[n].y=j;
            }
        int q;
        len=h*w;
        scanf("%d",&q);
        for(int i=1;i<=d;i++)
        {
            int l=i,r=len,sum=0;
            ans[i]=0;
            while(l<=r-d)
            {
                sum=sum+abs(p[l].x-p[l+d].x)+abs(p[l].y-p[l+d].y);
                l=l+d;
                ans[l]=sum;
            }

        }
        while(q--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",ans[r]-ans[l]);
        }
    }




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

int main (void){
  int R,G,B,N,a,ans = 0;
  cin >> R >> B >> G >> N;
  
  
  for(int i = 0; i*R <= N; i++){
    for(int j = 0; i*R+j*G <= N; j++){
      a = R*i + G*j;
        if((N-a) % B == 0 && N >= a){
          ans++;
        }
      }
  }
  
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 100005
 
int p[MAX];
int q[MAX];
 
int find(int x){
  if(p[x]==x)return x;
  return p[x]=find(p[x]);
}
 
void unite(int x,int y){
  x=find(x);y=find(y);
  if(x==y)return;
  p[x]=y;
  q[y]+=q[x];
}
 
bool same(int x,int y){
  return (find(x)==find(y));
}
 
int V,E;
vector<int> G[MAX];
vector<int> nG[MAX];
map<int,bool> used[MAX];
 
int s[MAX],t[MAX];
int depth[MAX];
int cnt[MAX];
int visited[MAX];
bool flg[MAX];
 
 
void dfs(int pos,int prev){
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    if(!visited[to]){
      depth[to]=depth[pos]+1;
      dfs(to,pos);
      cnt[pos]+=cnt[to];
      if(cnt[to])unite(pos,to);
    }else if(depth[to]<depth[pos]){
      unite(pos,to);
      cnt[pos]++;
      cnt[to]--;
    }else{
      unite(pos,to);
    }
  }
}
 
P solve(int pos,int prev=-1){
  int res=-1,res2=0,sum=t[pos];
  for(int i=0;i<(int)nG[pos].size();i++){
    int to=nG[pos][i];
    if(to==prev || to==pos)continue;
    P pw=solve(to,pos);
    res=max(res,pw.first);
    if(pw.first!=-1){
      sum+=pw.first;
      res2=max(res2, -pw.first+pw.second);
    }else{
      res2=max(res2,pw.second);
    }
  }
  if(q[pos]==1 && res==-1){
    return P(-1,sum+res2);
  }
  return P(sum,sum+res2);
}
 
int main(){
  scanf("%d %d",&V,&E);
  for(int i=0;i<V;i++){
    scanf("%d",&s[i]);
    p[i]=i;
    q[i]=1;
  }
  for(int i=0;i<E;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0,-1);
  for(int pos=0;pos<V;pos++){
    for(int i=0;i<(int)G[pos].size();i++){
      int to=find(G[pos][i]);
      if(used[pos].count(to)>0)continue;
      used[pos][to]=true;
      nG[ find(pos) ].push_back( to );
    }
    t[ find(pos) ]+=s[pos];
  }
  P ans=solve(find(0),-1);
  printf("%d\n", ans.second);
  return 0;
}

Measured memory_bytes: 38812
/**
 *    author:  tourist
 *    created: 09.01.2018 10:40:48       
**/
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2018;
const int MAX_A = 2018;

int main() {
  int n;
  cin >> n;
  bitset<MAX_N * MAX_A> b;
  b[0] = 1;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    b |= (b << a);
    sum += a;
  }
  for (int j = (sum + 1) / 2; j <= sum; j++) {
    if (b[j] == 1) {
      cout << j << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
from collections import deque
def son(generation,life):
    if life > 1:
        nextson = (generation+1, life//2)
    else:
        nextson = (0, 0)
    return nextson
    
def generationnum(generation):
    return 2**generation

def bfs(startlife,startgeneration):
    queue = deque([(startgeneration,startlife)])
    totalnum = 0
    while queue:
        label = queue.popleft()
        if label == (0, 0):
            break
        totalnum += generationnum(label[0])
        queue.append(son(label[0],label[1]))
    return totalnum
            
if __name__ == '__main__':
    print(bfs(int(input()), 0))

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> v;
string s;
int k;
int main(){
	cin>>s>>k;
	int len=s.size();
	for(int i=0;i<len;i++){
		for(int j=1;j<=min(len-i,k);j++){
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	unique(v.begin(),v.end());
	cout<<v[k-1];
} 

Measured memory_bytes: 4276
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int f(int n)
{
	if(n%4 == 0)
		return n;
	if(n%4 == 1)
		return 1;
	if(n%4 == 2)
		return n + 1;
	return 0;
}

int32_t main()
{
	IOS;
	int a, b;
	cin>>a>>b;
	int ans = f(b) ^ f(max(0LL, a - 1));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int S = a*b;
        int l = (2*a) + (2*b);

        System.out.println(S + " " + l);
    }
}

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

# define fr first
# define sc second
# define ll unsigned long long
# define mk make_pair
# define pb emplace_back
# define sz(s) (int)s.size()
# define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const ll inf = 1e18;

int n, k;
bool u[N];
vector<pair <int, pair <int, int> > > v;

int main () {
    cin >> n >> k;
    for(int i = 1, x, y, z; i <= n; i++) {
        cin >> x >> y >> z;
        v.pb(mk(x, mk(y, z)));
    }
    sort(all(v));
    int ans = 0, cnt = n;
    while(cnt) {
        ans++;
        int b = 0, ch = -1;
        for(int i = 0; i < sz(v); i++) {
            if(u[i]) continue;
            if((v[i].fr >= b && ch == v[i].sc.sc) || (v[i].fr > b && ch != v[i].sc.sc)) {
                u[i] = 1; cnt--;
                b = v[i].sc.fr;
                ch = v[i].sc.sc;
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 1912
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    int k = 0, s = 0;
    cin >> k >> s;
    int ans = 0;
    for (int i=0; i<=k; i++) {
        for (int j=0; j<=k; j++) {
            if (s-i-j >= 0 && s-i-j <= k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int MAX = 200001;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    Int B, W; cin >> B >> W;
    Int bmax = 0, norm = 1, wmax = 0, demo = inv[2];
    for (int i = 0; i < B + W; i++) {
        Int b = COM(i, B);
        Int w = COM(i, W);
        cout << (norm - b + w + wmax * 2 + MOD) % MOD * demo % MOD << endl;
        bmax = (bmax * 2 + b) % MOD;
        norm = (norm * 2 - b - w + MOD + MOD) % MOD;
        wmax = (wmax * 2 + w) % MOD;
        demo = demo * inv[2] % MOD;
    }
    return 0;
}

Measured memory_bytes: 6912
#import heapq
import copy

N,K=map(int,input().split())
V=list(map(int,input().split()))
V.append(0)#右から取る時用

S=[0]*(N+1)#累積和
for i in range(N):
    S[i+1]=S[i]+V[i]

#左からi番目まで見たときに，持っている負の宝石
left=[[] for _ in range(N+1)]
for i in range(N):
    left[i+1]=copy.deepcopy(left[i])
    if V[i]<0:
        left[i+1].append(V[i])
        left[i+1].sort()
       
        
ans=0
#左からi個，右からj個とったときについて考える
for i in range(N+1):
    temp=S[i]
    rem=copy.deepcopy(left[i])
    #heapq.heapify(rem)
    for j in range(N+1-i):
        if i+j>K:
            break
        temp+=S[-1]-S[N-j]
        if V[N-j]<0:
            #heapq.heappush(rem,V[N-j])
            rem.append(V[N-j])
            rem.sort()
        ret=K-(i+j)#負の宝石を返却できる回数
        if ret>0:
            for k in range(min(ret,len(rem))):
                temp-=rem[k]
        ans=max(ans,temp)
        temp=S[i]
        
print(ans)




Measured memory_bytes: 40304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC142_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var odd = N % 2 == 1;
            var numOdd = odd ? (N + 1) / 2 : N / 2;
            Console.WriteLine(1.0 * numOdd / N);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

const int N = 2e5 + 100;

int fen[N];
void clear() {
	fill_n(fen, N, 0);
}
void add(int i) {
	for (; i < N; i |= i + 1) {
		++fen[i];
	}
}
int sum(int i) {
	int s = 0;
	for (; i >= 0; i = (i & (i + 1)) - 1) {
		s += fen[i];
	}
	return s;
}

int n, a[N];

int check(int x) {
	int p = 1e5, ans = 0;
	clear();
	add(p);
	for (int i = 0; i < n; ++i) {
		if (a[i] < x) {
			++p;
		} else {
			--p;
		}
		ans += sum(p - 1);
		add(p);
	}
	return ans;
}

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int need = n * (n + 1) / 4;
	int lef = 0, rig = 1e9 + 2;
	while (rig - lef > 1) {
		int mid = (lef + rig) / 2;
		if (check(mid) <= need) {
			lef = mid;
		} else {
			rig = mid;
		}
	}
	cout << lef << "\n";
    return 0;
}


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

const ll mod = 1e9 + 7;
const int maxn = 1e4 + 10;
int number[maxn]; // K
int N;
int D;
ll DP[maxn][105][2];
string s;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s;
    cin >> D;
    N = s.size();
    for(int i = 0; i < N; ++i){
        number[i + 1] = s[i] - '0';
    }
    // [1 , K]
    // no leading zero
    // flag of strictly less
    DP[0][0][0] = 1;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < D; ++j){
            for(int k = 0; k < 2; ++k){
                if(DP[i][j][k] == 0)continue;
                for(int cur = 0; cur < 10; ++cur){
                    if(k == 0 && cur > number[i + 1])break;
                    DP[i + 1][(j + cur) % D][k || cur < number[i + 1]] += DP[i][j][k];
                    DP[i + 1][(j + cur) % D][k || cur < number[i + 1]] %= mod;
                }
            }
        }
    }
    ll ret = DP[N][0][0] + DP[N][0][1];
    cout << (ret - 1 + mod)% mod << endl;
}


Measured memory_bytes: 16768
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll x, ll y, ll p)
{ll res = 1;x = x % p;while (y > 0){if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll modInverse(ll n, ll p)
{return power(n, p-2, p);}
ll nCr(ll n, ll r, ll p)
{if (r==0) return 1;ll fac[n+1];fac[0] = 1;for(ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p;return (fac[n]*modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll i, j, k, n, m, t, p, temp, flag, x, y, z, count, a, b, c, d, sum, ans;
	cin >> n >> k;
	ll arr[n];
	for(i=0; i<n; i++)
		cin >> arr[i];
	sort(arr, arr+n);
	ans=0;
	for(i=0; i<k; i++)
		ans+=arr[i];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int N,M;
int a[300000];
int b[300000];
ll c[300000];
ll sum[300001];
int main(){
  cin>>N;
  for(int i=0;i<N;i++)cin>>a[i];
  cin>>M;
  for(int i=0;i<M;i++)cin>>b[i];
  for(int i=0;i<M;i++)cin>>c[i];
  sort(a,a+N);
  sum[0]=a[0];
  for(int i=1;i<N;i++)sum[i]=a[i]+sum[i-1];
  for(int i=0;i<M;i++){
    int* it=upper_bound(a,a+N,b[i]);
    ll d=(it==a?0:sum[it-a-1]);
    if(d>=c[i])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 9968
#include<stdio.h>
int main()
{
  int ans = 0;
  char S[4],T[4];
  scanf("%s",S);
  getchar();
  scanf("%s",T);
  for(int i = 0;i<3;i++)
  {
    if(S[i]==T[i])
      ans++;
  }
  
  
  printf("%d\n",ans);
 return 0; 
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int lps[200005];
vector<int> t, p, ret;

void preprocess() {
    lps[0] = 0;
    int m = p.size(), j = 0;
    for (int i=1; i<m; i++) {
        while (j != 0 && p[i] != p[j])
            j = lps[j-1];
        lps[i] = (j += (p[i] == p[j]));
    }
}

void kmp() {
    preprocess();
    int n = t.size(), m = p.size(), j = 0;
    for (int i=0; i<n; i++) {
        while (j != 0 && t[i] != p[j])
            j = lps[j-1];
        if ((j += (t[i] == p[j])) == m) {
            ret.push_back(i - j + 1);
            j = lps[j-1];
        }
    }
}

int a[200005], b[200005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    t.resize(n);
    for (int i=0; i<n; i++)
        t[i] = a[i] ^ a[(i + 1) % n];
    t.insert(t.end(), t.begin(), t.end() - 1);

    p.resize(n);
    for (int i=0; i<n; i++)
        p[i] = b[i] ^ b[(i + 1) % n];

    kmp();
    for (int k : ret)
        cout << k << " " << (a[k] ^ b[0]) << "\n";

    return 0;
}


Measured memory_bytes: 10256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
string str[55];
int h, w, f[55][55], res;
const int INF = 10000;
vector<P> vec[10000];
int x[4] = {0, 1, 0, -1}, y[4] = {1, 0, -1, 0};

int bfs(int k) {
    if (vec[k].empty()) return res;
    while(!vec[k].empty()) {
        P p = vec[k][0]; vec[k].erase(vec[k].begin());
        for (int i = 0; i < 4; i++) {
            int nx = p.first + x[i], ny = p.second + y[i];
            if (nx < 0 || nx >= h) continue;
            if (ny < 0 || ny >= w) continue;
            if (f[nx][ny] != INF) continue;
            if (str[nx][ny] == '#') continue;
            if (nx == h - 1 && ny == w - 1) return k + 1;
            f[nx][ny] = k + 1;
            vec[k + 1].push_back(P(nx, ny));
        }
    }
    return bfs(k + 1);
}

int main(void){
    // Your code here!
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> str[i];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if(str[i][j] == '.') res++;
            f[i][j] = INF;
        }
    }
    f[0][0] = 0;
    vec[0].push_back(P(0, 0));
    cout << res - bfs(0) - 1 << endl;
}


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

int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int count = 0;
  
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(500*i+100*j+50*k == x){
          count++;
        }
      }
    }
  }
  
  cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    if(s[0]=='9' || s[1]=='9') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)
    cnt_a = 0

    idx = 0
    ans = 0
    while idx<slen:
        while idx < slen and s[idx] == 'A':
            cnt_a += 1
            idx += 1
        
        if idx<slen and idx+1 < slen:
            if s[idx] == 'B' and s[idx+1] == 'C':
                ans += cnt_a
                idx += 2
            else:
                idx += 1
                cnt_a = 0
        else:
            break
    
    print(ans)



solve()


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
const double PI=3.141592653589;
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
#include <iomanip>


// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

double a, b, x; cin >> a >> b >> x;
double hx = x / a / a;

// 横から見る．
// 面積不変で傾ける．
cout << fixed << setprecision(10);

if (hx < b / 2.0){
    cout << 90.0 - atan(2*x/a/b/b) * 180.0 / PI << "\n";
}
else {
    cout << 90.0 - atan(a/2/(b-hx)) * 180.0 / PI << "\n";
}


}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  FOR(i,1,s.length()) {
    int len = s.length() - i;
    if(len % 2 == 1) continue;
    bool ok = true;
    FOR(j,0,len/2) {
      if(s[j] != s[j+len/2]) {
        ok = false;
        break;
      }
    }
    if(ok) {
      cout << len << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll now = 0;
    ll sum = 0;
    ll right = 0;
    ll res = 0;
    for(ll left = 0; left < N; left++) {
        while(right < N && ((now ^ A[right]) == sum + A[right])) {
            sum += A[right];
            now = now ^ A[right];
            right++;
        }
        res += right - left;
        now = now ^ A[left];
        sum -= A[left];
    }
    cout << res << endl;
    return 0;
}

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

int main(){
 int N,K;
 cin >> N;
 cin >> K;
 int i,A[200001];
 for(i=1;i<=N;i++){
  cin >> A[i];
 }
 for(i=K+1;i<=N;i++){
  if(A[i-K] < A[i] ){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
 }
 return 0;
}

Measured memory_bytes: 4400
#include <stdio.h>

int main(void) {
	char w[101];
	int q['z'-'a'] = {0};
	scanf("%s",w);
	int i;
	for (i=0;w[i] != '\0';i++) {
		q[w[i]-'a']++;
	}
	for (i=0;i<('z'-'a');i++) {
		if (q[i]%2) {
			puts("No");
			return 0;
		}
	}
		puts("Yes");
		return 0;
}


Measured memory_bytes: 128
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int x;
    cin >> x;

    vector<Int> a;
    for (Int i = -1024; i <= 1024; i++) {
        a.push_back(i * i * i * i * i);
    }

    Int n = a.size() - 1;
    for (Int i = 0; i <= n; i++) {
        for (Int j = 0; j <= n; j++) {
            if (a[i] - a[j] == x) {
                cout << i - 1024 << ' ' << j - 1024 << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;

int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=k;i<n;i++){
        if(a[i-k] < a[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4824
N,A,B = gets.split(" ").map{|v|
	v.to_i
}
 
ar = gets.split(" ").map{|v|
	v.to_i
}
 
# 貪欲 上位A個を取る A個目とA+1個目が異なるなら1通り
ar.sort!.reverse!
sum = ar[0 .. A-1].inject{|s, v|
	s + v
}
ave = sum.to_f/ A 
puts ave

if ar[A-1] != ar[A] then
	puts 1
	exit
end
 
n0 = ar.select{|x| x == ar[A-1]}.length
nb = ar.select{|x| x > ar[A-1]}.length
 
def fac(i)
	return (1 .. i).to_a.inject(1) { |sum, j| sum * j }
j = 1
1.upto(i) do |k|
	j = j * k
end
return j
end
 
 
# 上位A個が異なる値ならば
if ave != ar[0]
	# n0 C (A-nb)
	puts fac(n0) / (fac(A-nb) * fac(n0-A+nb))
else
	#上位A個が全て同じ→A+1個以上取っても良い
	m = [n0, B].min
	
	sum = 0
	A.upto(m) do |i|
		sum += fac(n0) / (fac(i) * fac(n0-i))
	end
	puts sum
end


Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
  int ret, i;
  int H, N, A, total;

  ret = scanf("%d %d", &H, &N);
  total = 0;
  for ( i=0; i<N; i++ ) {
    ret = scanf("%d", &A);
    total += A;
  }
  if ( H <= total )
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int& x:a) cin>>x;
	sort(a.begin(),a.end(),greater<int>());
	cout<<accumulate(a.begin(),a.begin()+k,0)<<'\n';
}




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

int main() {
  int64_t A,B;
  cin>>A>>B;
  int64_t C=B/A,D=2,Z=1;
  while(C>=D){
    D*=2;
    Z++;
  }
  cout<<Z<<endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

class check {
  public:
  std::vector<ll> p, m;

  check(std::vector<ll> t, ll X) {
    for(int i=0; i<t.size(); i++) t[i] = (t[i] % X);
    std::sort(t.begin(), t.end(), [] (ll &x, ll &y) { return x < y; } );
    for(auto i=0; i<t.size(); i++) {
      if ( t[i] == 0 ) continue;
      if ( p.size() == 0 ) {
        p.push_back( (X - t[i]) );
        m.push_back(t[i]);
        continue;
      }
      p.push_back(p.back() + (X-t[i]));
      m.push_back(m.back() + t[i]);
    }
  }

  ll GetK(ll i) { // 0 ~ i : - , i+1 ~ N-1 : +
    ll mm = m[i];
    ll pp = p.back() - p[i];
    return std::max(pp, mm);
  }
};

int main (void) {

  ll N, K; std::cin >> N >> K;

  ll Asum = 0;
  std::vector<ll> A(N);
  for(auto i=0; i<N; i++) {
    std::cin >> A[i];
    Asum += A[i];
  }

  std::vector<ll> g;
  for(auto i=1; i<=std::sqrt(Asum); i++) {
    if ( Asum % i == 0 ) {
      g.push_back(i);
      g.push_back(Asum/i);
    }
  }

  std::sort(g.begin(), g.end(), [](ll &x, ll &y) { return x>y; });

  for(auto&& l : g) { // candidate loop
    check ch(A, l);
    ll trial = 1e18;
    for(auto i=0; i<(int)ch.p.size(); i++) { trial = std::min(trial, ch.GetK(i)); }
    if ( trial == 1e18 ) trial = 0;
    if ( trial <= K ) {
      std::cout << l << std::endl;
      return 0;
    }
  }

  assert(0);
  return 0;
}


Measured memory_bytes: 256
import sys
SA = str(input())
SB = str(input())
SC = str(input())
turn = "A"
while (1):
    if( turn == "A"):
        if SA == "":
            break
        if SA[0] == "a":
            turn = "A"
        elif SA[0] == "b":
            turn = "B"
        else:
            turn = "C"
        SA = SA[1:]
    elif( turn == "B"):
        if SB == "":
            break
        if SB[0] == "a":
            turn = "A"
        elif SB[0] == "b":
            turn = "B"
        else:
            turn = "C"
        SB = SB[1:]
    else:
        if SC == "":
            break
        if SC[0] == "a":
            turn = "A"
        elif SC[0] == "b":
            turn = "B"
        else:
            turn = "C"
        SC = SC[1:]
print(turn)


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll a,v,b,w,t,d,x; cin>>a>>v>>b>>w>>t;
    d=abs(a-b); x=v-w;
    cout<<(x*t>=d ? "YES" : "NO")<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;

void solve(ll N, ll x, vector<ll> a) {
  ll ans(0);
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  FOR(i, 1, N) {
    if (a[i - 1] + a[i] <= x)
      continue;
    ans += a[i - 1] + a[i] - x;
    a[i] = x - a[i - 1];
  }
  cout << ans << endl;
}

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

  ll N, x;
  cin >> N >> x;

  vector<ll> a(N);
  REP(i, N)
    cin >> a[i];

  solve(N, x, move(a));

  return 0;
}


Measured memory_bytes: 3972
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[] a;
	static int[][] arr;
	
	static void go(int l1,int r1,int l2,int r2,int idx)
	{
		if(l1>l2 || r1>r2)
		{
			return;
		}
		
		if(l1==l2)
		{
			for(int i=r1;i<=r2;i++)
			{
				arr[l1][i]=a[idx++];
			}
		}
		else if(r1==r2)
		{
			for(int i=l1;i<=l2;i++)
			{
				arr[i][r1]=a[idx++];
			}
		}
		
		else
		{
			for(int i=l1;i<=l2;i++)
			{
				arr[i][r1]=a[idx++];
			}
			
			for(int i=r1+1;i<=r2;i++)
			{
				arr[l2][i]=a[idx++];
			}
			
			for(int i=l2-1;i>=l1;i--)
			{
				arr[i][r2]=a[idx++];
			}
			
			for(int i=r2-1;i>r1;i--)
			{
				arr[l1][i]=a[idx++];
			}
		}
		
		go(l1+1,r1+1,l2-1,r2-1,idx);
	}
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt(),ptr=0;a=new int[n*m];
		
		for(int i=0;i<k;i++)
		{
			int x=sc.nextInt();
			
			for(int j=0;j<x;j++)
			{
				a[ptr++]=i+1;
			}
		}
		
		arr=new int[n][m];
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				arr[i][j]=-1;
			}
		}
		
		go(0,0,n-1,m-1,0);
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				out.print(arr[i][j]+" ");
			}
			
			out.println("");
		}
		
		out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 25684
#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d %d %d\n",&a,&b,&c);
    
    if(a <= b && b <= c){
    printf("%d %d %d\n" ,a, b, c);}
    
    else if(a <= c && c <= b){
    printf("%d %d %d\n" ,a, c, b);}

    else if(b <= a && a <= c){
    printf("%d %d %d\n" ,b, a, c);}

    else if(b <= c && c <= a){
    printf("%d %d %d\n" ,b, c, a);}

    else if(c <= a && a <= b){
    printf("%d %d %d\n" ,c, a, b);}

    else{
    printf("%d %d %d\n" ,c, b, a);}
    

    return 0;
}


Measured memory_bytes: 2072
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int ans = 1;

        // iが1の場合は何度かけても1となるので、初期値は2とする
        for (int b = 2; b <= x; b++) {
            int power = b * b;

            // pの初期値も同様
            for (int p = 2; ; p++) {
                if (power > x) {
                    break;
                }

                ans = Math.max(ans, power);

                power *= b;

            }

        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 22868
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
    public function nextString() {
        return (string)$this->next();
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();

$sum = 0;
$result = 0;

for($i=0; $i < 2; $i++) {
  if ($a < $b) {
    $sum = $b;
    $b--;
  } else {
    $sum = $a;
    $a--;
  }
  $result += $sum;
}

echo $result;

Measured memory_bytes: 3576
def main():
    y, m, d = map(int, input().split())
    a = (y - 1) // 3
    b = (y - 1) % 3
    c = a * 590 + 195 * b 
    if y % 3:
        a = (m - 1) // 2
        b = (m - 1) % 2
        c += a * 39 + b * 20
    else:
        c += (m - 1) * 20
    c += d - 1
    print(196470-c)
n = int(input())
for i in range(n):
    main()


Measured memory_bytes: 5600
import java.util.Scanner;

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

		System.out.println(c=='A'?"T": c=='T'?"A": c=='C'?"G":"C");

		sc.close();
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define Maxn 1000007
using namespace std;
int n;
int a[Maxn],p[Maxn];
bool calc(int x,int y)
{
    return ((p[x]-p[y]-p[x-y])==0);
}
int main()
{
    scanf("%d",&n);
    bool flag=false;
    for (int i=1;i<=n;i++)
    {
        char ch=getchar();
        while (ch<'1'||ch>'3') ch=getchar();
        a[i]=ch-'0'-1;
        if (a[i]==1) flag=true;
    }
    for (int i=1;i<=n;i++)
        if (i%2==1) p[i]=0; else p[i]=p[i/2]+1;
    for (int i=1;i<=n;i++)
        p[i]+=p[i-1];
    if (flag)
    {
        int ans=0;
        for (int i=1;i<=n;i++)
            if (calc(n-1,i-1)) ans^=(a[i]%2);
        printf("%d\n",ans);
    } else
    {
        int ans=0;
        for (int i=1;i<=n;i++)
            if (calc(n-1,i-1)) ans^=(a[i]/2);
        printf("%d\n",2*ans);
    }
    return 0;
}

Measured memory_bytes: 11588
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  long long a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  if (a == b ){
    cout << "YES\n";
    return 0;
  }
  else if ((a > b && v * t - w * t >= a - b) || (a < b && v * t - w * t >= b - a)){
    cout << "YES\n";
  }
  else{
    cout << "NO\n";
  }
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int p[20],n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	int ans=0;
	for(int i=1;i+1<n;i++)
	{
		int a[3];
		a[0]=p[i-1];
		a[1]=p[i];
		a[2]=p[i+1];
		sort(a,a+3);
		if(a[1]==p[i])
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define ALL(V) V.begin(),V.end()
#define f1(a,b) for(int a=1;a<=b;a++)
#define f0(a,b) for(int a=0;a<b;a++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define de(x) cout<<#x<<": "<<x<<endl
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
LL n,odw[N];
vector <pair<pll,LL>> vek1,vek2;
pll odl(int v,pll nw) {
    //cout<<v<<" "<<nw.f<<" "<<nw.s<<endl;
    if(v>=nw.f&&v<=nw.s) return MP(0,v);
    if(v>nw.s) return MP(abs(nw.s-v),nw.s);
    return MP(abs(nw.f-v),nw.f);
}
int32_t main(void) {
    boost;
    cin>>n;
    f0(i,n) {
        int a,b;
        cin>>a>>b;
        vek1.PB(MP(MP(a,b),i));
        vek2.PB(MP(MP(b,a),i));
    }
    LL wynik=0;
    f0(uesifhd,2) {
        int poz=0;
        sort(ALL(vek1));
        sort(ALL(vek2));
        reverse(ALL(vek1));
        int p1=0,p2=0;
        LL re=0;
        f0(i,n) {
            if(i%2==0) {
                while(odw[vek1[p1].s]==1) p1++;
                re+=odl(poz,vek1[p1].f).f;
                poz=odl(poz,vek1[p1].f).s;
                odw[vek1[p1].s]=1;
            }
            if(i%2==1) {
                while(odw[vek2[p2].s]==1) p2++;
                pll nw=vek2[p2].f;
                swap(nw.f,nw.s);
                re+=odl(poz,nw).f;
                poz=odl(poz,nw).s;
                odw[vek2[p2].s]=1;
            }
            //de(re);
        }
        re+=abs(poz);
        f0(i,n+3) odw[i]=0;
        wynik=max(wynik,re);
        f0(i,n) {
            vek1[i].f.f*=-1;
            vek1[i].f.s*=-1;
            vek2[i].f.f*=-1;
            vek2[i].f.s*=-1;
            swap(vek1[i].f.f,vek1[i].f.s);
            swap(vek2[i].f.f,vek2[i].f.s);
        }
        //de(wynik);
    }
    cout<<wynik<<endl;
}


Measured memory_bytes: 6820
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {
	int k;
	cin >> k ;

	ll ans = 0;

	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			for (int z = 1; z <= k; z++)
			{
				ans += GCD(i, GCD(j, z));
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    var a = readLine()!!.split(" ").map{it.toInt()}


    //先頭がプラス
    var move1=0L
    var sum1=0L
    for(i in 0..n-1){
        sum1+=a[i]
        if(i%2==0 && sum1<1){
            move1 += 1-sum1
            sum1 = 1
        }
        if(i%2==1 && sum1>-1){
            move1 += sum1-(-1)
            sum1 = -1
        }
    }

    //先頭がマイナス
    var move2=0L
    var sum2=0L
    for(i in 0..n-1){
        sum2+=a[i]
        if(i%2==1 && sum2<1){
            move2 += 1-sum2
            sum2 = 1
        }
        if(i%2==0 && sum2>-1){
            move2 += sum2-(-1)
            sum2 = -1
        }
    }


    println(Math.min(move1,move2))

}

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

    void solve(set<string> &s, vector<int> &x)
    {
        char id = 'a';
        int pp = 20;
        vector<char> ans(30, 0);
        for (int i = 0; i < x.size(); i++)
        {
            if (x[i] == -1)
            {
                x[i] = pp++;
                ans[x[i]] = id++;
                continue;
            }
            if (ans[x[i]]) continue;
            ans[x[i]] = id++;
        }
        string t = "";
        for (int i = 0; i < x.size(); i++) 
        {
            t += ans[x[i]];
            if (x[i] > 15) x[i] = -1;
        }
        s.insert(t);
    }

    void dfs(set<string> &s, vector<int> &x, int n)
    {
        int cnt = 0;
        for (int i = 0; i < x.size(); i++)
        {
            cnt += x[i];
            if (x[i] == 0)
            {
                if (i == 0)
                {
                    for (int j = 1; j < n; j++)
                    {
                        if (j * x.size() > n) break;
                        x[i] = j;
                        dfs(s, x, n);
                    }
                    x[i] = 0;
                    return ;
                }
                for (int j = x[i - 1]; j < n; j++)
                {
                    if (cnt + j * (x.size() - i) > n) break;
                    x[i] = j;
                    dfs(s, x, n);
                }
                x[i] = 0;
                return ;
            }
        }
        if (cnt != n) return ;
        vector<int> y;
        for (int i = 0; i < x.size(); i++)
        {
            if (x[i] == 1)
            {
                y.push_back(-1);
                continue;
            }
            for (int j = 0; j < x[i]; j++) y.push_back(i);
        }
        sort(y.begin(), y.end());
        do {
            solve(s, y);
        } while (next_permutation(y.begin(), y.end()));
    }

    int main()
    {
        int n;
        cin >> n;
        set<string> s;
        string t = "";
        for (int i = 0; i < n; i++) t += "a";
        s.insert(t);
        t = "";
        for (int i = 0; i < n; i++) t += ('a' + i);
        s.insert(t);
        for (int i = 2; i <= n - 1; i++)
        {
            vector<int> x(i, 0);
            dfs(s, x, n);
        }
        auto ptr = s.begin();
        while (ptr != s.end()) cout << *(ptr++) << endl;
    }


Measured memory_bytes: 14208
def checkPalindrome(word)
  word = word.to_s
  size = word.length / 2
  (word[0..size] == word.reverse[0..size])
end
s = gets.chomp!

unless checkPalindrome(s)
  puts 'No'
  exit
end

if checkPalindrome(s[0..(s.size / 2 - 1)]) && checkPalindrome(s[((s.size + 3) / 2 - 1)..s.size])
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#define min(a,b) a < b ? a : b
#define INF 0x7FFFFFFF

int main(void){
	int n, t[16][17], i, j, k, l, dp[1<<17];
	while(1){
		scanf("%d",&n);
		if(n == 0)
			break;
		for(i = 0;i < n;i++){
			for(j = 0;j <= n;j++)
				scanf("%d",&t[i][j]);
		}
		for(i = 0;i < 1 << (n + 1);i++)
			dp[i] = INF;
		dp[1] = 0;
		for(i = 0;i < n;i++){
			for(j = (1 << (n + 1)) - 1;j >= 0;j--){ // 装備品をビットであらわしたもの
				if(dp[j] != INF){
					for(k = 0;k <= n;k++){ // 装備を選ぶ
						if(j & 1 << k){ // 持っている装備品かどうか
							for(l = 1;l <= n;l++) // ステージ
								if(!(1 << l & j))
									dp[(1 << l) + j] = min(dp[(1 << l) + j],dp[j] + t[l - 1][k]);
						}
					}
				}
			}
		}
		printf("%d\n",dp[(1 << (n + 1)) - 1]);
	}
	return 0;
}

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

typedef pair<int, int> ii;
typedef long long ll;
const int mod = 1000000007;

int mul(int x, int y) {
  return (ll)x * y % mod;
}
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
int mpow(int x, int y) {
  if (y == 0) return 1;
  int ret = mpow(x, y / 2);
  ret = mul(ret, ret);
  if (y & 1) ret = mul(ret, x);
  return ret;
}
int inv(int x) {
  return mpow(x, mod - 2);
}
int two[200005];

struct X {
  int a, b, c;
  X() {}
  X(int x, int y, int z): a(x), b(y), c(z) {}
};

int n;
vector<int> v[200005];
int sz[200005];

deque<X> pl[200005];
deque<X> *dq[200005];

int cnt;
deque<X>* newd() {
  return &pl[cnt ++];
}

deque<X>* merge(deque<X>* d1, deque<X>* d2, int &ssz) {
  if (d1->size() < d2->size()) swap(d1, d2);
  deque<X> &p = *d1;
  deque<X> &q = *d2;

  ssz = max(ssz, (int)q.size());
  for (int i = 0; i < (int)q.size(); i ++) {
    p[i].a = add(p[i].a, q[i].a);
    p[i].b = mul(p[i].b, q[i].b);
    p[i].c = add(p[i].c, q[i].c);
  }
  return d1;
}

void dfs(int x) {
  if (v[x].size() == 0) {
    dq[x] = newd();
    dq[x]->push_back(X(1, 1, 1));
    return;
  }
  dq[x] = nullptr;
  int ssz = 0;

  for (int i = 0; i < (int)v[x].size(); i ++) {
    int y = v[x][i];
    dfs(y);

    if (dq[x] == nullptr) dq[x] = dq[y];
    else {
      dq[x] = merge(dq[x], dq[y], ssz);
    }
  }

  auto &d = *dq[x];
  for (int i = 0; i < ssz; i ++) {
    d[i].a = mul(d[i].a, d[i].b);
    d[i].b = sub(two[d[i].c], d[i].a);
    d[i].a = mul(d[i].a, inv(d[i].b));
  }
  d.push_front(X(1, 1, 1));
}

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

  two[0] = 1;
  for (int i = 1; i <= n + 1; i ++) {
    two[i] = mul(two[i - 1], 2);
  }

  for (int i = 1; i <= n; i ++) {
    int pi;
    scanf("%d", &pi);
    v[pi].push_back(i);
  }

  dfs(0);

  int ans = 0;
  for (X x : *dq[0]) {
    int tmp = mul(mul(x.a, x.b), two[n + 1 - x.c]);
    ans = add(ans, tmp);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 172928
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)

U = 10 ** 5 + 1
b = np.bincount(A, minlength=U)
c = np.zeros(U, dtype=int)
c[:-1] += b[1:]
c[1:] += b[:-1]
c += b

print(c.max())

Measured memory_bytes: 22616
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A,B,C = sorted(Is()),sorted(Is()),sorted(Is())

Bs = [0]*N
b,j = 0,0
for i in range(N):
    while j < N:
        if B[i] >= C[j]:
            b += 1
        else:
            Bs[i] = N - b
            break
        if j == N-1:
            Bs[i] = N - b
        j += 1

all = sum(Bs)
ans,sum,j = 0,0,0
for i in range(N):
    while j < N:
        if A[i] >= B[j]:
            sum += Bs[j]
        else:
            ans += all - sum
            break
        if j == N-1:
            ans += all - sum
        j += 1
print(ans)


Measured memory_bytes: 23212
N = int(raw_input())
nums = list(map(int,raw_input().split()))
dp = [10000000000 for x in range(N)]
dp[0] = 0
for i in range(N):
    if i<N-1:
        dp[i+1] = min(dp[i+1],dp[i]+abs(nums[i+1]-nums[i]))
    if i<N-2:
        dp[i+2] = min(dp[i+2],dp[i]+abs(nums[i+2]-nums[i]))
print dp[N-1]

Measured memory_bytes: 12164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ll H, W;
    cin >> H >> W;
    ll ans =  (H*W+1)/2;
    if (H == 1 or W == 1) {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    A = tuple(map(int, input().split()))

    ans = [0] * (n + 1)
    for a in A:
        ans[a] += 1
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 32304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int x; cin >> x;
   if (x == 1){
      cout << 1 << endl;
      return 0;
   }
   int ans = 0;
   for (int i = 1; i <= x; i++){
      int j = i*i;
      while(j<=x){
         ans = max(ans, j);
         if (j == 1)break;
         j *= i;
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3612