akhauriyash/Code-Regression huggingface dataset:
/*  ex9_1
    Rikuta  */
#include <stdio.h>
#include<stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 10
//スタックの定義
typedef struct stack
{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;
//スタックの初期化
void initialize_stack(stack *string);
//データの追加
void push(stack *string, char elem);
//データの取り出し
void pop(stack *string);
//stackの出力
void print_stack(stack *string);

int main(void)
{   
    //スタックを宣言
    stack string;
    //スタックを初期化
    initialize_stack(&string);
    while (1)
    {   
        //受け取る変数の宣言
        char temp_char;
        //入力
        scanf("%c", &temp_char);
        //入力が終了なら終わり
        if (temp_char=='\n')
        {
            break;
        }
        //Bが入力されたらスタックをpop
        if (temp_char=='B')
        {
            pop(&string);
        }
        //0,1ならそれをスタックにpush
        if (temp_char=='0'||temp_char=='1')        
        {
            push(&string, temp_char);
        }
    }
    //スタックを出力
    print_stack(&string);

    return 0;
}

//スタックの初期化
void initialize_stack(stack *string)
{   
    //スタックの要素数と最大の大きさとtopを初期化
    string->count = 0;
    string->size = SIZE;
    string->top = &(string->data[SIZE]);
}

//データの追加
void push(stack *string, char elem)
{   
    //スタックの長さが最大を超えていたら標準エラー出力
    if (string->count >= string->size)
    {
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else
    {   
        //スタックのtopは一個戻り，戻ったtopに要素が入る．要素数が1増える．
        string->top--;
        *(string->top) = elem;
        string->count++;
    }
}

//データの取り出し
void pop(stack *string)
{   
    //データに何も入っていなかったら
    if (string->count > 0)
    {   
        //スタックのトップを奥へ，要素数が1減る
        string->top++;
        string->count--;
    }
}

void print_stack(stack *string)
{   
    //ポインタの宣言
    char *pointer;
    //ポインタはスタックの一番古い要素を指す
    pointer = string->top+string->count-1;
    for (int i = 0; i < string->count; i++)
    {   
        //ポインタがさす要素を新しくしながら出力していく．
        printf("%c", *(pointer--));
    }
    //改行
    printf("\n");
}


Measured memory_bytes: 1592
import math


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __repr__(self):
        return f"({self.x},{self.y})"


class Segment:
    def __init__(self, x: Point, y: Point):
        self.pt1 = x
        self.pt2 = y
        self.vector = self.pt2 - self.pt1
        self.norm = pow(self.vector.x, 2) + pow(self.vector.y, 2)
        self.abs = math.sqrt(self.norm)

    def dot(self, other):
        return self.vector.x * other.vector.x + self.vector.y * other.vector.y

    def cross(self, other):
        return self.vector.x * other.vector.y - self.vector.y * other.vector.x

    def projection(self, pt: Point)-> Point:
        vec_p1_to_pt = Segment(self.pt1, pt)
        t = self.dot(vec_p1_to_pt) / self.abs
        x = self.pt1.x + t / self.abs * self.vector.x
        y = self.pt1.y + t / self.abs * self.vector.y
        return Point(x, y)

    def __repr__(self):
        return f"{self.pt1},{self.pt2},{self.vector}"


def main():
    p0_x, p0_y, p1_x, p1_y = map(int, input().split())
    seg_1 = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
    num_query = int(input())
    for i in range(num_query):
        pt_x , pt_y = map(int, input().split())
        proj = seg_1.projection(Point(pt_x, pt_y))

        print("{:.10f} {:.10f}".format(proj.x, proj.y))
    return

main()


Measured memory_bytes: 5724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

struct UnionFind {
    vector<int> parent;

    UnionFind(int n) : parent(n, -1) {}
    void Init(int n) { parent.assign(n, -1); }

    int Root(int x) {
        if (parent[x] < 0) return x;
        else return parent[x] = Root(parent[x]);
    }

    bool IsSame(int x, int y) {
        return Root(x) == Root(y);
    }

    bool Merge(int x, int y) {
        x = Root(x); y = Root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }

    int Size(int x) {
        return -parent[Root(x)];
    }
};

void Compress(vector<long long>& x, map<long long, long long>& zip, vector<long long>& unzip) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());

    unzip.resize(x.size());
    for(long long i = 0; i < x.size(); ++i) {
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
}

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

    Int N; cin >> N;
    vector<Int> x(N), y(N), orgX(N), orgY(N);
    rep(i, 0, N) cin >> x[i] >> y[i];
    orgX = x; orgY = y;

    map<long long, long long> zipx;
    vector<long long> unzipx;
    Compress(x, zipx, unzipx);
    map<long long, long long> zipy;
    vector<long long> unzipy;
    Compress(y, zipy, unzipy);

    Int nx = x.size(), ny = y.size();
    UnionFind uf(nx+ny);

    rep(i, 0, N) {
        uf.Merge(zipx[orgX[i]], zipy[orgY[i]]+nx);
    }

    map<Int, Int> mx, my;
    rep(i, 0, nx) {
        mx[uf.Root(i)]++;
    }
    rep(i, nx, nx+ny) {
        my[uf.Root(i)]++;
    }

    Int res = 0;
    rep(i, 0, nx+ny) {
        res += mx[i] * my[i];
    }

    cout << res - N << endl;
}

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

