akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QMIN        (1)
#define QMAX        (150)
#define QMAX_LENGTH (3)
#define QVALUE      (20)
#define MIN         (1)
#define MAX         (1000)
#define VALUE       (100)

typedef enum
{
    ERROR  =-1,
    SUCCESS= 0
} ResultType;

static ResultType checkRangeOfNum(int, int, int);
static ResultType getString(char *str, int nMax);
static void initLCS(int M, int N);
static int calcLCS(int M, int N);

int LCS[MAX + 1][MAX + 1]; 
char X[MAX + 1];
char Y[MAX + 1];

int main(void)
{
    int i;
    char q[QMAX_LENGTH + 1];
    ResultType eResult;

    /* input line 1 */
    eResult = getString(q, QMAX_LENGTH);
    eResult = checkRangeOfNum(atoi(q), QMIN, QMAX);
    if(eResult < SUCCESS)
    {
        printf("Err: input line 1 is invalid.\n");
        return eResult;
    }

    for(i=0; i<atoi(q); i++)
    {
        /* input line 2q */
        eResult = getString(X, MAX);
        if(eResult < SUCCESS)
        {
            printf("Err: input line %d is invalid.\n", 2 * atoi(q));
            return eResult;
        }

        /* input line 2q + 1 */
        eResult = getString(Y, MAX);
        if(eResult < SUCCESS)
        {
           printf("Err: input line %d is invalid.\n", 2 * atoi(q) + 1);
           return eResult;
        }

        /* check constraint */
        if((strlen(X) > VALUE) || (strlen(Y) > VALUE))
        {
            eResult = checkRangeOfNum(atoi(q), QMIN, QVALUE);
            if(eResult < SUCCESS)
            {
                printf("Err: input line 1 is invalid.\n");
                return eResult;
            }
        }

        /* calcurate LCS */
        printf("%d\n", calcLCS(strlen(X),strlen(Y)));
    }

    return SUCCESS;
}

static ResultType checkRangeOfNum(int n, int nMin, int nMax)
{
    if((n < nMin) || (nMax < n))
    {
        return ERROR;
    }
    return SUCCESS;
}

static ResultType getString(char *str, int nMax)
{
    int i = 0;
    int ch;

    while((ch = getchar()) != EOF) 
    {
        if(ch == '\n')
        {
            break;
        }
        else
        {
            str[i++] = ch;
            if(i > nMax)
            {
                return ERROR;
            }
        }
    }

    str[i++] = '\0';
    return SUCCESS;
}

static void initLCS(int M, int N)
{
    int i, j;

    for(i=0; i<=M; i++)
    {
        LCS[i][0] = 0;
    }
    for(j=0; j<=N; j++)
    {
        LCS[0][j] = 0;
    }
}

static int calcLCS(int M, int N)
{
    int i, j;

    /* initialize LCS */
    initLCS(M,N);

    for(i=1; i<=M; i++)
    {
        for(j=1; j<=N; j++)
        {
            if(X[i-1]==Y[j-1])
            {
                LCS[i][j] = LCS[i-1][j-1] + 1;
            }
            else
            {
                if(LCS[i-1][j] > LCS[i][j-1] )
                {
                    LCS[i][j] = LCS[i-1][j];
                }
                else
                {
                    LCS[i][j] = LCS[i][j-1];
                }
            }
        }
    }

    return LCS[M][N];
}


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);
vector<vector<ll>> seg;
ll N;
string s;

void update(int b, char c){
  seg[b + N - 1][s[b] - 'a']--;
  seg[b + N - 1][c - 'a']++;
  s[b] = c;
  b = b + N - 1;
  while (b > 0){
    b = (b - 1) / 2;
    for (int i = 0; i < 26; i++){
      seg[b][i] = seg[b * 2 + 1][i] | seg[b * 2 + 2][i];
    }
  }
}

vector<ll> query(int a, int b, int l, int r, int k){
  if (r <= a || b <= l) return vector<ll>(26, 0);
  if (a <= l && r <= b){
    return seg[k]; // ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
  }
  else {
    // 一部だけ範囲が被る場合は左右の子に委託する
    vector<ll> c1 = query(a, b, l, (l + r) / 2, 2 * k + 1); // 左の子に値を聞く
    vector<ll> c2 = query(a, b, (l + r) / 2, r, 2 * k + 2); // 右の子に値を聞く
    vector<ll> c3(26, 0);
    for (int i = 0; i < 26; i++){
      c3[i] = c1[i] | c2[i];
    }
    return c3; // 左右の子の値の min を取る
  }
}

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

  N = 1;
  while (N < n)
    N *= 2;


  seg = vector<vector<ll>>(2*N - 1, vector<ll>(26, 0));

  for (int i = 0; i < n; i++){
    seg[i + N - 1][s[i] - 'a']++;
    update(i, s[i]);
  }


  int q; cin >> q;
  int a, b, l, r;
  char c;
  for (int i = 0; i < q; i++){
    cin >> a;
    if (a == 1){
      cin >> b >> c;
      b--;
      update(b, c);
    }
    else {
      cin >> l >> r;
      l--; r--;
      vector<ll> d = query(l, r + 1, 0, N, 0);
      int ret = 0;
      for (int j = 0; j < 26; j++){
        if (d[j] > 0)
          ret++;
      }
      cout << ret << endl;
    }
  }

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int x, y;
  cin >> x >> y;

  cout << x + y / 2 << "\n";
  return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ac_list = [0] * n
