akhauriyash/Code-Regression huggingface dataset:
n = list(map(int, input().split()))

count = 0
flag = 0

for x in range(n[0] + 1):

	for y in range(n[0] + 1 - x):

		if (n[1] == (10000 * x + 5000 * y + 1000 * (n[0] - (x + y) ))):
			flag = 1
			z = (n[0] - (x + y))
			break

	if flag == 1:
		break

if flag == 0:
	x = -1
	y = -1
	z  = -1

print(x ,y , z)	


Measured memory_bytes: 3060
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

string ConvertFrom10(int value, int base)
{
    if(base < 2 || base > 36)
        return "0";

    bool isNegative = (value < 0);
    if(isNegative)
        value *= -1;

    // NOTE: it's probably possible to reserve string based on value
    string output;

    do
    {
        char digit = value % base;

        // Convert to appropriate base character
        // 0-9
        if(digit < 10)
            digit += '0';
        // A-Z
        else
            digit = digit + 'A' - 10;

        // Append digit to string (in reverse order)
        output += digit;

        value /= base;

    } while (value > 0);

    if(isNegative)
        output += '-';

    // Reverse the string - NOTE: could be done with std::reverse
    int len = output.size() - 1;
    for(int i = 0; i < len; ++i)
    {
        // Swap characters - NOTE: Could be done with std::swap
        char temp = output[i];
        output[i] = output[len-i];
        output[len-i] = temp;
    }

    return output;
}


 main()

{
    fast
    int n;
    cin>>n;
    int x[n+6];
    f(i,1,n)cin>>x[i];
    int ses=inf;
    f(i,1,100)
    {
        int p=i;
        int sum=0;
        f(j,1,n)
        {
           sum+=((x[j]-p)*(x[j]-p));
        }
        ses=min(ses,sum);
    }
    cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
const ll MAX_N=(1<<19);

ll n,N,dat[2*MAX_N-1];//n...segmenttreeの葉の大きさ,N...与えられた数列等の大きさ
ll a[1000000];

ll unit(){
    return 0;//単位元
}

ll calc(ll a,ll b){
    return a+b;//演算
}

//初期化
void init(){
    n=1;
    while(n<N) n*=2;//座標とかであれば n<N ではなく n<(座標の最大値)　下も同様
    //for(int i=0;i<N;i++) dat[i+n-1]=a[i];
    //for(int i=N;i<n;i++) dat[i]=unit();//単位元で埋める
}

void update(ll k,ll s){
    k+=n-1;
    dat[k]+=s;//変更する式
    while(k>0){
        k=(k-1)/2;
        dat[k]=calc(dat[2*k+1],dat[2*k+2]);//条件
    }
}

ll query(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l) return unit();//単位元
    if(a<=l&&r<=b) return dat[k];

    ll m=(l+r)/2;
    ll u=query(a,b,2*k+1,l,m);
    ll v=query(a,b,2*k+2,m,r);
    return calc(u,v);//条件
}
//abc166e

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //ll N;
    cin>>N;
    ll a[N+1];
    for(ll i=1;i<=N;i++) cin>>a[i];
    V<P> d;
    V<ll> dd;
    for(ll i=2;i<=N;i++){
        d.push_back(make_pair(i-a[i],i));
        dd.push_back(i-a[i]);
    } 
    init();
    sort(all(d));
    sort(all(dd));
    for(ll i=0;i<N-1;i++) update(i,1);
    map<ll,ll> mp;
    for(ll i=0;i<N-1;i++){
        mp[d[i].sc]=i;
    }
    ll ans=0;
    for(ll i=1;i<N;i++){
        ll x=lb(all(dd),a[i]+i)-dd.begin();
        ll y=ub(all(dd),a[i]+i)-dd.begin();
        ans+=query(x,y,0,0,n);
        update(mp[i],0);
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

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

using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string front, back;
    front = s.substr(0,n/2);
    back = s.substr(n/2);
    if(front == back) cout << "Yes" << endl;
    else cout << "No" <<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    cin>>a>>b;
    cout<<(a%b?a%b:b)<<endl;
  }
}

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