int N,M;
int ans;
long nCr(int n, int r);


int main(){
    std::cin >> N >> M;
    ans = nCr(N+M,2) - N*M;
    std::cout << ans;
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

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

using namespace std;
int main() {
  int n;
  cin >> n;
  pair<pair<string, int>, int> p[110];

  for (int i = 0; i < n; i++) {
    string s;
    int point;
    cin >> s >> point;
    p[i] = make_pair(make_pair(s, -point), i);
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++) {
    cout << p[i].second + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)
__gcd(a,b)は最大公約数を取ってくれる、aとb
の大きい方をNとしたとき、計算量は√N
*/
const int mod = 1e9 + 7;
//ここから書き始める
int main(){
	int n ;
	cin >> n;
	string s; 
	cin >> s;
	int ans = 0 ;
	int now = 0;
	rep(i,n){
		if(s[i]=='I'){
			now ++;
		}
		else now --;
		ans =max(ans,now);
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
s = []
c = []

for i in range(n):
    s.append(list(map(int, input().split())))

for i in range(m):
    c.append(list(map(int, input().split())))

for student in s:
    index = 1000
    idist = 1e9

    for i in range(m):
        dist = abs(student[0] - c[i][0]) + abs(student[1] - c[i][1])
        if (dist < idist):
            idist = dist
            index = i

    print(index + 1)

Measured memory_bytes: 9048
N = int(input())
lst = [input() for _ in range(N)]
lst = [sorted(i) for i in lst]
lst = ["".join(i) for i in lst]

cnt = 0
dic = {}

for i in lst:
    if i in dic:
        cnt += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1

print(cnt)

Measured memory_bytes: 31260
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int w, h;
char field[100][100];
int pdir[110][110];
int mapto[300];
int mapfrom[300];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, -1, 0, 1 };

void PrintField() {
  REP(y, h) {
    printf("%s\n", field[y]);
  }
  puts("");
}

void Push(int nx, int ny, int dir) {
  if (dir == 2) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 2) { return; }
  if (dir == 3) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 3) { return; }
  if (dir == 0) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 0) { return; }
  if (dir == 1) { pdir[ny][nx] = dir; }
  if (pdir[ny][nx] == 1) { return; }
}

int Person() {
  int ret = 0;
  REP(y, h) {
    REP(x, w) {
      if (mapto[(int)field[y][x]] <= 3) { ret++; }
    }
  }
  return ret;
}

