akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define f first
#define s second

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, X, D; cin >> N >> X >> D;
	
	if (D == 0) {
		if (X != 0) print(N+1);
		else print(1);
		return 0;
	}

	if (D < 0) {
		X = X + (N-1) * D; D = abs(D);
	}

	map<int, vector<pll>> seqs;
	F0R(i, N+1) {
		ll lo = X * i + D * i * (i-1)/2;
		ll hi = X * i + D * ((N-1) * N / 2 - (N-i-1) * (N-i)/2);
		seqs[X * i % D].push_back({lo, hi});
	}

	ll ans = 0;
	for (pair<int, vector<pll>> data : seqs) {
		vector<pll> seq = data.second;
		sort(seq.begin(), seq.end());
		ll lval = -1;
		ll hval = -1;
		for (int i = 0; i < seq.size(); ++i) {
			pll range = seq[i];
			if (lval == -1) {
				lval = range.first;
				hval = range.second;
			} else if (range.first <= hval) {
				hval = max(hval, range.second);
			} else {
				ans += (hval - lval) / D + 1;
				lval = range.first;
				hval = range.second;
			}
		}
		ans += (hval - lval) / D + 1;
	}
	print(ans);
}

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

#define DIV 1000000007

long long dp[100005][15];
string S;

int main(){
	cin >> S;
	dp[0][0] = 1;

	for(long long i = 0; i < S.size(); i++){
		if(S[i] == '?'){
			for(long long num = 0; num < 10; num++){
				for(long long j = 0; j < 13; j++){
					dp[i+1][(10*j + num)%13] += dp[i][j];
					dp[i+1][(10*j + num)%13] %= DIV;
				}
			}
		}else{
			long long num = S[i] - '0';
			for(long long j = 0; j < 13; j++){
				dp[i+1][(10*j + num)%13] += dp[i][j];
				dp[i+1][(10*j + num)%13] %= DIV;
			}
		}
	}
	cout << dp[S.size()][5] % DIV << endl;


}



Measured memory_bytes: 12160
module Main where

import Control.Applicative
import Data.List

inf = 10 ^ 20 :: Integer

solve :: Integer -> Integer -> Integer
solve x y = minimum [ if y - x >= 0 then y - x else inf
                    , if (-x - y) >= 0 then (-x - y) + 1 else inf
                    , if x + y >= 0 then x + y + 1 else inf
                    , if x - y >= 0 then x - y + 2 else inf
                    ]

main :: IO ()
main = do
  [x, y] <- map read . words <$> getLine
  print $ solve x y