wa_list = [0] * n
for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        ac_list[p] = 1
    if s == "WA":
        if ac_list[p] == 0:
            wa_list[p] += 1
for k in range(n):
    if ac_list[k] == 0:
        wa_list[k] = 0
print(sum(ac_list), sum(wa_list))

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

int main(){
  int n, m;
  cin >> n >> m;
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  
  int x[100005] = {0};
  int diff[100005]={0};
  
  for(int i = 0; i < m; i++){
    cin >> x[i];
  }
  sort(x,x+m);
  for(int i = 0; i < m - 1; i++){
    diff[i] = x[i+1] - x[i];
  }
  sort(diff,diff+m-1);

  
  long long int ans = 0;
  for(int i = 0;i < m - n; i++){
    ans += diff[i];
  }
  cout << ans << endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	
	char[] target;
	int cnt=0;
	
	void check(char[] o){
		int space, work;
		boolean flag;
		
		for(int j=0; j<o.length; j++){
			flag=true;
			if(target[0]==o[j]){//??????????????????????????£??????
				
				for(int k=j+1; k<o.length; k++){
					if(target[1]==o[k]){//??????????????????????????£??????
						
						space = k-j;
						if(o.length<=space*(target.length-1)+j) break;//??????????????\???????????¨????????£??????
						work = k;
						
						for(int l=2; l<target.length; l++){
							work+=space;
							if(o[work]!=target[l]) break;//??????????????\???????????£??????
							if(l==target.length-1){
								cnt++;
								flag = false;//???????????£???????????§?¬?????????????
							}
						}
						if(flag==false) break;
					}
				}
			}
			if(flag==false) break;
		}
	}
	
	void doIt(){
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		m.target = sc.next().toCharArray();
		char[] old;
		
		for(int i=0; i<n; i++){
			old = sc.next().toCharArray();
			m.check(old);
		}
		
		System.out.println(m.cnt);
	}
	
	public static void main(String[] args){
		new Main().doIt();
	}
	
}

Measured memory_bytes: 27488
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>

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

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

vector< vector<int> > memo;

int gcd(int a, int b, int c) {
	int min_num = (a > b) ? b : a;
	if (min_num > c) min_num = c;
	while (min_num != 1) {
		if (a % min_num == 0 && b % min_num == 0 && c % min_num == 0) break;
		min_num--;
	}
	return min_num;
}

int gcd(int a, int b) {
	int m = (a < b) ? a : b;
	while (m != 1) {
		if (a % m == 0 && b % m == 0)break;
		m--;
	}
	return m;
}



int main() {
	string s;
	cin >> s;
	if (s[1] == 'B') cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
}


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

int main() {
  string a,b; cin>>a>>b;
  string ans="No";
  REP(i,1000){
    if(i*i==stoi(a+b)) ans="Yes";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
div = [i for i in range(a,b+1) if c%i==0]
print(len(div))

'''??????????§£?????¨??????.
a,b,c = map(int,input().split())
div = 0
for i in range(a,b+1):
    if c%i == 0:
        div += 1
print(div)
'''

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int a;
    string s;
    std::cin >> a;
    std::cin >> s;
    if(a<3200)std::cout << "red" << std::endl;
    else std::cout << s << std::endl;
}


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

long long int modPow(long long int a, long long int n){//繰り返し自乗法(a^n mod p)。計算量 O(logN)
    long long int p = pow(10, 9) + 7;//任意のp(素数) modのやつで使える 
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a % p;
    }
    if (n % 2 == 1){ 
        return (a * modPow(a, n - 1)) % p;
    }      
    long long t = modPow(a, n / 2);
    return (t * t) % p;
}