int main() {
  MEMSET(mapto, 0x0f);
  mapto[(int)'E'] = 0;
  mapto[(int)'N'] = 1;
  mapto[(int)'W'] = 2;
  mapto[(int)'S'] = 3;
  mapfrom[0] = 'E';
  mapfrom[1] = 'N';
  mapfrom[2] = 'W';
  mapfrom[3] = 'S';
  while (scanf("%d %d", &w, &h), w|h) {
    REP(y, h) {
      scanf("%s", field[y]);
    }
    REP(t, 181) {
      //PrintField();
      MEMSET(pdir, 0x0f);
      if (Person() == 0) {
        printf("%d\n", t);
        goto next;
      }
      REP(y, h) {
        REP(x, w) {
          int dir = mapto[(int)field[y][x]];
          if (dir <= 3) {
            REP(i, 4) {
              int ndir = (dir + i + 3) % 4;
              int nx = x + dx[ndir];
              int ny = y + dy[ndir];
              if (field[ny][nx] == '.' ||
                  field[ny][nx] == 'X') {
                field[y][x] = mapfrom[ndir];
                Push(nx, ny, ndir);
                break;
              }
            }
          }
        }
      }
      REP(y, h) {
        REP(x, w) {
          int dir = pdir[y][x];
          if (dir <= 3) {
            int px = x + dx[(dir + 2) % 4];
            int py = y + dy[(dir + 2) % 4];
            field[py][px] = '.';
            if (field[y][x] == '.') {
              field[y][x] = mapfrom[dir];
            }
          }
        }
      }
    }
    puts("NA");
next:;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t a, int64_t b, int64_t t) {
  return (t / a) * b;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a;
  std::cin >> a;
  int64_t b;
  std::cin >> b;
  int64_t t;
  std::cin >> t;
  auto const res = solve(a, b, t);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    char input[100];
    char *tp;
    int n,q,x,y,t;
    int i,j;
    int **s;
    int *p;

    if(fgets(input,sizeof input, stdin)!=NULL){
        tp=strtok(input," ");
        n=atoi(tp);
        tp=strtok(NULL," ");
        q=atoi(tp);
    }

    s=malloc(sizeof(int *) * n);
    for(i=0;i<n;i++)s[i]=malloc(sizeof(int)*1000000);

    p=calloc(n,sizeof(int));

    for(i=0;i<q;i++){
        if(fgets(input,sizeof input, stdin)!=NULL){
            tp=strtok(input," ");
            y=atoi(tp);
            tp=strtok(NULL," ");
            t=atoi(tp);
            switch(y){
                case 0: tp=strtok(NULL," ");
                        x=atoi(tp);
                        s[t][p[t]]=x;
                        p[t]++;
                    break;
                case 1:
                    if(p[t]>0)printf("%d\n",s[t][p[t]-1]);
                    break;
                case 2:
                    if(p[t]>0)p[t]--;
                    break;
                default: break;
            }
        }
    }

    for(i=0;i<n;i++)free(s[i]);
    free(s);
    free(p);
    
    return 0;
}


Measured memory_bytes: 6348
let cal x op y =
	match op with
	|"+" -> x + y
	|"-" -> x - y
	|"*" -> x * y
	|"/" -> x / y
	|_ -> 0;;

let rec loop () =
	Scanf.sscanf(read_line()) "%d %s %d" (fun x op y -> if op <> "?" then (Printf.printf "%d\n" (cal x op y);loop()) else ());;

loop ();;



Measured memory_bytes: 2436
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int K = sc.nextInt();
    
   int count = 0;
   while(N>0)
   {
     N /= K ;
     count++;
   }
   System.out.print(count);
 }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[100000];
ll S[100000];

int main()
{
	int n;
	ll ans = (ll)1e18, tmp = 0,  add = 0;

	cin >> n;
	rep(i, n) cin >> a[i];

	rep(i, n) {
		if (i == 0) S[i] = a[i];
		else S[i] = S[i - 1] + a[i];
	}

	// positive first
	rep(i, n) {
		ll num = S[i] + add;

		// positive
		if (i % 2 == 0) { 
			if (num > 0) continue;
			add += 1 - num;
			tmp += abs(1 - num);
		}
		// negative
		else {
			if (num < 0) continue;
			add += -1 - num;
			tmp += abs(-1 - num);
		}
	}
	ans = min(ans, tmp);

	tmp = 0;
	add = 0;

	// negative first
	rep(i, n) {
		ll num = S[i] + add;

		// positive
		if (i % 2 == 1) {
			if (num > 0) continue;
			add += 1 - num;
			tmp += abs(1 - num);
		}
		// negative
		else {
			if (num < 0) continue;
			add += -1 - num;
			tmp += abs(-1 - num);
		}
	}
	ans = min(ans, tmp);

	cout << ans << endl;

	return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mp ;
vector <ll> vec ;

int main()
{
    ll n, x, m, ans = 0, cur = 0, val, rep, repVal = 0, need, vx, vy = 0 ;
    cin >> n >> x >> m ;

    for (int i = 0; i < n; i++, cur++) {
        if (mp[x] != 0) {
            val = x ;
            rep = (i + 1) - mp[x] ;
            break ;
        }
        vec.push_back(x) ;
        mp[x] = i + 1 ;
        ans += x ;
        x *= x ;
        x %= m ;
    }
    need = n - cur ;
    if (need <= 0) {
        cout << ans ;
    }
    else {
        for (int i = 0; i < vec.size(); i++) {
            if (vec[i] == val) {
                break ;
            }
            repVal += vec[i] ;
        }
        repVal = ans - repVal ;
        vx = need / rep ;
        ans += (repVal * vx) ;
        vx = need % rep ;

        for (int i = 0; i < vec.size(); i++) {
            if (vx <= 0)    break ;
            if (vec[i] == val) {
                vy = 1 ;
            }
            if (vy) {
                ans += vec[i] ;
                vx-- ;
            }
        }
        cout << ans ;
    }

    return 0 ;
}


Measured memory_bytes: 6692
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

#define Tcmp(X, Y) (abs(aryvec[i]->x) == X && abs(aryvec[i]->y) == Y)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
};

int main(){

	long long n;
	long long *a;

	in(n);
	a = new long long [n];
	input(a, n);

	long long max = 0;

	bool flag = false;

	long long min = abs(a[0]);

	For(i, n){
		max += abs(a[i]);
		if(a[i] < 0){
			flag = !flag;
		}
		if(min > abs(a[i])){
			min = abs(a[i]);
		}
	}

	if(flag){
		max -= min * 2;
	}

	out(max);
	
	return 0;

}