Measured memory_bytes: 508
#include<iostream>
#include<climits>
using namespace std;
int main(){
  int n,k;
  cin>>n;
  int h[n];
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
  int dpa[n],dpb[n],dpc[n];
  dpa[0]=a[0];
  dpb[0]=b[0];
  dpc[0]=c[0];
  for(int i=1;i<n;i++) dpa[i]=dpb[i]=dpc[i]=INT_MIN;
  for(int i=1;i<n;i++){
      dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
      dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
      dpc[i]=max(dpa[i-1],dpb[i-1])+c[i];
  }
  cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]));
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
const int MOD = (int)1e9 + 7;

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

    LL n, k;
    cin >> n >> k;
    n++;
    LL res = 0;
    for (int i = k; i <= n; i++) {
        LL cur = 1LL * (n + (n - i + 1)) * i / 2 - 1LL * (i + 1) * i / 2 + 1;
        res = (res + cur) % MOD;
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 3656
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define mp make_pair
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define endl "\n"

using namespace std;

const int N = 1500510;
const int inf = (int)(1e18) + 123;
const int mod = (1e9) + 7;
const double eps = 1e-9;

int n, sz;

multiset <int> S;

bool move(int x, multiset <int> &cur) {
    auto it = S.lower_bound(x);
    if (it == S.begin()) {
        return false;
    }
    it--;
    S.erase(it);
    cur.insert(*it);
    return true;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    sz = (1 << n);
    for(int i = 0; i < sz; ++i) {
        int x; cin >> x;
        S.insert(x);
    }
    multiset <int> a;
    move(inf, a);

    for(int i = 1; i <= n; ++i) {
        multiset <int> b;
        for(auto num : a) {
            if (!move(num, b)) {
                cout << "No";
                return 0;
            }
        }
        for(auto it : b) {
            a.insert(it);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 18688
import numpy as np
N,M=map(int,input().split())
S=np.ones(N)
H=list(map(int,input().split()))

for j in range(M):
  a,b=map(int,input().split())
  
  if H[a-1]<H[b-1]:
    S[a-1]=0

  elif H[a-1]>H[b-1]:
    S[b-1]=0

  else:
    S[a-1]=0
    S[b-1]=0

print(int(np.sum(S)))

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

int gcd(int a, int b);

int main() {
    int N; cin >> N;
    int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
    int left[N], right[N], max_gcd = 0;
    left[0] = 0; right[N-1] = 0;
    for (int i = 1; i < N; i++) {
        left[i] = gcd(left[i-1], A[i-1]);
        right[N-i-1] = gcd(right[N-i], A[N-i]);
    }
    for (int i = 0; i < N; i++) {
        max_gcd = max(max_gcd, gcd(left[i], right[i]));
    }
    cout << max_gcd << endl;
}

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


Measured memory_bytes: 1408
import collections
N = int(input())
s = [input() for i in range(N)]
 
counter = collections.Counter(s)
count = counter.most_common()
 
most = count[0][1]
 
c =[]
for i in range(len(count)):
    if count[i][1] == most:
        c.append(count[i][0])
 
c.sort()
 
for i in range(len(c)):
    print(c[i])

Measured memory_bytes: 47640
import sys
from collections import deque
from collections import defaultdict
from collections import Counter

def conn(n,m,e):
    d=dict(zip(range(1,n+1),range(-1,(-1)*n-1,-1)))
    td=defaultdict(lambda:deque([])) #tdは同値類がキーで中の元が値
    c=1
    for edge in e:
        a=edge[0]
        b=edge[1]
        da=d[a] #da,dbはa,bの含まれる同値流のラベル
        db=d[b]
        if da<0 and db<0:
            d[a]=c
            d[b]=c
            td[c].append(a)
            td[c].append(b)
            c+=1
        elif da>0 and db<0:
            d[b]=da
            td[d[a]].append(b)
        elif da<0 and db>0:
            d[a]=db
            td[d[b]].append(a)
        elif da>0 and db>0 and da!=db:
            for x in td[db]:
                d[x]=da
                td[da].append(x)

    return list(d.values())

def main(n,k,l,e1,e2):
    d1=conn(n,k,e1)
    d2=conn(n,l,e2)
    p=tuple(zip(iter(d1),iter(d2)))
    d=Counter(p)
    # print(d1,d2,d,p)
    d[(k,l)]=1
    print(' '.join([str(d[x]) for x in p]))

if __name__=='__main__':
    ssr=sys.stdin.readline
    n,k,l=map(int,ssr().strip().split())
    e1=[]
    e2=[]
    for _ in range(k):
        e1.append(tuple(map(int,ssr().strip().split())))
    for _ in range(l):
        e2.append(tuple(map(int,ssr().strip().split())))
    main(n,k,l,e1,e2)


Measured memory_bytes: 101948
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<#x" = "<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef pair<int,int> pii;
typedef long long ll;
const int inf=~0u>>1,MOD=1e9+7;//*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=((TT=but)+fread(but,1,1<<15,stdin)),TT==mo))?-1:*TT++)//*/
inline int rd() {
	int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
	while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
int main(){
	int H=rd(),W=rd(),h=rd(),w=rd();
	if(H%h==0&&W%w==0)puts("No");
	else{
		puts("Yes");
		int a=2333,b=-(h*w-1)*a-1;
		rep(i,1,H)rep(j,1,W)
			printf("%d%c",(i%h||j%w)?a:b," \n"[j==W]);
	}
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            switch (x)
            {
                case 3:
                case 5:
                case 7:
                    Console.WriteLine("YES");
                    break;
                default:
                    Console.WriteLine("NO");
                    break;
            }
        }
    }
}


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

int main()
{
	int a,b;
	scanf ("%d%d", &a, &b);
	int aa,ab,bb;
	aa=a+a-1;
	ab=a+b;
	bb=b+b-1;
	if (aa>=ab && aa>=bb)	printf("%d\n",aa);
	else if (bb>=ab && bb>=aa ) printf("%d\n", bb);
	else if (ab>=aa && ab>=bb ) printf("%d\n", ab);
	
	return 0;
}

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

int N,K,A[100010],d[100010] = {0},ans = 0;
vector<vector<int>> v(100010);
int dfs(int n){
	for(int i=0;i<v[n].size();i++){
		dfs(v[n][i]);
		d[n] = max(d[n],d[v[n][i]]+1);
	}
	if(n!=1 && d[n]==K-1 && A[n]!=1){
		ans++;
		d[n] = -1;
	}
}

int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		if(i==1 && A[i]!=1) ans++;
		if(i!=1) v[A[i]].push_back(i);
	}
	dfs(1);
	cout << ans << endl;
}

Measured memory_bytes: 11136
using System;
using System.Linq;

class MondaiB
{
    static void Main()
    {
        var n = Int32.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var array = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var nearTemperature = double.MaxValue;
        var ansIndex = 0;
        for (int i=0;i<n; ++i)
        {
            var num =Math.Abs((line[0] - array[i] * 0.006)-line[1]);
            if(num< nearTemperature)
            {
                nearTemperature = num;
                ansIndex = i+1;
            }
        }
        Console.WriteLine(ansIndex);
    }
}

Measured memory_bytes: 13340
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] c) {
        Scanner scan = new Scanner(System.in);
        double t = scan.nextInt();
        double half = 2;
        double s = t % half;
        if (s == 0) {
            System.out.println(new BigDecimal((t / half) / t).setScale(6));
        } else {
            double v = Math.ceil(t / half);
            System.out.println(new BigDecimal(v / t).setScale(6, BigDecimal.ROUND_HALF_UP));
        }
    }
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

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

	while(1){
		int n,ans_k,ans_sum = INT_MAX,m = 0;
		cin >> n;
		if(n == 0) break;
		VI a(n),b(n),c(n);
		rep(i,n){
			cin >> a[i] >> b[i] >> c[i];
			if(m < a[i] || m < b[i])
				m = a[i] > b[i]? a[i]:b[i];
		}
		VI cost(m + 1);
		priority_queue<PII,vector<PII >,greater<PII> > que;
		rep(k,cost.size()){
			int res = 0;
			fill(all(cost), INT_MAX);
			que.push(mp(0,k));
			cost[k] = 0;
			while(!que.empty()){
				int d = que.top().first, u = que.top().second;
				que.pop();
				if(cost[u] < d) continue;
				rep(i,n){
					if(u == a[i] && cost[u] + c[i] < cost[b[i]]){
						cost[b[i]] = cost[u] + c[i];
						que.push(mp(cost[b[i]], b[i]));
					}
					if(u == b[i] && cost[u] + c[i] < cost[a[i]]){
						cost[a[i]] = cost[u] + c[i];
						que.push(mp(cost[a[i]], a[i]));
					}
				}
			}
			rep(i,cost.size()){
				res += cost[i];
			}
			if(res < ans_sum){
				ans_k = k;
				ans_sum = res;
			}
		}
		cout << ans_k << " " << ans_sum << endl;
	}
	return 0;
}

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

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

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