int main()
{
  int n, l;
  cin >> n >> l;
  string s[100];
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  sort(s, s + n);
  string ans = "";
  for (int j = 0; j < n; j++)
  {
    ans += s[j];
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "Yes"; else return "No"; }

int main() {

    int n,m;
    cin >> n>>m;
    
    cout << (n-1)*(m-1) << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

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

#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A)
{
    if(A.size() == n+1)
    {
        int now = 0;
        for(int i=0; i<q; i++)
        {
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return ;
    }
    A.push_back(A.back());
    while(A.back() <= m)
    {
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    for(int i=0; i<q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
# pragma comment(linker, "/STACK: 2000000")
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n';
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
int s[1 << 20];
int was[1 << 20];
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,k;
    fi>>n>>k;
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    ll ans = accumulate(s+1,s+1+n,0ll);
    static ll w[1 << 20];
    for (int i = 1;i <= n;++i)
        w[i] = s[i];
    for (int t = 1;t <= n;++t)
    {
        for (int i = 1;i <= n;++i)
            {
                int Next = (i + t - 1 + n) % n + 1;
                w[Next] = min(w[Next],1ll * s[i]);
            }
        ans = min(ans,accumulate(w+1,w+1+n,0ll) + 1ll * t * k);
    }
    fo << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        int l = s.length();
        
        for(int i=0; i<l; i++){
            if(i<l-1){
                if(s.charAt(i)==s.charAt(i+1)){
                    System.out.println(i + 1 + " " + (i + 2));
                    return;
                }
            }
            if(i<l-2){
                if(s.charAt(i)==s.charAt(i+2)){
                    System.out.println(i + 1 + " " + (i + 3));
                    return;
                }
            }
        }
        System.out.println("-1 -1");
    }
}

Measured memory_bytes: 24656
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for(auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(all(a)); }
template<class T> inline auto min(const T& a){ return *min_element(all(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  vector<vector<int>> vecc(10,vector<int>(10,0));
  int N;cin>>N;
  REP(i,1,N+1){
    string s=to_string(i);
    vecc[(int)(s.at(0)-'0')][(int)(s.at(s.size()-1)-'0')]++;
  }
  ll ans=0;
  REP(i,0,10)REP(j,0,10){
    ans+=vecc[i][j]*vecc[j][i];
  }
  print(ans)

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

Total = 0

for i in range(1,N):
    Total += abs(A[i]-A[i-1])
Total += abs(A[0]) + abs(A[N-1])

for i in range(N):
    ans = Total
    if i == 0:
        ans -= abs(A[i]) + abs(A[i+1]-A[i])
        ans += abs(A[i+1])
    elif i == N-1:
        ans -= abs(A[i]) + abs(A[i]-A[i-1])
        ans += abs(A[i-1])
    else:
        ans -= abs(A[i]-A[i-1]) + abs(A[i+1]-A[i])
        ans += abs(A[i+1]-A[i-1])
    print(ans)
    

Measured memory_bytes: 14164
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> A(N); 
    vector<int> B(N); 
    repp(i,0,N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B.begin(), B.end(), greater<int>());
    repp(i,0,N) {
        if (A[i] == B[0]) cout << B[1] << endl;
        else cout << B[0] << endl;
    }
}                 


Measured memory_bytes: 3200
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    n <- readLn
    as <- r n
    print $ U.maximum as - U.minimum as

Measured memory_bytes: 508
#include<stdio.h>

int n, pos, c;
int pre[100], in[100], post[100];

void rec(int left, int right){
	if( left >= right ){ return; }
	int root = pre[pos++];
	int m, i;
	for(i=0; i<n; i++){
		if( root==in[i]){ m = i; break; }
	}
	rec(left, m);
	rec(m+1, right);
	post[c++] = root;
}

int main(void){
	int i;
	scanf("%d", &n);
	for(i=0; i<n; i++){ scanf("%d", &pre[i]); }
	for(i=0; i<n; i++){ scanf("%d", &in[i]); }
	rec(0, n);
	for(i=0; i<n-1; i++){ printf("%d ", post[i]); }
	printf("%d\n", post[i]);
	
	return 0;
}


Measured memory_bytes: 2108
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

#apizza
a = int(arr_data[0][0])
#bpizza
b = int(arr_data[0][1])
#abpizza
c = int(arr_data[0][2])

#apizzaの枚数
x = int(arr_data[0][3])

#bpizzaの枚数
y = int(arr_data[0][4])

mysum1 = a * x + b * y
mysum2 = c * max(x, y) * 2
mysum3 = c * min(x, y) * 2 + a * (x-min(x, y)) + b * (y-min(x, y))

arr=[mysum1,mysum2,mysum3]
arr.sort()
print(arr[0])

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	o, e := readString(), readString()
	pass := ""
	for i := 0; i < len(e); i++ {
		pass += string(o[i])
		pass += string(e[i])
	}
	if len(o) != len(e) {
		pass += string(o[len(o)-1])
	}
	fmt.Println(pass)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    vector<int> v[3*m+1];
    rep(i,0,n){
        int l,r;cin>>l>>r;
        if(l==0&&r==m+1)continue;
        v[r].push_back(l+m);
        v[r+m].push_back(l+2*m);
    }
    int ans[3*m+1];
    ans[0]=0;
    int t=0;
    multiset<int> st;
    rep(i,1,3*m+1){
        ans[i]=ans[i-1];
        rep(j,0,v[i].size()){
            st.insert(v[i][j]);
        }
        if(st.size()>0){
            
            st.erase(st.begin());
            ans[i]++;
            
        }
        while(st.size()>0&&*st.begin()==i)st.erase(st.begin());
        if(i>=m)t=max(t,ans[i]-ans[i-m]);
    }
    cout<<n-t<<endl;
}





Measured memory_bytes: 28032
#include<stdio.h>
int max(int a,int b,int c) {
    int mx = a;
    mx = mx < b ? b : mx;
    mx = mx < c ? c : mx;
    return mx;
}
int main(void) {
    int a,b,c,r;
    scanf("%d %d %d",&a,&b,&c);
    r = a+b+c-max(a,b,c);
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int counting_sort(int,int[],int[],int);
void printArray(int,int[]);
int max(int,int);

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    int array[size];
    for(int i = 0; i < size; i++)
        scanf("%d", &array[i]);
    int sort[size];
    
    int maxVal = -1;
    for(int i = 0; i < size; i++)
        maxVal = max(maxVal,array[i]);
    
    counting_sort(size,array,sort,maxVal);
    printArray(size,sort);
    return (EXIT_SUCCESS);
}

int counting_sort(int size, int orig[size], int sorted[size], int maxVal){
    int countSize = maxVal+1;
    int count[countSize];
    for(int i = 0; i < countSize; i++)
        count[i] = 0;
    for(int j = 0; j < size; j++)
        count[orig[j]] = count[orig[j]]+1;
    for(int i = 1; i < countSize; i++)
        count[i] = count[i] + count[i-1];
    for(int j = 0; j < countSize; j++)
        count[j]--;
    for(int j = size-1; j >= 0; j--)
        sorted[count[orig[j]]--] = orig[j];
}

void printArray(int size, int a[size]){
    for(int i = 0; i < size; i++){
        if(i != size - 1)
            printf("%d ", a[i]);
        else printf("%d\n", a[i]);
    }
}

int max(int a, int b){
    if(a > b)
        return a;
    return b;
}



Measured memory_bytes: 17516
<?php

fscanf(STDIN, '%s', $s);

$s = str_split($s);


if($s[0]!='A'){
    echo 'WA';
    return;
}
$found = 0;
for($i=2;$i<=count($s)-2;$i++){
    if($s[$i]=='C'){
        $found++;
    }
}
if($found!=1){
    echo 'WA';
    return;
}
for($i=1;$i<=count($s)-1;$i++){
    if($s[$i]=='C'){
        continue;
    }
    if(ctype_upper($s[$i])){
    echo 'WA';
    return;    
    }
}
echo 'AC';


Measured memory_bytes: 4604
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
      
      int x = a*b;
      
      if(x%2==0){
          System.out.print("Even");
      }else{
          System.out.print("Odd");
      }
          
    }
}

Measured memory_bytes: 22996
from collections import deque

def main():

  n,m=map(int,input().split())
  INF=10**9
  d=[[INF]*3 for i in range(n)]
  to=[[] for i in range(n)]
  for i in range(m):
    u,v=map(lambda x:int(x)-1,input().split())
    to[u].append(v)
  s,t=map(lambda x:int(x)-1,input().split())

  #print(to)
  # calc d (after 3 times dist)
  d[s][0]=0
  cnt=0
  q=deque([(s,cnt)])
  while q:
    u,c=q.popleft()
    for v in to[u]:
      nc=(c+1)%3
      if d[v][nc]!=INF: continue;
      d[v][nc]=d[u][c]+1
      q.append((v,nc))
      
  #print(d)
  ans=d[t][0]
  print(ans//3 if ans!=INF else -1)

  
if __name__=='__main__':
  main()

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

int main() {
    int n;
    cin >> n;
	int t = 0;
	while(n){
		t += n % 10;
		n /= 10;
	}
	if(t == 1){
		cout << 10 << endl;
    }
	else{
		cout << t << endl;
    }
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int gcd(int a, int b) {
    if(a==0||b==0) return max(a, b);
    if (a<b) swap(a, b);

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

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

    vector<int> a(n);
    for(int in=0;in<n;in++) {
        cin >> a.at(in);
    }

    vector<int> l(n+1);
    vector<int> r(n+1);

    l.at(0) = 0;
    r.at(n) = 0;
    for(int in=0;in<n;in++) {
        l.at(in+1) = gcd(l.at(in), a.at(in));
    }
    for(int in=0;in<n;in++) {
        r.at(n-in-1) = gcd(r.at(n-in), a.at(n-in-1));
    }

    int ans = 1;
    for(int in=0;in<n;in++) {
        ans = max(ans, gcd(l.at(in), r.at(in+1))); 
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int h1 = sc.nextInt();
    int m1 = sc.nextInt();
    int h2 = sc.nextInt();
    int m2 = sc.nextInt();
    int k = sc.nextInt();

    System.out.println((h2-h1)*60 + m2 - m1 - k);
    
    


    


    
    


    
	}
}

Measured memory_bytes: 35728
n = int(input())
h = list(map(int, input().split()))
l = [0] + h + [0]
n += 2
ans = 0
while sum(l) != 0:
    for i in range(1, n):
        if (l[i] == 0) and (l[i-1] != 0):
            ans += 1
    for i in range(1, n):
        if l[i] != 0:
            l[i] -= 1
print(ans)

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

int main(){
  int N;
  scanf("%d", &N);
  
  int count = 0;
  int a = 2;
  
  while(a <= N){
    count++;
    a = a*2;
  }
  
  if(count == 0) printf("%d\n",N);
  else printf("%d\n", a/2);
  
  return 0;
}


Measured memory_bytes: 3808
#include<iostream>
#include<vector>

using namespace std;

int rec(int n, int k){

   if(n==1) return 0;
   else return (rec(n-1, k)+k)%n;
}

void hoge(int n, int k, int m){

   cout<< (rec(n-1, k)+m)%n+1<< endl;

}

int main(){

   while(1){
      int n, k, m;
      cin>> n>> k>> m;
      if(!(n||k||m)) break;

      hoge(n, k, m);
   }

   return 0;
}

Measured memory_bytes: 3320
from collections import defaultdict

n = int(input())
d = defaultdict(int)
m = 0
for i in range(n):
    s = input()
    d[s] += 1
    m = max(m,d[s])

ans = []
for k,v in d.items():
    if v == m:
        ans.append(k)

ans.sort()
for a in ans:
    print(a)


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

using namespace std;

typedef long long ll;

inline void update(ll &x,ll y) {
  x=max(x,y);
}

int num[505][505];

ll sum1[505][505],sum2[505][505];

void pre(int n) {
  for(int i=0;i<=n;i++)
    for(int j=i+1;j<=n;j++) sum1[i][j]=sum1[i][j-1]+num[i][j];
  for(int i=n;i>=0;i--)
    for(int j=i+1;j<=n;j++) sum1[i][j]=sum1[i+1][j]+sum1[i][j];
  for(int i=0;i<=n;i++)
    for(int j=i+1;j<=n;j++) sum2[i][j]=sum2[i][j-1]+num[j][i];
  for(int i=n;i>=0;i--)
    for(int j=i+1;j<=n;j++) sum2[i][j]=sum2[i+1][j]+sum2[i][j];
}

ll f[505][505];

void dp(int n) {
  for(int i=0;i<n;i++)
    for(int j=0;j<=i;j++)
      for(int k=i+1;k<=n;k++) 
        update(f[k][i],f[i][j]+sum1[0][k]-sum1[0][i]-sum1[i+1][k]+sum2[j+1][k]-sum2[j+1][i]);
}

int main() {
  int n;
  scanf("%d",&n);
  ll s=0;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      if (i!=j) {
	    scanf("%d",&num[i][j]);
	    s+=num[i][j];
	  }
  pre(n);
  dp(n);
  ll ans=0;
  for(int i=0;i<=n;i++) update(ans,f[n][i]);
  printf("%lld\n",s-ans);
  return 0;
}

Measured memory_bytes: 7168
K, N = map(int, input().split())
Ai = list(map(int, input().split()))
Di = [0]*len(Ai)

for i in range(len(Ai)):
    if i == len(Ai) - 1:
        Di[i] = (K - Ai[i]) + Ai[0]
    else:   
        Di[i] = Ai[i + 1] - Ai[i]

ans = K - max(Di)

print(ans)

Measured memory_bytes: 26444
print[0,1,2,12,84,770,8340,106400,1546888,25343766,461133960,232367169,627905865,632459808,928262728,919805769,382796331,887217496,639768068,869694124,205875097,205589953,487772376,239955313,998339621,31622834,902930073,146839084,449786840,982224660,865803735,21834818,721531716,26008837,471774471,69010090,700009308,776938882,645550477,526939604,142728157,654489641,128201240,185493259,789721045,977049419,589149550,700648836,25087729,874433491,352791804][input()]

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

int main(){
  int n;
  int tmap[101][101] = {0};

  for(;;){
    cin>>n;
    if(!n) break;

    int w,h;
    cin>>w>>h;

    for(int i=1; i<=100; i++)
      for(int j=1; j<=100; j++)
	tmap[i][j] = 0;

    int x,y;
    for(int i=0; i<n; i++){
      cin>>x>>y;
      tmap[x][y]=1;
    }

    int s,t;
    cin>>s>>t;

    int max=0,tmp=0;
    for(int i=1; i<=w-s+1; i++){
      for(int j=1; j<=h-t+1; j++){
	for(int k=i; k <= i+s-1; k++){
	  for(int l=j; l <= j+t-1; l++){
	    if(tmap[k][l] == 1) tmp++;
	  }
	}
	if(tmp > max) max = tmp;
	tmp=0;
      }
    }

    cout<<max<<endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

#define VARNUM (2)
#define ROUNDOFF(x) (floor(1e3 * (x) + 0.5) * 1e-3)

int main()
{
	int i;
	double a[VARNUM][VARNUM + 1], x, y;
	
	while (scanf("%lf%lf%lf%lf%lf%lf", &a[0][2], &a[0][1], &a[0][0], &a[1][2], &a[1][1], &a[1][0]) != EOF) {
		if (a[0][VARNUM] == 0.0) continue;
		
		for (i = 0; i <= VARNUM; ++i) {
			a[0][i] /= a[0][VARNUM];
			a[1][i] -= a[1][VARNUM] * a[0][i];
		}
		
		if (a[1][VARNUM - 1] == 0.0) continue;
		
		y = a[1][0] / a[1][VARNUM - 1];
		x = (a[0][0] - a[0][VARNUM - 1] * y) / a[0][VARNUM];
		
		printf("%.3lf %.3lf\n", ROUNDOFF(x), ROUNDOFF(y));
	}
		
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 3e5 + 10;
int n, t;
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> t;
    int a, b;
    int ret = INF;
    for(int i = 0; i < n; i ++){
        cin >> a >> b;
        if(b <= t){
            ret = min(ret, a);
        }
    }
    if(ret == INF){
        cout << "TLE\n";
    }
    else{
        cout << ret << endl;
    }
    return 0;
}



Measured memory_bytes: 256
m=int(raw_input())
n=int(raw_input())
A=[[] for i in range(m+1)]
B=[1]+range(3,m+1)
ans=[2]
for i in range(n):
    a,b=map(int,raw_input().split())
    if b!=2:
        A[a].append(b)
while(len(B)!=0):
    kb=[]
    for b in B:
        if A[b]==[]:
            ans.append(b)
            kb.append(b)
            for a in A:
                if b in a:
                    a.remove(b)
    for k in kb:
        B.remove(k)
ans.reverse()
for a in ans:
    print a
    

Measured memory_bytes: 6464
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();
		int takahashi = 0;

		for (int i=1; i<=a; i++){
			if (i < a || i <= b){
				takahashi++;
			}
		}
		System.out.println(takahashi);
	}

}


Measured memory_bytes: 21588
#include <iostream>
using namespace std;
 
int n;
int a[101][101];
int flg[101];
int t[101];
int sum = 0;
 
void visit(){
  int ima = 0;
  int mine = 100000000;
   
   
  for(int k=0;k<n-1;k++) {
    mine = 10000000;
    for(int i=0;i<n;i++) {
      if(flg[i] == 0 && mine > t[i]) {
    mine = t[i];
    ima = i;
      }
    }
    sum += mine;
    flg[ima] = 1;
     
    for(int i=0;i<n;i++) 
      if(a[ima][i] != -1) 
    if(t[i] > a[ima][i] ) t[i] = a[ima][i];
     
     
  }
}
 
int main() {
 
  cin >> n;
 
  for(int i=0;i<n;i++) 
    for(int j=0;j<n;j++) 
      cin >> a[i][j];
   
  for(int i=0;i<n;i++) {
    flg[i] = 0;
    t[i] = 100000000;
  }
   
  t[0] = 0;
  flg[0] = 1;
  for(int i=0;i<n;i++) 
    if(a[0][i] != -1) t[i] = a[0][i];
 
  visit();
 
  cout << sum << endl;
  
  return 0; 
   
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  cout << a[n-1] << " ";
  int k=-1;
  int h=1e9;
  for(int i=0;i<n-1;i++){
    if(abs(a[i]*2-a[n-1])<h){
      k=i;
      h=abs(a[i]*2-a[n-1]);
    }
  }
  cout << a[k] << endl;
}
       
            

    

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#define re register int
using namespace std;

int n;
long long ans=1;
const int mod=1000000007;

int main()
{
	std::scanf("%d",&n);
	
	for(re i=1;i<=n;i++)
		ans=(ans*i)%mod;
	
	std::printf("%lld",ans);
	return 0;
}

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

int main()
{
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a > b) swap(a,b);
	ll k = b - a;
	if(k & 1) printf("%lld\n",min(a-1ll+(b-a+1)/2,n-b+(b-a+1)/2));
	else printf("%lld\n",(b-a)/2);
	return 0;
}

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

namespace Counting_Characters
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputAll = "";

            while (true)
            {
                string input = Console.ReadLine();
                
                if (string.IsNullOrEmpty(input) == true)
                { break; }

                inputAll += input;

                
            }

            inputAll = inputAll.ToLower();


            List<char> letter = new List<char>();
            int[] count = new int[26];

            for (char i = 'a'; i <= 'z'; ++i)
            {
                letter.Add(i);
            }

            for (int i = 0; i < 26; ++i)
            {
                count[i] = 0;
            }

            foreach (char c in inputAll)
            {
                foreach (char c2 in letter)
                {
                    if (c == c2)
                    {
                        ++count[letter.IndexOf(c2)];
                    }
                }
            }

            int cc = 0;

            foreach (char item in letter)
            {                
                Console.WriteLine(item + " : " + count[cc]);
                ++cc;
            }

            
        }
    }
}



Measured memory_bytes: 15880
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N, M;
	cin >> N >> M;
	vector<int>H(N);
	rep(i, N)cin >> H[i];
	vector<int>v(N, -INF);
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		v[A] = max(v[A], H[B]);
		v[B] = max(v[B], H[A]);
	}
	int ans = 0;
	rep(i, N)if (H[i] > v[i])ans++;
	cout << ans;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