Measured memory_bytes: 1024
def progression_operation(arr)
  count = 0
  while true do
    index_dev2 = -1
    arr.each_with_index do | n, i |
      if (n%2 == 0) then
        index_dev2 = i
        arr[i] = arr[i] >> 1
        count += 1
      end
    end
    if index_dev2 == -1 then
      break
    end
  end
  p count
end

input = gets()
input = gets()
progression = input.split(" ")
progression.map!(&:to_i)

progression_operation(progression)


Measured memory_bytes: 2300
#include<stdio.h>

int n;
int p;

int main(void)
{
	int ans;
	int i;
	
	scanf( "%d", &n );
	
	ans = 0;
	for( i=0; i<n; i++ ) {
		scanf( "%d", &p );
		if ( p == i + 1 ) {
			ans++;
			scanf( "%d", &p );
			i++;
		}
	}
	
	printf( "%d\n", ans );
	
	return 0;
}

Measured memory_bytes: 128
def check(s):
  if s[0]!="A":
    return 0
  c = 0
  for i in range(1,len(s)):
    if s[1].isupper() or s[-1].isupper():
      return 0
    if s[i].isupper():
      if c!=0:
        return 0
      if s[i]=="C":
        c=1
      else:
        return 0
  if c==0:
    return 0
  return 1    

s = list(input())
if check(s):
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define tam 3100
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
set<int> rocks;
int main()
{
    string txt;
    cin>>txt;
    forr(i,0,txt.size())
    {
        if (txt[i]=='g')
            rocks.insert(i);
    }
    int papel=0;
    for(int i=txt.size()-1;i>=0;i--)
    {
        if (txt[i]=='p'){
            set<int>::iterator ite=rocks.upper_bound(i);
            if (ite!=rocks.end())
            {
                rocks.erase(ite);
            }
            else
                papel++;
        }
    }
    papel=rocks.size()-papel;
    cout<<papel/2<<endl;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll H, W, K;
    cin >> H >> W >> K;
    string s[H];
    for(i = 0; i < H; i++) {
        cin >> s[i];
    }
    ll dp[H+1][W+1];
    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            if(s[i][j] == '1') {
                dp[i+1][j+1] = 1;
            } else {
                dp[i+1][j+1] = 0;
            }
        }
    }
    for(i = 0; i <= H; i++) {
        for(j = 1; j <= W; j++) {
            dp[i][j] += dp[i][j - 1];
        }
    }
    for(i = 0; i <= W; i++) {
        for(j = 1; j <= H; j++) {
            dp[j][i] += dp[j - 1][i];
        }
    }
    ll ret = INF;
    for(i = 0; i < (1 << (H-1)); i++) {
        ll bef = 0;
        vector<ll> v;
        v.push_back(0);
        ll sum = 0;
        for(j=0;j<H-1;j++){
            if((i>>j) &1){
                v.push_back(j+1);
                sum++;
            }
        }
        v.push_back(H);
        for(j=bef;j<W;j++){
            ll flag = 0;
            for(k=0;k<v.size()-1;k++){
                if(dp[v[k+1]][j+1]-dp[v[k]][j+1]-dp[v[k+1]][bef]+dp[v[k]][bef]>K){
                    if(bef==j){
                        flag = 2;
                        sum = INF;
                        break;
                    }
                    bef = j;
                    flag = 1;
                    sum++;
                    break;
                }
            }
            if(flag == 2)break;
        }
        ret = min(ret,sum);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 384
#include <atcoder/segtree>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll f_op(ll x, ll y) { return max(x,y);}
ll f_e() {return 0;}

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    ll AX = 3e5;
    atcoder::segtree<ll, f_op, f_e> sg(AX+1);
    for ( int i = 0; i < N; i++ ) {
        ll k1 = max(0LL, A[i]-K), k2 = min(AX, A[i]+K);
        ll nx = sg.prod(k1,k2+1) + 1;
        sg.set(A[i], nx);
    }
    ll ans = sg.all_prod();
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 16200
#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>;
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
    
    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
    
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
    
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(void) {
    int x, y; cin >> x >> y;
    UnionFind uf(13);
    uf.merge(1,3); uf.merge(3,5); uf.merge(5,7); uf.merge(7,8); uf.merge(8,10); uf.merge(10,12); uf.merge(12,1);
    uf.merge(4,6); uf.merge(9,11); uf.merge(11,4);
    if(uf.issame(x, y)) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int x,y,r=1;
scanf("%d%d",&x,&y);
if(x>=y){
while(r!=0){
r=x%y;
x=y;
y=r;
}
printf("%d\n",x);
}
else if(x<y){
while(r!=0){
r=y%x;
y=x;
x=r;
}
printf("%d\n",y);
}
return 0;
}



Measured memory_bytes: 2120
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

struct node{
	int key;
	node *pa,*le,*ri;
};

node *root,*NIL;

void Insert(int k)
{
	node *y=NIL;
	node *x=root;
	node *z;
	z=(node *)malloc(sizeof(node));
	z->le=NIL;
	z->ri=NIL;
	z->key=k;
	while(x!=NIL){
		y=x;
		if(z->key < x->key){
			x=x->le;
		}else{
			x=x->ri;
		}
	} 
	z->pa=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key < y->key){
			y->le=z;
		}else{
			y->ri=z;
		}
	}
}