#define MOD (1000 * 1000 * 1000 + 7)
#define INF (1LL << 60)
#define pb push_back
#define po pop_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;

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

    map<int, int> niz;
    int t;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        ++niz[t];
    }

    for (auto &i : niz) {
        if (i.se > 2) {
            cout << '0' << endl;
            return 0;
        } else if (i.fi == 0 && i.se > 1) {
            cout << '0' << endl;
            return 0;
        }
    }

    ll cnt = 1;
    for (auto &i : niz) {
        cnt *= i.se;
        cnt = cnt % MOD;
    }

    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
#define fore(i,ii,iii) for(ll i=ii;i<iii;i++)
#define SZ(a) int((a).size())

const ll N=1e5+15,INF=1e12;
string s1,s2;
ll dp[3030][3030];


ll f(int x, int y){
  if(x*y==0){return 0;}
  if(dp[x][y]>=0){return dp[x][y];}
  if(s1[x-1]==s2[y-1]){dp[x][y]=1+f(x-1,y-1);}else
  {dp[x][y]=max(f(x-1,y),f(x,y-1));}
  return dp[x][y];
  
}

string res(int x,int y){
  string sol;
  while(x*y>0){
    if((f(x,y)==f(x-1,y))){x--;}else
    if((f(x,y)==f(x,y-1))){y--;}else
    if(f(x,y)-f(x-1,y-1)==1){sol+=s1[x-1];x--;y--;}
  }
  reverse(sol.begin(),sol.end());
   return sol; 
}

