akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 18

def main():
    N,x = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    ans = 0
    for a in A:
        if x - a >= 0:
            x -= a
            ans += 1
        else:
            x = 0
            break
    if x > 0:
        ans -= 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int n,m,t;
char ch[20];
int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	scanf("%s",ch);
	int len=strlen(ch);
	int flag=0;
	for(i=0;i<len;i++){
		if(i==n){
			if(ch[n]=='-')
				flag=1;
			else{
				flag=0;
				break;
			}
		}
		else{
			if(ch[i]>'9'||ch[i]<'0'){
				flag=0;
				break;
			}
			else
				flag=1;
		}
	}
	if(flag==0)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
} 

Measured memory_bytes: 128
/* ABC109 */
/* A */
#include <iostream>
#include <string>
using namespace std;

int main(void){
    int A, B;
    cin >> A >> B;
    if (A*B%2 == 1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

int p[1050];

int main(){

    int n, k;

    cin >> n >> k;

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

    sort(p, p+n);

    int tol = 0;
    for(int i=0;i<k;i++){
        tol+=p[i];
    }

    cout << tol << endl;
}


Measured memory_bytes: 3612
// Date: 2020-08-28

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    LL a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(v > w && abs(a-b) <= t*(v-w)) puts("YES");
    else puts("NO");

    return 0;
}

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

using namespace std;
const int N = 1E4 + 7;
bool vis[N];
int n, m;
typedef struct node
{
   int to,dis,cost;
   node(){}
   node(int a,int b,int c) : to(a),dis(b),cost(c) {}
   bool operator < (const node &a) const {
       return dis == a.dis ? cost > a.cost : dis > a.dis;
   }
}P;
vector<P>g[N];
int dij()
{
    int ans = 0;
    priority_queue<P> pq;
    pq.push(P(1,0,0));
    while(!pq.empty()) {
        P now = pq.top() ; pq.pop();
        if(vis[now.to]) continue;
        vis[now.to] = true;
        ans += now.cost;
        for(int i = 0;i < g[now.to].size();i ++) {
            P temp = g[now.to][i];
            pq.push(P(temp.to, now.dis + temp.dis, temp.cost));
        }
    }
    return ans;
}
int main()
{
   // freopen("f:\\jj.txt","r",stdin);
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    while(cin >> n >> m) {
        if(n + m == 0)  break;
        for(int i = 1;i <= n;i ++)  g[i].clear();
        memset(vis, 0, sizeof(vis));
        for(int i = 1;i <= m;i ++) {
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            g[a].push_back(P(b,c,d));
            g[b].push_back(P(a,c,d));
        }
        cout << dij() << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  N++;
  vector<int> A(N), ans(N);
  for (int i = 1; i < N; i++) cin >> A.at(i);
  for (int i = N - 1; i >= 1; i--) {
    int sum = 0;
    for (int j = i; j < N; j += i) sum += ans.at(j);
    ans.at(i) = A.at(i) ^ (sum % 2);
  }
  cout << accumulate(ans.begin(), ans.end(), 0) << "\n";
  for (int i = 1; i < N; i++) if (ans.at(i)) cout << i << "\n";
}

Measured memory_bytes: 2432
N = gets.to_i
D = (1..N).map{gets.split.map(&:to_i)}
count = 0
D.each do|di|
  if di[0] == di[1]
    count += 1 
    break if count >= 3
  else
    count = 0
  end
end
  
puts count >= 3 ? 'Yes' : 'No'

Measured memory_bytes: 14324
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  int a,b,c,d; cin>>a>>b>>c>>d;
  while(a>0&&c>0){
    c-=b;
    if(c<=0){
      cout<<"Yes\n";
      return 0;
    }
    a-=d;
    if(a<=0){
      cout<<"No\n";
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
    int i, n, cnt = 0, max = 0;
    scanf("%d", &n);
    int h[n];

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

    for (i = 0; i < n; i++){
        if (max <= h[i]){
            max = h[i];
            cnt++;
        }else{
            continue;
        }
    }
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var ABC = Sarray();
            Array.Sort(ABC);
            WriteLine(ABC[2] * 10 + ABC[1] + ABC[0]);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

using namespace std;

typedef long long ll;

int main()
{
  int n, m;
  while(cin >> n >> m, n || m){
    ll d[20000];
    for(int i = 0; i < n+m; i++) cin >> d[i];
    sort(d, d + n+m);
    ll ans = d[0];
    for(int i = 1; i < n+m; i++){
      ans = max(ans, d[i] - d[i-1]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1332
N, M, C = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
result = 0
for i in range(N):
    A = [int(i) for i in input().split()]
    if sum([A[i] * B[i] for i in range(M)]) + C > 0:
        result += 1
    
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

struct BinaryIndexedTree {
	vector<int> data;
	void init(int _sz){
		data.assign(_sz+1, 0);
	}
	
	int Sum(int k)
	{
		int sum = 0;
		for(; k > 0; k -= k & -k) {
			sum += data[k];
		}
		return sum;
	}
	void Add(int k, int x)
	{
		for(; k < data.size(); k += k & -k){
			data[k] += x;
		}
	}
};

int main(){
    int N, T; cin >> N >> T;
    vector<int> a(N), b(N);
    vector<pair<int, int> > p(N);
    for (int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        p[i] = {a[i], b[i]};
    }

    int content[3030*2]; fill(content, content+3030*2, -1);
    content[0] = 0;
    sort(p.begin(), p.end());
    int ans = 0;
    
    for (int i = 0; i < N; i++){
        for (int j = T-1; j >= 0; j--){
            if (content[j] == -1) continue;
            content[j+p[i].first] = max(content[j+p[i].first], content[j] + p[i].second);
        }
    }

    for (int i = 0; i <= 6000; i++){
        ans = max(ans, content[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int A,B,K;
  cin >> A >> B >> K;

  int turn = 0;

  for(int i=0;i<K;i++){
    if(turn == 0){
      if(A % 2 == 1)
        A--;;
      B += A / 2;
      A /= 2;
      turn = 1;
    }
    else{
      if(B % 2 == 1)
        B--;
        A += B / 2;
        B /= 2;
      turn = 0;
    }
  }

  cout << A << " " << B << endl;

  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

const int N = 1e5;
vector<int> g[N];
int n, a, b;
pair<int, int> distA[N], distB[N];

void bfs(int x, pair<int, int> dist[N]) {
  queue<pair<int, int>> q;
  dist[x] = make_pair(0, x);
  q.emplace(0, x);
  while (!q.empty()) {
    int d = q.front().first;
    int u = q.front().second;
    q.pop();
    for (int v: g[u]) {
      if (dist[v].first != -1) continue;
      if (x == a && v == b) continue;
      dist[v] = make_pair(d+1, v);
      q.emplace(d+1, v);
    }
  }
}

int main() {
  scanf("%d%d%d", &n, &a, &b);
  if (n == 2) return !printf("0");
  --a; --b;
  for (int i = 0; i < n-1; ++i) {
    int u, v; scanf("%d%d", &u, &v);
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < n; ++i) distA[i].first = distB[i].first = -1;
  bfs(a, distA);
  bfs(b, distB);
  sort(distB, distB+n, greater<pair<int, int>>());
  for (int i = 0; i < n; ++i) {
    int vert = distB[i].second;
    if (distA[vert].first == -1) continue;
    if (distB[i].first <= distA[vert].first) continue;
    debug(vert);
    debug(distA[vert].first);
    debug(distB[i].first);
    printf("%d", distB[i].first-1);
    return 0;
  }
  return 0;
}


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

signed main () {
	int m, k;
	cin >> m >> k;
	if (m == 1) {
		if (k >= 1)
			cout << "-1\n";
		else
			cout << "0 1 1 0\n";
	}
	else if (k >= (1 << m))
		cout << "-1\n";
	else {
		for (int i = 0; i < (1 << m); ++i) {
			if (i != k)
				cout << i << ' ';
		}
		cout << k << ' ';
		for (int i = (1 << m) - 1; i >= 0; --i) {
			if (i != k)
				cout << i << ' ';
		}
		cout << k << '\n';
	}
}


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

bool isprime(int x);

int main()
{
    //データ定義
    int dataCnt;
    int data;
    int primeCnt = 0;

    //データ入力
    cin >> dataCnt;

    //主処理
    for(int i = 0; i< dataCnt; i++){
        cin >> data;
        if(isprime(data)){
            primeCnt++;
        }
    }

    //結果出力
    cout << primeCnt << endl;
}

bool isprime(int x)
{
  if(x == 2){
      return true;
  }

  if(x < 2 || x % 2 == 0){
      return false;
  }

  int i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0){
        return false;
    }
    i += 2;
  }

 return true;
}


Measured memory_bytes: 3104
import sys

def calc(a, b, c, d, e, f):
    tmp = a * e - b * d
    x = c * (e / tmp) + f * (-b / tmp)
    y = c * (-d / tmp) + f * (a / tmp)
    return (x, y)

for i in sys.stdin.readlines():
    i = i.strip()
    a, b, c, d, e, f = map(float, i.split())
    print "{0[0]:.3f} {0[1]:.3f}".format(calc(a, b, c, d, e, f))

Measured memory_bytes: 4248
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch=='A') return 1;
    else if (ch=='G') return 2;
    else if (ch=='C') return 3;
    else if (ch=='T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum=0, p=1, i;
    for(i=0;i<strlen(str);i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key%M;
}

int h2(int key){
    return 1 + (key%(M-1));
}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if (strlen(H[h])==0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if (strlen(H[h])==0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++) H[i][0]='\0';
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%s %s", com, str);
        if(com[0]=='i'){ insert(str);}
        else{
            if(find(str)){printf("yes\n");}
            else{printf("no\n");}
        }
    }
    return 0;

}



Measured memory_bytes: 16108
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 100005

// it's swapnil07 ;)


signed main(){
    // fast    
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n; cin>>n;
    double dp[n+1][n+1];
    double p[n+1];
    For(i, 1, n+1){
        cin>>p[i];
    }
    dp[0][0]=1.0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=i; j++){
            dp[i][j]=0.0;
            if(j>0){
                dp[i][j]+=(dp[i-1][j-1]*p[i]);
            }
            if(j<i){
                dp[i][j]+=(dp[i-1][j]*(1.0-p[i]));
            }
        }
    }
    double ans = 0;
    for(int i=n/2+1; i<=n; i++){
        ans += dp[n][i];
    }
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 70400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N);
    for(int i = 0;i < N;i++) {
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    vector<ll> F(N);
    for(int i = 0;i < N;i++) {
        cin >> F.at(i);
    }
    sort(F.begin(),F.end());
    reverse(F.begin(),F.end());
    ll ok = 10000000000000;
    ll ng = -1;
    ll middle;
    while(ok - ng > 1) {
        middle = (ok + ng) / 2;
        ll cnt = 0;
        for(int i = 0;i < N;i++) {
            cnt += max(0ll,A.at(i) - middle / F.at(i));
        }
        if(cnt <= K) {
            ok = middle;
        }
        else {
            ng = middle;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> P;

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

    if(d==25) cout << "Christmas" << endl;
    else if(d==24) cout << "Christmas Eve" << endl;
    else if(d==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,1,-1};

bool dfs(int sx,int sy,vector<vector<bool> >&c){
    if(c[sx][sy]==false) return false;
    c[sx][sy]=false;
    for(int i=0;i<8;i++){
        int nx=sx+dx[i];
        int ny=sy+dy[i];
        bool flag=dfs(nx,ny,c);
    }
    return true;
}

int main(void){
    int h,w,temp;
    while(1){
        cin>>w>>h;
        if(w==0) break;
        vector<vector<bool> > c(h+2,vector<bool>(w+2,false)) ;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin>>temp;
                if(temp==1) c[i][j]=true;
            }
        }
        int t=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                bool flag=dfs(i,j,c);
                if(flag) t++;
            }
        }
        cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 3184
n = int(input())
k=2
arr = list(map(int,input().split(" ")))

l=list()
l.append(0)

for i in range(1,n):
	mini= abs(arr[i] - arr[i-1]) + l[i-1]

	for j in range(2,min(k+1,i+1)):
		mini = min(mini, abs(arr[i] - arr[i-j]) + l[i-j])
	l.append(mini)

# print(l)
print(l[-1])

Measured memory_bytes: 56588
#include <stdio.h>
int main()
{
int L,R,d,i,m=0;
scanf("%d %d %d",&L,&R,&d);
for(i=L;i<=R;i++)
{
    if(i%d==0)
    {
        m++;
    }
}
  printf("%d",m);
return 0;
}

Measured memory_bytes: 1732
n, m = map(int, input().split())
ps = [float('inf')] * 2**n
for _ in range(m):
    a, b = map(int, input().split())
    s = sum([2**(i - 1) for i in map(int, input().split())])
    ps[s] = min(ps[s], a)
    for i in range(2**n):
        if i == s:
            ps[i] = min(ps[i], ps[s])
        elif i & s == i:
            ps[i] = min(ps[i], ps[s])
        elif i & s == s:
            ps[s] = min(ps[i], ps[s])
        else:
            ps[i | s] = min(ps[i | s], ps[i] + ps[s])
if ps[2**n - 1] == float('inf'):
    print(-1)
else:
    print(ps[2**n - 1])

Measured memory_bytes: 51928
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line1[i]);
        int min = 4950;
        for(int i = 0; i < n; i++){
            int a = 0;
            int b = 0;
            for(int j = 0; j <= i; j++)
            a += ary[j];
            for(int k = i + 1; k < n; k++)
            b += ary[k];
            int c = a - b;
            if(c < 0)
            c = b - a;
            if(c < min)
            min = c;
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 22732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
int a[N], b[N];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n;
	cin >> n;
	
	for(int i = 0; i <= n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];

	ll ans = 0;

	for(int i = 0; i < n; i++){
		if(a[i] < b[i]){
			ans += a[i];
			b[i] -= a[i];

			ans += min(a[i+1], b[i]);
			a[i+1] = max(0, a[i+1] -b[i]);
		}
		else ans += b[i];
	}
	cout << ans;
}	

Measured memory_bytes: 1024
def main():
    import heapq
    import sys

    input = sys.stdin.readline

    n,m = map(int,input().split())
    def int2(x):
        a = -int(x)
        return a
    s = list(map(int2,input().split()))
    heapq.heapify(s)

    for i in range(m):
        mi = heapq.heappop(s)
        if mi % 2 == 1:
            mi = (mi // 2) + 1
        else:
            mi = mi // 2
        heapq.heappush(s,mi)
    
    s1 = -(sum(s))
    print(s1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14380
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r;
ll l,ans,num;
ll x[500005],y[500005],z[500005];
bool dame,flag;
char s[500005],t[500005];
bool used[500005];

int main(){
    cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x,x+n);
	sort(y,y+n);
	reverse(x,x+n);
	for(j=32;j>=0;j--){
		num = (1 << j);
		//p(num);
		for(i=0;i<n;i++){
			if(used[i])continue;
			a = num - x[i];
			b = lb(y,y+n,a+1) - lb(y,y+n,a);
			if(b >= 1){
				c = lb(y,y+n,a) - lb(y,y+n,-1);
				c = n - 1 - c;
				c -= (b - 1);
				while(i == c){
					c++;
				}
				while(used[c] && x[c+5000] == a && used[c + 5000]){
					c += 5000; 
				}
				while(used[c]){
					c++;
					if(x[c] != a)break;
				}
				while(i == c){
					c++;
				}
				if(!used[c] && x[c] == a){
					used[c] = true;
					used[i] = true;
					ans++;
					//pe(i);p(c);
				}
			}
		}
	}
	p(ans);
    return 0;
}

Measured memory_bytes: 33024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    if(k == 1)
        cout << "YES" << endl;
    else
    {
        if(n >= k*2-1)
        {
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int N,L;
  cin>>N>>L;
  int X;
  int MIN = INF;
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
    int P = L  + i;
    if(chmin(MIN,abs(P)))
    {
      X = P;
    }
    // DEBUG(X);
    SUM += P;
  }
  cout<<SUM - X<<endl;
  
  return;
}




int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a[4] = { 4, 6, 9, 11 };
    int b[7] = { 1, 3, 5, 7, 8, 10, 12 };

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

    if( find( a, a + 4, x ) != a + 4 && find( a, a + 4, y ) != a + 4 ){
        cout << "Yes" << endl;
    }else if( x == 2 && y == 2 ){
        cout << "Yes" << endl;
    }else if( find( b, b + 7, x ) != b + 7 && find( b, b + 7, y ) != b + 7 ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main(){
    string s;
    cin >> s;
    
    int n = s.size();
    
    vector<int> a(26);
    rep(i,n) a[i] = 0;
    rep(i,n){
        a[s[i]-'a']++;
    }
    bool flag = false;
    rep(i,26){
        if(a[i]>1){
            flag = true;
            break;
        }
    }
    if(flag) cout << "no";
    if(!flag) cout << "yes";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> v(n, 0);
    int res = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        res += v[i] - 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 3624
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30;

LL s;
LL x[5],y[5];

int main(){
	scanf("%lld",&s);
	if(s<=1e9){
		printf("0 0 %lld 0 1 1\n",s);
		return 0;
	}
	
	x[1]=0;x[3]=1e9;y[2]=0;
	LL y1p=s/x[3];
	if(y1p>1e9)y1p=1e9;
	y[1]=y1p;
	LL rst=s-x[3]*y[1];
//	printf("rst=%lld\n",rst);
	if(rst==0)y[3]=y[1];
	else y[3]=y[1]+1;
	x[2]=rst;
	for(int i=1;i<=3;i++)printf("%lld %lld ",x[i],y[i]);
	puts("");

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] cards = line2.split(" ");

		String[] suit = new String[n];
		for (int i = 0; i < n; i++) {
			suit[i] = cards[i].substring(0, 1);
		}

		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(cards[i].substring(1));
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;

					String w = suit[j];
					suit[j] = suit[j - 1];
					suit[j - 1] = w;
				}
			}
		}

		String[] suit2 = new String[n];
		for (int i = 0; i < n; i++) {
			suit2[i] = cards[i].substring(0, 1);
		}

		int[] num2 = new int[n];
		for (int i = 0; i < n; i++) {
			num2[i] = Integer.parseInt(cards[i].substring(1));
		}

		for (int i = 0; i < n - 1; i++) {
			int min = num2[i];
			int x = i;
			for (int j = i + 1; j < n; j++) {
				if (min > num2[j]) {
					min = num2[j];
					x = j;
				}
			}

			int v = num2[i];
			num2[i] = num2[x];
			num2[x] = v;

			String w = suit2[i];
			suit2[i] = suit2[x];
			suit2[x] = w;
		}

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(suit[i]);
			str.append(num[i]);
			str.append(" ");
		}
		str.append(suit[n - 1]);
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println("Stable");

		StringBuilder str2 = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str2.append(suit2[i]);
			str2.append(num2[i]);
			str2.append(" ");
		}
		str2.append(suit2[n - 1]);
		str2.append(num2[n - 1]);

		System.out.println(str2);

		int strCount = 0;

		for (int i = 0; i < n; i++) {
			if (suit[i].equals(suit2[i])) {
				strCount++;
			}
		}

		if (strCount == n) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}

	}

}

Measured memory_bytes: 26048
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
# p=1,2,3
for p in range(1,4):
    print("{0:.6f}".format(sum([abs(a-b)**p for a,b in zip(X,Y)])**(1/p)))
# p=infinity
print("{0:.6f}".format(max([abs(a-b) for a,b in zip(X,Y)])))



Measured memory_bytes: 5652
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
B = lma()
D = [B[i]-A[i] for i in range(n)]
tmp = 0

for d in D:
    if d>0:
        d//=2
    tmp+=d
f=False
if tmp>=0:
    f=True

yn(f)


Measured memory_bytes: 10816
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e5+1;
vector<int> isprime(N1,1);
set<int>prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.insert(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.insert(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};
ll comp[N1];
void pre1(){
  seive();
  comp[0]=0;comp[1]=0;
  rep(i,2,N1){
    if(i%2==1 && isprime[i] && isprime[(i+1)/2]) comp[i]=comp[i-1]+1;
    else comp[i]=comp[i-1];
  }
}
void solve(){
  pre1();
  int q;
  cin>>q;
  while(q--){
    int l,r;
    cin>>l>>r;
    cout<<comp[r]-comp[l-1]<<endl;
  }
}

int main(){
    optimizeIO();

    {solve();}
}


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

ll power(ll x,ll N){
  ll ret=1;
  for(int i=0;i<N;i++)
    ret*=x;
  return ret;
}

int main(){
  ll N,P;cin>>N>>P;
  ll P1=P;
  map<ll,ll>factor;
  for(ll i=2;i*i<=P1;i++){
    while(P%i==0){
      factor[i]++;
      P/=i;
    }
  }
  
  if(P!=1)
    factor[P]++;
  
  ll res=1;
  
  for(auto p:factor){
    res*=power(p.first,p.second/N);
    //cout<<p.first<<" "<<p.second<<endl;
  }
  
  cout<<res;
}

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

int main() {
	int n;
	cin >> n;
	int nums[n];
	for(int i = 0; i < n; ++i) {
		cin >> nums[i];
	}
	
	sort(nums, nums + n);
	cout << nums[n/2] - nums[n/2-1];
}


Measured memory_bytes: 640
N = int(input())
ans = []
def f(n):
    if int(n) > N:
        return
    if '7' in n and '5' in n and '3' in n:
        ans.append(n)
    f(n+'7')
    f(n+'5')
    f(n+'3')
f('7')
f('5')
f('3')
print(len(ans))

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int,int> P;

const int modnum=1e9+7;

const int N = 22;
int a[N][N], dp[N][(1 << N)];


int main() {
    int n; cin >> n;
    rep(i, n) rep(j, n) cin >> a[i][j];

    // 初期値は1
    dp[0][0] = 1;
    // 男性をiで見ていく
    // maskの方で, N通りを見ていく, (1 << 3) == 8,,,<< の右側で指定した数字の１のbitがたった状態の数値になる
    // (1 << 3)を2進数で表すと 1000 になる
    rep(i, n) for(int mask = 0; mask < (1 << n); mask++) {
        // すでに更新されている箇所は飛ばす
        if(!dp[i][mask]) continue;
        // N人の女性を見ていく
        for(int k = 0; k < n; k++) {
            // i番目の男性とk番目の女性が相性○　かつ その女性がまだマッチング済みでない場合
            if(a[i][k] && (mask & (1 << k)) == 0)
                // 今の状態からk番目の女性だけを新たにbit立てたのが欲しいので排他的論理和をとる
                // 現在確定済みのマッチング集合に、現在見ている男性と女性のマッチング状態を追加した部分集合を作り、そこに現在確定済みのマッチング集合のパターン数を加算する
                dp[i + 1][(mask ^ (1 << k))] += dp[i][mask] % modnum;
                dp[i + 1][(mask ^ (1 << k))] %= modnum;
        }
    }
    cout << dp[n][(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 190720
object Main extends App {
  import scala.io.StdIn._
  val mod = 1000000007L
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val notExists = calNotExists(n, m)
  println(
    (exp(n)
      + mod
      - notExists)
      % mod
  )
  def exp(e: Int): Long = {
    e match {
      case 0 ⇒ 1
      case 1 ⇒ 2
      case _ ⇒ exp(e / 2).let(it ⇒ it * it * exp(e % 2)) % mod
    }
  }
  def calNotExists(size: Int, m: Int): Long = {
    val result = Array.tabulate(size + 1){_ ⇒ 0L}
    result(0) = 1
    for (i ← result.indices.tail){
      if (i < m) result(i) = (result(i - 1) * 2) % mod
      else if (i == m) result(i) = (result(i - 1) * 2 - 1) % mod
      else result(i) = (result(i - 1) * 2 - result(i - m - 1) + mod) % mod
    }
    result.last
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 46712
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<int>adj[100005];
std::vector<pair<int,pair<int,int>>>edges ;
bool vis[100005];
int costs[1003][1003];
int32_t main(){
    int n,m,r;
    cin>>n>>m>>r;
    int arr[r];
    for(int i=0;i<r;i++)cin>>arr[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j)costs[i][j]=0;
            else costs[i][j]=100000000444;
        }
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        costs[a][b]=c,costs[b][a]=c;
    }
    int N=n;
     for(int k=1;k<=N;k++) {
        for(int i=1;i<=N;i++) {
            for(int j=1;j<=N;j++) {
                costs[i][j] = min(costs[i][j], costs[i][k]+costs[k][j]);
            }
        }
    }
    sort(arr,arr+r);
    int ans=1e18+7;
    do{
        int d=0;
        for(int i=0;i<r-1;i++){
            d+=costs[arr[i]][arr[i+1]];
        }
        ans=min(ans,d);
    }while(next_permutation(arr,arr+r));
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
}; 

int dist(int lv, int rv){
    return min(abs(lv), abs(rv)) + abs(rv - lv);
}

int main(){
    Stream io;
    
    int N, K;
    io.read(N, K);
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        io.read(x[i]);
    }

    int ans = dist(x[0], x[K - 1]);
    for(int l = 1, r = K; r < N; l++, r++){
        ans = min(ans, dist(x[l], x[r]));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1005,maxm=3005,maxp=9000005,INF=0x7FFFFFFF;
struct data { int L,R,pos; } cowx[maxn],cowy[maxn];
struct disc { int num,kind,No; } disx[maxm],disy[maxm];
int n,m,px,py,r,c,sx,sy,p,No[maxm][maxm];
LL orix[maxm],oriy[maxm],com[maxp],S[maxm][maxm];
bool row[maxm][maxm],col[maxm][maxm];
bool cmp(disc A,disc B) { return A.num<B.num; }
int finds(int A) { return com[A]<0?A:com[A]=finds(com[A]); } 
void connect(int A,int B)
{
	int x=finds(A),y=finds(B);
	if (x==y) return;
	if (com[x]<com[y])
		com[x]+=com[y],com[y]=x; else
		com[y]+=com[x],com[x]=y;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&cowx[i].L,&cowx[i].R,&cowx[i].pos);
		py++; disy[py].num=cowx[i].L; disy[py].No=i; disy[py].kind=1;
		py++; disy[py].num=cowx[i].R; disy[py].No=i; disy[py].kind=2;
		px++; disx[px].num=cowx[i].pos; disx[px].No=i; disx[px].kind=3;
	}
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&cowy[i].pos,&cowy[i].L,&cowy[i].R);
		py++; disy[py].num=cowy[i].pos; disy[py].No=i; disy[py].kind=4;
		px++; disx[px].num=cowy[i].L; disx[px].No=i; disx[px].kind=5;
		px++; disx[px].num=cowy[i].R; disx[px].No=i; disx[px].kind=6;
	}
	disx[++px].kind=7;
	disy[++py].kind=8;
	sort(disx+1,disx+1+px,cmp);
	sort(disy+1,disy+1+py,cmp);
	disx[0].num=disy[0].num=INF;
	for (int i=1;i<=px;i++)
	{
		if (disx[i].num!=disx[i-1].num) r++;
		orix[r]=disx[i].num;
		if (disx[i].kind==3) cowx[disx[i].No].pos=r; else
		if (disx[i].kind==5) cowy[disx[i].No].L=r; else
		if (disx[i].kind==6) cowy[disx[i].No].R=r; else sx=r;
	}
	for (int i=1;i<=py;i++)
	{
		if (disy[i].num!=disy[i-1].num) c++;
		oriy[c]=disy[i].num;
		if (disy[i].kind==1) cowx[disy[i].No].L=c; else
		if (disy[i].kind==2) cowx[disy[i].No].R=c; else
		if (disy[i].kind==4) cowy[disy[i].No].pos=c; else sy=c;
	}
	/*
	cerr<<">>>>>>"<<r<<" "<<c<<endl;
	cerr<<">>>>>>"<<sx<<" "<<sy<<endl;
	for (int i=1;i<=n;i++) printf("%d %d %d\n",cowx[i].L,cowx[i].R,cowx[i].pos);
	for (int i=1;i<=m;i++) printf("%d %d %d\n",cowy[i].pos,cowy[i].L,cowy[i].R);
	*/
	for (int i=1;i<=n;i++)
		for (int j=cowx[i].L;j<cowx[i].R;j++)
			row[cowx[i].pos][j]=true;
	for (int i=1;i<=m;i++)
		for (int j=cowy[i].L;j<cowy[i].R;j++)
			col[j][cowy[i].pos]=true;
	for (int i=1;i<r;i++)
		for (int j=1;j<c;j++)
		{
			No[i][j]=++p;
			S[i][j]=(LL)(orix[i+1]-orix[i])*(oriy[j+1]-oriy[j]);
			com[p]=-S[i][j];
		}
	com[0]=-1;
	/*
	for (int i=1;i<r;i++)
	{
		for (int j=1;j<c;j++) printf("%d ",S[i][j]);
		puts("");
	}
	*/
	for (int i=1;i<=r;i++)
		for (int j=1;j<c;j++)
			if (!row[i][j])
				connect(No[i-1][j],No[i][j]);
	for (int j=1;j<=c;j++)
		for (int i=1;i<r;i++)
			if (!col[i][j])
				connect(No[i][j-1],No[i][j]);
	int x=finds(No[sx][sy]),y=finds(0);
	if (x!=y) printf("%lld\n",-com[x]); else puts("INF");
	return 0;
}


Measured memory_bytes: 194012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define rep(i,n) for(ll i=0; i<(n); i++)
template<class T> inline void chmax(T &a, T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a, T b){if(a>b)a=b;}

int main(){
    ll t; cin >> t;
    vl beki(32,1);
    rep(i,31){
        beki[i+1] = beki[i] * 3;
    }
    vl bekisum(33,0);
    rep(i,32){
        bekisum[i+1] = bekisum[i] + beki[i];
    }
    ll now = 0;
    bekisum[0] = 1;
    while(bekisum[now+1]+bekisum[now]-1<=t){
        now++;
    }
    now--;
    ll ans = now+1+max(now-1,0LL);
    t -= bekisum[now+1]+bekisum[now]-1;
    while(now>=0){
        ll tmp = t;
        if(t>=beki[now]){
            tmp = t%beki[now];
            ans += t/beki[now];
        }
        now--;
        t = tmp;
        if(now==-1) break;
        if(t==0) break;
    }
    cout << ans << endl;
}


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x"="<<x<<endl

bool IsTimeOut(clock_t start_timer){
  clock_t current_timer = clock();
  double T = static_cast<double>(current_timer - start_timer) / CLOCKS_PER_SEC;
  return T > 1.98;
}

unsigned long XorShift(){
    static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned long t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int penalty_func(int delta, int c) {
  return delta * (delta - 1) * c / 2;
}

int main(){

  clock_t start_timer = clock();

  const int N = 26;
  int D;
  cin >> D;
  vector<int> C(N);
  rep(i,N) cin >> C[i];
  vector<vector<int>> S(D, vector<int>(N));
  rep(i,D)rep(j,N) cin >> S[i][j];

  vector<int> schedule_table(D, 0), current_penalty(N, 0);
  int current_score = 0;
  rep(i,D){
    rep(j,N){
      current_penalty[j] += C[j];
    }

    int mx = 0;
    rep(j,N){
      if(S[i][mx]+current_penalty[mx]<S[i][j]+current_penalty[j])mx=j;
    }

    schedule_table[i] = mx;

    current_score+=S[i][mx];
    current_penalty[mx]=0;
    rep(j,N){
      current_score-=current_penalty[j];
    }
  }
  /*vector<vector<int>> last_table(D + 1, vector<int>(N, 0));
  repl(i,1,D+1){
    rep(j,N){
      if(schedule_table[i]==j) last_table[i][j]=i;
      else last_table[i][j]=last_table[i-1][j];
    }
  }*/

  while(!IsTimeOut(start_timer)) {
    int a = (int)(XorShift() % (unsigned long) D);
    int b = (int)(XorShift() % (unsigned long) D);
    int ca = schedule_table[a], cb = schedule_table[b];
    if(a == b || schedule_table[a] == schedule_table[b]) continue;
    if(a > b) swap(a, b);

    int next_score = 0;
    vector<int> next_schedule_table = schedule_table;
    swap(next_schedule_table[a], next_schedule_table[b]);
    current_penalty.assign(N, 0);
    rep(i,D){
      rep(j,N){
        current_penalty[j] += C[j];
      }
      next_score += S[i][next_schedule_table[i]];
      current_penalty[next_schedule_table[i]] = 0;
      rep(j,N){
        next_score -= current_penalty[j];
      }
    }
    if(current_score < next_score) {
      current_score = next_score;
      schedule_table = next_schedule_table;
    }
  }
  rep(i,D)cout<<schedule_table[i]+1<<"\n";
  dbg(current_score);

  return 0;
}


Measured memory_bytes: 3656
//
// Created by Hideaki Imamura on 2019-06-06.
//

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

ll N;
vector<ll> A, absA;
ll n_minus = 0;

int main() {
    cin >> N;
    A.resize(N);
    absA.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        absA[i] = (ll)abs(A[i]);
        if (A[i] <= 0) n_minus++;
    }

    ll ans = accumulate(absA.begin(), absA.end(), 0LL);
    if (n_minus % 2) ans -= 2 * *min_element(absA.begin(), absA.end());
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector<string> s(3);
  cin>>s.at(0)>>s.at(1)>>s.at(2);
  int n=0;
  
  while(true){
    
    if(s.at(n).empty()){
      if(n==0){
        cout<<'A'<<endl;
      }else if(n==1){
        cout<<'B'<<endl;
      }else if(n==2){
        cout<<'C'<<endl;
      }
      break;
    }
    
    if(s.at(n).at(0)=='a'){
      s.at(n).erase(s.at(n).begin());
      n=0;
    }else if(s.at(n).at(0)=='b'){
      s.at(n).erase(s.at(n).begin());
      n=1;
    }else if(s.at(n).at(0)=='c'){
      s.at(n).erase(s.at(n).begin());
      n=2;
    }
    
    
  }
  
}

Measured memory_bytes: 256