node* getMin(node *x)
{
	while(x->le!=NIL){
		x=x->le;
	}
	return x;
}

node* getNext(node *x)
{
	node *y;
	if(x->ri!=NIL){
		return getMin(x->ri);
	}
	y=x->pa;
	while(y!=NIL&&x==y->ri){
		x=y;
		y=y->pa;
	}
	return y;
}

void deleteNode(node *z)
{
	node *y,*x;
	if(z->le==NIL||z->ri==NIL){
		y=z;
	}else{
		y=getNext(z);
	}
	
	if(y->le!=NIL){
		x=y->le;
	}else{
		x=y->ri;
	}
	
	if(x!=NIL){
		x->pa=y->pa;
	}
	
	if(y->pa==NIL){
		root=x;
	}else if(y==y->pa->le){
		y->pa->le=x;
	}else{
		y->pa->ri=x;
	}
	
	if(y!=z){
		z->key=y->key;
	}
}

node* Find(node *x,int k)
{
	while(x!=NIL&&k!=x->key){
		if(k< x->key){
			x=x->le;
		}else{
			x=x->ri;
		}
	}
	return x;
}

void inorder(node *u)
{
	if(u==NIL)return;
	inorder(u->le);
	cout<<' '<<u->key;
	inorder(u->ri);
}

void preorder(node *u)
{
	if(u==NIL)return;
	cout<<' '<<u->key;
	preorder(u->le);
	preorder(u->ri);
}

int main()
{
	int n;
	cin>>n;
	string str;
	int k;
	while(n--){
		cin>>str;
		if(str[0]=='i'){
			cin>>k;
			Insert(k);
		}else if(str[0]=='f'){
			cin>>k;
			node *t=Find(root,k);
			if(t!=NIL){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}else if(str[0]=='p'){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}else if(str[0]=='d'){
			cin>>k;
			node *t=Find(root,k);
			deleteNode(t);
		}
	}
	return 0;	
}


Measured memory_bytes: 21780
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    map<ll, ll> ma;
    rep(i, 0, n){
        ma[a[i]]++;
    }
    if(n%2 == 0){
        for(auto it : ma){
            if(it.se != 2){
                co(0);
                return 0;
            }
        }
        // 2^(n/2)
        ll ans = 1;
        rep(i, 0, n/2){
            ans *= 2;
            ans %= MOD;
        }
        co(ans);
    }else{
        for(auto it : ma){
            if((it.fi == 0 && it.se != 1)||(it.fi != 0 && it.se != 2)){
                co(0);
                return 0;
            }
        }
        ll ans = 1;
        rep(i, 0, n/2){
            ans *= 2;
            ans %= MOD;
        }
        co(ans);
    }

    return 0;
}


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

const int inf = 1e9 + 13;

signed main () {
    int n, m, r;
    cin >> n >> m >> r;
    vector < vector < int > > floyd(n + 1, vector < int > (n + 1, inf));
    vector < int > order(r);
    for (int i = 0; i < r; ++i)
        cin >> order[i];
    sort(order.begin(), order.end());
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        floyd[u][v] = min(w, floyd[u][v]); 
        floyd[v][u] = min(w, floyd[v][u]);
    }
    for (int i = 0; i <= n; ++i)
        floyd[i][i] = 0;
    for (int k = 0; k <= n; ++k) {
        for (int u = 0; u <= n; ++u) {
            for (int v = 0; v <= n; ++v)
                floyd[u][v] = min(floyd[u][v], floyd[u][k] + floyd[k][v]);
        }
    }
    int ans = inf;
    do {
        int res = 0;
        for (int i = 0; i < r - 1; ++i)
            res += floyd[order[i]][order[i + 1]];
        ans = min(res, ans);
    } while (next_permutation(order.begin(), order.end()));
    cout << ans << '\n';
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=1<<9;
const int mod=1000000007;
int s[N][N];
int dp[N][N];
int l[N],r[N];
void upd(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int sum(int k,int a,int b){int ret=s[k][b]-s[k][a-1]+mod;ret%=mod;return ret;}
int main()
{IOS;
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;++i)
		cin>>l[i];
	for(int i=1;i<=n;++i)
		cin>>r[i];
	for(int i=1;i<N;++i)
		s[0][i]=1;
	for(int i=1;i<N;++i)
		for(int j=1;j<N;++j)
			s[i][j]=1LL*s[i-1][j]*j%mod;
	for(int i=0;i<N;++i)
		for(int j=1;j<N;++j)
			(s[i][j]+=s[i][j-1])%=mod;
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=k;++j)
			for(int o=0;o<=j;++o)
				upd(dp[i][j],1LL*dp[i-1][j-o]*sum(o,l[i],r[i])%mod);
	cout<<dp[n][k]<<Endl;
}

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