int main(){
    long long int n, d;
    cin >> n >> d;
    d = d*d;
    long long int tmpx, tmpy;
    long long int count = 0;
    for(int i = 0; i < n; i++){
        cin >> tmpx >> tmpy;
        if(d >= tmpx*tmpx + tmpy*tmpy){
            count++;
        }
    }

    cout << count << endl;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	int A[1000000];
	int B[1000000];
	A[0]=B[0]=0;
	for(int i = 1; i<1000000;i++){
		A[i] = i;
		B[i] =i;
		for(int j=1;;j++){
			int t =j*(j+1)*(j+2)/6;
			if(t > i)
				break;
			A[i]=min(A[i],A[i-t]+1);
			if(t%2==1)
				B[i]=min(B[i],B[i-t]+1);
		}
	}
	while(cin>>n,n){
		if(n==0)
			break;
		cout <<A[n]<<" "<<B[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 8972
#include<bits/stdc++.h>
using namespace std;
#define null NULL
#define S 1000005
typedef long long int lli;
#define newline cout<<"\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)

lli dp[300][S];

void ans(lli *v,lli *wt,lli n,lli w)
{
    lli i,j;
    for(i=0;i<=n;i++)
    dp[i][0]=0;
    for(i=0;i<=w;i++)
    dp[0][i]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(wt[i-1]<=j)
            dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            else  
            dp[i][j]=dp[i-1][j];
        }
    }

}

int main()
{
lli n,w,i;
cin>>n>>w;
lli wt[n],v[n];
    for(i=0;i<n;i++)
    cin>>wt[i]>>v[i];
    ans(v,wt,n,w);
    cout<<dp[n][w];
  
}


Measured memory_bytes: 289792
#include<stdio.h>
#include<stdlib.h>
int main(){
  int m,n,k,sum,M;
  scanf("%d %d",&m,&n);
  M=0;
  for(int i=0;i<m;i++){
    sum=0;
    for(int j=0;j<n;j++){
      scanf("%d",&k);
      sum+=k;
    }
    if(M<sum){
      M=sum;
    }
  }
  printf("%d\n",M);
  return 0;
}



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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&a==c){
    cout <<"No"<<endl;
  }
  else if(a!=b&&b!=c&&c!=a){
    cout <<"No"<<endl;
  }
  else {
    cout <<"Yes"<<endl;
  }
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  map<string,int> s;
  //map<string,int> s{};
  string res;
  
  cin >> n;
  
  for (int i = 0; i <= n; i++){
    cin >> res;
    if(s.count(res) == 0){
      s.insert(make_pair(res,1));
    }else{
      s[res] = s[res] + 1;
    }
  }
  int ans = s.size();
  cout << ans << endl;
 }

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

using namespace std;


const long long mod = 1e9 + 7 ;
const int MAX = 1010 ;
long long dp[MAX][MAX] ;
int n , m ;
char arr[MAX][MAX];

bool check(int x , int y)
{
    return (x >= 0 && x < n && y >= 0 && y < m && arr[x][y] == '.') ;
}

long long solve(int x , int y)
{
    if(x == n-1 && y == m-1)
        return 1ll ;
    long long &ret = dp[x][y] ;
    if(ret != -1)
        return ret ;
    ret = 0;
    if(check(x+1,y))
        ret = (ret + solve(x+1 , y)) % mod;
    if(check(x , y+1))
        ret = (ret + solve(x , y+1)) % mod;
    return ret ;
}

int main()
{
    memset(dp , -1 , sizeof(dp));
    cin>>n>>m ;
    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < m ; ++j)
            cin>>arr[i][j] ;
    return cout<<solve(0 , 0)<<"\n" , 0 ;
}


Measured memory_bytes: 9344
#
# abcxxx b
#
import unittest
from io import StringIO
import sys


def input():
    return sys.stdin.readline().rstrip()


def resolve():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))

    ans = 1
    tmpt = float('inf')
    for i in range(N):
        tmp = abs(T-H[i]*0.006-A)
        if tmp == min(tmp, tmpt):
            tmpt = tmp
            ans = i+1
    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
12 5
1000 2000"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
21 -11
81234 94124 52141"""
        output = """3"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 5988
a, b, h, m = map(int, input().split())

#長針は60分で一周、短針は720分で一周
#長針は1分で6、短針は1分で0.5 合わせて5.5度離れる

min = (60 * h) + m
ang0 = (min * 5.5) % 360

if ang0 <= 180:
    ang = ang0
else:
    ang = 360 - ang0

import math
cos_ang = math.cos(math.radians(ang))

x = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos_ang))

print(x)


Measured memory_bytes: 9308
#include<iostream>
 
int main(void){
  int L, R, d;
  std::cin >> L >> R >> d;
  int counter = 0;
  int i = L;
  while(true){if(i >= L && !(i % d)) break; else i++;}
  for(; i <= R; i += d)
    if(i % d == 0) counter++;
  std::cout << counter << std::endl;
  return 0;
}

Measured memory_bytes: 3616
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] # 2 5 4 3 nsew
        self.nowkey = 0
        self.c_key = 5
        self.nowval = li[0]
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 
    def operate(self, s):
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = self.c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = self.c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = self.c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = self.c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]
        self.c_key = abs(5 - self.nowkey)
        self.distvals = []
        tmp = self.nextkeys + [self.nowkey,self.c_key]
        for t in tmp:
            self.distvals.append(self.vals[t]) 

a = list(map(int, input().split()))
b = list(map(int, input().split()))
diceA = DICE(li = a)
diceB = DICE(li = b)
s = 'NNNNWNNNNWNNNNWNNNN'+'NEEEENEEEENEEEENEEEE'+'ENWWWWNWWWWNWWWWNWWWWW'
flag = False
for i in s:
    diceA.operate(i)
    if diceA.distvals == diceB.distvals:
        print('Yes')
        flag = True
        break