const int mod = 1e9 + 7 ;
vector<vector<int>> prefix_left(vector< string > mat , int n , int m){
	vector< vector<int> > ans(n,vector<int>(m,0));
	for( int i = 0 ; i < n ; i++) if(mat[i][0]=='.') ans[i][0] = 1 ;
	//for( int i = 0 ; i < m ; i++) if(mat[0][i]=='.') ans[0][i] = 1 ;
	for( int i = 0 ; i < n ; i++){
		for( int j = 1 ; j < m ; j++){
			if(mat[i][j]=='.'){
				ans[i][j] = 1 ;
				ans[i][j] += ans[i][j-1];
			}
		}
	} 
	return ans ;
}
vector<vector<int>> suffix_right(vector< string > mat , int n , int m){
	vector< vector<int> > ans(n,vector<int>(m,0));
	for( int i = 0 ; i < n ; i++) if(mat[i][m-1]=='.') ans[i][m-1] = 1 ;
	//for( int i = 0 ; i < m ; i++) if(mat[0][i]=='.') ans[0][i] = 1 ;
	for( int i = 0 ; i < n ; i++){
		for( int j = m-2 ; j >=0 ; j--){
			if(mat[i][j]=='.'){
				ans[i][j] = 1 ;
				ans[i][j] += ans[i][j+1];
			}
		}
	} 
	return ans ;
}
vector<vector<int>> prefix_up(vector< string > mat , int n , int m){
	vector< vector<int> > ans(n,vector<int>(m,0));
	//for( int i = 0 ; i < n ; i++) if(mat[i][m-1]=='.') ans[i][m-1] = 1 ;
	for( int i = 0 ; i < m ; i++) if(mat[0][i]=='.') ans[0][i] = 1 ;
	for( int j = 0 ; j < m ; j++){
		for( int i = 1 ; i < n ; i++){
			if(mat[i][j]=='.'){
				ans[i][j] = 1 ;
				ans[i][j] += ans[i-1][j];
			}
		}
	} 
	return ans ;
}
vector<vector<int>> suffix_down(vector< string > mat , int n , int m){
	vector< vector<int> > ans(n,vector<int>(m,0));
	//for( int i = 0 ; i < n ; i++) if(mat[i][m-1]=='.') ans[i][m-1] = 1 ;
	for( int i = 0 ; i < m ; i++) if(mat[n-1][i]=='.') ans[n-1][i] = 1 ;
	for( int j = 0 ; j < m ; j++){
		for( int i = n-2 ; i >=0 ; i--){
			if(mat[i][j]=='.'){
				ans[i][j] = 1 ;
				ans[i][j] += ans[i+1][j];
			}
		}
	} 
	return ans ;
}
void solve(){
	int n , m ;
	cin >> n >> m ;
	vector < string > mat(n);
	for( int i = 0 ; i < n ; i++) cin >> mat[i] ;
	vector < vector < int > > pl(n,vector<int>(m,1)) , sr(n,vector<int>(m,1)) , up(n,vector<int>(m,1)) , sd(n,vector<int>(m,1));
	pl = prefix_left(mat,n,m);
	sr = suffix_right(mat,n,m);
	up = prefix_up(mat,n,m);
	sd = suffix_down(mat,n,m);
	int ans = 0;
	for( int i = 0 ; i < n ; i++){
		for( int j = 0  ; j < m ; j++){
			if(mat[i][j]!='#'){
				int l = j==0?0:pl[i][j-1];
				int r = j==m-1?0:sr[i][j+1];
				int u = i==0?0:up[i-1][j];
				int d = i==n-1?0:sd[i+1][j];
				//cout << l+r+d+u+1 << " " ;
				ans = max(ans,l+r+u+d+1);
			}
		}
		//cout << "\n";
	}
	cout << ans ;
	
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 87112
#include<iostream>
#include<vector>
using namespace std;
int main () {
  int H, W, N;
  cin >> H >> W >> N;
  int x, y;
  cin >> x >> y;
  vector<vector<int>>T(2, vector<int>(N, 0));  //W->H,R = D = 1, L = U = -1
  vector<vector<int>>A(2, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    char c;
    cin >> c;
    switch(c) {
      case 'L': T[0][i] = -1; break;
      case 'R': T[0][i] = 1; break;
      case 'U': T[1][i] = -1; break;
      case 'D': T[1][i] = 1; break;
    }
  }
  for (int i = 0; i < N; i++) {
    char c;
    cin >> c;
    switch(c) {
      case 'L': A[0][i] = -1; break;
      case 'R': A[0][i] = 1; break;
      case 'U': A[1][i] = -1; break;
      case 'D': A[1][i] = 1; break;
    }
  }
  int mav, miv, mal, mil;
  mav = H;
  miv = 1;
  mal = W;
  mil = 1;
  for (int i = N - 1; i >= 0; i --) {
    if (A[1][i] == 1 && miv > 1) miv --;
    if (A[1][i] == -1 && mav < H) mav ++;
    if (A[0][i] == 1 && mil > 1) mil --;
    if (A[0][i] == -1 && mal < W) mal ++;
    if (T[1][i] == 1) mav --;
    if (T[1][i] == -1) miv ++;
    if (T[0][i] == 1) mal --;
    if (T[0][i] == -1) mil ++;
    if (mav == 0 || mal == 0 || miv == H + 1 || mil == W + 1) {
      cout << "NO" << endl;
      return 0;
    }
    //cout << mav << ' ' << miv << ' ' << mal << ' ' << mil << endl;
  }
  if (x >= miv && x <= mav && y >= mil && y <= mal) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}
  



Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'


int32_t main()
{
	ninja
	// int t;cin>>t;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=0;bool f=0;
	if(a>=k){
		cout<<k; return 0;
	}
	else if(a<k){
		sum=a;k-=a;
		
	}
	if(k>0){
			if(k>=b){
				k-=b;
			}
			else{
				k=0;
			}
		}
	if(k>0){
				
					sum-=k;
	}
	cout<<sum;
}



Measured memory_bytes: 3692
N = int(input())
ans = [ 0 for _ in range(10500)]
for i in range(1, 105):
  for j in range(1, 105):
    for k in range(1, 105):
      v = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if v < 10500:
        ans[v] += 1
for i in range(N):
  print(ans[i + 1])

Measured memory_bytes: 9144
#include<stdio.h>

void insertionSort(int [], int, int);
void shellSort(int [],int);

int c=0;

main() {
  int i,j,n;
  int A[1000000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  shellSort(A, n);
  printf("%d\n",c);
  for(i=1;i<=n;i++){
    printf("%d\n",A[i-1]);
  }
  return 0;
}

void insertionSort(int A[], int n, int g){

  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      c++;
    }
    A[j+g]=v;
  }
}