ll N, A, B, C, D, d;

int main() {
	cin >> N >> A >> B >> C >> D;
	N--;
	d = abs(A-B);

	for(int x = 0; x <= N; x++) {
		ll s = C*x - D*(N-x), e = D*x - C*(N-x);
		if(s <= d && d <= e) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i,n;
  int p[100];
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &p[i]);
  }
  int count=0;
  for(i=0;i<n;i++){
    if(p[i]!=i+1) count++;
  }
  if(count==0 || count==2) printf("YES\n");  
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<char> > g(100,vector<char>(100,'.'));
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        cin>>g[i][j];
      }
    }
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        int cnt=0;
        for(int k=-1;k<=1;k++){
          for(int l=-1;l<=1;l++){
            if((k!=0||l!=0) && g[i+k][j+l]=='#'){
              cnt++;
            }
          }
        }
        if(g[i][j]=='.'){
          g[i][j]=char(cnt+'0');
        }
      }
    }
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        cout<<g[i][j];
      }
      cout<<'\n';
    }
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    string a, b, c;
    cin >> a>>b>>c;
    
    cout << "A" << b[0] << "C" << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <memory.h>
#include <queue>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define ll long long
#define N 3002
int add(int x, int y, int p) {
	int ret = (x + y);
	if (ret >= p) {
		ret -= p;
	}
	else if (ret < 0) {
		ret += p;
	}
	return ret;
}
int mul(int x, int y, int p) {
	int ret = (ll)x*y%p;
	if (ret < 0) {
		ret += p;
	}
	return ret;
}
int mypow(int x, int c, int p) {
	int ret = 1;
	while (c > 0) {
		if (c & 1) {
			ret = mul(ret, x, p);
		}
		x = mul(x, x, p);
		c /= 2;
	}
	return ret;
}
int a[N][N];
int combi[N][N];
int val[N], fac[N], invFac[N];
void init(int p) {
	
	for (int i = 0; i < N; ++i) {
		combi[i][i] = combi[i][0] = 1;
		if (i == 0) {
			fac[i] = 1;
		}
		else {
			fac[i] = mul(fac[i - 1], i, p);
		}
		invFac[i] = mypow(fac[i], p - 2, p);
		for (int j = 1; j < i; ++j) {
			combi[i][j] = add(combi[i - 1][j], combi[i - 1][j - 1], p);
		}
	}
}
int ret[N], tmp[2][N];
void solve() {
	int p; scanf("%d", &p);
	init(p);
	for (int i = 0; i <= p - 1; ++i) {
		scanf("%d", &a[0][i]);
	}
	for (int i = 1; i <= p - 1; ++i) {
		int sz = p - 1 - i;
		for (int j = 0; j <= sz; ++j) {
			a[i][j] = add(a[i - 1][j + 1] ,- a[i - 1][j], p);
		}
	}
	int bit = 0;
	for (int i = 1; i <= p - 1; ++i) {
		int nbit = bit ^ 1;
		if (i == 1) {
			tmp[nbit][1] = 1, tmp[nbit][0] = 0;
		}
		else {
			memset(tmp[nbit], 0, sizeof(tmp[nbit]));
			for (int j = 0; j < i; ++j) {
				tmp[nbit][j + 1] = add(tmp[nbit][j + 1], tmp[bit][j],p);
				tmp[nbit][j] = add(tmp[nbit][j], mul(tmp[bit][j], -i+1, p), p);
			}
		}
		bit = nbit;
		int m = mul(a[i][0], invFac[i], p);

		for (int j = 0; j <= i; ++j) {
			ret[j] = add(ret[j], mul(tmp[bit][j], m, p), p);
		}
	}
	ret[0] = add(ret[0], a[0][0], p);
	for (int i = 0; i < p; ++i) {
		printf("%d ", ret[i]);
	}
	putchar('\n');
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 68864
let n = read_int ()
let _ = for h = 1 to 3500 do
  for m = 1 to 3500 do let d = 4 * h * m - n * m - n * h in if d > 0 && n * h * m mod d = 0 then (Printf.printf "%d %d %d\n" h m @@ n * h * m / d; exit 0) done done

Measured memory_bytes: 384
n = gets.to_i

if n == 0
    puts 0
    exit
end

ans = []
c = 0
i = -2
loop do
    x, y = n.divmod(i)
    
    if c % i == y
        ans << 0
    else
        ans << 1
        c += i / -2
    end

    i *= -2
    if x == 0
        ans << 1 if c % i != y % i
        break
    end
end

ans.reverse!
j = ans.index(1)
puts ans[j..-1].join

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <cstring>
#include <utility>
using namespace std;

int main(){
  char s1[100][11];
  char s2[100][11];

  int m, n;
  cin >> n;
  for (int i = 0; i < n; i++){
    scanf("%s", s1[i]);
  }
  cin >> m;
  for (int i = 0; i < m; i++){
    scanf("%s", s2[i]);
  }

  int ma = 0;
  for (int i = 0; i < n; i++){
    int cnt = 0;
    for (int j = 0; j < n; j++){
      if (strcmp(s1[i], s1[j]) == 0) cnt++;
    }
    for (int j = 0; j < m; j++){
      if (strcmp(s1[i], s2[j]) == 0) cnt--;
    }
    ma = max(ma, cnt);
  }

  printf("%d\n", ma);
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int X,A;
        X = scan.nextInt();
        A = scan.nextInt();
        if(X<A){
            System.out.println("0");
        }else{
            System.out.println("10");
        }
    }
}

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