if flag == False:
    print('No')



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(n<26){
        vector<int> a(26);
        rep(i,n) a[s[i]-'a']++;
        cout<<s;
        rep(i,26){
            if(!a[i]){
                cout<<(char)(i+'a')<<endl;
                return 0;
            }
        }
    }

    vector<int> a(26);
    reverse(s.begin(),s.end());
    for(int i=0; i<n-1; i++){
        if(s[i]-'a'>s[i+1]-'a'){
            a[s[i]-'a']++;
            rep(j,26){
                if(a[j] && (s[i+1]-'a')<j){
                    for(int k=25; k>i+1; k--){
                        cout<<s[k];
                    }
                    cout<<(char)(j+'a')<<endl;
                    return 0;
                }
            }
        }else{
            a[s[i]-'a']++;
        }
    }
    cout<<"-1"<<endl;
}

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

long long int lcm(long long int x, long long int y)
{
    if (x == 0)
        return y;
    if (y == 0)
        return x;
    long long int r = 0, a, b;
    a = (x > y) ? x : y; // a is greater number
    b = (x < y) ? x : y; // b is smaller number
    r = b;
    while (a % b != 0)
    {
        r = a % b;
        a = b;
        b = r;
    }
    return (x * y) / r;
}

int ans1(int arr[],int n)
{
    int dp[n+1]={0};
    dp[1]=0;
    dp[2]=abs(arr[1]-arr[0]);
    // dp[1]=min(abs(arr[2]-arr[1])+dp[1],abs(arr[2]-arr[0]));
    for (int i = 3; i < n+1     ; i++)
    {
        dp[i] = min(dp[i - 2] + abs(arr[i-1] - arr[i - 3]), dp[i - 1] + abs(arr[i-1] - arr[i - 2]));
    }
    return dp[n];
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {

            cin>>arr[i];
    }
    cout<<ans1(arr,n);
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  double A, B, H, M, ans = 0.0, len, pi = M_PI  ;
  cin >> A >> B >> H >> M ;
  double ang1 = ( (H + M / 60) / 6 ) * pi ;
  double ang2 = ( M / 30) * pi ;
  double ang = ang1 - ang2 ;
  if(ang < 0.0) ang = 0.0 - ang ;
  if(ang >= pi) ang = (2 * pi) - ang ;
  ans += A * A + B * B ;
  ans -= 2 * A * B * cos(ang) ;
  ans = sqrt(ans) ;
  cout << fixed ;
  cout << setprecision(15) << ans << endl ;
  return 0 ;
}  

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

using namespace std;

long long Webkaru(long long a, long long b) {
	long long x =a * b;
	if (a < b) {
		long long tmp = a;
		a = b;
		b = tmp;
	}
	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return x / b;
}

int main()
{
	long long N, M;
	string S, T;

	cin >> N >> M;
	cin >> S;
	cin >> T;

	long long L = Webkaru(N, M);

	int Nup, Mup;
	int Snum, Tnum;
	
	Nup = L / M;
	Mup = L / N;

	Snum = N - Nup;
	Tnum = M - Mup;
	while (S[Snum] == T[Tnum]) {
		Snum -= Nup;
		Tnum -= Mup;
		if (Snum <= 0) {
			cout << L << endl;
			return 0;
		}

	}

	cout << -1 << endl;
	return 0;

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N);
    rep(i, N) cin >> p[i];
    sort(p.begin(), p.end());
    ll ans = 0;
    rep(i, K) ans += p[i];
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int MAX_N = 1000;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  char hina[MAX_N];
  string str = "Three";
  for (int i = 0; i < n; i++) {
    cin >> hina[i];
    if (hina[i] == 'Y') {
      str = "Four";
    }
  }

  cout << str << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;int M,l;main(){string s,t,u;map<string,int>m;for(;cin>>u;t=t.size()<u.size()?u:t)if(++m[u]>M)M=m[u],s=u;cout<<s<<' '<<t<<endl;}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//const int mod=1e9+7;
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
void ckmax(int &x,int y){
	if (x<y)
		x=y;
}
void ckmin(int &x,int y){
	if (x>y)
		x=y;
}
const int N=300005;
int n;
int v[N],w[N];
vector <pii> gao(vector <pii> v){
	vector <pii> res(1,mp(0,0));
	for (auto i : v){
		vector <pii> now;
		for (auto j : res)
			now.pb(mp(i.fi+j.fi,i.se+j.se));
		vector <pii> tmp;
		while (!now.empty()&&!res.empty())
			if (now.back()>res.back())
				tmp.pb(now.back()),now.pop_back();
			else
				tmp.pb(res.back()),res.pop_back();
		while (!now.empty())
			tmp.pb(now.back()),now.pop_back();
		while (!res.empty())
			tmp.pb(res.back()),res.pop_back();
		reverse(tmp.begin(),tmp.end());
		swap(res,tmp);
	}
	return res;
}
void solve(){
	int x=read(),L=read();
	vector <pii> vv;
	while (x){
		vv.pb(mp(v[x],w[x]));
		x/=2;
	}
	vector <pii> va=gao(vector <pii>(vv.begin(),vv.begin()+vv.size()/2));
	vector <pii> vb=gao(vector <pii>(vv.begin()+vv.size()/2,vv.end()));
	For(i,1,(int)va.size()-1)
		ckmax(va[i].se,va[i-1].se);
	For(i,1,(int)vb.size()-1)
		ckmax(vb[i].se,vb[i-1].se);
	int ans=0;
	For(i,0,(int)va.size()-1){
		while (!vb.empty()&&va[i].fi+vb.back().fi>L)
			vb.pop_back();
		if (vb.empty())
			break;
		ans=max(ans,va[i].se+vb.back().se);
	}
	printf("%d\n",ans);
}
int main(){
	n=read();
	For(i,1,n)
		w[i]=read(),v[i]=read();
	int Q=read();
	while (Q--)
		solve();
	return 0;
}