void shellSort(int A[],int n){

  int i,m=0;
  int B[n];

  B[0]=0;
  for(i=0;i<n;i++){
    B[i+1]=3*B[i]+1;
    m++;
    if(B[i+1]>1000000){
      break;
    }
  }
  while(B[m] > n){
    m--;
  }
  printf("%d\n",m);
  for(i=m;i>1;i--){
    printf("%d ",B[i]);
  }
  printf("%d\n", B[1]);
  for(i=m;i>=0;i--){
    insertionSort(A, n, B[i]);
  }
}



Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	vl v(n),s(100002);
	rep(i,n)cin>>v[i];
	rep(i,n)s[v[i]]++;
	rep(i,s.size()-1)s[i+1]+=s[i];
	rep(i,s.size()){
		if(n/2==s[i])ans++;
	}
	cout<<(n%2==0?ans:0)<<endl;
}


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

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	
	rep(i,N){
		cin >> A[i];
	}
	
	ll max = 0;
	ll temp = 0;
	
	rep(i,N){
		if(max < A[i]){
			max = A[i];
			temp = i;
		}
	}
	
	A[temp] = 0;
	
	ll max2 = 0;
	
	rep(i,N){
		if(max2 < A[i]){
			max2 = A[i];
		}
	}
	
	rep(i,N){
		if(i == temp){
			cout << max2 << endl;
		}else{
			cout << max << endl;
		}
	}
	
}