/* 
 * So basically you want to find the fastest way to perform the operations 
 * Before reading this solution 
 * You should understand how deque works (Google it :D)
 * If you understand how a deque works you should understand this solution 
 * So first thing you should notice is that we don't really need to reverse the whole string 
 * All we need to know is where the front is currently and where the back is currently 
 * So in my code I have a variable swapped 
 * If swapped is true you know that the end has become the front and the front has become the end 
 * So if swapped is true and you get an end operation then it should go to the front and vice-versa 
 * And if swapped isn't true then you should perform the operations as usual 
 * You can look at the code to understand it better 
 * Solution runs in O(Q log n) time
 * Hope this helps!
 */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  deque<char> deck;
  for (const char& ch : s) 
    deck.push_back(ch);
  int ops;
  cin >> ops;
  bool swapped = false;
  while (ops--) {
    int op;
    cin >> op;
    if (op == 1) swapped = !swapped; // this is just a fancy way of changing the value of swapped (true -> false) and (false -> true)
    else {
      int f;
      char ch;
      cin >> f >> ch;
      if (f == 1) {
        if (swapped)
          deck.push_back(ch); // if swapped this should now go to the back instead of the front 
        else
          deck.push_front(ch); // if not swapped this should go to the front as usual
      } else {
        if (swapped)
          deck.push_front(ch); // if swapped this should now go to the front instead of the back
        else 
          deck.push_back(ch); // if not swapped this should go to the back as usual 
      }
    }
  }
  if (swapped)  // if swapped you need to print the result in reverse
    reverse(deck.begin(), deck.end());
  for (char& ch : deck)
    cout << ch;
  cout << '\n';
  return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> P;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i += 2) {
        cout << s.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 512
#pragma optimization_level 3
#include <iostream>
#include <algorithm>
using namespace std;

int N;
int A[100010];

inline bool u(int x, int y) {
  if (A[x] <= y) return true;
  return !u(x, y+1);
}
inline bool r(int x, int y) {
  if (x >= N || A[x] <= y) return true;
  return !r(x+1, y);
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) cin >> A[i];
  sort(A, A+N, greater<int>());
  int i = 0;
  while (i < N-1 && A[i+1] > i+1) i++;
  cout << (!(r(i+1,i) && u(i,i+1)) ? "First\n" : "Second\n");
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
using namespace std;


int32_t main()
{
    int N;
    cin >> N;
    int A[N],B[N],C[N];
    for(int i = 0 ; i < N ; i++)
        cin >> A[i] >> B[i] >> C[i];
    int dp[N][3];
    memset(dp,0,sizeof(dp));
    dp[0][0] = A[0];
    dp[0][1] = B[0];
    dp[0][2] = C[0];
    
    for(int i = 1 ; i < N ; i++)
    {
        for(int j = 0 ; j < 3 ; j++)
        {
            if(j == 0)
                dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + A[i];
            else if(j == 1)
                dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + B[i];
            else dp[i][j] = max(dp[i-1][0], dp[i-1][1]) + C[i];
        }
    }
    
    int ans =max({dp[N-1][0], dp[N-1][1], dp[N-1][2]});
    cout << ans;
    return 0;
}


Measured memory_bytes: 8228
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    int n;
    cin>>str>>n;
    int a, b;
    string p, command;
    for(int i=0; i<n; i++) {
        cin>>command>>a>>b;
        if(command=="print") {
            cout<<str.substr(a, b-a+1)<<'\n';
        }else if(command=="reverse") {
            for(; a<b; a++, b--) {
                swap(str[a], str[b]);
            }
        }else if(command=="replace") {
            cin>>p;
            str.replace(a, b-a+1, p);
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;

unsigned int temp;
int n;
unsigned long long K;

unsigned int adj[51][51];

unsigned int c[51][51], curr[51][51];

void mult (const unsigned int a[51][51], const unsigned int b[51][51]) { // c = a * b (matrices)
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			c[i][j] = 0;
			for (int k = 0; k < n; k++) {
				temp = int((1ll * (a[i][k]) * (b[k][j])) % MOD);
				c[i][j] += temp;
				c[i][j] %= MOD;
			}
		}
	}
}

void copyM (unsigned int A[51][51], const unsigned int B[51][51]) { // by reference
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			A[i][j] = B[i][j];
}

void solve () {
	int digits = int(floor(log2(K))) + 1; // number of digits in K
	for (int i = 0; i < n; i++) { // identity matrix
		for (int j = 0; j < n; j++)
			curr[i][j] = 0;
		curr[i][i] = 1;
	}
	//copyM(c, adj);	
	for (int i = 0; i < digits; i++) {
		if ((1ll << i) & K) {
		//	cout << i << "th bit is on in K\n";
			mult(curr, adj);
			copyM(curr, c);
			
			/*
			for (int j = 0; j < n; j++) { // identity matrix
				for (int k = 0; k < n; k++)
					cout << curr[j][k];
				cout << "\n";
			}
			*/				
		}
		mult(adj, adj);
		copyM(adj, c);
		/*
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++)
				cout << c[j][k] << " ";
			cout << "\n";
		}
		*/
	} // curr/c has final answer
	unsigned long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans += curr[i][j];
			ans %= MOD;
		}
	}
	cout << ans << "\n";
	return;
}

