akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
  A[i] = [-1]+[int(c)-1 for c in input().split()][::-1]

def f(cand):
  can_use = []
  candl = set()
  for i in cand:
    c = A[i][-1]
    if A[c][-1]==i:
      can_use += [i]
  for n in can_use:
    A[n].pop()
    candl.add(n)
    if A[n][-1]!=-1:
      candl.add(A[n][-1])
  return len(can_use),candl

ans = 0
rest = N*(N-1)
cand = set(range(N))
while True:
  ans += 1
  x, cand = f(cand)
  if x==0:
    ans = -1
    break
  rest -= x
  if rest==0:
    break
print(ans)

Measured memory_bytes: 62172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=4e3+10;
int n;
char str[N];
ll s[N][N];
int main(){
	scanf("%d",&n);
	scanf("%s",str+1);
	int n=strlen(str+1);
	for(int i=1;i<=n;i++){
		s[i]['R'-'A']=s[i-1]['R'-'A'];
		s[i]['B'-'A']=s[i-1]['B'-'A'];
		s[i]['G'-'A']=s[i-1]['G'-'A'];
		s[i][str[i]-'A']++;
	}
	ll sum=0;
	for(int i=1;i<=n-2;i++){
		for(int j=i+1;j<=n-1;j++){
			if(str[i]==str[j])continue;
			if(str[i]!='B'&&str[j]!='B')
			{
				sum+=s[n]['B'-'A']-s[j]['B'-'A'];
				if(j+j-i>n)continue;
				if(str[j+j-i]=='B'){
					sum--;
				}
			}
			if(str[i]!='R'&&str[j]!='R')
			{
				sum+=s[n]['R'-'A']-s[j]['R'-'A'];
				if(j+j-i>n)continue;
				if(str[j+j-i]=='R'){
					sum--;
				}
			}
			if(str[i]!='G'&&str[j]!='G')
			{
				sum+=s[n]['G'-'A']-s[j]['G'-'A'];
				if(j+j-i>n)continue;
				if(str[j+j-i]=='G'){
					sum--;
				}
			}
		}
	}
	printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 20248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> X(n), Y(n), P(n);
  rep(i, n) cin >> X[i] >> Y[i] >> P[i];
  vector<vector<ll>> xmin(1<<n, vector<ll>(n)), ymin(1<<n, vector<ll>(n));
  rep(i, 1<<n) {
    rep(j, n) {
      xmin[i][j] = abs(X[j]);
      ymin[i][j] = abs(Y[j]);
    }
    rep(k, n) {
      if((i>>k)&1) {
        rep(j, n) {
          xmin[i][j] = min(abs(X[j]-X[k]), xmin[i][j]);
          ymin[i][j] = min(abs(Y[j]-Y[k]), ymin[i][j]);
        }
      }
    }
  }
  vector<ll> ans(n+1, longinf);
  auto dfs = [&](auto dfs, int i, ll xb, ll yb) -> void {
    if(i == n) {
      ll cost = 0;
      rep(j, n) cost += P[j] * min(xmin[xb][j], ymin[yb][j]);
      int cnt = __builtin_popcount(xb) + __builtin_popcount(yb);
      if(cnt > n) return;
      ans[cnt] = min(cost, ans[cnt]);
      return;
    }
    dfs(dfs, i+1, xb, yb);
    dfs(dfs, i+1, xb|(1<<i), yb);
    dfs(dfs, i+1, xb, yb|(1<<i));
  };
  dfs(dfs, 0, 0, 0);

  /* dummy */
  vector<ll> pw(n+1);
  pw[0] = 1;
  rep(i, n) pw[i+1] = pw[i] * 3;
  rep(i, pw[n]) {
    ll x = 0, y = 0;
    rep(j, n) {
      if(i/pw[j]%3 == 1) {
      } else if(i/pw[j]%3 == 2) {
      }
    }
    ll cur = 0;
    rep(j, n) cur += P[j] * min(xmin[x][j], ymin[y][j]);
    int cnt = __builtin_popcount(x) + __builtin_popcount(y);
    if(cnt > n) continue;
  }
  /* dummy */

  rep(i, n+1) cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 12968
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    boolean flg = true;
    ArrayList<List<Integer>> list = new ArrayList<>();
    while(flg) {
      int h = sc.nextInt();
      int w = sc.nextInt();

      if(h == 0 && w == 0) {
        flg = false;
        sc.close();
        break;
      }
      List<Integer> data = new ArrayList<Integer>();
      data.add(h);
      data.add(w);
      list.add(data);
    }

    for(int i = 0; i < list.size(); i++) {
      int h = list.get(i).get(0);
      int w = list.get(i).get(1);
      for(int j = 0; j < h; j++) {
        for(int k = 0; k < w; k++) {
          if(j == 0 || k == 0 || k == (w - 1) || j == (h - 1)) {
            System.out.print('#');
          } else {
            System.out.print('.');
          }
        }
        System.out.print('\n');
      }
        System.out.print('\n');
    }
  }
}