Measured memory_bytes: 3200
import math
N,D = map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
c = 0
for i in range(N):
    for j in range(i+1,N):
        di = 0
        for k in range(D):
            di += (L[i][k]-L[j][k])**2
        if math.sqrt(di).is_integer():
            c += 1 
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (N == 1) {
		cout << 0 << endl;
	}
	else {
		cout << max((int)1, (N + K - 3)  / (K - 1)) << endl;
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i=(a); i < (b); ++i)
#define pb push_back
#define fs first
#define sc second
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const ll mod = 998244353;

ll egcd(ll a, ll b, ll& x, ll& y) {
  if(b == 0) { x = 1; y = 0; return a; }
  ll d = egcd(b, a % b, x, y);
  x -= a / b * y; swap(x, y); return d; }

ll mod_inv(ll a, ll m) {
  ll x, y, d = egcd(a, m, x, y);
  return d == 1 ? (x%m+m)%m : -1; }

ll mod_pow(ll b, ll e, ll m) {
  ll res = 1; while(e) {
    if(e & 1) res = (res*b%m+m)%m;
    b *= b; b %= m; e >>= 1; }
  return res; }

const ll inv9 = mod_inv(9, mod);
vector<ll> p10;

struct node {
  int l, r;
  int x, lazy;
  node() {}
  node(int _l, int _r) : l(_l), r(_r), x(0), lazy(0) { }
  node(int _l, int _r, int _x) : node(_l,_r) { x = _x; }
  node(node a, node b) : node(a.l,b.r) { x = (p10[b.r - b.l + 1] * a.x + b.x) % mod; }
  void update(int v) { x = v; }
  void range_update(int v) { lazy = v; }
  void apply() { if(lazy != 0) x = ((lazy * (p10[r - l + 1] - 1)) % mod) * inv9 % mod; lazy = 0; }
  void push(node &u) { if(lazy != 0) u.lazy = lazy; } };