Measured memory_bytes: 5780
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{

    ll n;
    cin >> n;

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

    ll sum = 0;

    ll result = 0;

    for(int i= 0;i< n;i++){
        sum += d[i];
    }

    for(int i= 0;i< n;i++){
        result += (sum - d[i]) * d[i];
    }

    cout << result / 2 << endl;

    
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 10 20"""
        output = """30
50
90
170
330
650
1290
2570
5130
10250"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4 40 60"""
        output = """200
760
3000
11960
47800
191160
764600
3058360
12233400
48933560"""
        self.assertIO(input, output)

def resolve():
    (r,D,x)=(int(i) for i in input().split())
    for i in range(10):
        x=r*x-D
        print(x)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 5820
(loop with N = (read) for i from 2 to N 
      with lst = (loop repeat (read) collect (cons (read) (read)))
      and ht = (make-hash-table)
      and divisor = 998244353 and diff
      initially (setf (gethash 1 ht) 1)
      do (setf diff (loop for x in lst
                          sum (- (or (gethash (- i (car x)) ht) 0)
                                 (or (gethash (- i (cdr x) 1) ht) 0)))
               (gethash i ht) (mod (+ (gethash (1- i) ht) diff) divisor))
      finally (princ (mod diff divisor)))

Measured memory_bytes: 45872
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        String[] postal = s.split("-");
        if (postal.length == 2 && postal[0].length() == a && postal[1].length() == b) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<numeric>
#include<math.h>
using namespace std;
 
void sortarray(long a[], long b[], long n){
    //int n = av.size();
    long p[n], a2[n], b2[n];
    iota(p, p+n, 0);
    sort(p, p+n, [&](long ia, long ib) { return a[ia] < a[ib]; });
    for (int i = 0; i < n; i++) {
        a2[i] = a[p[i]];
        b2[i] = b[p[i]];
    }
    for (int i = 0; i < n; i++) {
        a[i] = a2[i];
        b[i] = b2[i];
    }
}
 
int main(){
    long N, D, A;
    cin >> N >> D >> A;
    long X[N],H[N];
    for(int i=0; i<N; i++){
        cin >> X[i] >> H[i];
    }
    sortarray(X,H,N);
    long count=0;
    long accdam[N+1];
    for(long i=0; i<N+1; i++) accdam[i]=0;
 
    for(long i=0; i<N; i++){
        accdam[i+1] = accdam[i];
        auto iter = lower_bound(&X[0],&X[i],X[i]-2*D);
        long idam = (long) distance( X, iter );
        long pdam = accdam[i] - accdam[idam];
        H[i] -= pdam;
        //cout << "i X[i] H[i] " << i << " " << X[i] << " " << H[i] << endl;
        if( H[i] <= 0 ) continue;
        long ndam = (long) ceil((double) H[i]/A);
        long dam = A * ndam;
        count += ndam;
        accdam[i+1] += dam;
        //cout << "i idam accdam[i] accdam[idam]" << i << " " << idam << " " << accdam[i] << " " << accdam[idam] << endl;
    }
 
    cout << count <<  endl;
 
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
bool arr[109];
 
int main() {
	
	memset(arr, false, sizeof arr);
	int x, n, xx;
	cin>>x>>n;
	for(int i = 0; i < n; i++) {
		cin>>xx;
		arr[xx] = true;
	}
	int ans = INT_MAX;
	for(int i = x; i <= 101; i++) {
		if(!arr[i]){
			ans = i;
			break;
		}
	}
	for(int i = x; i >= 0; i--) {
		if(!arr[i] && abs(x - i) <= abs(ans - x)){
			ans = i;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static bool[,] adja;
    //static int[] discoveryTime;
    //static int[] finishTime;
    //static int time = 0;
    static int[] distance;
    static Queue<int> queue = new Queue<int>();

    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        adja = new bool[n, n];
        distance = Enumerable.Repeat<int>(-1, n).ToArray();
        for (int i = 0; i < n; i++)
        {
            int[] inputs = Console.ReadLine().Split(' ')
                                        .Select(val => int.Parse(val))
                                        .ToArray();
            for (int j = 0; j < inputs[1]; j++)
            {
                adja[inputs[0] - 1, inputs[2 + j] - 1] = true;
            }
        }
        BreadthFirstDinstance();
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine("{0} {1}", i + 1, distance[i]);
        }
    }

    /*
    static void DepthFirstSearch(int nodeNum)
    {
        discoveryTime[nodeNum] = ++time;
        for (int i = 0; i < adja.GetLength(1); i++)
        {
            if(adja[nodeNum, i] && discoveryTime[i] == 0)
            {
                DepthFirstSearch(i);
            } 
        }
        finishTime[nodeNum] = ++time;
    }
    */

    static void BreadthFirstDinstance()
    {
        int d = 0;
        distance[0] = d;
        queue.Enqueue(0);
        while(queue.Count() > 0)
        {
            int nodeNum = queue.Dequeue();
            for (int i = 0; i < adja.GetLength(1); i++)
            {
                if(adja[nodeNum, i] && distance[i] == -1)
                {
                    queue.Enqueue(i);
                    distance[i] = distance[nodeNum] + 1;
                }
            }
        }
        
    }
}

Measured memory_bytes: 10556
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
  ll n, m;
  cin >> n >> m;
  ll total = 0;
  vector<ll> as = {};

  for (auto i = 0; i < m; i++)
  {
    ll a;
    cin >> a;
    total += a;
    as.push_back(a);
  }

  ll ans = total > n ? -1 : n - total;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3756
N, M = map(int, raw_input().split())

ab_dict = dict()
for i in range(N):
    a, b = map(int, raw_input().split())
    if a in ab_dict:
      ab_dict[a] += b
    else:
      ab_dict[a] = b

answer = 0
for a in sorted(ab_dict.keys()):
    b = ab_dict[a]
    if M <= b:
        answer += a * M
        break
    else:
        answer += a * b
        M -= b

print(answer)

Measured memory_bytes: 19132
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

void Solve(vector<ll> A, vector<ll> B, vector<ll> Q) {
    int n = Q.size();
    for (int i = 0; i < n; i++) {
        int la, ra, lb, rb;
        ra = lower_bound(A.begin(), A.end(), Q[i]) - A.begin();
        rb = lower_bound(B.begin(), B.end(), Q[i]) - B.begin();
        la = ra - 1;
        lb = rb - 1;
        ll res = 1e12;
        if (ra < A.size()) {
            if (rb < B.size()) {
                res = min(res, max(A[ra], B[rb]) - Q[i]);
            }
            if (lb >= 0) {
                res = min(res, A[ra]- B[lb] + min(Q[i] - B[lb], A[ra] - Q[i]));
            }
        }
        if (la >= 0) {
            if (rb < B.size()) {
                res = min(res, B[rb] - A[la] + min(Q[i] - A[la], B[rb] - Q[i]));
            }
            if (lb >= 0) {
                res = min(res, Q[i] - min(A[la], B[lb]));
            }
        }
        cout << res << endl;
    }
}


int main() {
    ios::sync_with_stdio(false);
    int n_a, n_b, n_q;
    cin >> n_a >> n_b >> n_q;
    vector<ll> A(n_a);
    vector<ll> B(n_b);
    vector<ll> Q(n_q);
    for (int i = 0; i < n_a; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < n_b; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < n_q; i++) {
        cin >> Q[i];
    }
    Solve(A, B, Q);



    return 0;
}


Measured memory_bytes: 6016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//https://atcoder.jp/contests/abc079/tasks/abc079_c

string abcd;
string OP;

static bool dfs(int sum, string op) {
    if (op.length() == 3) {
        OP = op;
        return sum == 7;
    }

    if (dfs(sum + (abcd[op.length()+1] - '0'), op+"+")) return true;
    if (dfs(sum - (abcd[op.length()+1] - '0'), op+"-")) return true;

    return false;

}

int main() {
    cin >> abcd;
    if (dfs(abcd[0]-'0', "")) {
        printf("%c%c%c%c%c%c%c=7\n", abcd[0], OP[0], abcd[1], OP[1], abcd[2], OP[2], abcd[3]);
    }

    return 0;
}

Measured memory_bytes: 256
import math
import sys
import resource
MAX_N = 202020
sys.setrecursionlimit(MAX_N)
E = [[] for i in range(MAX_N)]
depth = [0]*MAX_N
K = (int)(math.log2(MAX_N) + 10)

#db[i][j] = 頂点jの2^i個上の頂点
#iは高々、log2(頂点数)の切り上げを超えない。(このコードでは念のため少し余裕を持たせている。)
db = [[-1]*(MAX_N) for i in range(K)] 

#根からの深さを記録するためのdfs
def dfs(now,parent,d):
    #nowの2^0(=1)個上は、親頂点である。
    db[0][now] = parent
    depth[now] = d
    for to in E[now]:
        if(to != parent):dfs(to,now,d+1)

#ダブリング
def doubling():
    for i in range(K-1):
        for j in range(MAX_N):
            if(db[i][j] < 0):
                #頂点jの2^i個上が-1→jの2^i個上は根を飛び越えてしまっているので、2^(i+1) 個上も当然根を飛び越えている。
                db[i+1][j] = -1
            else:
                #頂点jの2^i個上がdb[i][j]→頂点jの2^(i+1) 個次の頂点は、「jの2^i個次の頂点」の「2^i個次の頂点」である。
                db[i+1][j] = db[i][db[i][j]]

def LCA(u,v):
    #uのほうが浅い場合は、swapする。(これにより、一般性を失わずuを深いほうにできる。)
    if(depth[u] < depth[v]):u,v = v,u
    if(u == v):return u

    

    #uとvについて、根からの距離をそろえる
    #iの降順に見ていっていることに注意
    #uの2^i個上がまだvの深さ以上の場合、2^i個さかのぼる
    for i in range(K-1,-1,-1):
        if(db[i][u] == -1):continue
        if(depth[db[i][u]] >= depth[v]):u = db[i][u]
    #この時点でuとvの深さは等しい。
    if(u == v):return u

    #u,vの2^i個上の頂点について、等しいなら2^i個さかのぼり、そうでないならとどまる、という動きの繰り返し
    #iの降順に見ていっていることに注意
    for i in range(K-1,-1,-1):
        if(db[i][u] != db[i][v]):
            u = db[i][u]
            v = db[i][v]
    #上り終わった後のuの親がLCAとなっている。
    return db[0][u]
    



n = int(input())
for i in range(n):
    li = list(map(int,input().split()))
    for j in range(li[0]):E[i].append(li[j+1])

dfs(0,-1,0)
doubling()

q = int(input())
for i in range(q):
    u,v =li = list(map(int,input().split()))
    print(LCA(u,v))



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

using namespace std; 

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define PQ priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl; 
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1e9; 
const int N = 1005; 
const int dx[] = {-1, 0, 1, 0}; 
const int dy[] = {0, 1, 0, -1}; 

inline ll read()
{
	ll x = 0; int f = 1, c = getchar(); 
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; 
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); 
	return x * f; 
}

int n; 
vector <int> p; 

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin); 
		freopen("output.txt", "w", stdout); 
	#endif
	
	n = read(); 
	REP(i, n)
	{
		int x = read(); 
		p.pb(x); 
	}
	
	sort(all(p)); 
	printf("%d\n", p[n / 2] - p[n / 2 - 1]); 
	
	return 0; 
}