Measured memory_bytes: 37240
import itertools
def main():
  N = int(input())
  posi = []
  for i in range(N):
    posi.append(list(map(int, input().split())))
  posi.sort()
  num = [i for i in range(N)]
  ans = 1000000000
  for pair in itertools.combinations(num,2):
    p = posi[pair[1]][0]-posi[pair[0]][0]
    q = posi[pair[1]][1]-posi[pair[0]][1]
    ch = [True]*N
    ans_temp = 0
    for i in range(N):
      if ch[i]:
        ans_temp += 1
        ch[i] = False
      now = posi[i]
      while [now[0] +  p, now[1] + q] in posi:
        ch[posi.index([now[0] +  p, now[1] + q])] = False
        now = [now[0] +  p, now[1] + q]
    ans = min(ans, ans_temp)
  if N == 1:
    ans = 1
  print(ans)
    
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;
    cout << (((A * B) % 2 == 0) ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

def main():
    N, K = map(int, input().split())
    if N <= K:
        print('0')
        exit()
    else:
        H = list(map(int, input().split()))
        H.sort(reverse=True)
        print(sum(H[K:]))

if __name__ == '__main__':
    main()



Measured memory_bytes: 88908
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    int n,m; cin>>n>>m;
    vector <pair<int,int>> data(m);
    rep(i,m){
        int a,b; cin>>a>>b;
        int to = 0;
        rep(i,b){
            int x; cin>>x; x--;
            to |= (1<<x);
        }
        data[i] = {a, to};
    }
    vector <int> dp((1<<n), INF); 
    dp[0] = 0;
    for(int i=0;i<(1<<n);i++){
        rep(j,m){
            
            chmin(dp[ (data[j].S | i) ], dp[i] + data[j].F);
        }
    }
    if(dp[(1<<n)-1] == INF) cout<<-1<<endl;
    else cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int64_t> as(n); for (auto& a : as) { cin >> a; }
	int64_t s = 0;
	FOR_LT(i, 0, n) {
		s ^= as[i];
	}
	FOR_LT(i, 0, n) {
		cout << (s ^ as[i]) << " ";
	}
	cout << endl;

	return 0;
}

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

const int iMod	= 1000000007;

int ModF( const int N, const int M )
{
int i;
long long F;
int A;
int B;
int C;

	if( N <= M )
	{
		A = N;
		B = M;
	}
	else
	{
		A = M;
		B = N;
	}

	F = 1;
	for( i = 2; i <= A; i++ )
	{
		F *= i;
		F %= iMod;
	}

	C = F;
	for( i = A + 1; i <= B; i++ )
	{
		F *= i;
		F %= iMod;
	}

	F *= C;
	F %= iMod;
		
	return F;
}

int main( int argc, char *argv[] )
{
int N;
int M;
long long F;

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

	cin >> N;
	cin >> M;
	if( N > M + 1 || N + 1 < M )
	{
		cout << 0 << endl;

		return 0;
	}

	F = ModF( N, M );
	if( N == M )
	{
		F *= 2;
		F %= iMod;
	}

	cout << F << endl;

	return 0;
}




Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuGCD solver = new AizuGCD();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuGCD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();

            out.printf("%d\n", gcd(x, y));
        }

        private int gcd(int x, int y) {
            while (y != 0) {
                int t = x % y;
                x = y;
                y = t;
            }

            return x;
        }

    }
}




Measured memory_bytes: 26476
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