struct segment_tree {
  int n;
  vector<node> arr;
  segment_tree() { }
  segment_tree(const vector<ll> &a) : n(a.size()), arr(4*n) {
    mk(a,0,0,n-1); }
  node mk(const vector<ll> &a, int i, int l, int r) {
    int m = (l+r)/2;
    return arr[i] = l > r ? node(l,r) :
      l == r ? node(l,r,a[l]) :
      node(mk(a,2*i+1,l,m),mk(a,2*i+2,m+1,r)); }
  node update(int at, ll v, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (at < hl || hr < at) return arr[i];
    if (hl == at && at == hr) {
      arr[i].update(v); return arr[i]; }
    return arr[i] =
      node(update(at,v,2*i+1),update(at,v,2*i+2)); }
  node query(int l, int r, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return node(hl,hr);
    if (l <= hl && hr <= r) return arr[i];
    return node(query(l,r,2*i+1),query(l,r,2*i+2)); }
  node range_update(int l, int r, ll v, int i=0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return arr[i];
    if (l <= hl && hr <= r)
      return arr[i].range_update(v), propagate(i), arr[i];
    return arr[i] = node(range_update(l,r,v,2*i+1),
                         range_update(l,r,v,2*i+2)); }
  void propagate(int i) {
    if (arr[i].l < arr[i].r)
      arr[i].push(arr[2*i+1]), arr[i].push(arr[2*i+2]);
    arr[i].apply(); } };