Measured memory_bytes: 892
import math
a, b, x = map(int, input().split())
if a ** 2 * b <= 2 * x:
    tan = 2 * (a **2 * b - x) / (a ** 3)
else:
    tan = a * b ** 2 / (2 * x)
print(math.degrees(math.atan(tan)))

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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return x * f;
}

int n, a[200005], b[200005], ans;

inline bool check(int x) {
	for (int i = 1; i <= n; i++) b[i] = (a[i] >= x);
	for (int i = 1; i <= n / 2; i++) {
		if ((!b[n/2-i+1] && !b[n/2-i+2]) || (!b[n/2+i] && !b[n/2+i+1])) return 0;
		if ((b[n/2-i+1] && b[n/2-i+2]) || (b[n/2+i] && b[n/2+i+1])) return 1;
	}
	return b[1];
}

inline void solve() {
	int l = 1, r = n, mid;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (check(mid)) {
			ans = mid; l = mid + 1;
		} else r = mid - 1;
	}
}

int main() {
	n = read() * 2 - 1;
	for (int i = 1; i <= n; i++) a[i] = read();
	solve();
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 200005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF 1e18
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define mod 1000000007
#define pii pair<ll,ll>
ll getans(ll n,ll k)
{  if(k==1)
  return n+1;  
  ll ans=n;
  for(ll i=0;i<=(k-2);i++)
    ans*=(n-i);
  return ans;
}
int main()
{
  ll w,a,b;
  cin>>w>>a>>b;
  ll i=a;
  ll j=a+w;
  ll ni=b;
  ll nj=b+w;
  if(ni>=j)
  {
    cout<<ni-j;
    return 0;
  }
  if(nj<=i)
  {
    cout<<i-nj;
    return 0;
  }
  cout<<0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ct=0;
		for(int i=0;i<n-2;i++){
			if(s.substr(i,3)=="ABC")
				ct++;
		}
		cout<<ct<<endl;
	}
}