signed main(){
    ll n,k;
    cin >> n >> k;
    ll a[n] = {};
    rep(i,0,n) cin >> a[i];
    sort(a,a+n);
    ll sum = 0;
    rep(i,0,k) sum += a[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]

flag = 0
for i in range(n-2):
  if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
    flag = 1
if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9144
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
typedef pair<long long , long long> P;
int main() {
	long long N;
	cin >> N;
	vector<string>S(N);
	vector<vector<long long>>A(N, vector<long long>(26, 0));
	rep(i, N) {
		cin >> S.at(i);
		rep(j, S.at(i).size()) {
			int num = S.at(i).at(j) - 97;
			A.at(i).at(num)++;
		}
	}
	vector<int>ans(26, 0);
	rep(i, 26) {
		long long num = 1e9;
		rep(j, N) {
			num = min(num, A.at(j).at(i));
		}
		ans.at(i) = num;
	}
	rep(i, 26) {
		if (ans.at(i) != 1e9) {
			rep(j, ans.at(i)) {
				cout << char('a' + i);
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 1e5 + 100;
int n, W;
long long a[maxn], dp[maxn], v[maxn], w[maxn];
int main()
{
    cin>>n>>W;
    for(int i = 1; i <= n; i++) cin>>w[i]>>v[i];
    for(int i = 1; i <= n; i++){
        for(int j = W; j >= w[i]; j--){
            dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
        }
    }
    cout<<dp[W]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;

template< typename T >
T bellman_ford(Edges< T > &edges, int V, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(V, INF);
    vector< int > negative(V);
    dist[s] = 0;
    for(int i = 0; i < V - 1; i++) {
        for(auto &e : edges) {
            if(dist[e.src] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
        }
    }
    for(int i = 0; i < V; i++) {
        for(auto &e : edges) {
            if(dist[e.src] == INF) continue;
            if(dist[e.src] + e.cost < dist[e.to]) {
                negative[e.to] = 1;
                dist[e.to] = dist[e.src] + e.cost;
            }
            if(negative[e.src]) {
                negative[e.to] = 1;
            }
        }
    }
    if(negative[V-1]) {
        return 1;
    }
    return dist[V-1];
}


int main(void) {
    int N, M, P;
    cin >> N >> M >> P;
    Edges<int> g;
    while(M--) {
        int A, B, C;
        cin >> A >> B >> C;
        --A; --B;
        g.emplace_back(A, B, P-C);
    }

    int ans = bellman_ford(g, N, 0);
    if(ans == 1) {
        cout << -1 << endl;
    } else {
        cout << max(-ans, 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
  {int K, s{}; cin >> K;
  for (int a = 1; a <= K; ++a) for (int b = 1; b <= K; ++b) for (int c = 1; c <= K; ++c) s += gcd(gcd(a, b), c);
  cout << s << endl;}

Measured memory_bytes: 3592
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(x) cout <<#x<<": "<<x<<endl
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=1e6+10;
const int MAX=10000007;
inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}
inline void out(ll x) {   
    if(x>9) out(x/10);   
    putchar(x%10+'0'); 
}
const int mod=1e9+7;

int main(){
     int n;
     cin>>n;
     int z;
     z=n/1000;
     if(n%1000!=0)z++;
    cout<<z*1000-n;
    return 0;
} 

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

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

using namespace std;

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

string calReverse(string s) {
  string res = "";
  for (char c : s) {
    string app;
    switch (c) {
      case 'U':
        app = 'D';
        break;
      case 'D':
        app = 'U';
        break;
      case 'L':
        app = 'R';
        break;
      default:
        app = 'L';
        break;
    }
    res += app;
  }
  return res;
}

string calGo(int sx, int sy, int tx, int ty) {
  string res = "";
  while (sx != tx || sy != ty) {
    if (ty - sy > 0) {
      res += 'U';
      sy += 1;
    } else if (ty - sy < 0) {
      res += 'D';
      sy -= 1;
    } else if (tx - sx > 0) {
      res += 'R';
      sx += 1;
    } else {
      res += 'L';
      sx -= 1;
    }
  }
  return res;
}

string calFirst(int sx, int sy, int tx, int ty) {
  string res = calGo(sx, sy, tx, ty);
  res += calReverse(res);
  return res;
}

string calSecond(int sx, int sy, int tx, int ty) {
  int ssx, ssy, ttx, tty;
  char beginGo;
  char endGo;
  char beginBack;
  char endBack;
  if (tx >= sx) {
    ttx = tx + 1;
    ssx = sx - 1;
    if (ty >= sy) {
      tty = ty + 1;
      ssy = sy - 1;
      beginGo = 'L';
      endGo = 'D';
      beginBack = 'R';
      endBack = 'U';
    } else {
      tty = ty - 1;
      ssy = sy + 1;
      beginGo = 'L';
      endGo = 'U';
      beginBack = 'R';
      endBack = 'D';
    }
  } else {
    ttx = tx - 1;
    ssx = sx + 1;
    if (ty >= sy) {
      tty = ty + 1;
      ssy = sy - 1;
      beginGo = 'R';
      endGo = 'D';
      beginBack = 'L';
      endBack = 'U';
    } else {
      tty = ty - 1;
      ssy = sy + 1;
      beginGo = 'R';
      endGo = 'U';
      beginBack = 'L';
      endBack = 'D';
    }
  }
  string go = calGo(ssx, ssy, ttx, tty);
  go[0] = beginGo;
  go[go.size() - 1] = endGo;
  string back = calReverse(go);
  back[0] = beginBack;
  back[back.size() - 1] = endBack;
  return go + back;
}

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string first = calFirst(sx, sy, tx, ty);
  string second = calSecond(sx, sy, tx, ty);
  string res = first + second;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for i in range(m)]
ans=[-1]*n
i=0
for a,b in ab:
  t=10**12
  j=0
  for c,d in cd:
    if abs(a-c)+abs(b-d)<t:
      t=abs(a-c)+abs(b-d)
      ans[i]=j+1
    j+=1
  i+=1
print(*ans,sep='\n')




Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;

struct Node{
	int key;
	Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int key){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = key;
	z->l = NIL;
	z->r = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key)		x = x->l;
		else	x = x->r;
	}

	z->p = y;
	if(y == NIL)
		root = z;
	else{
		if(z->key < y->key)		y->l = z;
		else	y->r = z;
	}
}

void preParse(Node *u){
	if(u == NIL)	return;
	cout << " " << u->key;
	preParse(u->l);
	preParse(u->r);
}

void inParse(Node *u){
	if(u == NIL)	return;
	inParse(u->l);
	cout << " " << u->key;
	inParse(u->r);
}

int main(){
	int n, temp;
	char s[10];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		if(s[0] == 'i'){
			cin >> temp;
			insert(temp);
		}
		else{
			inParse(root);
			cout << endl;
			preParse(root);
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 26460
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int num = Integer.valueOf(sc.nextInt());
    
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("AC", 0);
    map.put("WA", 0);
    map.put("TLE", 0);
    map.put("RE", 0);    

    while(sc.hasNext()) {
      String str = sc.nextLine();
      if (map.containsKey(str)) {
        map.put(str, map.get(str)+1);
      }
    }

    System.out.println("AC x "+ map.get("AC"));
    System.out.println("WA x "+ map.get("WA"));
    System.out.println("TLE x "+ map.get("TLE"));
    System.out.println("RE x "+ map.get("RE"));

    sc.close();
  }
}

Measured memory_bytes: 61304
n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))

# print(f"{n} {m} {x}")
# print(a_list)

n_list = [0] * (n + 1)
# print(n_list)

n_list[x] = 'X'
for i in range(m):
    n_list[a_list[i]] = 1
# print(n_list)

# print(n_list[:x])
# print(n_list[x + 1:])
print(min(sum(n_list[:x]), sum(n_list[x + 1:])))

Measured memory_bytes: 9124
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if( z->key < x->key )
      x = x->left;
    else
      x = x->right;
  }

  z->parent = y;
  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else
    y->right = z;
  
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);   
    inorder(u->right); 
  }
}

