akhauriyash/Code-Regression huggingface dataset:
using System;

namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.Exchange.Run();
        }
    }
    public class Exchange
    {
        public Exchange()
        {
        }
        public static void Run(){
            int A, B, K;
            string s = Console.ReadLine();
            A = int.Parse(s.Split(' ')[0]);
            B = int.Parse(s.Split(' ')[1]);
            K = int.Parse(s.Split(' ')[2]);
            for (int i = 0; i < K;i++){
                if (i % 2 == 0)
                {
                    //
                    if (A % 2 == 1) A--;
                    B += A / 2;
                    A /= 2;
                }
                else
                {                //
                    if (B % 2 == 1) B--;
                    A += B / 2;
                    B /= 2;
                }

            }
            Console.WriteLine("{0} {1}", A, B);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    int n;
    cin>>n;
    LL ans=0;
    int a[100005]={0};
    LL maxi=-1;
    for(int i=0;i<n;++i){
        LL b;cin>>b;
        if(b>100000)ans++;
        else{
        a[b]++;
        }
    }
    for(int i=0;i<=100002;++i){
        if(a[i]==0)continue;
        else if(a[i]<i)ans+=a[i];
        else if(a[i]>i)ans+=a[i]-i;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 640
#include<stdio.h>
int main(){
int s[1111111],c[1111111],i,m;
scanf("%d",&s[1]);
for(i=0;i<1111111;i++)
c[i]=0;
c[s[1]]++;
m=1;
while(1){
if(s[m]%2==0)
s[m+1]=s[m]/2;
else
s[m+1]=s[m]*3+1;
if(c[s[m+1]]==1){
printf("%d\n",m+1);
return 0;
}
else
c[s[m+1]]++;
m++;
}
return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	int n; cin >> n;
	int lim = -1;
	int ans = 0;

	rep(i, 0, n) {
		int k; cin >> k;
		ans += (k >= lim);
		lim = max(lim, k);
	}

	cout << ans << endl;
}


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

Measured memory_bytes: 256
// Transformation.c
// 文字列 str に対して、与えられた命令の列を実行するプログラムを
// 作成してください。命令は以下の操作のいずれかです：
//
// ・print a b: strの a 文字目から b 文字目までを出力する。
// ・reverse a b: strの a 文字目から b 文字目までを逆順にする。
// ・replace a b p: strの a 文字目から b 文字目までを p に置き換える。
//
// ここでは、文字列 strの最初の文字を 0 文字目とします。
//
// 【入力】
// 1 行目に文字列 str が与えられます。strは英小文字のみ含みます。
// 2 行目に命令の数 qが与えられます。
// 続く q行に各命令が上記の形式で与えられます。
// 【出力】
// 各 print 命令ごとに文字列を１行に出力してください。
// 【制約】
// ・1≤strの長さ≤1000
// ・1≤q≤100
// ・0≤a≤b<strの長さ
// ・replace 命令では b−a+1=pの長さ
// 【例】
// 入力１：
// abcde
// 3
// replace 1 3 xyz
// reverse 0 2
// print 1 4
// 出力１：
// xaze
// 入力２：
// xyz
// 3
// print 0 2
// replace 0 2 abc
// print 0 2
// 出力２：
// xyz
// abc
#include<stdio.h>
#include<string.h>

void print( char *str, int a, int b) {
  for ( int i = a; i <= b; i++) {
    printf( "%c" ,str[i]);
  }
  printf( "\n");
}

void reverse( char *str, int a, int b) {
  char swap_c;

  for ( int i = a, j = b; i < j; i++, j--) {
    swap_c = str[i]; str[i] = str[j]; str[j] = swap_c;
  }
}

void replace( char *str1, char *str2, int a, int b) {
  for ( int i = a; i <= b; i++) {
    str1[i] = str2[ i-a];
  }
}

int main( void) {
  char str[1001];
  int op_num;
  char op[8];
  int a, b;
  char rep_str[1001];

  scanf( "%s", str);
  scanf( "%d", &op_num);

  for ( int i = 0; i < op_num; i++) {
    scanf( "%s %d %d", op, &a, &b);
    if ( strcmp( op, "print") == 0 ) print( str, a, b);
    else if ( strcmp( op, "reverse") == 0) reverse( str, a, b);
    else if ( strcmp( op, "replace") == 0 ) {
      scanf( "%s", rep_str);
      replace( str, rep_str, a, b);
    }
  }

  return 0;
}



Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		int c = Integer.parseInt(line[2]);
		int d = Integer.parseInt(line[3]);

		String ans = "No";

		if (Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
			ans = "Yes";
		} else if (Math.abs(a - c) <= d) {
			ans = "Yes";

		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int origin =sc.nextInt();
		int a = origin/100;
		int b = origin/10 -a*10;
		int c = origin - b*10 -a*100;
		System.out.print(a+b+c);

	}

}

Measured memory_bytes: 21332
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            

            if (N[0] == N[1] && N[0] == N[2] ||
                N[1] == N[2] && N[1] == N[3])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

using namespace std;

int main(){

    string S; cin >> S;
    bool f = false;
    for (int i = 0; i < S.length() - 1; i++){
        if (S[i] == 'A' && S[i + 1] == 'C'){
            f = true;
            cout << "Yes" << endl;
            break;
        }
    }

    if (f == false){
        cout << "No" << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <thread>
#define endl "\n"
using namespace std;
#define ios ios_base::sync_with_stdio(false);
#define lll __int128_t
#define ll long long int
#define XOX
#define FOR(i,a,b) for(ll i=a;i<(ll)b;i++)
#define FORr(i,a,b) for(ll i =a;i>=(ll)b;i--)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define print(arr)  for(auto a: arr) cout << a<< " "; cout << endl;
#define case(i) cout << "Case " << i << ": ";
#define in(a) ll a = read();
#define inp(arr,n) vector<ll>arr(n); for(auto &a: arr) a = read(); 
#define pb emplace_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define f first
#define s second
#define mod 998244353
#define pll pair<ll, ll>
inline ll read()
{
    ll x=0; static ll p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define DEBUG
#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
void solve(int pk);


int main()
{
  //freopen("in", "r", stdin);
   ll nn = 1;
   //nn= read();
 //  ios
  // cin >> nn;
    rep(i, nn) solve(i);
}
void solve(int tt)
{
   string ami; cin >> ami;
   if(ami.back() == 's') ami = ami + "es";
   else ami = ami + 's';
   cout << ami << endl;
}

Measured memory_bytes: 3632
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    sum_ = 0
    for k, v in count.items():
        sum_ += (v * (v - 1)) // 2
    for a in A:
        print(sum_ - count[a] + 1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 91160
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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



void solve(long long a){
    cout<<a+pow(a,2)+pow(a,3)<<endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    solve(a);
    return 0;
}


Measured memory_bytes: 4348
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;
vec a;

int dp[3030][3030];

int rec(int l, int r, int turn) {
  if (dp[l][r] != INF) return dp[l][r];
  if (r < l || r == -1 || l == N) return 0;

  int res;
  if (turn == 0) {
    res = max(rec(l, r - 1, (turn + 1) % 2) + a[r], rec(l + 1, r, (turn + 1) % 2) + a[l]);
  } else {
    res = min(rec(l, r - 1, (turn + 1) % 2) - a[r], rec(l + 1, r, (turn + 1) % 2) - a[l]);
  }

  return dp[l][r] = res;
}

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    a.pb(tmp);
  }

  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      dp[i][j] = INF;
    }
  }

  cout << rec(0, N - 1, 0) << endl;
  return 0;
}


Measured memory_bytes: 72064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<cctype>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=2e5+10;
int n,k;
long long ans;
long long po3(int n){return 1ll*n*n*n;}
int main()
{
	n=read();k=read();
	ans+=po3(n/k);
	if((k&1)==0)
	ans+=po3((n+(k>>1))/k);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll r = 0, b = 0;
    REP(i, n){
        if(s[i] == 'R') r++;
        else b++;
    }
    if(r > b){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     
	 int s,w;
	 cin>>s>>w;
	 
	 if(w>=s)
	 {
	 	
	   cout<<"unsafe"<<endl;	
	 	
	 }   
	 
	 else
	 {
	 	
	 	cout<<"safe"<<endl;
	 	
	 }
    
    
    return 0;
    
}

Measured memory_bytes: 3632
#define debug_switch
#ifdef debug_switch
#define debug if(1) puts("debug");
#define dout if(1) cout
#else
#define debug if(0) puts("debug");
#define dout if(0) cout
#endif
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N = 1e5 + 7;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;

int main()
{
	int n;
	cin>>n;
	cout<<((n+1)/2 - 1)<<endl;
	return 0;
}






Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    int i,j;
    
    int max=0;
    for(i=0;i<n;i++){
        int sum=0;
        int a[27]={};
        for(j=0;j<i;j++)
            a[s[j]-'a']=1;
        for(j=i;j<n;j++){
            if(a[s[j]-'a']==1)
                sum++;
            a[s[j]-'a']=0;
        }
       max= (max>sum)? max:sum;
    }
    printf("%d",max);
}


Measured memory_bytes: 128
unittest
{
	assert( [ "2 2919" ].parse.expand.solve == 3719 );
	assert( [ "22 3051" ].parse.expand.solve == 3051 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nr = input.front.split.to!( long[] );
	return tuple( nr[ 0 ], nr[ 1 ] );
}

auto solve( long n, long r )
{
	return ( n < 10 ) ? r + 100 * ( 10 - n ) : r;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int H, W;
int mat[2010][2010], xors[2010][2010];
int acc[2010][2010];

template <int n, int m>
int maximumRectangle(const int (&arr)[n][m], int w, int h){
    for(int i=0;i<w-1;++i){
        for(int j=0,k=0;j<h-1;j=k){
            while(k < h - 1 && arr[k][i] == 1){++k;}
            j = k;
            while(k < h - 1 && arr[k][i] == 0){
                acc[k][i] = k - j + 1;
                ++k;
            }
        }
    }

    // for(int i=0;i<=10;++i){
    //     for(int j=0;j<=8;++j){
    //         std::cout << std::setw(2) << acc[i][j];
    //     }
    //     std::cout << std::endl;
    // }

    int res = 0;
    for(int i=0;i<h-1;++i){
        std::stack<std::tuple<int, int>> st;
        st.emplace(0, acc[i][0]);
        for(int j=1;j<w;++j){
            int p, h;
            std::tie(p, h) = st.top();

            if(h < acc[i][j]){
                st.emplace(j, acc[i][j]);
            }else if(h > acc[i][j]){
                int _p, _h;
                while(!st.empty() && snd(st.top()) >= acc[i][j]){
                    std::tie(_p, _h) = st.top();
                    res = std::max(res, (j - _p + 1) * (_h + 1));
                    st.pop();
                }

                st.emplace(_p, acc[i][j]);
            }
        }
    }

    return res;
}

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

    std::cin >> H >> W;

    for(int i=0;i<H;++i){
        std::string S;
        std::cin >> S;

        for(int j=0;j<W;++j){
            mat[i][j] = S[j] == '.' ? 0 : 1;
        }
    }

    for(int i=0;i+1<H;++i){
        for(int j=0;j+1<W;++j){
            xors[i][j] = mat[i][j] ^ mat[i+1][j] ^ mat[i][j+1] ^ mat[i+1][j+1];
        }
    }

    // for(int i=0;i<=10;++i){
    //     for(int j=0;j<=8;++j){
    //         std::cout << xors[i][j];
    //     }
    //     std::cout << std::endl;
    // }
    // std::cout << "----------" << std::endl;

    int res = max({maximumRectangle(xors, W, H), W, H});
    std::cout << res << std::endl;
}


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

int main(){
	int n; cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i += 2){
		int num = 0;
		for(int j = 1; j <= i; ++j){
			if(i % j == 0) ++num;
		}
		if(num == 8) ++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

INF = 10**18

N, M, P = map(int, input().split())
G = []
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G.append((a, b, c-P))
D = [0]*N
for i in range(N):
    D[i] = -INF
D[0] = 0
for i in range(N):
    for j in range(M):
        fr, to, cost = G[j]
        if D[fr] != -INF and D[fr]+cost > D[to]:
            D[to] = D[fr]+cost
updated = [False]*N
for _ in range(N):
    for j in range(M):
        fr, to, cost = G[j]
        if (D[fr] != -INF and D[fr]+cost > D[to]) or updated[fr]:
            updated[to] = True
if updated[N-1]:
    print(-1)
elif D[N-1] < 0:
    print(0)
else:
    print(D[N-1])


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

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

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
int A[MAX];
VI graph[MAX];
int memo[MAX];
VI v;

int dfs(int now) {
    if (memo[now] != -1) return memo[now];
    int res = graph[now].size();
    VI vv;
    FORE(e, graph[now]) {
        vv.EB(dfs(e));
    }
    RSORT(vv);
    REP(i, vv.size()) vv[i] += i + 1;
    FORE(e, vv) chmax(res, e);
    return memo[now] = res;
}

int main(void) {
    memset(memo, -1, sizeof(memo));
    scanf("%d", &N);
    A[0] = -1;
    FOR(i, 1, N) {
        scanf("%d", &A[i]);
        A[i]--;
        if (A[i] == 0) v.EB(i);
        graph[A[i]].EB(i);
    }
    cout << dfs(0) << endl;
}


Measured memory_bytes: 17408
#include<stdio.h>
#define N 100

int main(){
  int A[N], n, i, j, a;
  int count=0;

  scanf("%d", &n);

  for(i =0; i < n; i++)
    scanf("%d", &A[i]);

  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(A[j] < A[j-1]){
	a = A[j];
	A[j] = A[j-1];
	A[j-1] = a;
	count++;
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("%d", A[i]);
    if(i == n-1) break;
    printf(" ");
  }

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

Measured memory_bytes: 604
n=int(input())
a,b=[0]*n,[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
a.sort()
b.sort()
if n&1:
    print(b[n//2]-a[n//2]+1)
else:
    print(1+(b[n//2]+b[(n-1)//2])-(a[n//2]+a[(n-1)//2]))

Measured memory_bytes: 82256
fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();

    let ans = (1..=n)
        .into_iter()
        .step_by(2)
        .filter(|&x| (1..=x).into_iter().filter(|&y| x % y == 0).count() == 8)
        .count();
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2252
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename F>
void search(int n, int m, vector<int> &s, F f) {
  if (n + 1 == s.size()) {
    f();
  } else {
    for (int j = s.back(); j <= m; j++) {
      s.push_back(j);
      search(n, m, s, f);
      s.pop_back();
    }
  }
}

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i];
    b[i];
  }

  int result = 0;
  vector<int> s(1, 1);
  search(N, M, s, [&]() {
    int score = 0;
    rep(i, Q) {
      if (s[b[i]] - s[a[i]] == c[i]) {
        score += d[i];
      }
    }
    result = max(result, score);
  });
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3552
from collections import Counter
import sys
sys.setrecursionlimit(4100000)

n, m, k = map(int, input().split())

#友達関係
F = [[] for i in range(n)] #Friend
for i in range(m):
    a, b = map(int, input().split())
    F[a-1].append(b)
    F[b-1].append(a)

#DFSで連結部分ごとのグループに分ける
G = [0] * n #Group
gid = 0 #group id

#DFSを行うための関数
def using_DFS(p):
    if G[p] == 0:
        G[p] = gid
        for j in F[p]:
            if G[j-1] == 0:
                using_DFS(j-1)
            else:   #すでに登場
                pass
    else:
        pass

for i in range(n):
    if G[i] == 0:
        gid += 1
        using_DFS(i)
    else:
        pass
#print('G=',G)
#print('S=',S)

#ブロック関係
BinG = [[] for i in range(n)] #Block in Group
for i in range(k):
    c, d = map(int, input().split())
    if G[c-1] == G[d-1]:
        BinG[c-1].append(d)
        BinG[d-1].append(c)
    else:
        pass
#print('F=',F)
#print('B=',B)

GS = Counter(G) #Group Size
for i in range(n):
    ans =  GS[G[i]] - 1 - len(F[i]) - len(BinG[i])
    print(ans)

Measured memory_bytes: 47916
#!/usr/bin/env ruby

n = gets.to_i
x = gets.split(" ").map{|i| i.to_i}
y = gets.split(" ").map{|i| i.to_i}

div = Array.new(n)
sigma = 0

for i in 0..(n - 1)
  div[i] = (x[i] - y[i]).abs
end

puts div.inject(:+)

for i in 0..(n - 1)
  sigma += div[i] ** 2
end

puts Math::sqrt(sigma)

sigma = 0

for i in 0..(n - 1)
  sigma += div[i] ** 3
end

puts sigma ** (1.0 / 3.0)
puts div.max

Measured memory_bytes: 6188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
    int N;
    char s[101];

    scanf("%d",&N);
    scanf("%s",s);

    int x[101];
    x[0] = 0;
    for(int i=1;i<=N;i++){
        if(s[i-1]=='I') x[i] = x[i-1] + 1;
        if(s[i-1]=='D') x[i] = x[i-1] - 1;
    }

    int max = 0;
    for(int i=1;i<=N;i++){
        if(max<x[i]) max = x[i];
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
   //cin>>test;


  while(test--)
  {
  int n,W;
  cin>>n>>W;
  vi w(n+1),v(n+1);
  int k[n+1][W+1];
  memset(k,0,sizeof k);
  for(int i=1;i<=n;i++)cin>>w[i]>>v[i];

  for(int i=0;i<=n;i++)
  {
    for(int wt=0;wt<=W;wt++)
    {
      if(i==0||wt==0)k[i][wt]=0;
      else if(w[i]<=wt)
      {
        k[i][wt]=max(v[i]+k[i-1][wt-w[i]],k[i-1][wt]);
      }
      else k[i][wt]=k[i-1][wt];
    }
  }
 
cout<<k[n][W];

  //while loop ending 
  }

return 0;
}

Measured memory_bytes: 79232
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
//unordered_map
typedef long long ll;
ll a[MAXN],b[MAXN],sum1[MAXN],sum2[MAXN];
int main()
{
	int n,m;ll k,ans=0;
	scanf("%d %d %lld",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum1[i]=sum1[i-1]+a[i];
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&b[i]);
		sum2[i]=sum2[i-1]+b[i];
	}
	for(int i=0;i<=n;i++)
	{
		if(k>=sum1[i])
		{ 
		ll num=upper_bound(sum2+1,sum2+1+m,k-sum1[i])-sum2-1+i;
		ans=max(ans,num);
		} 
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9980
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll x,k,d,c,mi;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(x),sc(k),sc(d);
    if(x<0) x=-x;
    if(x==0){
        if(k%2==0) mi=0;
        else mi=d;
    }
    else{
        if(x%d==0) c=x/d;
        else c=x/d+1;
        if(c>=k) mi=abs(x-k*d);
        else {
            mi=abs(x-c*d);
            if((k-c)%2==1) mi=x-c*d+d;
            else mi=abs(x-c*d);
        }
    }
    pr(mi);
    return 0;
}

Measured memory_bytes: 3824
n = int(input())
a = [int(x) for x in input().split()]
c = 1
ans = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    c += 1
  else:
    ans += c // 2
    c = 1
ans += c // 2
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

template<typename T>
vector<T> make_v(size_t a){
  return vector<T>(a);
}
 
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main(){
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
 
  long long n, a;
  cin >> n;
  vector<ll> ans(n, 0);
  for(int i = 1; i < n; i++){
    cin >> a;
    ans[a-1]++;
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4788
#include<stdio.h>

int main()
{
	int n,a,b,c,m,x;
	scanf("%d",&n);
	for(m=0;m<n;m++)
	{
		scanf("%d %d %d",&a,&b,&c);
			if(a<b){
				x=a;
				a=b;
				b=x;
		}
			if(a<c){
				x=a;
				a=c;
				c=x;
		}
			if(a*a==b*b+c*c)
				printf("YES\n");
			else
				printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
int m[]={5,1,2,4,1,3,1,0,0,2,3,2,2,4,5,1,4,0,4,3,3,5,0,5},a,b,c,d,r;char s[99];int main(){for(s[87]=1,s[78]=4,s[69]=3,s[83]=2;~scanf("%s",s);*s<60?(printf(r?"%d\n":"",r),a=c=0,b=r=1):(d=s[*s],d?d=d+c&3,a=m[4*a+d],b=m[4*b+d]:c+=*s-76?1:3,r+=a%3?b%3?(b+6-a)%6<3?2:5:b?3:4:a?6:1));}

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

long min_long(long a,long b){
  if(a > b) return b;
  else return a;
}
int main(){
  int N,K; cin >> N >> K;
  vector<int> h(N,0);
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  
  long ans = 10000000091;
  for(int i = 0; i+K-1 < N; i++){
    int dh = h.at(i+K-1)-h.at(i);
    ans = min_long(ans,dh);
  }
  cout << ans << endl;
}



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

using namespace std;

int main () {
	int N; 
	cin >> N;
	
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int x; cin >> x;
		v.push_back(x);
	}
	
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += v[i];
	}
	
	int big = v[0];
	for (int i = 0; i < N; i++) {
		big = max(big,v[i]);
	}
	
	cout << sum - big/2 << endl;
	
	return 0;
}

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

int main() {
	int N;
	int K;
	int p;
	int q;
	int g;
	int r;

	cin >> N >> K;
 	vector<int> a(N);
	rep(i, N) cin >> a.at(i);
	p=1;
	q=1000000000;

	while (p<q) {
		r=(p+q)/2;
		g=0;
		rep(i,N) {
			g+=a.at(i)/r;
			if (a.at(i)%r==0) g--;
		}
		if (g>K) p=r+1;
		else q=r;
	}
	cout << q << endl;
	return 0;
}


Measured memory_bytes: 4052
# AOJ 0150 Twin Prime
# Python3 2018.6.17 bal4u

MAX = 10001
SQRT = 100     # sqrt(MAX)

prime = [True]*MAX
def sieve():
#	for i in range(4, MAX, 2):
#		prime[i] = False
	for i in range(3, SQRT, 2):
		if prime[i] is True:
			for j in range(i*i, MAX, i):
				prime[j] = False
sieve()
tbl, ans = [0]*MAX, 0
for i in range(5, MAX, 2):
	if prime[i] and prime[i-2]: ans = i
	tbl[i] = ans
	
while True:
	n = int(input())
	if n == 0: break
	if (n & 1) == 0: n -= 1
	print(tbl[n]-2, tbl[n])


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

signed main(){
    //A
    /*
    int s,w;cin>>s>>w;
    if(s<=w) cout<<"unsafe"<<endl;
    else  cout<<"safe"<<endl;
    */
   //B
   /*
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   while(a!=0&&c!=0){
       c-=b;
       if(c<=0){
           cout<<"Yes"<<endl;
           return 0;
       }
       a-=d;
       if(a<=0){
           cout<<"No"<<endl;
           return 0;
       } 
   }
   */
   //C
    int n;cin>>n;
    string p;
    set<string>st; 
    rep(i,0,n){
        cin>>p;
        st.insert(p);
    }
    cout<<st.size()<<endl;
}

Measured memory_bytes: 19256
n,k = [int(i) for i in input().split()]
a = [0] + [int(i) for i in input().split()]

pos = 1
move= 0
colors = [-1]*(n+1)

while(colors[pos]==-1):
    colors[pos] = move
    move += 1
    pos = a[pos]
    if move==k:
        print(pos)
        break
else:
    turn = move - colors[pos]
    rest = (k-colors[pos]) % turn
    while rest:
        pos = a[pos]
        rest -= 1
    print(pos)

Measured memory_bytes: 32316
#include <stdio.h>
#include <string.h>
 
int main(void)
{
  char s[101];
  int i,n;
 
    scanf("%s",s);
    n=strlen(s);
    for(i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='L'){
             printf("No\n");
             return 0;
            }
        }
        else {
            if(s[i]=='R'){
            printf("No\n");
            return 0;
            } 
        }
    }
    printf("Yes\n");
 
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll N, K;
    cin >> N >> K;
    double ans = 0, d = 0.5;
    FOR(i, 1, N + 1){
        ans += pow(0.5, ceil(max(0.0, log2((K + i - 1) / i))));
        if(i <= 100) cerr << ans << endl;
    }
    ans /= N;
    printf("%.9f\n", ans);
    return 0;
}

Measured memory_bytes: 4072
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename T>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const vector<T> &data) {
    cout << to_string<vector<T>, T>(data) <<endl;
}

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);
    
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    vector<int> values(n);
    for(int i = 0; i < n; ++i) {
        cin >> values[i];
    }
    sort(all(values));
    int mid, ans = 0;
    if(n & 1 ^ 1) {
        mid = n / 2;
        ans = abs(values[mid] - values[mid-1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }

ll pow(ll a, ll b){
    ll ans = 1;
    while(b--) ans *= a;
    return ans;
}
ll comb(ll n, ll r){
    ll ans = 1;
    for(ll i = 0; i < r; i++){
        ans *= n - i;
        ans /= i + 1;
    }
    return ans;
}
ll solve(string n, ll k){
    ll size = n.size();
    if(size < k) return 0;
    if(k == 0) return 1;
    ll ans = 0;
    // n より桁数が少ないもの
    if(size > k) ans += comb(size - 1, k) * pow(9LL, k);
    // n と桁数が同じで、最上位が n[0] より小さいもの
    ans += (n[0] - '1') * comb(size - 1, k - 1) * pow(9LL, k - 1);
    // n と桁数が同じで、最上位が n[0] と同じもの
    ll at = 1;
    while(n[at] == '0') at++;
    ans += solve(n.substr(at, size - at), k - 1);
    return ans;
}
int main(){
    string n;
    ll k;
    cin >> n >> k;
    cout << solve(n, k) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <string>
using namespace std;

int main() {
	string w,w2,t,t2;
	cin >> w;
	w2 = w;
	for(int i=0; i<w.size();i++){
		w2[i] = tolower(w[i]);
	}
	int count=0;
	while(cin >> t){
		if(t == "END_OF_TEXT") break;
		t2 = t;
		for(int i=0; i<t.size();i++){
			t2[i] = tolower(t[i]);
		}
		if(t2 == w2){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
string s;
bool isPalindrom(string x)
{
  int n=x.length();
  int l=0,r=n-1;
  while(l<=r)
  {
    if(x[l]!=x[r])return 0;
    l++;r--;
  }
  return 1;
}
int main()
{
cin>>s;
  int n=s.length();
  string x1=s.substr(0,(n-1)/2);
  string x2=s.substr((n+3)/2-1,n-((n+3)/2)+1);
 
  if(isPalindrom(s)&&isPalindrom(x1)&&isPalindrom(x2))
    cout<<"Yes\n";
  else cout<<"No\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;

	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt()%1000;



		if(N == 0) {
			N = 1000;
		}

		System.out.println(1000-N);
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}
}


Measured memory_bytes: 35636
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  int ans = 0;
  rep(i, 1, n + 1) {
    rep(j, i + 1, n + 1) {
      if ((i & 1 && !(j & 1)) || (j & 1 && !(i & 1)))
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans=0
for a in range(0,A+1):
    for b in range(0,B+1):
        for c in range(0,C+1):
            if (10*a)+(2*b)+c==X//50:
                ans+=1
                
print(ans)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}



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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

main(){
  string in;
  string key;
  int size;
  vector<int> pos;
  int find[50];
  int npos;
  while(1){
    in="";
    string tmp;
    while(1){
      getline(cin, tmp);
      if(tmp.size()==0) break;
      in+=tmp;
    }
    key="";
    while(1){
      getline(cin, tmp);
      if(tmp.size()==0) break;
      key+=tmp;
    }
    if(key.size()==0) break;
    int l=0, u=0;
    size=10000000;
    npos=0;
    for(int i=0;i<key.size();i++) find[i]=0;
    pos.clear();
    int nf=0;
    while(u<in.size()){
      for(int i=0;i<key.size();i++){
        if(in[u]==key[i]){
          if(find[i]==0){
            nf++;
          }
          find[i]++;
          break;
        }
      }
      if(nf==key.size()){
        bool end=false;
        while(l<u && !end){
          for(int i=0;i<key.size();i++){
            if(in[l]==key[i]){
              if(find[i]==1){
                end=true;
                if(size>u-l+1){
                  pos.clear();
                  size=u-l+1;
                  pos.push_back(l);
                  npos=1;
                }else if(size==u-l+1){
                  npos++;
                }
                find[i]--;
                nf--;
                break;
              }else{
                find[i]--;
              }
              break;
            }
          }
          l++;
        }
      }
      u++;
    }
    cout << npos << endl << endl;;
    if(npos!=0){
      string r;
      for(int i=0;i<size;i++){
        r+=in[i+pos[0]];
      }
      for(int i=0;i<r.size();i++){
        cout << r[i];
        if(i+1==r.size()) continue;
        if(i&&(i+1)%72==0) cout << endl;
      }
      cout << endl << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1776
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n)  cin >> l[i];

    vector<int> d(n+1);
    d[0] = 0;
     int ans = 1;
   
    for(int i = 1; i < n+1; i++){
        d[i] = d[i-1] + l[i-1];
        if(d[i] <= x)ans++;
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int A,B,T,ans=0;

    cin >>A>>B>>T;

    ans = (T/A) * B;

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256