Measured memory_bytes: 3652
#A-B間の運賃の入力 #B-C間の運賃の入力
X, Y= map(int, input().split())
#制約
if  X < 1 or Y%2 != 0 or Y > 100:
    SystemExit
#A-C合計運賃の計算と出力
print(int(X+Y/2))

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int A, B, C, D;
int num;
int ans;

int main(){
	
	cin>>A>>B>>C>>D;
	num = max( A, C );
	
	ans = min( B, D );
	
	ans -= num;
	
	if( ans < 0 ) ans = 0;
	
	cout<<ans<<endl;
	
	return 0;
	
}

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

const int N = 2e5;
vector<int>ele;
int a[N+100],ans[N+100];
vector<int>g[N+100];

void dfs(int v,int par,int cur)
{
	auto in = lower_bound(ele.begin(),ele.end(),a[v])-ele.begin();
	int pre = ele[in];
	if(in==cur){
		cur++;
	}
	ele[in] = a[v];
	ans[v] = cur;
	for(auto it:g[v])
	{
		if(it!=par){
			dfs(it,v,cur);
		}
	}
	ele[in] = pre;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n+100;i++){
		ele.push_back(1e9+1);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
}


Measured memory_bytes: 31080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;


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

   int n,ans=0,v[20],c[20],p[20];
   cin >> n;
   rep(i,0,n) cin >> v[i];
   rep(i,0,n) cin >> c[i]; 
   rep(i,0,n){
   	if(v[i]-c[i]>0) {
   		ans+=v[i];
   		ans-=c[i];
   	}
   }	 
   cout << ans << endl;
}