int main () {
	cin >> n >> K;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> adj[i][j];
	solve();
	return 0;
}

Measured memory_bytes: 512
N = int(input())

def sumOfDigits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n //= 10
    return sum
ans = 10**5
for A in range(1,N//2+1):
    B = N - A
    ans = min(ans, sumOfDigits(A) + sumOfDigits(B))

print(ans)

Measured memory_bytes: 40812
/*
 *created by Kraken on 19-04-2020 at 17:29
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    FastReader sc = new FastReader();
    int n = sc.nextInt();
    int[] res = new int[n + 1];
    for (int i = 0; i < n - 1; i++) {
      int a = sc.nextInt();
      res[a]++;
    }
    for (int i = 1; i <= n; i++)
      System.out.println(res[i]);
  }

  static class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      }
      catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


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

using ll = long long;
using pll = pair<ll, ll>;
 
constexpr ll M = 1e9+7;

pll expression(string const& s, int& p);
pll term(string const& s, int& p);
pll factor(string const& s, int& p);
void variable(string const& s, int& p);
 
pll expression(string const& s, int& p) {
    pll res = term(s, p);
    while(p < s.size() && s[p] == '|') {
        auto v2 = term(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * (v2.first + v2.second) + v2.first * (t1 + t2) - t1 * v2.first;
        res.second = t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll term(string const& s, int& p) {
    pll res = factor(s, p);
    while(p < s.size() && s[p] == '&') {
        pll v2 = factor(s, ++p);
        ll t1 = res.first, t2 = res.second;
        res.first = t1 * v2.first;
        res.second = t2 * (v2.first + v2.second) + v2.second * (t1 + t2) - t2 * v2.second;
        res.first %= M;
        res.second %= M;
    }
    return res;
}
 
pll factor(string const& s, int& p) {
    if(s[p] == '~') {
        pll res = factor(s, ++p);
        swap(res.first, res.second);
        return res;
    }
    if(s[p] == '(') {
        auto res = expression(s, ++p);
        p++;
        return res;
    }
    if(s[p] == 'x') {
        variable(s, p);
        return make_pair(1, 1);
    }
    assert("factor error" && false);
}
 
void variable(string const& s, int& p) {
    ++p;
    while(isdigit(s[p])) {
        ++p;
    }
}
 
ll eord, enew;
 
int main() {
    const int SIZE = 128 * 1024 * 1024;
    void* p = malloc(SIZE);
    enew = (ll)p + SIZE - 1;
    __asm__("mov %rsp, eord");
    __asm__("mov enew, %rsp");
    string s;
    cin >> s;
    int pos = 0;
    cout << expression(s, pos).first << endl;
    __asm__("mov eord, %rsp");
}


Measured memory_bytes: 58932
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#include <bitset>

#define mod 1e9+7
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    ll m=1000000;
    cin >> n;
    vector<ll> x(n);
    ll ans = 0;
    rep(i, n){
    	cin >> x[i];
        if(m>x[i]) ans++;
        m=min(m,x[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792