void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);  
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
import queue

def bfs(i,j,d):
    already[i][j] = d
    next = []
    for a,b in [[-1,0], [1,0],[0,1],[0,-1]]:
        if 0<=i+a<H and 0<=j+b<W and A[i+a][j+b]=='.' and already[i+a][j+b]==-1:
            if [i+a,j+b] not in next:
                next.append([i+a,j+b])
    for ni, nj in next:
        bfs(ni,nj,d+1)




H,W = map(int,input().split())
A = [list(input()) for i in range(H)]


ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j]!='.':
            continue
        q = queue.Queue()
        q.put((i,j))
        already = [[-1]*W for _ in range(H)]
        already[i][j] = 0
        while not q.empty():
            x,y = q.get()
            for a,b in [[-1,0], [1,0],[0,1],[0,-1]]:
                if 0<=x+a<H and 0<=y+b<W and A[x+a][y+b]=='.' and already[x+a][y+b]==-1:
                    q.put((x+a, y+b))
                    already[x+a][y+b] = already[x][y]+1
        t = 0
        for al in already:
            t = max(t, max(al))

        ans = max(ans, t)

print(ans)


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  reverse(v.begin(), v.end());
  ll ans = 0LL;
  for(int i = 0; i < N-2; i++) {
    for(int j = i+1; j < N-1; j++){
      for(int k = j+1; k < N; k++) {
        if(v[i]>=v[j]+v[k]) break;
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n , s[1000005] , a[100005] , ans;
  cin>>n;
  s[0]=0,s[n+1]=0; 
  for(int i=1;i<=n;i++){
    cin>>s[i];
    if(i == n){
      a[n+1]=abs(s[i]);
      ans+=a[n+1];
    }
    a[i]=abs(s[i]-s[i-1]);
    ans+=a[i];
  }
  
  for(int i=1;i<=n;i++){
    cout<<ans-(a[i]+a[i+1])+abs(s[i-1]-s[i+1])<<endl;
  }
  return(0);
}
      

Measured memory_bytes: 3968
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,x,y,a[20005],m;
int main(){
	cin>>n;
	if(n==3)puts("2 5 63");
	else if(n==4)puts("2 5 20 63");
	else{
		while(1){
			++y;
			if(y%4==1||y%4==2) continue;
			x=0;
			for(int i=15;i>=0;--i){
				int X=x+(1<<i);
				if(X+y-min(X*2,y*3)/6<n)x=X;
			}
			++x;
			if(x<=15000&&x%3!=1) break;
		}
		for(int i=1;i<=x;++i)a[++m]=i*2;
		for(int i=1;i<=y;++i)if(i*3>x*2||(i&1))a[++m]=i*3;
		for(int i=1;i<n;++i)printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
    return 0;
}


Measured memory_bytes: 3840
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents

main :: IO()
main = do
  n <- readLn :: IO Int
  ts <- read2dInts
  solve' ts

type AdjList = IntMap.IntMap [Int]
toAdjList :: [[Int]] -> AdjList
toAdjList = foldr f IntMap.empty 
  where
    f :: [Int] -> AdjList -> AdjList
    f (i:n:edges) adjList = IntMap.insert i edges adjList


solve' ts = mapM_ showTree . sortBy (\(a,_,_) (b,_,_) -> compare a b) $ dfs [(root, -1, 0)] IntSet.empty
  where
    adjList = toAdjList ts
    root = findRoot adjList
    findRoot :: AdjList -> Int
    findRoot adjl = head $ [ key | key <- IntMap.keys adjl, key `notElem` (join $ IntMap.elems adjl)]

    dfs :: [(Int, Int, Int)] -> IntSet.IntSet -> [(Int, Int, Int)]
    dfs [] _ = []
    dfs (c:cs) visiteds 
      = c:(dfs (unv++cs) (IntSet.insert current visiteds))
      where
        (current, parent, depth) = c
        unvisiteds = [ x | x <- adjList IntMap.! current, IntSet.notMember x visiteds]
        unv = zip3 unvisiteds (repeat current) (repeat $ depth+1)

    showTree :: (Int, Int, Int) -> IO()
    showTree (c, p, d) = 
      putStrLn $ "node " ++ (show c) ++ ": parent = " ++ (show p) ++ ", depth = " ++ (show d) 
        ++ kind ++ ", [" ++ (intercalate ", " (map show $ adjList IntMap.! c)) ++ "]"
        where
          kind | p == -1 = ", root"
              | null $ adjList IntMap.! c = ", leaf"
              | otherwise = ", internal node"



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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL inv(LL a , LL p){
	LL ret = 1;
	for(LL i = p-2 ; i ; i /= 2){
		if(i&1) (ret *= a) %= p;
		a = a * a % p;
	}
	return ret;
}

const int RH_prime = 3;
const LL RH_mod[] = {1000000007,1000000021,1000000033};
const LL base = 314159;

struct RH{
	int n;
	vector<LL> hash[RH_prime];
	vector<LL> pw[RH_prime];
	
	RH(){n=0;}
	RH(const string &s){
		n = (int)s.size();
		for(int i = 0 ; i < RH_prime ; ++i){
			hash[i].push_back(0);
			pw[i].push_back(1);
			for(int j = 0 ; j < n ; ++j){
				if(s[j] == '+' || s[j] == '-'){
					hash[i].push_back((hash[i][j] + (s[j]=='-'?RH_mod[i]-pw[i][j]:pw[i][j])) % RH_mod[i]);
					pw[i].push_back(pw[i][j]);
				} else {
					hash[i].push_back(hash[i][j]);
					pw[i].push_back(pw[i][j] * (s[j]=='>'?base:inv(base,RH_mod[i])) % RH_mod[i]);
				}
			}
		}
	}
};

int main(){
	int N; cin >> N;
	string S; cin >> S;
	RH rh(S);
	map<tuple<LL,LL,LL>,int> M;
	LL ans = 0;
	repm(i,N,0){
		++M[make_tuple(rh.hash[0][i],rh.hash[1][i],rh.hash[2][i])];
		tuple<LL,LL,LL> z = make_tuple((rh.hash[0][N]*rh.pw[0][i-1]+rh.hash[0][i-1])%RH_mod[0],
							 (rh.hash[1][N]*rh.pw[1][i-1]+rh.hash[1][i-1])%RH_mod[1],
							 (rh.hash[2][N]*rh.pw[2][i-1]+rh.hash[2][i-1])%RH_mod[2]);
		ans += M[z];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 51432
/*

Author: @karngyan
Team: BlundersPride

*/

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
//MIT OCW DP PROBLEM
const ll N = 3010;
ll a[N];
ll dp[N][N];

ll go(ll i , ll j)
{
	if(i == j)
		return a[i];

	ll &ans = dp[i][j];
	if(ans != -1)
		return ans;

	ans = max( a[i] - go(i+1 , j) , a[j] - go(i, j-1));
	return ans;
}

signed main()
{

	fast;
	memset( dp , -1 , sizeof dp );
////////////////////////////////////////////////////////////////////////////////////////////
		
	ll n;
	cin >> n;
	ll tot = 0;
	rep(i,0,n)
		cin >> a[i];

	cout<<go(0 , n-1)<<endl;


	
	return 0;
}


Measured memory_bytes: 71168
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)


vvint vv;
int h,w;

int func(int x){
	vvint dp;
	initvv(dp,h+1,h+1,INF);
	vvint sum;
	initvv(sum,h+1,h+1,0);
	rep(i,h){
		rep(j,h){
			int a = h-1-i;
			int b = h-1-j;
			if(i&&j){
				sum[a][b]=sum[a+1][b+1]+(vv[h-1-a][x]==vv[h-1-b][x+1]);
			}
			else if(i==0){
				sum[a][b]=(vv[0][x]==vv[h-1-b][x+1]);
			}
			else{
				sum[a][b]=(vv[h-1-a][x]==vv[0][x+1]);
			}
		}
	}
	dp[0][0]=0;
	rep(i,h+1){
		rep(j,h+1){
			int t = 0;
			// rep(k,h){
			// 	if(i+k>=h||j+k>=h) break;
			// 	if(vv[k][x]==vv[j][x+1]) t++;
			// }
			t=sum[i][j];
			if(i+1<=h) mins(dp[i+1][j],dp[i][j]+t);
			if(j+1<=h) mins(dp[i][j+1],dp[i][j]+t);
		}
	}
	return dp[h][h];
}

void mainmain(){
	cin>>h>>w;
	initvv(vv,h,w);
	rep(i,h){
		string s;
		cin>>s;
		rep(j,s.size()){
			vv[i][j]=int(s[j]-'a');
		}
	}
	int ans = 0;
	rep(i,w-1){
		ans += func(i);
		// cout<<func(i)<<endl;
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1416
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int sheep, wolf;
    cin >> sheep >> wolf;
    if(wolf>=sheep){
        cout << "unsafe\n";
    }else{
        cout << "safe\n";
    }
    return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>

main(){
    int N;
    scanf("%d",&N);
    int l,r;
    int sum=0;

    int i;
    for(i=0;i<N;i++){
        scanf("%d %d",&l,&r);
        sum+=r-l+1;
    }
    printf("%d\n",sum);
    return 0;
}

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

int main()
{
    int iNumX = 0;
    int iNumY = 0;
    
    while (cin >> iNumX >> iNumY)
    {
        if ((0 == iNumX) && (0 == iNumY))
        {
            break;
        }
        
        if (iNumX > iNumY)
        {
            int iTmp = iNumX;
            iNumX = iNumY;
            iNumY = iTmp;
        }
        
        cout << iNumX << " " << iNumY << endl;
    }
    
    return 0;
}


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

int main()
{
  int M, D;
  cin >> M >> D;
  int d1, d10;
  int m, d;
  int i, k;
  
  int cnt = 0;
  
  for (i=1;i<=M;i++){
    for (k=22;k<=D;k++){
      d1 = k % 10;
      d10 = k / 10;
      if (d1>=2 && d10>=2){
        if (d1 * d10 == i){
          cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200020];
long long z;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		a[i] -= i;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		z += abs(a[i] - a[n / 2]);
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  while(true){
    int h,m,s;
    cin>>h>>m>>s;
    if(h==-1 && m==-1 && s==-1)break;
    int als = h*60*60+m*60+s;
    als = 2*60*60 - als;
    h = als/(60*60);
    m = als%(60*60)/60;
    s = als%(60);
    printf("%02d:%02d:%02d\n",h,m,s);
    als *= 3;
    h = als/(60*60);
    m = als%(60*60)/60;
    s = als%(60);
    printf("%02d:%02d:%02d\n",h,m,s);
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int main(){
	int n, count;
	while(cin >> n){
		count = 0;
		for(int i=0;i<10;++i){
			for(int j=0;j<10;++j){
				for(int k=0;k<10;++k){
					for(int l=0;l<10;++l){
						if(i+j+k+l == n) count++;
					}
				}
			}
		}
	cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
c=[0]*(n+1)
for i in range(0,m):
  a,b = map(int, input().split())
  c[a]=c[a]+1
  c[b]=c[b]+1
for i in range(1,n+1):
  print(c[i])


Measured memory_bytes: 2940
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

typedef pair<int,int> P;

const int INF=INT_MAX/3;
//const int V_MAX=10000,E_MAX=10000;
//int V,E;
const int N=10000;

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



int main(){
  int a,b;
  while(cin>>a>>b)
    cout<<gcd(a,b)<<endl;

  return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) {
    return a < b ? b = a, true : false;
}
template<typename T> bool chmax(T a, T &b) {
    return a > b ? b = a, true : false;
}

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*----------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    str s; ll w;
    std::cin >> s >> w;

    for (ll i = 0; i < s.length(); i += w)
        std::cout << s[i];
    std::cout << '\n';
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

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

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

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

  for (int i = 0; i < s.size(); i++){
    int b;
    b = ((int)s.at(i) - 65 + n) % 26 + 65;
    cout << (char)(b);
  }


  return 0;
}

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

int pow(int A, int P){
	int a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	int adash = a * a;
	if(p % 2) return pow(adash, p / 2) * a;
	else return pow(adash, p / 2);
}

int main(){
	int N;
	cin >> N;
	int count = 1000000;
	for(int i=0;i<=N;i++){
		int count1 = 0;
		int t = i;
		while(t>0){
			count1 += t % 6;
			t /= 6;
		}
		t = N - i;
		while(t>0){
			count1 += t % 9;
			t /= 9;
		}
		count = min(count, count1);
	}
	cout << count << endl;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  ll x[1010], y[1010];
  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int parity = abs(x[0]+y[0])%2;
  rep(i, n) {
    if (parity != abs(x[i]+y[i])%2) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<ll> arms;
  rep(i, 32) arms.push_back(1LL << 31-i);
  if (parity == 0) {
    arms.push_back(1);
  }

  cout << arms.size() << endl;
  for (auto i : arms) cout << i << " ";
  cout << endl;

  rep(i, n) {
    ll nx = 0, ny = 0;
    for(auto arm : arms) {
      if (abs(x[i]-nx) > abs(y[i]-ny)) {
        if (x[i]-nx > 0) {
          nx += arm;
          cout << 'R';
        } else {
          nx -= arm;
          cout << 'L';
        }
      } else {
        if (y[i]-ny > 0) {
          ny += arm;
          cout << 'U';
        } else {
          ny -= arm;
          cout << 'D';
        }
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (300 + 2)

ld dp[MAX_N][MAX_N][MAX_N];

ld rec(int n, int x, int y, int z){
  if (x < 0 || y < 0 || z < 0){
    return 0;
  }

  if (dp[x][y][z]){
    return dp[x][y][z];
  }

  if (x + y + z == 0){
    dp[x][y][z] = 0;
    return dp[x][y][z];
  }

  dp[x][y][z] = x * rec(n, x-1, y, z) + y * rec(n, x+1, y-1, z) + z * rec(n, x, y+1, z-1) + n;
  dp[x][y][z] /= x + y + z;

  // printf("dp[%d][%d][%d] = %Lf\n", x, y, z, dp[x][y][z]);

  return dp[x][y][z];
}

void exec(){
  int n, tmp;
  int count[4];
  count[1] = count[2] = count[3] = 0;

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

  printf("%.10Lf\n", rec(n, count[1], count[2], count[3]));

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 428288
from collections import deque

d = deque()
q = int(input())

for _ in range(q):
    x = list(map(int, input().split()))
    if x[0]==0:
        dr = x[1]
        val = x[2]
        if dr==1:
            d.append(val)
        else:
            d.appendleft(val)
    elif x[0]==1:
        print(d[x[1]])
    elif x[0]==2:
        dr = x[1]
        if dr==0:
            d.popleft()
        else:
            d.pop()


Measured memory_bytes: 21976
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

class Point {
public:
    int x, y;
    Point(int a = 0, int b = 0)
    {
        int x = a;
        int y = b;
    };
    bool operator <(const Point& p) const {
        return y < p.y || (y == p.y && x < p.x);
    }
};

inline bool direct(Point& base, Point& a, Point& b) {
    return (a.x - base.x)*(b.y - base.y) - (a.y - base.y)*(b.x - base.x) < 0;
}


int main() {
    int n, i;
    int k = 2;
    scanf("%d", &n);
    vector <Point> P(n), H(2 * n);
    for (i = 0; i < n; ++i) {
        scanf("%d%d",&P[i].x, &P[i].y);
    }
    sort(P.begin(), P.end());
    H[0] = P[0];
    H[1] = P[1];
    for (i = 0; i < n - 2; ++i) {
        while (k >= 2 && direct(H[k - 2],H[k - 1],P[i + 2])) k--;
        H[k++] = P[i + 2];
    }
    H[k++] = P[n - 2];
    for (i = n; i > 2; i--) {
        while (k >= 2 && direct(H[k - 2],H[k - 1],P[i - 3])) k--;
        H[k++] = P[i - 3];
    }
    printf("%d\n", k - 1);
    for (i = 0; i < k - 1; ++i) {
        printf("%d %d\n", H[i].x, H[i].y);
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	string s; cin >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
#define LL long long
#define INF 0x3f3f3f3f

const int MAXN = 1e5 + 5;
const LL MOD = 1e9+7;

int vis[MAXN];

int main() 
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
#endif

    int n, a;
    cin >> n >> a;
    for(int i = 0; i <= a; i++)
    {
        for(int j = 0; ; j++)
        {
            if(i+j*500>MAXN)
                break;
            vis[i+j*500] = 1;
        }
    }
    if(vis[n])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n;
    cin >> n;
    vector<int > a(n-1);
    REP(i,n-1) cin >> a[i];
    vector<int > ans(n);
    REP(i,n) ans[i] = 0;

    REP(i,n-1){
        ans[a[i]-1]++;
    }

    REP(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}


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

string ss = "abcdefghijklmnopqrstuvwxyz";

int main() {
  ll N;
  cin >> N;
  N--;
  // for (int n = 676; n <= 680; n++) {
  // N = n;
  int size = 1;
  while (pow(26, size) - 1 < N) {
    size += 1;
    N -= pow(26, size - 1);
  }

  string ans = "";
  for (int i = 0; i < size; i++) {
    ans = ss[N % 26] + ans;
    N /= 26;
  }
  //  cout << n << " " << ans << endl;
  //}
  cout << ans << endl;
}

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

int main()
{
    ll h;
    cin >> h;

    ll l = 1; ll r = 2;
    while (!(l <= h && h < r)) {
        l *= 2;
        r *= 2;
    }
    cout << r -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[10000005];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i) cnt[j]++;
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans += i*1ll*cnt[i];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 42876