Measured memory_bytes: 256
import heapq
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int, input().split())
    A = list(map(lambda x:-int(x), input().split()))
    heapq.heapify(A)
    for _ in range(M):
        heapq.heappush(A, -(-heapq.heappop(A)//2))
    print(-sum(A))

if __name__ == "__main__":
    main()

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

int main()
{
  	int64_t n;
	cin >> n;
  	vector<int64_t> data(n);
  	REP(i, n){
      cin >> data[i];
    }
  
  	int64_t bf = 0;
  int64_t sum = 0;
  
  REP(i,n){
    int64_t current = data[i];
    int64_t step = 0;
    if(bf > current){
      step = bf - current;
    }
    bf = current + step;
    sum += step;
  }
  
  cout << sum;
    return 0;
}

Measured memory_bytes: 4828
$N = <STDIN>;
chomp $N;
#print "$N\n";
if($N==2){print "1";exit}

my $count =2;#NとN-1

for(my $i=2;$i<=sqrt($N);$i++){
    $task =&ch($i,$N);
    #print "i$i $task\n";
    if( $task ==1){
        $count++;
    }
}
for(my $i=2;$i<sqrt($N-1);$i++){
    my $mod = ($N-1)%$i;
    if( $mod == 0){
        $count++;
    }
}

print "$count\n";

sub ch {
    my ($a,$b) = @_;
    #print "ch $a $b\n";
    my $mod = $b%$a;
    if( $mod == 0){
        $ans = &ch($a,($b/$a));
        return $ans;
    }else{
      return $mod;
    }
}


Measured memory_bytes: 512
//b棟f階のr番目の部屋にv人が追加で入居したことを示します。vが負の値の場合、v人退去したことを示します。 

import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        
        
        
        int[][] A = new int[n][m];
        
        int[] b = new int[m];
        
      //Aの配列にforとscanner使って代入
        for(int i = 0 ; i < n ; i++ ){
        	for(int j = 0 ; j < m ; j++ ){
        		A[i][j] = sc.nextInt();
        	}
        }
        
      //bの配列にforとscanner使って代入
        for(int k = 0 ; k < m ; k++ ){
        	b[k] = sc.nextInt();
        }
        
        //計算作業
        
        int x,y;
        int sum;
        
        for( x = 0 ; x < n ; x++ ){
        	sum = 0;
        	for(y = 0 ; y < m ; y++ ){
        		
        		
        		sum = sum + A[x][y] * b[y];
        		
        	}
        System.out.println(sum);
        }
    }
}

Measured memory_bytes: 40392
#include <cstdio>
using namespace std;

int n, m;
int t[5010][5010];

void imos(int a, int b, int x){
	++t[a][b];
	--t[a][b+1];
	--t[a+x+1][b];
	++t[a+x+2][b+1];
	++t[a+x+1][b+x+2];
	--t[a+x+2][b+x+2];
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i=0; i<m; ++i){
		int a, b, x;
		scanf("%d %d %d", &a, &b, &x);
		imos(a, b, x);
	}
/*
	for(int i=1; i<=n+2; ++i){
		for(int j=1; j<=n+2; ++j)
			printf("%d\t", t[i][j]);
		printf("\n");
	}
*/
	for(int i=1; i<=n; ++i)
		for(int j=2; j<=n; ++j)
			t[i][j] += t[i][j-1];
	for(int i=1; i<=n; ++i)
		for(int j=2; j<=n; ++j)
			t[j][i] += t[j-1][i];
	for(int i=1; i<=n; ++i)
		for(int j=2; j<=i; ++j)
			t[i][j] += t[i-1][j-1];
	int ans = 0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=i; ++j)
			if(t[i][j] > 0) ans++;
	printf("%d\n", ans);
/*
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=n; ++j)
			printf("%d ", t[i][j]);
		printf("\n");
	}
*/
}

Measured memory_bytes: 100612