akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    map<int,int> A,B;
    vector<int> v;
    rep(i,n){
        int a,b;
        cin >>a >>b;
        ++A[a];
        ++B[b];
        v.pb(a);
        v.pb(b);
    }

    sort(all(v));
    v.erase(unique(all(v)), v.end());

    int ans = 0;
    int now = 0;
    for(int i:v){
        now += A[i];
        ans = max(ans,now);
        now -= B[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 22324
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;



int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n + 2);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	cout << (n - 1 + k - 2) / (k - 1) << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

// ユークリッドの互除法
// 最大公約数を求めるアルゴリズム
Int Euclidean(Int a, Int b) {
    if (b == 0) {
        return a;
    } else {
        if (a < b) {
            std::swap(a, b);
        }
        return Euclidean(b, a % b);
    }
}

int main(void) {
    Int n;
    cin >> n;
    Int result = 1;
    Int input;
    for (Int i = 0; i < n; ++i) {
        cin >> input;
        Int gcd = Euclidean(result, input);
        result /= gcd;
        result *= input;
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 3632
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    k,t = LI()
    a = LI()
    q = []
    for i in a:
        heappush(q,-i)
    while len(q) > 1:
        x = heappop(q)
        y = heappop(q)
        x += 1
        y += 1
        if x:
            heappush(q,x)
        if y:
            heappush(q,y)
    if not q:
        print(0)
    else:
        print(-q[0]-1)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 46040
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) { LL ans = 1LL; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; }  return ans; }

int a[N];

void solve() {
    LL n, m;
    scanf("%lld %lld", &n, &m);

    LL tmp1 = 0LL, tmp2 = 0LL;
    if(n) tmp1 = n * (n - 1) / 2;
    if(m) tmp2 = m * (m - 1) / 2;
    printf("%lld\n", tmp1 + tmp2);
}


int main() {
//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  rep(i,h){
    cin>>s[i];
  }
  int ans=0;
  
  map<P,int> dist0;
  rep(i,h){
    rep(j,w){
      dist0[make_pair(i,j)]=-1;
    }
  }
  
  

  rep(i,h){
    rep(j,w){//出発マス..(i,j)
      map dist=dist0;

      if(s[i][j]=='#'){
        continue;
      }

      queue<P> q;
      q.push(make_pair(i,j));
      dist[make_pair(i,j)]=0;

      while(!q.empty()){
        auto p=q.front();
        q.pop();
        int i0=p.first;
        int j0=p.second;
        rep(k,4){
          int i1=i0+dx[k];
          int j1=j0+dy[k];
          P q0=make_pair(i0,j0);
          P q1=make_pair(i1,j1);
          if(i1<0 || j1<0 || i1>=h || j1>= w){
            continue;
          }
          if(s[i1][j1]=='#'){
            continue;
          }
          if(dist[q1]>=0){
            continue;
          }
          dist[q1]=dist[q0]+1;
          q.push(q1);
          ans=max(ans,dist[q1]);
        }
      }



    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code here!
    int n;
    
    cin >> n;
    
    vector<int> v(n);
    vector<int> c(n);
    
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    for (int i=0; i<n; i++) {
        cin >> c[i];
    }
    
    int ans = 0;
    for (int i=0; i<n; i++) {
        ans = ans+max(0,v[i]-c[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3580
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p=p[:x]
q=q[:y]

p.extend(q)#白なし
p.sort()
r=r[:x+y]# able add
lenR=len(r)

temp=p[:lenR]# 白なしの小さいものたち
temp.extend(r)#白と前の小さい者たちの合計
temp.sort(reverse=True)
temp=temp[:lenR]#白ありでのMAX

print(sum(p[lenR:])+sum(temp))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll x, p = 100, ans = 0;
    cin>>x;
    while(p < x){
        p += p/100;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>

using namespace std;
int main(){
  int n;
  cin>> n;
  string ans = "No";
  for(int i = 0;i < 100;i+=7){
    for(int j = 0;j <= 100;j+=4){
      if(n == i+j) ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long int coin,bigcoin,smallcoin;
    cin>>coin;
    bigcoin=(coin/500)*1000;
    //cout<<"BIG : "<<bigcoin<<endl;
    smallcoin = ((coin%500)/5)*5;
    //cout<<"SMALL : "<<smallcoin<<endl;
    cout<<bigcoin+smallcoin<<endl;

}

Measured memory_bytes: 256
import heapq
N, M, S, T = map(int, input().split())
S, T = S-1, T-1
G1 = [[] for i in range(N)]
G2 = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u-1, v-1
    G1[u].append((v, a))
    G1[v].append((u, a))
    G2[u].append((v, b))
    G2[v].append((u, b))


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


toChange = dijkstra(S, G1)
toGoal = dijkstra(T, G2)

ans = [float('inf')]
for i in range(N-1, -1, -1):
    ans.append(min(ans[-1], toChange[i] + toGoal[i]))

del ans[0]
money = 10 ** 15
for cost in ans[::-1]:
    print(money - cost)


Measured memory_bytes: 123628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000 

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int stack[MAX];
int top;

int main(){
  int a,b;
  char box[100];
  initialize();
  while(scanf("%s",box) != EOF){
    if(box[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(box[0] == '-'){
      a = pop();
      b = pop();
      push(b - a);
    }
    else if(box[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else if(box[0] >= '0' && box[0] <= '9'){
      push(atoi(box));
    }
    else continue;
  }

  printf("%d\n",pop());

  
  return 0;
}

void initialize(){
  top = 0;
}

int isEmpty(void){
  if(top == 0) return 0;
  else return 1;
}

int isFull(void){
  if(top >= MAX - 1) return 0;
  else return 1;
}

void push(int x){
  if(isFull() == 0){
    printf("エラー　(オーバーフロー)\n");
    exit(2);
  }
  top++;
  stack[top] = x;
}

int pop(void){
  if(isEmpty() == 0){
    printf("エラー　(アンダーフロー)\n");
    exit(1);
  }
  top--;
  return stack[top + 1];
}



Measured memory_bytes: 2108
#include<stdio.h>
int main()
{
  while(1){
    int flag[21][21],n,x,y,m,i,j,k,px=10,py=10;
    char direction;
    int count=0;
  
    for(i=0;i<21;i++){
      for(j=0;j<21;j++){
	flag[i][j]=0;
      }
    }
  
    scanf("%d",&n);
    if(n==0) break;
  
    for(i=0; i<n; i++){
      scanf("%d%d",&x,&y);
      flag[x][y]=1;
    }
    scanf("%d",&m);
    for(i=0; i<m; i++){
      char tmp;
      scanf("%c",&tmp);
      scanf("%c%d",&direction,&k);

      for(j=0; j<k; j++){

	switch(direction){
	case'N':
	  py=py+1;
	  break;

	case'E':
	  px=px+1;
	  break;

	case'W':
	  px=px-1;
	  break;

	case'S':
	  py=py-1;
	  break;
	}

	if(flag[px][py]){
	  flag[px][py]=0;
	  count+=1;

	}
      }
    }
    if(count==n){
      printf("Yes\n");

    }else{
      printf("No\n");
    }
  }
  return 0;
}

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


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

namespace _0023
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] answer = new int[n];
            for (int i = 0; i < n; ++i)
            {
                double[] array = Console.ReadLine().Split().Select(double.Parse).ToArray();
                double xa = array[0];
                double ya = array[1];
                double ra = array[2];
                double xb = array[3];
                double yb = array[4];
                double rb = array[5];
                double ab = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
                if (ab > Math.Abs(ra + rb))
                {
                    answer[i] = 0;
                }
                else if (ab < Math.Abs(ra - rb))
                {
                    if (ra > rb)
                    {
                        answer[i] = 2;
                    }
                    else if (rb > ra)
                    {
                        answer[i] = -2;
                    }
                }
                else
                {
                    answer[i] = 1;
                }
                
            }
            foreach(var item in answer)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 18260
s=input()
ss=len(s)

while ss>0:
    if s[ss-5:ss]=="dream":
        ss=max(ss-5,0)
    elif s[ss-7:ss]=="dreamer":
        ss=max(ss-7,0)
    elif s[ss-5:ss]=="erase":
        ss=max(ss-5,0)
    elif s[ss-6:ss]=="eraser":
        ss=max(ss-6,0)
    else:
        print("NO")
        break
if ss<=0:
    print("YES")

Measured memory_bytes: 3316
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] a = new String[H];
		for(int i = 0 ; i < H ; i++) {
			a[i] = sc.next();
		}
		for(int i = 0 ; i < W + 2 ; i++) {
			System.out.print("#");
		}
		System.out.println();
		for(int i = 0 ; i < H ; i++) {
			System.out.print("#");
			System.out.print(a[i]);
			System.out.println("#");
		}
		for(int i = 0 ; i < W + 2 ; i++) {
			System.out.print("#");
		}
		System.out.println();
	}
}

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

using namespace std;
#define ll long long
#define mod 1000000007

vector<ll> g[100001];
ll n, dp[100001][3], p[100001];
bool leaf[100001];

void fill_par(ll vtx, ll par) {
    p[vtx] = par;
    bool b = true;
    for (int i : g[vtx]) {
        if (i != par) {
            b = false;
            fill_par(i, vtx);
        }
    }
    if (b) leaf[vtx] = true;
}

ll f(ll vtx, ll black) {
    if (leaf[vtx]) {
        if (black) {
            return 1;
        } else {
            return 2;
        }
    }

    if (dp[vtx][black] != -1) {
        return dp[vtx][black];
    }

    ll ans1 = (!black ? 1 : 0), ans2 = 1;
    for (ll i : g[vtx]) {
        if (i != p[vtx]) {
            if (!black) ans1 = (ans1 * f(i, 1)) % mod;
            ans2 = (ans2 * f(i, 0)) % mod;
        }
    }
    dp[vtx][black] = (ans1 + ans2) % mod;
    return dp[vtx][black];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, -1, sizeof(dp));

    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    fill_par(1, 0);

    cout << f(1, 0) << "\n";
}


Measured memory_bytes: 19100
#include <iostream>
#include <string>

using namespace std;
int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e - a > k)
    {
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

ll n;
ll dp[65][2][2];
ll dfs(int i, int a, int b){
    if(i == 60){
        if(a == 0 && b == 0) return 1;
        return 0;
    }
    if(dp[i][a][b] != -1) return dp[i][a][b];

    ll ans = 0;
    for(int x=0;x<=1;x++){
        for(int y=0;y<=1;y++){
            int na = (x+y+a)/2, nb = b;
            if(y > x) continue;

            if((x+y+a)%2 > ((n>>i)&1)) nb = 1;
            else if((x+y+a)%2 < ((n>>i)&1)) nb = 0;

            ans = (ans + dfs(i+1, na, nb))%mod;
        }
    }
    return dp[i][a][b] = ans;
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%lld", &n);
    printf("%lld\n", dfs(0, 0, 0));
}

Measured memory_bytes: 3812
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
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; }

using namespace std;

int main(void)
{
    vector<int> x(5); rep(i, 0, 5)cin >> x[i];
    int ans = 0;
    rep(i, 0, 5) {
        if (x[i] == 0) {
            ans = i + 1;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

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

int main(){
	
	COMinit();
	
     int n;
     cin >> n;
     vector<ll> a(n+1), vec(n+1);
     ll k =-1;
     int l, r;
     for(int i = 0; i <= n; ++i){
         cin >> a[i];
         if(vec[a[i]]== 1){k =a[i];r=i;}
         else{vec[a[i]]=1;}
     }
     
     for(int i = 0; i <= n; ++i){if(a[i]==k){l=i;break;}}
     r = n-r;
     
     for(int i = 1; i <= n+1; ++i){
         ll ans = (COM(n+1, i) - COM(l+r, i-1)+MOD)% MOD;
         cout << ans% MOD << endl;
    }
}


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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;
	int containerTop[2];
	bool flag;
	n = in();
	loop(i, 0, n)
	{
		containerTop[0] = containerTop[1] = -1;
		flag = true;
		
		loop(j, 0, 10)
		{
			int ball = in();
			if( containerTop[0] < ball )
			{
				containerTop[0] = ball;
			}
			else if( containerTop[1] < ball )
			{
				containerTop[1] = ball;
			}
			else
			{
				flag = false;
			}
		}
		printf("%s\n", flag ? "YES" : "NO");
	}
	return (0);
}

Measured memory_bytes: 1164
def main():
    N = int(input())
    P = list(map(lambda x: int(x) - 1, input().split()))
    # （例）N = K, P = [4, 2, 5, 1, 3]
    # a_i + b_i が全部同じ値の状態から始める
    #     base a: 1 < 2 < 3 < 4 < 5
    #     base b: 5 > 4 > 3 > 2 > 1
    # (1) 4番目以外の数字を+5する
    #     a: 1  < 2 < 3 < 4 < 10（4個目より右に+5）
    #     b: 10 > 9 > 8 > 2 > 1 （4個目より左に+5）
    # (2) 2番目以外の数字を+4する
    #     a: 1  < 2 < 7 < 8 < 14
    #     b: 14 > 9 > 8 > 2 > 1
    # (3) 5番目以外の数字を+3する
    #     a: 1  < 2  < 7  < 8 < 14
    #     b: 17 > 12 > 11 > 5 > 1
    # (4) 1番目以外の数字を+2する
    #     a: 1  < 4  < 9  < 10 < 16
    #     b: 17 > 12 > 11 > 5  > 1
    # (5) 3番目以外の数字を+1する
    #     a: 1  < 4  < 9  < 11 < 17
    #     b: 18 > 13 > 11 > 5  > 1
    #   sum: 19,  17,  20,  16,  18
    A, B = list(range(1, N + 1)), list(range(N, 0, -1))
    # いもす法で増分を計算していく
    imos_a, imos_b = [0] * N, [0] * N
    for i, p in enumerate(P):
        d = N - i
        if p < N - 1:
            imos_a[p + 1] += d
        if p > 0:
            imos_b[p - 1] += d
    for i in range(1, N):
        imos_a[i] += imos_a[i - 1]
        j = N - i - 1
        imos_b[j] += imos_b[j + 1]
    for i in range(N):
        A[i] += imos_a[i]
        B[i] += imos_b[i]
    print(' '.join(map(str, A)))
    print(' '.join(map(str, B)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14392
n,m=map(int,input().split())
L=[0]*n
W=[0]*n
cnt=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if L[p-1]==0:
        if s=="AC":
            L[p-1]=1
        else:
            W[p-1]+=1
for i in range(n):
    if L[i]==1:
        cnt += W[i]
print(sum(L),cnt)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, l;
  cin >> n >>  l;
  vector<string> s(n);
  rep(i, n)cin >> s.at(i);
  sort(all(s));
  rep(i, n) cout << s.at(i);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 200005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int a[N], n;
LL ans;
int main(){
	int i, j, l, r, t;
	n = read();
	for(i = 1; i <= n; i++) a[i] = read(), a[i] -= i;
	sort(a + 1, a + i);
	t = a[(n + 1) / 2];
	for(i = 1; i <= n; i++) ans += abs(a[i] - t);
	printf("%lld", ans);
	return 0;
}


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

using namespace std;

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
	double a;
	cin >> a;
	printf("%f\n",(a/3)*(a/3)*(a/3));
    return 0;
}

Measured memory_bytes: 256
def bfs(maze):
    d = [[0] * (w * 2 + 1) for i in range(h * 2 + 1)]
    d[1][1] = 1
    que = [(1, 1)]
    while que:
        x, y = que.pop(0)
        if x == 2 * w - 1 and y == 2 * h - 1:
            return d[y][x]
        for dx, dy in ((0, 1), (-1, 0), (0, -1), (1, 0)):
            mx, my = x + dx, y + dy
            nx, ny = mx + dx, my + dy
            if nx < 0 and w < nx and ny < 0 and h < ny:
                continue
            if maze[my][mx] == 0 and d[ny][nx] == 0:
                que.append((nx, ny))
                d[ny][nx] = d[y][x] + 1
    return 0

while True:
    w, h = map(int, input().split())
    maze = [[0] * (w * 2 + 1) for i in range(h * 2 + 1)]
    if w == h == 0:
        break
    for x in range(w * 2 + 1):
        maze[0][x] = maze[h * 2][x] = 1
    for y in range(h * 2 + 1):
        maze[y][0] = maze[y][w * 2] = 1

    for y in range(1, h * 2):
        a = [int(i) for i in input().split()]
        if y % 2 == 1:
            for x in range(w - 1):
                maze[y][2 * x + 2] = a[x]
        else:
            for x in range(w):
                maze[y][2 * x + 1] = a[x]

    print(bfs(maze))

Measured memory_bytes: 7932
def main():
    nvertices, nedges = map(int, input().split())
    adj = [[0 for i in range(nvertices)] for j in range(nvertices)]
    for i in range(nedges):
        u, v, c = map(int, input().split())
        adj[u][v] = c

    INF = float('inf')
    ans = 0
    while True:
        parents = bfs(0, nvertices - 1, adj)
        if parents is None:
            break
        v = nvertices - 1
        f = INF
        while parents[v] != -1:
            f = min(f, adj[parents[v]][v])
            v = parents[v]

        ans += f
        v = nvertices - 1
        while parents[v] != -1:
            adj[parents[v]][v] -= f
            adj[v][parents[v]] += f
            v = parents[v]

    print(ans)


def bfs(s, t, adj):
    visited = [False] * len(adj)
    que = [s]
    parents = [-1] * len(adj)
    while que:
        u = que.pop(0)
        visited[u] = True
        if u == t:
            return parents

        for v in range(len(adj)):
            if not visited[v] and adj[u][v] > 0:
                parents[v] = u
                que.append(v)

    return None


main()

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const ll INF = 100000000;
const ll MOD = 1000000007;

void sieve(ll max, std::vector<bool> &isprime)
{
    if(max+1>isprime.size()){
        isprime.resize(max + 1, true);
    }
    isprime[0] = false;
    isprime[1] = false;

    for (ll i = 2; i * i <= max;i++){
        if(isprime[i]){
            for (ll j = 2; i * j <= max;j++){
                isprime[i * j] = false;
            }
        }
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //問題文中の添え字が0-indexか1-indexか確認!

    std::vector<bool> IsPrime;

    sieve(55556, IsPrime);

    ll n;
    std::cin >> n;

    ll temp = 11;
    rep(i, 0, n)
    {
        while(!IsPrime[temp]){
            temp += 5;
        }
        std::cout << temp << " ";
        temp += 5;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#include <vector>
#include <math.h> 
using namespace std;

int main()
{
	int a,b,c,aa,bb,cc,ans=0;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b && b==c)
	{
		printf("%d\n",(a%2) ? 0 : -1);
		return 0;
	}
	while(!(a%2+b%2+c%2))
	{
		ans++;
		aa=a/2,bb=b/2,cc=c/2;
		b=aa+cc;
		c=aa+bb;
		a=bb+cc;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  double d; cin >> d;
  printf("%.10f\n", max(1.0 + floor(d), d * sqrt(2)));
  
  return 0;
}

Measured memory_bytes: 3304
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
if sum(a) == x:
  print(n)
else:
  for i in range(n-1):
    if x >= a[i]:
      x = x - a[i]
      count += 1
    else:
      break
    
  print(count)

Measured memory_bytes: 3060
N,M=[int(x) for x in str(input()).split()]
lim=int(M**0.5)+100005




num=10**9+7
x=1
factorial=[1]
for i in range(1,2*10**5+1):
  x=(i*x)%num
  factorial.append(x)
 
rfactorial=[]
for i in factorial:
  rfactorial.append(pow(i,num-2,num))
 

def c(n,k):
  return (((factorial[n]*rfactorial[k])%num)*rfactorial[n-k])%num


ans=1
for i in range(2,int(M**0.5)+2):
  count=0
  while M%i==0:
    count+=1
    M=M//i
  ans=(ans*c(N+count-1,count))%num
if M>1:
  ans=(ans*c(N,1))%num

print(ans)

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

#define _GLIBCXX_DEBAC
using namespace std;
	
int findx(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

string divide[4] = { "dream","dreamer","erase","eraser" };

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









Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200050;
int pd[maxn];
int color[maxn];
ll sum[maxn];
ll sizes[maxn];
vector<int> tree[maxn];
set<int> col;
ll ans[maxn];
void find_size(int fa,int gfa){
    sizes[fa]=1;
    for(int i=0;i<tree[fa].size();i++){
        if(tree[fa][i]==gfa)    continue;
        find_size(tree[fa][i],fa);
        sizes[fa]+=sizes[tree[fa][i]];
    }
}
void find_ans(int fa,int gfa){
    ll tmp=0;
    if(sum[color[fa]]!=0){
        tmp=sum[color[fa]];
        sum[color[fa]]=0;
    }
    for(int i=0;i<tree[fa].size();i++){
        if(tree[fa][i]==gfa)    continue;
        find_ans(tree[fa][i],fa);
        ans[color[fa]]-=(sizes[tree[fa][i]]-sum[color[fa]])*(sizes[tree[fa][i]]-sum[color[fa]]-1)/2;
        sum[color[fa]]=0;
    }sum[color[fa]]=sizes[fa]+tmp;
}
int main(){
    int n,a,b;
    scanf("%d",&n);
        col.clear();
        for(int i=1;i<=n;i++){
            sum[i]=0;
            tree[i].clear();
        }
        for(int i=1;i<=n;i++){
            scanf("%d",&color[i]);
            pd[color[i]]++;
            col.insert(color[i]);
        }
        for(int i=1;i<=n;i++)if(pd[i])
        ans[i]=1ll*n*(n-1)/2;
        for(int i=1;i<n;i++){
            scanf("%d%d",&a,&b);
            tree[a].push_back(b);
            tree[b].push_back(a);
        }find_size(1,0);
        find_ans(1,0);
        set<int>::iterator pt=col.begin();
        for(;pt!=col.end();pt++){
            int cl=*pt;
            ans[cl]-=(n-sum[cl])*(n-sum[cl]-1)/2;
        }
        for(int i=1;i<=n;i++)
        {
            ans[i]+=pd[i];
        }
        for(int i=1;i<=n;i++)
        {
            printf("%lld\n",ans[i]);
        }
    return 0;
}


Measured memory_bytes: 42328
#include <stdio.h>

int main() {
  int n, cnt = 0;
  scanf("%d", &n);
  int a[n], b[n+1];
  for (size_t i = 0; i < n; i++) {
    scanf("%d", a+i);
  }
  for (size_t i = n; i > 0; i--) {
    int c = n/i, d = 0;
    if (c>1) {
      for (size_t j = 1; j < c; j++) {
        d += b[(j+1)*i];
      }
    }
    if (a[i-1] == d%2) {
      b[i] = 0;
    }else {
      b[i] = 1;
      cnt++;
    }
  }
  printf("%d\n", cnt);
  for (size_t i = 0; i < n; i++) {
    if (b[i+1] == 1) {
      printf("%d ", i+1);
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main()
{
    int n,ok=0;
    cin>>n;
    while(n>0){
        if(n%10==7){
            ok=1;
            
        }n=n/10;
    }
    if(ok==1){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


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

void shafle(int b, int e, int *ans)
{
    int tmp[50];
    b--;
    for (int i = 0; i < b; i++)
        tmp[i] = ans[i];
    for (int i = b; i < b + e; i++)
        ans[i - b] = ans[i];
    for (int i = e; i < b+e; i++)
        ans[i] = tmp[i - e];
}
int main()
{
    int n, r;
    while (cin >> n >> r, n)
    {
        int ans[50];
        for (int i = 0; i < n; i++)
            ans[i] = n - i;
        for (int i =0 ; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shafle(b, e, ans);
        }
        cout << ans[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<ios>
#include<iomanip>

using namespace std;

int main(void){

  int n,m;
  cin >> n;
  cin >> m;

  vector<int> p(m);
  vector<int> y(m);
  //cout << m << endl;
  for(int i=0;i<m;i++){

    cin >> p[i];
    cin >> y[i];

  }

  vector< vector<int> > pre(n+1,vector<int>(0));

  //cout << pre.size() << endl;
  //cout << pre[0].size() << endl;

  for(int i=0;i<m;i++){
    pre[p[i]].push_back(y[i]);
  }
  for(int i=1;i<n+1;i++){
    sort(pre[i].begin(),pre[i].end());
    for(int j=0;j<pre[i].size();j++){
      //cout << pre[i][j] << " ";
    }

    //cout << endl;
  }

  for(int i=0;i<m;i++){
    //auto itr = find(pre[p[i]].begin(),pre[p[i]].end(),y[i]);
    auto itr = lower_bound(pre[p[i]].begin(),pre[p[i]].end(),y[i]);
    //cout << distance(pre[p[i]].begin(),itr)+1 << endl;
    auto d=distance(pre[p[i]].begin(),itr)+1;
    cout << setfill('0') << right << setw(6) << p[i];
    cout << setfill('0') << right << setw(6) << d;
    cout << endl;
  }


  return 0;
}


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

namespace TokorotenLab
{
    class Logger
    {
    private:
        bool isEnable;

    public:
        Logger(bool isEnable = true) : isEnable(isEnable) {}

        template<class T>
        Logger& operator<<(const T& val)
        {
            if(isEnable)
            {
                std::cout << val;
            }
            return *this;
        }

        void set_enable()
        {
            isEnable = true;
        }

        void set_disable()
        {
            isEnable = false;
        }

        void endl()
        {
            if(isEnable)
            {
                std::cout << std::endl;
            }
        }
    };

    Logger logger;

    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

int main()
{
    int x, a, b;

    cin >> x >> a >> b;

    if(abs(a - x) < abs(b - x))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[100100];
int main()
{
	scanf("%s",c+1);
	int len=strlen(c+1);
	if(len%2==0){
		int ans=len/2;
		int mid=len/2;
		int l=mid;
		int r=mid+1;
		while(c[l]==c[r]&&c[l]==c[mid]&&l>=1&&r<=len){
			ans++;
			l--;
			r++;
		}
		cout<<ans<<endl;
	}
	else{
		int ans=len/2;
		int mid=len/2+1;
		int l=mid;
		int r=mid;
		while(c[l]==c[r]&&c[l]==c[mid]&&l>=1&&r<=len){
			ans++;
			l--;
			r++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

	int b[m+1] = {};
	int a[n+1][m+1] = {};

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

	for (int i = 1; i < m + 1; i++){
		cin >> b[i];
	}

	int c[n+1] = {};
	for (int k = 1; k < n+1; k++){
		for (int l = 1; l < m+1; l++){
			c[k] += a[k][l] * b[l];
		}
	}

	for (int p = 1; p < n+1; p++){
		cout << c[p] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3132
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int n;
vi slimes;
vector<ll> pre;
ll memo[401][401];

ll dp(int l, int r)
{
    if (l == r) return 0;
    if (memo[l][r] != -1) return memo[l][r];
    ll ans = 1e18L;
    for (int i = l; i < r; i++) {
        ans = min(ans, dp(l, i) + dp(i + 1, r) + pre[r + 1] - pre[l]);
    }
    return memo[l][r] = ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    memset(memo, -1, sizeof(memo));
    cin >> n;
    slimes.resize(n);
    for (int i = 0; i < n; i++) cin >> slimes[i];
    pre.resize(n + 1);
    pre[0] = 0;
    for (int i = 0; i < n; i++) {
        pre[i + 1] = pre[i] + slimes[i];
    }
    cout << dp(0, n - 1) << endl;

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#define min(a,b) ((a<b)?a:b)
#define max(a,b) ((a>b)?a:b)
#define ll long long int
#define BIG 1e9
using namespace std;
struct g{
	vector<int> s;
	bool f;
	ll n;
};
ll N,M,ans,dp[100001]={};
g a[100010];
int k(int node){
	if(a[node].f)return a[node].n;
	a[node].n = 0;
	for(int i=0; i<a[node].s.size(); i++){
		a[node].n = max(k(a[node].s[i])+1,a[node].n);
	}
	a[node].f = 1;
	return a[node].n;
}
int main() {
	cin>>N>>M;
	for(int i=0; i<M; i++){
		int t1,t2;
		cin>>t1>>t2;
		a[t1].s.push_back(t2);
	}
	for(int i=1; i<=N; i++){
		int aa=k(i);
		ans = max(aa,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pll, int > a, pair < pll, int > b)//true for a before b
{
	if(a.F.F*b.F.S <= b.F.F*a.F.S)
		return 1;
	return 0;
}

const int N = (2e3) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

int a[N], b[N];
ll dp[N][N], sum[N][N];

void solve()
{
	int n, m, i, j;
	cin >> n >> m;
	fo(i,1,n+1)
		cin >> a[i];
	fo(j,1,m+1)
		cin >> b[j];
	sum[0][0] = dp[0][0] = 1;
	fo(i,1,n+1)
		sum[i][0] = 1;
	fo(j,1,m+1)
		sum[0][j] = 1;
	fo(i,1,n+1)
		fo(j,1,m+1)
		{
			if(a[i] == b[j])
				dp[i][j] = sum[i-1][j-1];
			else
				dp[i][j] = 0;
			sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + mod + dp[i][j])%mod;
			// cout << i << " " << j << " : " << dp[i][j] << " " << sum[i][j] << '\n';
		}
	cout << sum[n][m] << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(2);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 63232
#include<stdio.h>
#include<string.h>
int main()
{
	int n,x=0,a,b,i,t=0;
	scanf("%d",&n);
	t=n;
	while(n>10)
	{
		x+=n%10;
		n=n/10;
	}
		x+=n;
		if((t%x)==0)
		printf("Yes");
		else
		printf("No");
	
	return 0;
}

Measured memory_bytes: 128
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
    yen = inputOnebyOne_Int()
    if(yen[2] <= yen[0]+yen[1]):
        print("Yes")
    else:
        print("No")

if __name__=='__main__':
    main()

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int K, N;
	int A[200010];
	cin >> K >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans = mod;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans = min(ans,  K - (K - (A[N - 1] - A[i])));
			ans = min(ans, K - (A[i + 1] - A[i]));
		}
		else if (i == N - 1) {
			ans = min(ans, K - (A[i] - A[i - 1]));
			ans = min(ans, K - (K - (A[N - 1] - A[0])));
		}
		else {
			ans = min(ans, K - (A[i] - A[i - 1]));
			ans = min(ans, K - ( A[i + 1] - A[i]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
a,b = list(map(int,input().split()))

if a > 0 and b > 0:
    print("Positive")
elif (a > 0 and b < 0) or (a < 0 and b > 0):
    print("Zero")
else:
    if (abs(a) - abs(b)) % 2 == 0:
        print("Negative")
    else:
        print("Positive")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <cmath>
#define PI acos(-1)
typedef long long ll;
const long long mod = 998244353;
const long long maxn = 1e7 + 5; 
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
		printf("hon\n");
	else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) 
		printf("pon\n");
	else 
		printf("bon\n");
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    int x=0,maxX=0;
    for(auto c:S){
        if(c=='I') x++;
        else if(c=='D') x--;
        maxX=max(maxX,x);
    }

    cout<<maxX<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x: a) cin >> x;
  vector<vector<int> > edge(n);
  for (int i = 0; i < n-1; i++) {
    int u, v;
    cin >> u >> v;
    edge[u-1].push_back(v-1);
    edge[v-1].push_back(u-1);
  }

  vector<int> ans(n);
  stack<Pii> history;
  history.emplace(0, 0);
  vector<int> dp(n+1, 1000000007);
  dp[0] = 0;
  stack<Pii> st;
  st.emplace(0, 0);
  while (!st.empty()) {
    auto now = st.top();
    st.pop();
    if (now.second == 0) {
      auto it = lower_bound(dp.begin(), dp.end(), a[now.first]);
      int idx = distance(dp.begin(), it);
      history.emplace(idx, dp[idx]);
      dp[idx] = a[now.first];
    }
    if (now.second == (int) edge[now.first].size()) {
      auto it = lower_bound(dp.begin(), dp.end(), 1000000007);
      int idx = distance(dp.begin(), it) - 1;
      ans[now.first] = idx;
      // revert
      auto prev = history.top();
      history.pop();
      dp[prev.first] = prev.second;
    }
    else {
      if (st.empty()) {
        st.emplace(now.first, now.second+1);
        st.emplace(edge[now.first][now.second], 0);
      }
      else {
        int prev = st.top().first;
        st.emplace(now.first, now.second+1);
        if (prev != edge[now.first][now.second]) st.emplace(edge[now.first][now.second], 0);
      }
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 19424
import java.util.*;

public class Main {
	static boolean[] comp = new boolean[1310];
	static ArrayList<Integer> list = new ArrayList<>();
	
	public static void main(String[] args) {
		sieve();
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0; i < N; i++) {
			if(i != 0)
				sb.append(" ");
			sb.append(list.get(i));
		}
		System.out.println(sb.toString());
	}
	
	public static void sieve() {
		for(int i = 2; i < comp.length; i++) {
			if(!comp[i]) {
				if(i % 5 == 3)
					list.add(i);
				for(int j = 2; i*j < comp.length; j++)
					comp[i*j] = true;
			}
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
void orz(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
}
int main()
{
   // orz();
    int n,d,x,ans,i;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    int maxx=0,id;
    for(i=0;i<n;i++){
        if(a[i]>maxx){
                maxx=a[i];
            id=i;
        }
    }

    a[id]=-1;
    int maxx2=0;
    for(i=0;i<n;i++){
        if(a[i]>maxx2){
                maxx2=a[i];
            id=i;
        }
    }

    for(i=0;i<n;i++){
        if(a[i]==-1)    
            cout<<maxx2;
        else
            cout<<maxx;
        cout<<"\n";
    }
       
}



Measured memory_bytes: 2432
from collections import defaultdict

N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
# print()
# print(*P)
# print(*C)
x = 0
used = [0] * N
path = defaultdict(list)
score = defaultdict(list)
for i in range(N):
    if used[i]:
        continue
    x = i
    while used[x] == 0:
        used[x] = 1
        path[i].append(x)
        score[i].append(C[x])
        x = P[x]
ans = -float('inf')
for r in path:
    pa, sc, le = path[r], score[r], len(path[r])
    # print(pa, sc, le)
    for i in range(le-1):
        sc[i+1] += sc[i]
    # print(sc)
    if sc[-1] <= 0 or K < le:
        m = -float('inf')
        for i in range(len(pa)):
            for j in range(i+1, len(pa)):
                if j - i <= K:
                    m = max(m, sc[j] - sc[i])
                if le - j + i <= K:
                    m = max(m, sc[-1] - sc[j] + sc[i])
        ans = max(ans, m)
    else:
        k = K % le
        m = 0 if k == 0 else -float('inf')
        for i in range(le):
            for j in range(i+1, le):
                if j - i <= k:
                    m = max(m, sc[j] - sc[i])
                if le - j + i <= k:
                    m = max(m, sc[-1] - sc[j] + sc[i])
        ans = max(ans, m + sc[-1] * (K // le))

        m = -float('inf')
        for i in range(le):
            for j in range(i+1, le):
                if j - i <= le:
                    m = max(m, sc[j] - sc[i])
                if le - j + i <= le:
                    m = max(m, sc[-1] - sc[j] + sc[i])
        ans = max(ans, m + sc[-1] * ((K // le) - 1))
print(ans)

Measured memory_bytes: 70452
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

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

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

    string s;
    cin >> s;

    int num010 = 0;
    int n = s.size();
    rep(i, n){
        char num = '0' + i%2; //char 01010101...
        if(s[i] == num) ++num010;
    }

    cout << min(num010, n-num010) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int n,k;
int main(){
  scanf("%d%d",&k,&n);
  for(int p=n-k+1;p<=n+k-1;p++) 
      printf("%d ",p);
}

Measured memory_bytes: 256