int main() {
    cin.sync_with_stdio(false);
    int n, q, l, r, d; cin >> n >> q;
    vector<ll> jnk(n, 1);
    p10.resize(n + 1);
    p10[0] = 1;
    rep(i,1,n+1) p10[i] = (10 * p10[i - 1]) % mod;
    segment_tree st(jnk);
    rep(i,0,q) {
        cin >> l >> r >> d;
        l--; r--;
        st.range_update(l, r, d);
        cout << st.query(0, n - 1).x << '\n';
    }
}


Measured memory_bytes: 14576
#include<stdio.h>

int main (void)
{
  int s,sum1,sum2;
  
  scanf("%d", &s);
     
    sum1 = s/500;
    s = s%500;
    sum2 = s/5;
   
  
  printf("%d", sum1*1000+sum2*5);
  
  return 0;
}

Measured memory_bytes: 128
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 0x3f3f3f3f
#define Inf 1LL*INF*INF
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
int n,q;
int a[maxn],b[maxn],c[maxn],mn[maxn];

class Edge{
public:
	int u,v,w;
	Edge(){}
	Edge(int _u,int _v,int _w):u(_u),v(_v),w(_w){}
	bool operator < (const Edge &o)const{
		return w<o.w;
	}
}e[maxn*2];

namespace Dsu{
	int f[maxn];
	void init(){
		rep(i,n)f[i]=i;
	}
	int find(int x){
		return f[x]==x?x:f[x]=find(f[x]);
	}
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&q);
	rep(i,n)mn[i]=0x3f3f3f3f;
	rep(i,q){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		mn[a[i]]=min(mn[a[i]],c[i]+1);
		mn[b[i]]=min(mn[b[i]],c[i]+2);
		e[i+n]=Edge(a[i],b[i],c[i]);
	}
	rep(it,2)rep(i,n)mn[(i+1)%n]=min(mn[(i+1)%n],mn[i]+2);
	rep(i,n)e[i]=Edge(i,(i+1)%n,mn[i]);
	sort(e,e+n+q);
	Dsu::init();
	ll ans=0;
	rep(i,n+q){
		int u=Dsu::find(e[i].u),v=Dsu::find(e[i].v);
		if(u==v)continue;
		Dsu::f[u]=v;
		ans+=e[i].w;
	} 
	printf("%lld\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 11904
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX],n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> R[i];
		}
	int maxv=-2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
		}
		
		
	cout << maxv <<endl;
	
	return 0;
	}

Measured memory_bytes: 1940