akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

template<typename T,bool directed>
struct FordFulkerson{
    struct edge{
        int to,rev; T cap;
        edge(int to,T cap,int rev):to(to),cap(cap),rev(rev){}
    };
    vector<vector<edge>> G;
    vector<bool> used;
    FordFulkerson(int n):G(n),used(n){}
    int add_edge(int from,int to,T cap){
        G[from].emplace_back(to,cap,G[to].size());
        G[to].emplace_back(from,directed?0:cap,G[from].size()-1);
        return G[to].back().rev;
    }
    T dfs(int v,int t,T f){
        if (v==t) return f;
        used[v]=true;
        for (auto &e:G[v]){
            if (!used[e.to]&&e.cap>0){
                T d=dfs(e.to,t,min(f,e.cap));
                if (d==0) continue;
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
    T max_flow(int s,int t,T lim){
        T flow=0;
        while(true){
            fill(all(used),false);
            T f=dfs(s,t,lim);
            if (f==0) break;
            flow+=f;
            lim-=f;
        }
        return flow;
    }
    T max_flow(int s,int t){
        return max_flow(s,t,numeric_limits<T>::max()/2);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    vector<string> field(H);
    rep(i,H) cin >> field[i];
    FordFulkerson<int,false> ff(H+W+2);
    int sh,sw,th,tw;
    rep(i,H) rep(j,W){
        if (field[i][j]!='.'){
            ff.add_edge(i,H+j,1);
        }
        if (field[i][j]=='S') sh=i,sw=j;
        if (field[i][j]=='T') th=i,tw=j;
    }
    if (sh==th||sw==tw){
        cout << -1 << endl;
        return 0;
    }
    ff.add_edge(H+W,sh,INF);
    ff.add_edge(H+W,H+sw,INF);
    ff.add_edge(H+W+1,th,INF);
    ff.add_edge(H+W+1,H+tw,INF);
    cout << ff.max_flow(H+W,H+W+1) << endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

c1 = 0
c2 = 0
c4 = 0
for ai in a:
    if ai % 4 == 0:
        c4 += 1
    elif ai % 2 == 0:
        c2 += 1
    else:
        c1 += 1

if c4 == 0:
    if 0 < c1 + c2 % 2:
        print("No")
    else:
        print("Yes")
else:
    if c1 + c2 % 2 <= c4 + 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 64180
text = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51"

tx = text.split(",")


index = int(input())

print(tx[index-1])

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

int main(){
    int H, W;
    cin>>H>>W;
    vector<string>A;
    string tmp1;
    for(int i=0;i<H;++i){
        cin>>tmp1;
        A.push_back(tmp1);
    }
    queue<vector<int> >stateque;
    queue<int>numque;
    vector<int> tmp;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(A[i][j] == '#'){
                tmp.clear();
                tmp.push_back(i);
                tmp.push_back(j);
                stateque.push(tmp);
                numque.push(0);
            }
        }
    }

    tmp.clear();
    int ans = 0;
    vector<int>state;
    int num;
    int i, j;
    while(!stateque.empty()){
        state = stateque.front();
        num = numque.front();
        if(ans<num)ans=num;
        stateque.pop();
        numque.pop();
        i = state[0];
        j = state[1];
        if(i-1>=0){
            if(A[i-1][j] == '.'){
                A[i-1][j] = '#';
                tmp.push_back(i-1);
                tmp.push_back(j);
                stateque.push(tmp);
                numque.push(num+1);
                tmp.clear();
            }
        }
        if(i+1<H){
            if(A[i+1][j] == '.'){
                A[i+1][j] = '#';
                tmp.push_back(i+1);
                tmp.push_back(j);
                stateque.push(tmp);
                numque.push(num+1);
                tmp.clear();
            }
        }
        if(j-1>=0){
            if(A[i][j-1] == '.'){
                A[i][j-1] = '#';
                tmp.push_back(i);
                tmp.push_back(j-1);
                stateque.push(tmp);
                numque.push(num+1);
                tmp.clear();
            }
        }
        if(j+1<W){
            if(A[i][j+1] == '.'){
                A[i][j+1] = '#';
                tmp.push_back(i);
                tmp.push_back(j+1);
                stateque.push(tmp);
                numque.push(num+1);
                tmp.clear();
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 60852
#include<bits/stdc++.h>
using namespace std;
int main(){
  long x,y,z,K;cin>>x>>y>>z>>K;
  vector<long>X(x);for(int i=0;i<x;i++)cin>>X[i];
  vector<long>Y(y);for(int i=0;i<y;i++)cin>>Y[i];
  vector<long>Z(z);for(int i=0;i<z;i++)cin>>Z[i];
  sort(X.begin(),X.end(),greater<long>());
  sort(Y.begin(),Y.end(),greater<long>());
  sort(Z.begin(),Z.end(),greater<long>());
  
  vector<long>XY(x*y);
  for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
      XY[i*y+j]=X[i]+Y[j];
    }
  }
  sort(XY.begin(),XY.end(),greater<long>());
  
  
  
  vector<long>XYZ;
  for(int i=0;i<z;i++){
    for(int j=0;j<(K<XY.size()?K:XY.size());j++){
      XYZ.push_back(Z[i]+XY[j]);
    }
  }
  sort(XYZ.begin(),XYZ.end(),greater<long>());
  for(int i=0;i<K;i++)cout<<XYZ[i]<<endl;
}



Measured memory_bytes: 42984
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] b = new int[n-1];
    int result = 0;

    for(int i=0; i<n-1; i++){
      b[i] = sc.nextInt();
    }
    for(int i=0; i<n; i++){
      if(i==0){
        result += b[0];
      }else if(i>0 && i<n-1){
        result += (b[i]<b[i-1])?b[i]:b[i-1];
      }else{
        result += b[n-2];
      }
    }
    System.out.println(result);

  }
}

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

 using namespace std;

 int main() {
   int N;
   cin >> N;
   vector<int> L(2 * N);

   for (int i = 0; i < 2 * N; i++) cin >> L.at(i);

   sort(L.begin(), L.end());

   int ans = 0;

   for (int i = 0; i < 2 * N; i += 2) {
     ans += L.at(i);
   }

   cout << ans << endl;
}


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

int main() {
  long long N;
  cin >> N;

  int X = sqrt(N);
  long long W = 0; 
  long long H = 0;
  for (int i = X; i >= 1; i--) {
    if (N % i == 0) {
      W = i;
      break;
    }
  }

  H = N / W;
  cout << H + W - 2 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (h, w) = readIntegerList()
    val (ch, cw) = readIntegerList().map { it - 1}
    val (dh, dw) = readIntegerList().map { it - 1 }
    val grid = Array(h) { br.readLine()!! }

    /** point of coordinate */
    data class Point(val x: Int, val y: Int, val cost: Long)

    val LINFMULT = 1L shl 31 // 2_147_483_648
    val countGrid = Array(h) { LongArray(w) { LINFMULT } }
    val checkedGrid = Array(h) { BooleanArray(w) }
    val junped = Array(h) { BooleanArray(w) }
    val queue = PriorityQueue<Point> { a, b -> a.cost.compareTo(b.cost) }
    queue.add(Point(cw, ch, 0))
    checkedGrid[ch][cw] = true
    junped[ch][cw] = true
    countGrid[ch][cw] = 0
    while (queue.isNotEmpty()) {
        val node = queue.remove()
        for (d in GridDirection.values()) {
            val x = node.x + d.dx
            val y= node.y + d.dy
            if (!(y in 0 until h && x in 0 until w)) continue
            if (checkedGrid[y][x]) continue

            if (grid[y][x] == '#') continue

            countGrid[y][x] = min(countGrid[node.y][node.x], countGrid[y][x])
            checkedGrid[y][x] = true
            queue.add(Point(x, y, countGrid[node.y][node.x]))
        }

        for (hh in -2..2) {
            for (ww in -2..2) {
                if (ww == 0 && hh == 0) continue
                val x = node.x + ww
                val y= node.y + hh

                if (!(y in 0 until h && x in 0 until w)) continue
                if (checkedGrid[y][x]) continue
                if (junped[y][x]) continue

                if (grid[y][x] == '#') continue

                countGrid[y][x] = min(countGrid[node.y][node.x] + 1, countGrid[y][x])
                junped[y][x] = true
                queue.add(Point(x, y, countGrid[node.y][node.x] + 1))
            }
        }
    }

//    for (e in countGrid) {
//        out.println(e.joinToString(" "))
//    }
    val ans = if (countGrid[dh][dw] == LINFMULT) -1 else countGrid[dh][dw]
    out.println(ans)
}

/** direction */
enum class GridDirection(val dx: Int, val dy: Int) {
    UP(0, -1),
    DOWN(0, 1),
    LEFT(-1, 0),
    RIGHT(1, 0),
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int n, want;

int main() {
  cin >> n;
  vector<int> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  want = 1;
  rep (i, n) {
    if (a[i] == want) want++;
  }
  if (want == 1) cout << -1 << endl;
  else cout << n - want + 1 << endl;
  return 0;
}


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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


int main(){
     vector<vector<int>> a(3,vector<int>(3));

     for(int i=0;i<3;i++){
         for(int j=0;j<3;j++){
             cin>>a.at(i).at(j);
         }
     }

     int n;
     cin>>n;
     int v;
     for(int i=0;i<n;i++){
         cin>>v;
         for(int j=0;j<3;j++){
             for(int k=0;k<3;k++){
                 if(v==a.at(j).at(k))a.at(j).at(k)=0;
             }
         }
     }

     int j=0;
     for(int i=0;i<3;i++){
        if(a.at(i).at(0)==a.at(i).at(1)&&a.at(i).at(1)==a.at(i).at(2))j=1;
    }
    for(int i=0;i<3;i++){
        if(a.at(0).at(i)==a.at(1).at(i)&&a.at(1).at(i)==a.at(2).at(i))j=1;
    }
    if(a.at(0).at(0)==a.at(1).at(1)&&a.at(1).at(1)==a.at(2).at(2))j=1;
    if(a.at(0).at(2)==a.at(1).at(1)&&a.at(1).at(1)==a.at(2).at(0))j=1;

    if(j==0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

// const string alphabet = "abcdefghijklmnopqrstuvwxyz";

// int count(string x) {
//     set<char> list;
//     for (auto a : x) {
//         list.insert(a);
//     }
//     return list.size();
// }

// vs standard(int n) {
//     if (n == 1) {
//         return {"a"};
//     }
//     vs res;
//     vs pre = standard(n-1);
//     for (auto s : pre) {
//         rep(i, count(s)+1) {
//             res.push_back(s+alphabet[i]);
//         }
//     }
//     return res;
// }

// void solve(long long N){
//     vs ans = standard(N);
//     for (auto x : ans) {
//         cout << x << endl;
//     }
// }

ll N;

void dfs(string s, char max){
    if (s.size() == N) {
        cout << s << endl;
        return;
    }
    for(char c='a'; c<=max; c++){
        dfs(s+c, (max==c) ? max+1 : max);
    }
}

void solve(){
    dfs("", 'a');
}

int main(){
    scanf("%lld",&N);
    solve();
    return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>
#include <atcoder/mincostflow>

using namespace std;
using namespace atcoder;
typedef long long ll;

int main()
{
   int N, K;
   cin >> N >> K;
   mcf_graph<ll, ll> graph(2 * N + 2); // start 2N, end 2N+1
   ll m = 1000000009;
   for (int i = 0; i < N; i++)
   {
      graph.add_edge(2 * N, i, K, 0);
      graph.add_edge(N + i, 2 * N + 1, K, 0);
   }
   for (int i = 0; i < N; i++)
   {
      for (int j = 0; j < N; j++)
      {
         ll a;
         cin >> a;
         graph.add_edge(i, N + j, 1, m - a);
      }
   }
   mcf_graph<ll, ll> graph2 = graph;
   auto slope = graph2.slope(2 * N, 2 * N + 1, N * K);
   ll f = -1;
   ll score = -1;
   for (auto point : slope)
   {
      ll curScore = point.first * m - point.second;
      //cout << point.first << " " << point.second << " " << curScore << endl;
      if (score < curScore)
      {
         f = point.first;
         score = curScore;
      }
   }
   auto result = graph.flow(2 * N, 2 * N + 1, f);
   cout << score << endl;
   vector<string> ans(N, string(N, '.'));
   auto edges = graph.edges();
   for (auto edge : edges)
   {
      if (edge.from < N && edge.cap == edge.flow)
      {
         ans[edge.from][edge.to - N] = 'X';
      }
   }
   for (int i = 0; i < N; i++)
   {
      cout << ans[i] << endl;
   }
   return 0;
}


Measured memory_bytes: 4092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int N,D;

int main(int argc, char *argv[]) {
	int sr;
	int i;
	int ret;

	sr=scanf("%d %d", &N, &D);

	printf("%d\n", (int)ceil((double)N/(D*2+1)));

}


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

ll solve(ll i,vector<int> graph[],ll dp[],bool visit[])
{
    visit[i]=true;
   // cout<<" "<<i<<" "<<endl;
   if(dp[i]!=0)
   {
       return dp[i];
   }
   
   else
   {
       for(int j=0;j<graph[i].size();j++)
       {
         //  cout<<i<<" "<<graph[i].size()<<endl;;
          // cout<<j;
           dp[i]=max(dp[i],1+solve(graph[i][j],graph,dp,visit));
       }
   }
   return dp[i];
   
    
}
int main()
{
    ll n,m;
    cin >>n>>m;
    vector<int> graph[n+1];
    ll from,to,ans;
    bool visit[n+1];
    ans=0;
    
    memset(visit,false,n+1);
    for(int i=0;i<m;i++)
    {
        cin >>from >>to;
        graph[from].push_back(to);
    }
    // for(int i=0;i<=n;i++)
    // {
    //     cout<<i<<" ";
    //     for(int j=0;j<graph[i].size();j++)
    //     cout<<graph[i][j]<<" ";
    //     cout<<endl;
    // }
    for(int i=1;i<=n;i++)
        sort(graph[i].begin(),graph[i].end());
    
        ll dp[n+1];
    memset(dp, 0, sizeof dp); 
        
        for(int i=1;i<=n;i++)
        {
            //cout<<i<<" "<<visit[i];
            if(!visit[i])
            {
              //  cout<<"i is"<<" "<<i<<endl;
                visit[i]=true;
                solve(i,graph,dp,visit);
            }
            
        }
        for(int i=1;i<=n;i++)
        ans=max(ans,dp[i]);
        cout<<ans;
}

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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int a=in(),b=in();
    if (a<b*2) cout << 0 << endl;
    else cout << a-b*2 << endl;
}

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

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

    int N;
    cin >> N;
    int cntEven = 0;
    int cntOdd = 0;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        if (A % 2 == 0) {
            cntEven++;
        } else {
            cntOdd++;
        }
    }

    if (cntOdd % 2 == 1) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import math

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, A, B, K = in_intlist()
NUM = 998244353

# 逆元
Inv = [0 for _ in range(N)]
for i in range(N):
    Inv[i] = pow(i+1, NUM-2, NUM)

# Combination
Comb = [0 for _ in range(N+1)]
Comb[0] = 1
for i in range(1, N+1):
    Comb[i] = (Comb[i-1] * (N-i+1) * Inv[i-1]) % NUM


ans = 0
for i in range(N+1):
    if ((K - i*A) % B == 0) and (0 <= (K - i*A) // B <= N):
        ans = (ans + Comb[i]*Comb[(K - i*A) // B]) % NUM 

print(ans)


Measured memory_bytes: 26868
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int H1=s.nextInt();
    int M1=s.nextInt();
    int H2=s.nextInt();
    int M2=s.nextInt();
    int K=s.nextInt();
    
    System.out.println(H2*60+M2-H1*60-M1-K);
  }  
}

Measured memory_bytes: 35792
# -*- coding: utf-8 -*-
import numpy
n = int(input())
a = [int(i) for i in input().split()]
dp = 1
for i in range(0, len(a)):
	dp = (dp | (dp << a[i]))
 
asum = 0
for i in range(0, len(a)):
	asum += a[i]
 
for i in range(int((asum + 1) / 2), asum + 1):
	if (dp >> i) & 1:
		print(i)
		break

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

using namespace std;
mt19937_64 rng(58);

/* O(sqrt(n))
   n =     100,000   cost ~  0.0sec, max prime =   1,299,709
   n =   1,000,000   cost ~  1.7sec, max prime =  15,485,867
   n =  10,000,000   cost ~ 46.1sec, max prime = 179,424,673, ram ~ 40MB
*/
void generate_primes(int n, vector<int> &primes) {
  primes = { 2, 3, 5 };
  n -= 3;
  auto is_prime = [](int t, vector<int> &primes) -> bool {
    for (auto p : primes) {
      if (p * p > t) break;
      if (t % p == 0) return false;
    }
    return true;
  };
  for (int six = 6; n > 0; six += 6) {
    if (is_prime(six + 1, primes)) primes.push_back(six + 1), n--;
    if (is_prime(six + 5, primes)) primes.push_back(six + 5), n--;
  }
}

/* return 2, 2, 2, 5, 7 for 2^3 * 5 * 7 */
vector<int> factorize(int x, vector<int> &primes) {
  vector<int> factors;
  int bound = x;
  for (auto p : primes) {
    if (x == 1 || p * p > bound) break;
    for (; x % p == 0; x /= p) factors.push_back(p);
  }
  if (x != 1) factors.push_back(x);
  return factors;
}

int sieve[1000000 + 1];

int main()
{
    vector<int> primes;
    generate_primes(1000, primes);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        sieve[a]++;
    }

    int ans = 0;
    for (int i=1; i<=1000000; i++) {
        if (sieve[i]) {
            ans += (sieve[i] == 1);
            for (int j=2; j*i <= 1000000; j++) sieve[j*i] = 0;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n; cin >> n;
  map<string,int> m;
  int max_cnt = 0;
  rep(i,n) {
    string s; cin >> s;
    m[s]++;
    max_cnt = max(m[s], max_cnt);
  }
  for (auto mi : m) {
    string k = mi.first;
    int v = mi.second;
    if (v == max_cnt) cout << k << endl;
  }
  return 0;
}


Measured memory_bytes: 19188
def ACGT(s):
    A = s.count('A')
    C = s.count('C')
    G = s.count('G')
    T = s.count('T')
    return len(s) == A+C+G+T

S = input()

ans = 0
for i in range(len(S)+1):
    for k in range(i+1, len(S)+1):
        sub = S[i:k]
        if ACGT(sub):
            if ans < len(sub):
                ans = len(sub)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

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

double hoge[] = {35.5,37.5,40,43,50,55,70};
double hage[] = {71,77,83,89,105,116,148};
string s[] = {"AAA","AA","A","B","C","D","E","NA"};

int main() {
  double a,b;
  while(cin>>a>>b) {
    REP(i,8) {
      if (i==7 || a<hoge[i]&&b<hage[i]) {
        cout << s[i] << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

const int MAX_N=1e2+5;
const int MAX_W=1e5+5;

long long dp[MAX_N][MAX_W];

long long w[MAX_N],v[MAX_N];

int main(){
  int N,W;
  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=1;j<=W;j++){
      if(w[i]<=j)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
      else dp[i][j]=dp[i-1][j];
    }
  }
  cout<<dp[N][W]<<endl;

}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

const int N = 3e2+1;

ll d[N][N], h[N];
int n, k;

inline ll get(int i, int j)
{
  return max(0ll, h[j]-h[i]);
}
inline void Min(ll &x, ll y)
{
  if (x > y) x = y;
}
ll dp(int sz, int end_at)
{
  ll &ret = d[sz][end_at];
  if (ret == -1)
    {
      if (sz == 0) return ret = 0;
      else if (end_at == 0) return ret = LLONG_MAX>>1;
      else if (sz == 1) return ret = get(0, end_at);
      ret = LLONG_MAX;
      for (int j = 0; j < end_at; ++j)
	Min(ret, dp(sz-1, j) + get(j, end_at));
      //      printf("dp[%d][%d] = %lld\n", sz, end_at, ret);
    }
  return ret;
}
int main()
{
  while (~scanf("%d %d", &n, &k))
    {
      for (int i = 1; i <= n; ++i) scanf("%lld", h+i);
      memset(d, -1, sizeof(d));
      ll ret = LLONG_MAX;
      for (int i = n-k; i <= n; ++i) Min(ret, dp(n-k, i));
      printf("%lld\n", ret);
    }
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll n;
    cin >> n;
    vector<ll> p(n);
    for (ll i = 0; i < n; i++) {
        cin >> p[i];
    }

    ll ans = 0;
    for (ll i = 0; i < n - 2; i++) {
        if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]
            || p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int n, c[510], s[510], f[510];
	scanf("%d", &n);
	for(int *pc = c, *ps = s, *pf = f; pc < c + n - 1; ++pc, ++ps, ++pf) scanf("%d%d%d", pc, ps, pf);
	++(f[n - 1] = s[n - 1] = c[n - 1] = 0);
	for(int i = 0; i < n; i++) for(int ans = 0, j = i; j < n || !printf("%d\n", ans); j++) ans = c[j] + (ans < s[j] ? s[j] : (ans / f[j] + (ans % f[j] != 0)) * f[j]);
}

Measured memory_bytes: 128
// Create time: 2019-08-24  20:36:56
#include <bits/stdc++.h>
#define rint register int
#define N 400005
using namespace std;
const int Mod = 1e9 + 7;

int n, a[N], c[N], d[N], x[N], y[N], q, p;
char s[N];
int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    scanf("%s", s + 1);
    for (rint i = 1; i <= n * 2; ++i)
        a[i] = (s[i] == 'B');
    for (rint i = 1; i <= n * 2 + 1; ++i)
        d[i] = a[i] ^ a[i - 1];
    c[1] = 0;
    for (rint i = 2; i <= n * 2; ++i)
        c[i] = !d[i] ? (c[i - 1] ^ 1) : c[i - 1];
    for (rint i = 1; i <= n * 2; ++i)
        if (c[i]) y[++p] = i;
        else x[++q] = i;
    if (d[1] == 0 || p != q) { puts("0"); return 0;}
    reverse(x + 1, x + q + 1);
    long long ans = 1, fac = 1;
    for (rint i = 1; i <= n; ++i) {
        int pos = upper_bound(y + 1, y + n + 1, x[i]) - y;
        ans = 1ll * ans * (n - pos + 1 - (i - 1)) % Mod;
        fac = 1ll * fac * i % Mod;
    }
    cout << 1ll * fac * ans % Mod;
    return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	double ar[n+1];
	int i;
	for(i=1;i<=n;i++)
	{
		double x;
		cin>>x;
		ar[i]=(double)x;
	}
	double dp[n+1][n+1];
	dp[0][0]=(double)1;
	for(i=1;i<=n;i++)
		dp[0][i]=(double)(1-ar[i])*dp[0][i-1];
	for(i=1;i<=n;i++)
		dp[i][0]=0;
	int j;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			dp[i][j]=(double)dp[i-1][j-1]*ar[j]+dp[i][j-1]*(1-ar[j]);
	}
	double ans=0;
	for(i=n/2+1;i<=n;i++)
		ans+=(double)dp[i][n];
	printf("%0.9lf\n",ans);
}


Measured memory_bytes: 70528
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a;
	while (cin>>a,a)
	{
		int b[100];
		for (int c = 0; c < a; c++)scanf("%d", &b[c]);
		int d; cin >> d;
		int MIN = 0, MAX = a - 1;
		int i = 0;
		while(MIN-MAX!=1) {
			int k = floor(double(MIN + MAX) / (double)2);
			if (b[k] > d) { MAX = k - 1; i++; }
			else if (b[k] < d) { MIN = k + 1; i++; }
			else { i++; break; }
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 3132
import heapq

n,m = map(int,input().split())
As = [-i for i in list(map(int,input().split()))]
heapq.heapify(As)
for i in range(m):
  a = -heapq.heappop(As)
  heapq.heappush(As,-int(a/2))
print(-sum(As))
  
  





Measured memory_bytes: 73196
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  ll p[n];
  for(ll i=0;i<n;i++)cin >> p[i];
  sort(p,p+n);
  ll ans=0;
  for(ll i=0;i<n-1;i++)ans+=p[i];
  ans+=p[n-1]/2;

  cout << ans << endl;

}

Measured memory_bytes: 3640
import numpy as np
import collections
n=int(input())
a=np.array(list(map(int,input().split())))
q=int(input())
d=collections.Counter(a)
sum=a.sum()
for i in range(q):
  b,c=map(int,input().split())
  sum+=d[b]*(c-b)
  d[c]+=d[b]
  d[b]=0
  print(sum)

Measured memory_bytes: 39316
def solve(string):
    n, t, *ct = map(int, string.split())
    c = [_c for _c, _t in zip(ct[::2], ct[1::2]) if _t <= t]
    return str(min(c)) if len(c) else "TLE"


if __name__ == '__main__':
    n, t = map(int, input().split())
    print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in range(n)])))


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

    ll N;
    cin >> N;
    vector<ll> a(N);
    ll ans = 0;
    REP(i, N){
        cin >> a[i];
        ans += a[i];
    }

    cout << ans - N << endl;
    
  
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool check(long long n, long long k) {
  while (n % k == 0) {
    n /= k;
  }
  return n % k == 1;
}

int main() {
  long long n;
  scanf("%lld", &n);
  int ans = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i != 0) {
      continue;
    }
    if (i > 1) {
      if (check(n, i)) {
        ++ans;
      }
    }
    if (n / i != i) {
      if (check(n, n / i)) {
        ++ans;
      }
    }
  }
  for (long long i = 1; i * i <= n - 1; ++i) {
    if ((n - 1) % i != 0) {
      continue;
    }
    if (i > 1) {
      ++ans;
    }
    if ((n - 1) / i != i) {
      ++ans;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007

ll dp[105][(int)1e5+5];
pair<ll,ll> arr[105];

ll func(ll idx, ll wt)
{
    if(wt==0 || idx==-1)
        return 0;
    if(wt<arr[idx].first)
        return func(idx-1,wt);
    if(dp[idx][wt]!=-1)
        return dp[idx][wt];
    return dp[idx][wt]=max(func(idx-1,wt),arr[idx].second+func(idx-1,wt-arr[idx].first));    
}

int main()
{
    fast;
    ll n,wt,x,y;
    cin>>n>>wt;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        arr[i]=pii(x,y);
    }
    memset(dp,-1,sizeof(dp));
    cout<<func(n-1,wt);
    return 0;
}

Measured memory_bytes: 82304
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int a = in.nextInt();
        int b = in.nextInt();
        out.println((3*a+b)/2);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21076
local mmi, mma = math.min, math.max
local n, k = io.read("*n", "*n", "*l")
local s = io.read()
local list0, list1 = {}, {}
local spos = 1
local iszero = true
table.insert(list1, 0)
for i = 1, n do
  local b = s:byte(i) - 48
  if b == 0 then
    if not iszero then
      table.insert(list1, i - spos)
      iszero = true
      spos = i
    end
  else
    if iszero then
      table.insert(list0, i - spos)
      iszero = false
      spos = i
    end
  end
end
if iszero then
  table.insert(list0, n + 1 - spos)
  table.insert(list1, 0)
else
  table.insert(list1, n + 1 - spos)
end

if #list0 <= k then
  print(n)
else
  local len = 0
  for i = 1, k do
    len = len + list0[i] + list1[i]
  end
  len = len + list1[k + 1]
  local ret = len
  for i = k + 1, #list0 do
    len = len + list0[i] - list0[i - k] + list1[i + 1] - list1[i - k]
    ret = mma(ret, len)
  end
  print(ret)
end


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

 
signed main(void){
    int N;
    int x[10],y[10];
    cin >> N;
    REP(i,N){
        cin >> x[i] >> y[i];
    }
    double Ans=0;
    int d[10]={0,1,2,3,4,5,6,7};
    do{
        REP(i,N-1){
            Ans+=hypot(x[d[i]]-x[d[i+1]],y[d[i]]-y[d[i+1]]);
        }
    }while(next_permutation(d,d+N));
    
    REP(i,N){
        Ans/=(i+1);
    }
    
    printf("%.10f\n",Ans);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=10009,mod=1e9+7;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	inline int qpow(int x,int y){
		int ret=1;
		while(y){
			if(y&1) ret=1LL*x*ret%mod;
			x=1LL*x*x%mod,y>>=1;
		}
		return ret;
	}
	int g[2][N],f[N],h[N],n,a,b;
	int main(){
		n=read<int>(),a=read<int>(),b=read<int>();
		if(a<b) swap(a,b);

		g[1][0]=1;
		for(int i=1;i<a;i++){
			for(int j=b;j<i;j++) g[1][i]=add(g[1][i],g[0][i-j]);
			for(int j=1;j<=i;j++) g[0][i]=add(g[0][i],g[1][i-j]);
		//	cout<<i<<" "<<g[0][i]<<" "<<g[1][i]<<endl;
			for(int j=1;j<b;j++) h[i+j]=add(h[i+j],g[0][i]);
		}
	//	for(int i=1;i<=n;i++) cout<<h[i]<<" ";cout<<endl;
		for(int i=0;i<b;i++) f[i]=1;
		for(int i=1;i<a;i++)
			for(int j=1;j<b;j++) f[i+j]=add(f[i+j],g[1][i]);
		for(int i=1;i<=n;i++)
			for(int j=1;j<min(i+1,a+b-1);j++) f[i]=add(f[i],1LL*f[i-j]*h[j]%mod);
	//	for(int i=1;i<=n;i++) cout<<f[i]<<" ";
	//	cout<<endl;
		
		int ans=0;
		for(int i=n-a+1;i<=n;i++) ans=add(ans,1LL*f[i]*add(g[0][n-i],g[1][n-i])%mod);
		printf("%d\n",sub(qpow(2,n),ans));
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 3852
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> S(N);
    rep(i, 0, N) cin >> S[i];
    ll ans = 0;
    rep(C, 1, N) {
        ll now_ans = 0;
        if ((N - 1) % C) {
            for (int x = 0; N - 1 - C * x >= C; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
        else {
            for (int x = 0; N - 1 - C * x > C * x; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int N;
vector<vi> ch;
vi a(N);
bool ans = true;

pii dfs( int from ){

    vii b;

    int sum = 0;

    for( int to : ch[from] ){
        b.push_back(dfs(to));
    }

    vector<bool> dp(a[from]+1,false);
    vector<bool> dpv(a[from]+1,false);
    dp[0] = true;
    bool tmp = false;
    for( pii t : b ){
        sum += t.first+t.second;
        Rep(di,a[from]+1){
            if( !dp[di] ) continue;
            int ai,bi;
            ai = di+t.first;
            bi = di+t.second;
            if( ai <= a[from] ) dpv[ai] = true;
            if( bi <= a[from] ) dpv[bi] = true;
            dp[di] = false;
        }
        tmp = false;
        Rep(di,a[from]+1){
            tmp = tmp || dpv[di];
            dp[di] = dpv[di];
            dpv[di] = false;
        }
        if( !tmp ) ans = false;
    }

    if( !ans ) return {INF,INF};

    int r = 0;

    Rep(i,a[from]+1){
        if( dp[i] ) r = i;
    }

    // printf ("%d-{%d,%d}(%d)\n", from, a[from], sum-r, r );

    return {a[from],sum-r};

}

int main() {

    Scd(N);
    ch.resize(N);
    a.resize(N);
    int x;
    Rep(i,N-1){
        Scd(x);
        ch[--x].push_back(i+1);
    }
    Rep(i,N){
        Scd(a[i]);
    }

    dfs(0);

    printf ("%sPOSSIBLE\n", ans?"":"IM" );

    return 0;
}



Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

class Pg
{
    static void Main()
    {
        const int ALPHABETS = 26;
        var stats = new char[ALPHABETS*2];
        for (char i = 'a'; i <= 'z'; i++)
            stats[i - 'a'] = i;
        for (char i = 'A'; i <= 'Z'; i++)
            stats[ALPHABETS + i - 'A'] = i;
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            var anslst = new List<char>();
            var m = Console.ReadLine().Split().Select(int.Parse).ToList();
            var p = Console.ReadLine().ToCharArray().ToList();
            for (var i = 0; i < p.Count(); i++)
            {
                var a = stats.ToList().IndexOf(p[i]);
                a += ALPHABETS*2 - m[i % n];
                a %= ALPHABETS*2;
                anslst.Add(stats[a]);
            }
            Console.WriteLine(string.Join("",anslst));
        }
    }
}


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

#define endl "\n"

long long int n, m, k;
long long int dp[105][1<<13];
long long int INF = 1e14;
long long int cost[15][15];

long long int kil(int idx, int mask)
{
    if(idx == n)
    {
        int arr[14] = {0};
        for(int j=0;j<n;j++)
            if(mask & 1<<j)
            {
                for(int i=1;i<=m;i++)
                    arr[i] += cost[j][i];
            }
        bool pos = true;
        for(int i=1;i<=m;i++)
            if(arr[i] < k)
            {
                pos = false;
                break;
            }
        return pos ? 0 : INF;
    }

    if(dp[idx][mask] != -1)
        return dp[idx][mask];

    dp[idx][mask] = INF;

    dp[idx][mask] = min(dp[idx][mask], kil(idx+1, mask | (1<<idx)) + cost[idx][0]);
    dp[idx][mask] = min(dp[idx][mask], kil(idx+1, mask));
    return dp[idx][mask];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long int x=0, y=0, ans=0;
    cin>>n>>m>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<=m;j++)
            cin>>cost[i][j];

    memset(dp, -1, sizeof dp);

    ans = kil(0, 0);
    cout<<(ans >= INF ? -1 : ans)<<endl;

 	return 0;
}


Measured memory_bytes: 10388
#include<bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

map<ll, ll> mp;

int main() {
    cin >> n;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
        if(v[i]>100005){
            cnt++;
        }else{
            mp[v[i]]++;
            k = max(k, v[i]);
        }
    }
    FOR(i,1,k+1) {
        if(mp[i]!=0){
            if(mp[i]<i){
                cnt += mp[i];
            }else{
                cnt += abs(mp[i] - i);
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

int main() {
	int n, data[6];
	int max_mini = 0;
	
	while (cin >> n) {
		if (n == 0)break;
		int x[86401] = { 0 };
		for (int i = 0; i < n; i++) {
			scanf("%d:%d:%d %d:%d:%d",&data[0],&data[1],&data[2],&data[3],&data[4],&data[5]);
			x[data[0] * 3600 + data[1] * 60 + data[2]]++;
			x[data[3] * 3600 + data[4] * 60 + data[5]]--;
			if (max_mini < data[3] * 3600 + data[4] * 60 + data[5])
				max_mini = data[3] * 3600 + data[4] * 60 + data[5];
		}
		int ans = 0, cnt = 0;
		for (int i = 0; i <= max_mini; i++) {
			cnt += x[i];
			ans = max(ans, cnt);
		}
		cout << ans << endl;
	}
	return 0;
	
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int cnt=0;
    rep(i,s.length()){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const double EPS = 1e-9;

void init() {
    
}

set<int> dp[55];
vector<int> freeday[35];
void solve(int n) {
    for (int i = 0; i < 35; i++) {
        freeday[i].clear();
    }
    for (int j = 0; j < 55; j++) {
        dp[j].clear();
    }
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        dp[i].insert(i);
        for (int j = 0; j < m; j++) {
            int b; cin >> b;
            freeday[b].emplace_back(i);
        }
    }
    for (int i = 0; i < 31; i++) {
        for (int j = 0; j < (int)freeday[i].size(); j++) {
            for (int k = 0; k < (int)freeday[i].size(); k++) {
                if (freeday[i][j] != freeday[i][k]) {
                    dp[freeday[i][j]].insert(begin(dp[freeday[i][k]]), end(dp[freeday[i][k]]));
                }
            }
        }
        for (int j = 0; j < (int)freeday[i].size(); j++) {
            for (int k = 0; k < (int)freeday[i].size(); k++) {
                if (freeday[i][j] != freeday[i][k]) {
                    dp[freeday[i][j]].insert(begin(dp[freeday[i][k]]), end(dp[freeday[i][k]]));
                }
            }
        }
        for (int j = 0; j < n; j++) {
            if (dp[j].size() == n) {
                cout << i << endl;
                return;
            }
        }
    }
    puts("-1");
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    init();
    while (cin >> n, n) {
        solve(n);
    }
}

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

namespace AtCoder {
    class _159c {
        static void Main() {
            string s = Console.ReadLine();
            int l = int.Parse(s);
            Console.WriteLine(Math.Pow(l / 3.0, 3));
        }
    }
}

Measured memory_bytes: 13140
# coding: utf-8

import statistics

n = int(input())
a = list(map(int, input().split()))

for i,num in enumerate(a):
    a[i] = a[i] - (i + 1)

b = statistics.median_low(a)

res = 0
for i in a:
    res += abs(i - b)

print(res)


Measured memory_bytes: 27244