int main() {
cin>>s1>>s2;
memset(dp,-1,sizeof dp);
cout<<res(SZ(s1),SZ(s2));
}

Measured memory_bytes: 72320
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a;
	return 0;
}
	

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ll Fact(ll n)
{
    if (n == 0) return 1;
    if (n == 1) return 1;
    return n * Fact(n - 1);
}

std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

void _main()
{
    int N, P;
    cin >> N >> P;
    int E = 0, O = 0;
    rep(i, 0, N)
    {
        int A;
        cin >> A;
        if (A % 2 == 0)
        {
            ++E;
        }
        else
        {
            ++O;
        }
    }

    ll e = 1;
    rep(i, 0, E) e *= 2;
    ll o = 0;
    for (int i = P; i <= O; i += 2)
    {
        o += comb(O, i)[O][i];
    }
    cout << e * o << endl;
}


Measured memory_bytes: 256
n = int(input())
A = sorted(int(input())for _ in range(n))

if n % 2 == 0:
    low = A[:n//2]
    high = A[n//2:]
    ans = abs(2*sum(high)-high[0]-(2*sum(low)-low[-1]))
else:
    low = A[:n//2]
    high = A[n//2+1:]
    mid = A[n//2]
    ans = abs(2*sum(high)-high[0]-(2*sum(low)-low[-1]))
    ans += max(high[0]-mid, mid-low[-1])
print(ans)

Measured memory_bytes: 7776
import Control.Monad (replicateM)

main :: IO ()
main = do
  ns <- map (read :: String -> Int) <$> getNLine_ 5
  print $ ans ns

ans :: [Int] -> Int
ans ns = ds + m
  where ds = (+(-10)) . sum $ map (\n -> let r = n `mod` 10 in if r == 0 then n else n - r + 10) ns
        m = (\k -> if k == [] then 10 else minimum k) . filter (/= 0) $ map (`mod` 10) ns

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	int ans = 1;
	for (int i = 1; i * i <= m; i++) {
		if (m % i != 0) continue;
		int r = m / i;
		if (i >= n) ans = max(ans, r);
		if (r >= n) ans = max(ans, i);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
[w, h, n] = list(map(int, input().split()))
list_x1 = []
list_x2 = []
list_y3 = []
list_y4 = []
for i in range(n):
  xya = list(map(int, input().split()))
  if xya[2] == 1:
    list_x1.append(xya[0])
  if xya[2] == 2:
    list_x2.append(xya[0])
  if xya[2] == 3:
    list_y3.append(xya[1])
  if xya[2] == 4:
    list_y4.append(xya[1])
try:
  min_x = min(list_x2)
except ValueError:
  pass  
try:
  max_x = max(list_x1)
except ValueError:
  pass  
try:
  min_y = min(list_y4)
except ValueError:
  pass  
try:
  max_y = max(list_y3)
except ValueError:
  pass  
try:
  w =min_x
except NameError:
  pass
try:
  w -= max_x
except NameError:
  pass
try:  
  h = min_y
except NameError:
  pass
try:
  h -= max_y
except NameError:
  pass
if w > 0 and h > 0:
  print(w*h)
else:
  print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <list>
using namespace std;

int main()
{

	string s;
    int w;

    cin >> s >> w;

    for(int i = 0; i < s.size(); i = i + w){
        cout << s[i];
    }

    cout << endl;

	return 0;

}


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int ans = Integer.MAX_VALUE;
    for (int i = 0; i < S.length() - 2; i++) {
      int A = Integer.parseInt(S.substring(i, i + 3));
      int B = Math.abs(753 - A);
      ans = Math.min(ans, B);
    }
    System.out.println(ans);
  }
}


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

int main () {

    int a, b;
    cin >> a >> b;

    int diff = b - a;

    int sum = 0;
    for (int i = 1; i <= diff; i++) {
        sum += i;
    }

    cout << sum - b << endl;

    return 0;
}

Measured memory_bytes: 256
var
	i:Longint;
	n,m,u:int64;
	s,t:String;
function gcd(a,b:int64):int64;
begin
	if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
begin
	readln(n,m);
	setlength(s,n);
	setlength(t,m);
	readln(s);
	readln(t);
	u:=gcd(n,m);
	for i:=0 to u-1 do if s[n div u*i+1]<>t[m div u*i+1]then begin
		writeln(-1);
		exit;
	end;
	writeln(n*m div u);
end.


Measured memory_bytes: 384
import sys
import heapq
from collections import deque

# sys.setrecursionlimit(100001)
INF = sys.maxsize


# ===CODE===
def main():
    ten = 10
    h,w = map(int, input().split())
    dist_mat=[]
    for i in range(ten):
        l = list(map(int, input().split()))
        dist_mat.append(l)

    table = []

    for i in range(h):
        l = list(map(int, input().split()))
        table.append(l)

    for k in range(ten):
        for i in range(ten):
            for j in range(ten):
                dist_mat[i][j] = min(dist_mat[i][j], dist_mat[i][k]+dist_mat[k][j])

    ans = 0
    for i in range(h):
        for t in table[i]:
            if t == -1: continue
            ans += dist_mat[t][1]


    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40284
#include<stdio.h>
int main(){
	int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(x==0 || y==0 || x==W || y==H)
	 {printf("No\n");}
	
	else if(x<r || W-x<r || y<r || H-y<r)
	 {printf("No\n");}
	
	else
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2684
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W;
    cin >> H >> W;
    VEC(string) Maze(H);
    READVEC(Maze);

    int ret = 1;
    FOR(h, 0, H)FOR(w, 0, W)
        if (Maze[h][w] == '.') {
            queue<Pii> bfsQ;
            VEC(VEC(int)) Dist(H, VEC(int)(W, -1));

            auto addToQ = [&](int y, int x, int dist)
            {
                if  (y >= 0 && y < H && x >= 0 && x < W && 
                        Maze[y][x] != '#' && Dist[y][x] < 0) {
                    Dist[y][x] = dist;
                    bfsQ.push(Pii(y, x));
                }
            };

            addToQ(h, w, 0);

            while (!bfsQ.empty()) {
                Pii pr = bfsQ.front();
                bfsQ.pop();
                int i = pr.first, j = pr.second;
                int d = Dist[i][j];

                addToQ(i, j + 1, d + 1);
                addToQ(i, j - 1, d + 1);
                addToQ(i + 1, j, d + 1);
                addToQ(i - 1, j, d + 1);
            }

            FOR(h2, 0, H)
                FOR(w2, 0, W)
                    if (Dist[h2][w2] >= 0)
                        ret = max(ret, Dist[h2][w2]);
        }

    cout << ret << endl;
    return 0;
};

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

int main() {
    int N;
    cin >> N;
    string S[N];
    int P[N];
    int num[N];
    for (int i=0; i<N; ++i) {
        cin >> S[i] >> P[i];
        num[i] = i+1;
    }

    int i = 0;
    int flag = 0;
    int swap_P;
    int swap_num;
    string swap_S;
    // 点数大きい順に並べる
    while (1) {
            if (flag == N-1) { // すべて無操作ならbreak
                break;
            } else if (i == N-1) { // 1巡したらreset
                i = 0;
            } else if (P[i] >= P[i+1]) { // 1つ無操作ならflag
                ++i;
                ++flag;
            } else { // swapしてflagをreset
                swap_P = P[i];
                P[i] = P[i+1];
                P[i+1] = swap_P;
                swap_S = S[i];
                S[i] = S[i+1];
                S[i+1] = swap_S;
                swap_num = num[i];
                num[i] = num[i+1];
                num[i+1] = swap_num;
                ++i;
                flag = 0;
            } 
    }

    i = 0;
    flag = 0;
    // 辞書順に並べる
    while (1) {
            if (flag == N-1) { // すべて無操作ならbreak
                break;
            } else if (i == N-1) { // 1巡したらreset
                i = 0;
            } else if (S[i] <= S[i+1]) { // 1つ無操作ならflag
                ++i;
                ++flag;
            } else { // swapしてflagをreset
                swap_P = P[i];
                P[i] = P[i+1];
                P[i+1] = swap_P;
                swap_S = S[i];
                S[i] = S[i+1];
                S[i+1] = swap_S;
                swap_num = num[i];
                num[i] = num[i+1];
                num[i+1] = swap_num;
                ++i;
                flag = 0;
            } 
    }

    for (int i=0; i<N; ++i) {
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int X, A;
    cin >> X >> A;
    cout << (X < A ? 0 : 10) << endl;
    return 0;
}

Measured memory_bytes: 764
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, D: number } => {
  const [N, D] = lines[0].split(' ').map(line => +line)
  const obj = { N, D }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, D } = parseLines(lines)
  let range = D * 2 + 1
  let person = Math.floor(N / range)
  if (N % range > 0) {
    person++
  }
  return `${person}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7500
def main():
    n, k, q = list(map(int, input().split()))
    particapant = [k] * n
    seikai = {}
    for i in range(q):
        s = int(input())
        seikai.setdefault(s, 0)
        seikai[s] += 1
    for i in range(1, n+1):
        point = k
        if i in seikai:
            point -= q - seikai[i]
        else:
            point -= q
        print('Yes') if point > 0 else print('No')


if __name__ == '__main__':
    main()

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

int main(void){
    int i;
    int a, b;
    int x, y, z, max1;

    scanf("%d %d", &a,&b);

    x = a + b;
    y = a - b;
    z = a*b;

    max1 = max(x,y);
    max1 = max(max1,z);

    printf("%d", max1);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

void ruiseki_inc(V &v, vector<P>&p){
    rep(i, v.size())v[i] = 0;
    rep(i, p.size()){
        v[p[i].first]++;
        v[p[i].second + 1]--;
    }
    rep(i, v.size() - 1)v[i + 1] += v[i];
    rep(i, p.size()){
        v[p[i].second + 1]-=p[i].second - p[i].first + 1;
    }
    rep(i, v.size() - 1)v[i + 1] += v[i];
}

int main(){

    ll N, M;
    cin >> N >> M;
    V a(N);
    rep(i, N)cin >> a[i];
    ll sum = 0;
    V v(2 * M + 10, 0);
    vector<P>p;
    rep(i, N - 1){
        ll x = a[i], y = a[i + 1];
        if(x > y)y += M;
        sum += y - x;
        p.push_back(P(x + 2, y));                
    }
    ruiseki_inc(v, p);
    ll ans = sum;
    rep1(i, M)chmin(ans, sum - v[i] - v[i + M]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;
int ans = 0;

int test(vector<bool> &switches, vector<vector<int>> &bulb, vector<int> &p)
{
    //switches is the state of switches being tested
    //bulb is every bulb and their corresponding switches
    //p is the requirement to light the bulbs
    for(int i = 0; i < bulb.size(); i++) //for every bulb
    {
        int oncnt = 0;
        for(int j = 0; j < bulb[i].size(); j++) //for every switch in each bulb
        {
            if(switches[bulb[i][j] - 1]) //this loop counts the number of switches that is on
            {
                oncnt++;
            }
        }
        if(oncnt % 2 != p[i] % 2) //tests to see whether the bulb will light
        {
            return 0;
        }
    }
    return 1; //all the bulbs lighted up, increment ans
}

int brute_force(int i, int n, vector<bool> switches, vector<vector<int>> &bulb, vector<int> &p)
{
    //i is iterator
    //n is number of switches
    //switches is the state of the switches
    //bulb is every bulb and their corresponding switches
    //p is odd and even of the bulbs

    //base case: when i = n, a new set of switches is constructed, so we test it
    if(i == n)
    {
        ans += test(switches, bulb, p); //test function will return 1 if the result is +ve
        return 69;
    }
    brute_force(i + 1, n, switches, bulb, p); //if ith switch is off
    switches[i] = 1;
    brute_force(i + 1, n, switches, bulb, p); //if ith switch is on
}

int main()
{
    /*
    2 2
    2 1 2
    1 2
    0 1
    */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> bulb(m);
    vector<int> p(m);
    vector<bool> switches(n, 0); //initialize all to off
    for(int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        bulb[i].resize(k);
        for(int j = 0; j < k; j++)
        {
            cin >> bulb[i][j];
        }
    }
    for(int i = 0; i < m; i++)
    {
        cin >> p[i];
    }
    brute_force(0, n, switches, bulb, p);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {
	
	int a, b;

	cin >> a >> b;
	cout << a * b - a - b +1<< endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

const int MAXA = 17;

int D[MAXA][MAXA], C[MAXA][MAXA];
vector <pair <PII, int> > E;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int a, b, n = 202;
	cin >> a >> b;
	FOR(i, 1, a + 1)
		FOR(j, 1, b + 1)
	{
		cin >> D[i][j];
		C[i][j] = INF;
	}
	REP(c1, 101)
		REP(c2, 101)
		REP(c3, 101)
	{
		bool ok = true, s = false;
		FOR(i, 1, a + 1)
			FOR(j, 1, b + 1)
		{
			int d = c1 * i + c2 * j + c3;
			if (d < D[i][j])
				ok = false;
			if (d == D[i][j] && C[i][j] > D[i][j])
				s = true;
		}
		if (ok && s)
		{
			FOR(i, 1, a + 1)
				FOR(j, 1, b + 1)
				C[i][j] = min(C[i][j], c1 * i + c2 * j + c3);
			E.push_back(MP(MP(c1 + 1, n - c2), c3));
		}
	}
	FOR(i, 1, a + 1)
		FOR(j, 1, b + 1)
	{
		if (C[i][j] > D[i][j])
		{
			cout << "Impossible\n";
			return 0;
		}
	}
	cout << "Possible\n";
	cout << n << ' ' << SZ(E) + n - 2 << '\n';
	REP(i, (n - 2) / 2)
		cout << i + 1 << ' ' << i + 2 << " X\n";
	REP(i, (n - 2) / 2)
		cout << n - i - 1 << ' ' << n - i << " Y\n";
	REP(i, SZ(E))
		cout << E[i].first.first << ' ' << E[i].first.second << ' ' << E[i].second << '\n';
	cout << "1 " << n << endl;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n,t;
    cin>>n>>t;
    int ans0=INT_MAX;
    rep(i,n)
    {
        int a,b;
        cin>>a>>b;
        if(a<ans0 &&b<=t)
        ans0=a;
    }
    if(ans0==INT_MAX) {
        cout<<"TLE"<<endl;
    }
    else cout<<ans0<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, t[100010], x[100010], y[100010];

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> t[i] >> x[i] >> y[i];
		if (t[i] < x[i] + y[i] || (t[i] % 2) != ((x[i] + y[i]) % 2)) {
			cout << "No" << endl;
			ggr
		}
	}
	cout << "Yes" << endl;
	ggr
}

Measured memory_bytes: 2560
N = int(input())
h = list(map(int, input().split()))
ans = 0

for l in range(N):
    while h[l] != 0:
        r = l+1
        for i in range(r, N):
            if h[i] == 0:
                break
            r += 1
        for i in range(l, r):
            h[i] -= 1
        ans += 1
print(ans)

Measured memory_bytes: 3064
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 1000000000005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
ll n,m;
bool issafe(ll i,ll j)
{
	if(i>=0 and i<n and j>=0 and j<m) return true;
	return false;
}
ll ha[] = {0,-1,-2,1,2};
signed main()
{
    fast;
    
    ll i,j;
    cin>>n>>m;
    ll sx,sy,dx,dy;
    cin>>sx>>sy>>dx>>dy;
    vector<string> v;
    for(i=0;i<n;i++)
    {
    	string s;
    	cin>>s;
    	v.pb(s);
    }
    sx--;
    sy--;
    dx--;
    dy--;
    vector<vector<ll>> d(n+2, vector<ll> (m+2,maxn));
    deque<pii> q;
    q.push_front({sx,sy});
    d[sx][sy] = 0;
    while(!q.empty())
    {
    	pii st = q.front();
    	q.pop_front();
        
        for(i=0;i<5;i++)
        {
        	for(j=0;j<5;j++)
        	{
        		ll nx = st.fi + ha[i],ny = st.se + ha[j];
        		if(issafe(nx,ny))
        		{
        			if(v[nx][ny]=='#') continue;
        			ll we;
        			if((nx==st.fi and ny==st.se+1) or 
        				(nx==st.fi and ny==st.se-1) or
        				(nx==st.fi+1 and ny==st.se) or
        				(nx==st.fi-1 and ny==st.se)){
        				we = 0;
        			}
        			else we = 1;
        			if(d[st.fi][st.se] + we < d[nx][ny])
        			{
        				d[nx][ny] = d[st.fi][st.se] + we;
        				if(we==1)
        				{
        					q.push_back({nx,ny});
        				}
        				else
        				{
        					q.push_front({nx,ny});
        				}
        			}
        		}
        	}
        }
    }
    if(d[dx][dy]==maxn) cout<<"-1";
    else cout<<d[dx][dy];
}

Measured memory_bytes: 12696
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,j;
        int count = 0;
        int min;
        int minnum;
        int n = sc.nextInt();
        int A[] = new int[n];
        for(i=0;i<n;i++){
            A[i] = sc.nextInt();
        }
        for(i=0;i<n-1;i++){
            min = A[i];
            minnum = i;
            for(j=i+1;j<n;j++){
                if(A[j]<min){
                    min = A[j];
                    minnum = j;
                }
            }
            if(minnum != i){
                int r = A[minnum];
                A[minnum] = A[i];
                A[i] = r;
                count++;
            }
        }
        for(i=0;i<n;i++){
            System.out.printf("%d",A[i]);
            if(i != n-1) System.out.printf(" ");
        }
        System.out.printf("\n");
        System.out.printf("%d\n",count);
    }
}



Measured memory_bytes: 26452
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define all(x) x.begin() , x.end()

int n , m , v[105] , s , md1 , md2; 
ll an , ans; 
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",v+i);
        s += v[i];
    }
    if(s % n != 0){
        int ss = s ; 
        while(s % n)++s;
        while(ss % n)--ss;
        md1 = s / n , md2 = ss/n;
    }
    else md1 = s/n;
    for(int i=0;i<n;++i){
        an += (md1 - v[i]) * (md1 - v[i]);
        ans += (md2 - v[i]) * (md2 - v[i]);
    }
     cout << min(an , ans) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#pragma warning(disable : 4996)
 
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
//最大公約数
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
//最小公倍数
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
 
int n,m,b;
int a[50];
 
int main(){
        cin >> n >> m;
 
        REP(i,m){
             int num;
             cin >> num >> b;
 
              a[num-1]++;
              a[b-1]++;
        }
 
        REP(i,n) printf("%d\n", a[i]);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;


vector<vector<pair<ll, ll > > > G;
//行きがけ順番を記憶（どんな順番で走査されたかを記憶）
vector<ll > pre;
//頂点から到達しうる最小の頂点
vector<ll > low;
//到達済みの頂点か
vector<bool > reach;
vector<pair<ll, ll > > ans;
//カウンター
void dfs(ll idx, ll from = -1, ll pre_count = -1){
    reach[idx] = true;
    pre[idx] = pre_count++;
    low[idx] = pre[idx];


    for(ll i = 0; i < G[idx].size(); i++){
        //cout << idx << endl;
        //次の行き先は？
        ll to = G[idx][i].first;
        //未探査のとき
        if(pre[to] == -1){
            //dfsを実行する
            //到達できる頂点の中で一番小さいpreを採用する
            dfs(to, idx, pre_count);
            low[idx] = min(low[idx], low[to]);
            //dfs(to, idx, pre_count);
            //low[idx] = min(low[idx], low[to]);

            //後退辺を使ったとしても根やそれ以上に戻ってきていない→つまりここが橋
            if( low[to] > pre[idx]){
                ans.push_back(make_pair(idx, to));
            }
        }else if(to != from){
            //すでに探査済みかつ根に戻ってきていないなら
            low[idx] = min(low[idx], pre[to]);
        }
 
    }

    //return low[idx];
}


int main(){
    ll N, M;
    cin >> N >> M;
    
    //初期化
    G.assign(N, vector<pair<ll, ll > >());
    //ns.assign(N, 0);
    pre.assign(N, -1);
    low.assign(N, -1);
    reach.assign(N, false);
 
    //グラフ入力
    for(ll i = 0; i < M; i++){
        ll u, v;
        //重みは今回は0
        ll w = 0;
        cin >> u >> v;
        u--;
        v--;
        //双方向に貼りましょうね
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    for(ll i = 0; i < N; i++){
        if(!reach[i])dfs(i);
    }
    
    cout << ans.size()<< endl;
    
    /*
    for(ll i = 0; i < ans.size(); i++){
        cout << ans[i].first << "," << ans[i].second << endl;
    }
    */
    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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;}

int main(){
    ll n,k;cin>>n>>k;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];

    sort(p.begin(),p.end());
    ll ans=0;
    rep(i,k){
        ans+=p[i];
    }

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

Measured memory_bytes: 3640
a,v = gets.chomp.split(' ').map(&:to_i)
b,w = gets.chomp.split(' ').map(&:to_i)
t = gets.chomp.to_i

kyorisa = (b-a).abs
hayasasa = (v-w)
puts (hayasasa * t) >= kyorisa ? 'YES' : 'NO'

Measured memory_bytes: 14332