akhauriyash/Code-Regression huggingface dataset:
import queue
import copy

def bfs(s1,s2):
    global ans
    cs = copy.deepcopy(s)
    queueX = queue.Queue()
    queueY = queue.Queue()
    queueX.put(s1)
    queueY.put(s2)
    cs[s1][s2] = 0
    while queueX.empty() == False:
        x = queueX.get()
        y = queueY.get()

        for i in range(4):
            nextX = x + moveR[i]
            nextY = y + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and cs[nextX][nextY] != '#'\
                and cs[nextX][nextY] == '.':
                cs[nextX][nextY] = cs[x][y] + 1
                ans = max(ans, cs[nextX][nextY])
                queueX.put(nextX)
                queueY.put(nextY)

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            bfs(i, j)

print(ans)

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

class _Class
{
	void _()
	{
		var _KT = _Ns();
		var a = _Ns();

		Array.Sort(a);
		Array.Reverse(a);

		int x = 0;
		for (int i=1 ;i<_KT[1];i++) {
			x += a[i];	
		}

		int c = 0;

		if (a[0] > x)
			c = a[0]-x-1;
		
		Console.WriteLine(c);

	}

	static void Main(string[] args)
  {
    new _Class()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


Measured memory_bytes: 2648
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e3 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		int K = in.nextInt();
		int arr[] = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
		boolean dp[] = new boolean[K + 1];
		for (int i = 0; i <= K; i++) {
			for (int x : arr) {
				if (i >= x && !dp[i - x]) {
					dp[i] = true;
				}
			}
		}
		if (dp[K]) {
			pw.println("First");
		} else {
			pw.println("Second");
		}
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 26176
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

int ans[501][501] = {};

void func(int l, int r, int level) {
	if (r - l <= 1) return;
	int mid = (l + r) / 2;


	rep(i, l, mid) {
		rep(j, mid, r) {
			ans[i][j] = level;
		}
	}


	func(l, mid, level + 1);
	func(mid, r, level + 1);



}

signed main(void) {

	int n;
	cin >> n;



	func(0, n, 1);

	REP(i, n) {
		rep(j, i + 1, n) {
			printf("%d ", ans[i][j]);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 1408
/* ex 9_2
   Sagzar1993 */

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int cnt = 0; //除去可能なキューブの数
    char cube; //キューブの色を表す文字
    //最初のノードの指す先
    node *first = NULL;
    
    //１文字ずつ入力してスタックを操作
    while(1){
        scanf("%c", &cube);
        //文字列の最後に来たら終了
        if(cube == '\n'){
            break;
        }
        if(first == NULL){
            push(&first, cube); //１文字目をスタックに追加
        }else if((first->elem == '0' && cube == '1') || (first->elem == '1' && cube == '0')){
            pop(&first); //入力されたcubeをスタックの先頭と比較し、０と１の組ならば除去可能
            cnt += 2; //取り出したスタックの先頭および入力の２文字が除去可能なので、cntを＋２
        }else{
            push(&first, cube); //０同士、１同士ならば除去不可なのでそのままスタックに追加
        }
    }
    
    printf("%d\n", cnt); //除去可能なキューブ数cntを出力
    return 0;
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size;
    UnionFind(int N): par(N),size(N) {

         //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
            par[i] = i;
            size[i] = -1;
        }
            
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[ry] += size[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int getsize(int x){
        return -size[root(x)];
    }
    int getNunion(){//これちょっと遅い sameと組み合わせて順次数えていけば早くなりそう。
        map<int,int> m;
        rep(i,par.size()){
            m[this->root(i)]++;
        }
        return int(m.size());
    }
};

int main(){
    ll N;
    cin >> N;
    ll M = N-1;
    vector<vector<ll>> G(N);
    vector<ll> a(N),b(N);
    rep(i,M){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    queue<ll> que;
    vector<ll> dist(N,1e18);
    que.push(0);
    dist[0] = 0;
    vector<ll> prev(N,-1);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(auto& u:G[v]){
            if(dist[u] != 1e18) continue;
            dist[u] = dist[v] + 1;
            prev[u] = v;
            que.push(u);
        }
    }
    ll add = (dist[N-1]/2);
    ll bdd = dist[N-1] - 1 - add;
    ll v = N-1;
    rep(i,bdd){
        v = prev[v];
    }
    ll eda = v;
    ll edb = prev[v];
    UnionFind tr(N);
    rep(i,M){
        if(a[i] == eda && b[i] == edb || a[i] == edb && b[i] == eda){
            continue;
        }
        tr.unite(a[i],b[i]);
    }
    if(tr.getsize(0) > tr.getsize(N-1)){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }
}

Measured memory_bytes: 13488
#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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (C >= A && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import collections

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

mod=10**9+7
n=int(input())
dic=collections.defaultdict(int)
cnt=0
for _ in range(n):
  a,b=map(int,input().split())
  if a!=0 and b!=0:
    g=gcd(abs(a),abs(b))
    if (a>0 and b>0) or (a<0 and b<0):
      dic[(abs(a)//g,abs(b)//g)]+=1
    elif (a<0 and b>0) or (a>0 and b<0):
      dic[(-abs(a)//g,abs(b)//g)]+=1
  else:
    if a==0 and b==0:
      cnt+=1
    elif a==0:
      dic[(1,0)]+=1
    elif b==0:
      dic[(0,1)]+=1
ans=1
s=set()
for a,b in dic.keys():
  if (a,b) in s:
    continue
  s.add((a,b))
  if a!=0 and b!=0:
    if a>0:
      if (-b,a) in dic:
        s.add((-b,a))
        cnt1=dic[(a,b)]
        cnt2=dic[(-b,a)]
        ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
        ans%=mod
      else:
        ans*=pow(2,dic[(a,b)])
        ans%=mod
    elif a<0:
      if (b,-a) in dic:
        s.add((b,-a))
        cnt1=dic[(a,b)]
        cnt2=dic[(b,-a)]
        ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
        ans%=mod
      else:
        ans*=pow(2,dic[(a,b)],mod)
        ans%=mod
  else:
    if (b,a) in dic:
      s.add((b,a))
      cnt1=dic[(a,b)]
      cnt2=dic[(b,a)]
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
    else:
      ans*=pow(2,dic[(a,b)],mod)
      ans%=mod
print((ans+cnt-1)%mod)

Measured memory_bytes: 152128
h, w = map(int, input().split())
list_c = [list(input()) for _ in range(h)]

cut_h = [i for i in range(h)]
cut_w = [j for j in range(w)]
for i in range(h):
  for j in range(w):
    if list_c[i][j] == "#":
      if i in cut_h:
        cut_h.remove(i)
      if j in cut_w:
        cut_w.remove(j)

for i in range(h):
  if i not in cut_h:
    temp = ""
    for j in range(w):
      if j not in cut_w:
        temp += list_c[i][j]
    print(temp)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        String S;

        try (Scanner sc = new Scanner(System.in)) {
            S = sc.next();
        }
        char[] c = S.toCharArray();
        int[] index = new int[c.length];
        for(int i=0;i < c.length;i++){
            index[i] = Integer.valueOf(S.substring(i, i+1));
        }

        long result = 0;

        for(int i = 0;i < index.length;i++){
            //i番目の文字について
            //1桁目→MAXのまで
            long sum = 0;
            int kMax = index.length - (i+1) +1;
            int p =1;
            for(int k=1; k <= kMax;k++){
                int aNum = i;
                int bNum = index.length - (i) -(k);

                long a ;
                long b;

                if(aNum ==0){
                    a = 1;
                }else{
                    a = (long) (Math.pow(2, aNum));
                }
                if(bNum ==0){
                    b = 1;
                }else{
                    b = (long) (Math.pow(2, bNum-1));
                }

                sum += a * b * p * index[i];
                //debug("index[i],a,b,p:"+index[i]+","+a+","+b+","+p);
                p *=10;
            }
            result += sum;
        }
        System.out.println(result);
    }

}


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

int main() {
  int N,sum=0;
  cin >> N;
  vector<int> data(N);
  for(int i=0;i<N;i++){
    cin >> data.at(i);
    sum+=data.at(i);
  }
  
  int d,s1=0,s2=0,ans;
  ans = 1000;
  for(int i=0;i<N;i++){
    s1+=data.at(i);
    s2=sum-s1;
    if(abs(s1-s2) < ans)
      ans = abs(s1-s2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

int main(void) {
	ll ans = 0, r, g, b, n;
	cin >> r >> g >> b >> n;
	for (ll i = 0;i <= 3000;i++) {
		for (ll j = 0;j <= 3000;j++) {
			if (n - r * i - g * j >= 0&&((n-r*i-g*j)%b==0))ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    cout << string(s.size(), 'x') << "\n";
    return 0;
}

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

#define ll long long
using namespace std;

const int N = 105, V = 1e3 + 5;
int n, v[N];
ll m, w[N], dp[N][V * N];

// dp = minimum weight that can achieve at least this value

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for(int j = 1; j < V * N; j++) dp[0][j] = LLONG_MAX;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < V * N; j++) {
            dp[i][j] = dp[i - 1][j];
            if(dp[i - 1][max(0, j - v[i])] < LLONG_MAX) {
                dp[i][j] = min(dp[i][j], w[i] + dp[i - 1][max(0, j - v[i])]);
            }
        }
    }
    cout << (lower_bound(dp[n], dp[n] + V * N, m + 1) - dp[n] - 1) << endl;
}

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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
	#define w2f freopen("output.txt","w",stdout)
#else
	#define de(x)
	#define rff
#endif

#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define PQ priority_queue
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=1e6+3;

vector <pii> g[MAXN];
vector <int> ng[MAXN*2],co[MAXN];
int v[MAXN];
int c[MAXN];
int n,m,comp,origin;
int dist[MAXN*2];
queue <int> q;
bool vis[MAXN];

void paint(const int &x){
	ng[x].pb(n+comp);
	ng[n+comp].pb(x);
	c[x]=origin;
	while (v[x]<g[x].size()){
		if (g[x][v[x]].fi>origin) break;
		if (c[g[x][v[x]].se]==origin){
			v[x]++;
			continue;
		}
		paint(g[x][v[x]].se);
		v[x]++;
	}
}

void bfs(const int &x){
	rep(i,ng[x].size()){
		if (dist[ng[x][i]]==0){
			dist[ng[x][i]]=dist[x]+1;
			q.push(ng[x][i]);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	int t1,t2,t3;
	cin>>n>>m;
	rep(i,m){
		cin>>t1>>t2>>t3;
		t1--;
		t2--;
		g[t1].pb(mp(t3,t2));
		g[t2].pb(mp(t3,t1));
		co[t3].pb(t1);
		co[t3].pb(t2);
	}
	rep(i,n){
		sort(g[i].begin(),g[i].end());
		c[i]=-1;
	}
	rep(i,1e6+1){
		if (co[i].size()==0) continue;
		origin=i;
		for (int j:co[i]){
			if (c[j]==origin) continue;
			paint(j);
			comp++;
		}
	}
	dist[0]=1;
	q.push(0);
	while (q.size()){
		bfs(q.front());
		q.pop();
	}
	if (dist[n-1]==0) dist[n-1]=-1; else dist[n-1]=(dist[n-1]-1)/2;
	cout<<dist[n-1];
	re 0;
}

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

int main(void){
  int N;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;
  int i4 = 0;
  scanf("%d",&N);
  for(int i = 0; i < N; i++){
    char str[3];
    scanf("%s", str);
    if(strcmp("AC", str) == 0){
      i1++;
    }else if(strcmp("WA", str) == 0){
      i2++;
    }else if(strcmp("TLE", str) == 0){
      i3++;
    }else if(strcmp("RE", str) == 0){
      i4++;
    }
  }
  printf("AC x %d\n",i1);
  printf("WA x %d\n",i2);
  printf("TLE x %d\n",i3);
  printf("RE x %d\n",i4);
  return 0;
}


Measured memory_bytes: 1736
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline


def F(S, i):
    if i == len(S):
        if eval(''.join(S)) == 7:
            print(''.join(S) + "=7")
            return True
        else:
            return False

    S1 = S.copy()
    S1.insert(i, "+")
    if F(S1, i + 2):
        return True
    S2 = S.copy()
    S2.insert(i, "-")
    if F(S2, i + 2):
        return True
    return False


S = list(input().rstrip('\n'))
F(S, 1)


# def cal(Sn, opt):
#     ans = Sn[0]
#     for i in range(3):
#         if opt[i] == '+':
#             ans += Sn[i+1]
#         else:
#             ans -= Sn[i+1]
#     return ans


# S = list(input().rstrip('\n'))
# Sn = [int(i) for i in S]
# op = ['+', '-']
# opL = [(i, j, k) for i in op for j in op for k in op]

# for opt in opL:
#     if cal(Sn, opt) == 7:
#         break

# ans = ''
# for i in range(3):
#     ans += S[i] + opt[i]
# ans += S[3] + '=7'
# print(ans)


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

#define N 1100

#define max(a, b) (a < b ? b : a)

int dp[N][N];
char X[N], Y[N];

int LCS(void);

int main()
{
  int n, i;

  scanf("%d\n", &n);

  for ( i = 0; i < n; i++ ){
    fgets(X, N, stdin);
    fgets(Y, N, stdin);
    printf("%d\n", LCS());
  }
  return 0;
}

int LCS(void)
{
  const int m = strlen(X) - 1; 
  const int n = strlen(Y) - 1;

  int i, j;

  memset(dp, 0, sizeof(dp));

  for (i = 1; i < m + 1; ++i) {
    for (j = 1; j < n + 1; ++j) {
      int mx = max(dp[i][j - 1], dp[i - 1][j]);
      if (X[i - 1] == Y[j - 1]) {
        mx = max(mx, dp[i - 1][j - 1] + 1);
      }
      dp[i][j] = mx;
    }
  }

  return dp[m][n];
}

Measured memory_bytes: 5340
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int K;

int gcd(int a, int b)
{
    if (b == 0)
        return a;

    return gcd(b, a % b);
}
int ggcd(int a, int b, int c)
{
    return gcd(a, gcd(b, c));
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

int main()
{
    cin >> K;
    ll ans = 0;
    for (int i = 1; i <= K; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            for (int k = 1; k <= K; k++)
            {
                ans += ggcd(i, j, k);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a != t:
      i = min(d[a], d[t])
    else:
      if d[a] == 1:
        break
      i = d[a] // 2
    result += i
    d[a] -= i
    d[t] -= i
    if d[a] == 0:
      break
print(result)


Measured memory_bytes: 44560
S = input()

t1 = "dream"
t2 = "dreamer"
t3 = "erase"
t4 = "eraser"

while True:
    if S[-5:] == t1 or S[-5:] == t3:
        S = S[0:-5]
    elif S[-6:] == t4:
        S = S[0:-6]
    elif S[-7:] == t2:
        S = S[0:-7]
    elif len(S) == 0:
        print("YES")
        break
    else:
        print("NO")
        break
    



Measured memory_bytes: 3188
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

vvll dp;
vll acc;
ll dfs(int l, int r) {
    if (dp[l][r] != HIGHINF) return dp[l][r];
    if (l + 1 == r) return dp[l][r] = acc[r] - acc[l];
    ll ret = HIGHINF;
    for (int i = l + 1; i < r; i++) chmin(ret, dfs(l, i) + dfs(i, r) + acc[r] - acc[l]);
    return dp[l][r] = ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    acc.resize(n + 1, 0);
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        acc[i + 1] = acc[i] + a;
    }
    dp.resize(n + 1, vll(n + 1, HIGHINF));
    cout << dfs(0, n) - acc.back() << '\n';
    return 0;
}


Measured memory_bytes: 4524
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve2(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if(s[i] and i%5==2)]

n = int(input())
a = sieve2(55555)
ans=a[:n]
print(" ".join(map(str,ans)))


Measured memory_bytes: 3444
s=list(input())
t=list(input())
n=len(s)
m=len(t)

if m==n+1:
  for i in range(n):
    if s[i]==t[i]:
      continue
    if s[i]!=t[i]:
      print('No')
      exit()
  print('Yes')
  
else:
  print('No')


Measured memory_bytes: 9012
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

const long long INF = LLONG_MAX;
const long long MOD = 1000000007;
const long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//long double d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

int main() {
    cin >> n;
	ans += n / 500 * 1000;
	m = n % 500;
    cout << ans + m / 5 * 5 << endl;
}


Measured memory_bytes: 256
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

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

using ll = long long;

#define REP(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template<class T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}else return false;}
template<class T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}else return false;}

int mod_[2][200010];

void init(int m){
  for(int i = 0;i < 200020;i++){
    if(i == 0) mod_[0][i] = 1;
    else mod_[0][i] = (mod_[0][i - 1] * 2) % (m + 1);
  }
  for(int i = 0;i < 200020;i++){
    if(i == 0) mod_[1][i] = 1;
    else mod_[1][i] = (mod_[1][i - 1] * 2) % (m - 1);
  }
}

int popcnt(int x){
  int ans = 0;
  for(int i = 0;i < 30;i++){
    if((1 << i) & x) ans++;
  }
  return ans;
}
void func(int ans,int x){
  if(x == 0){
    cout << ans << '\n';
    return;
  }else{
    func(ans + 1,x % popcnt(x));
  }
}

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

    int n;cin >> n;
    string x;cin >> x;

    int m = 0;
    REP(i,n) m += (x[i] == '1');

    // if m == 1 / 0 ??????

    if(m == 0){
      REP(i,n)cout << 1 << '\n';
      return 0;
    }else if(m == 1){
      if(x[n-1] == '1'){
        REP(i,n-2)cout << 2 << '\n';
        cout << 0 << '\n';
        return 0;
      }else{
        REP(i,n){
          if(x[i] == '1'){
            cout << 0 << '\n';
          }else if(i == n - 1){
            cout << 2 << '\n';
          }else cout << 1 << '\n';
        }
        return 0;
      }
    }

    init(m);

    int add = 0,dis = 0;
    REP(i,n) if(x[i] == '1'){
      add = (add + mod_[0][n - 1 - i]) % (m + 1);
      dis = (dis + mod_[1][n - 1 - i]) % (m - 1);
    }
    REP(i,n){
      if(x[i] == '1'){
        int sum = (dis + (m - 1) - mod_[1][n-1-i]) % (m - 1);
        func(1,sum);
      }else{
        int sum = (add + (m + 1) + mod_[0][n-1-i]) % (m + 1);
        func(1,sum);
      }
    }

}


Measured memory_bytes: 5316
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();

		int n = sc.nextInt();
		int y = sc.nextInt();

		int a = y / 10000;
		y -= a * 10000;
		int b = y / 5000;
		y -= b * 5000;
		int c = y / 1000;
		y -= c * 1000;

		if (y > 0 || a + b + c > n) {
			System.out.println("-1 -1 -1");
		} else {
			int dif = n - (a + b + c);
			int tmp = Math.min(a, dif / 9);
			a -= tmp;
			c += tmp * 10;

			dif = n - (a + b + c);
			tmp = Math.min(b, dif / 4);
			b -= tmp;
			c += tmp * 5;

			dif = n - (a + b + c);
			tmp = Math.min(a, dif);
			a -= tmp;
			b += tmp * 2;

			if (a + b + c == n) {
				System.out.println(a + " " + b + " " + c);
			} else {
				System.out.println("-1 -1 -1");
			}
		}
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};


int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> r(n,vector<int>(n,0));
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        r[a][b]++;
        r[b][a]++;
    }
    vector<vector<int>> dp(pow(2,n),vector<int>(n,INF));
    dp[pow(2,0)][0] = 1;
    for(int i = 1; i<pow(2,n); i++){
        rep(j,n){
            if(dp[i][j]==INF) continue;
            rep(k,n){
                if(r[j][k]==0) continue;
                int c = pow(2,k);
                if((i|c)==i) continue;
                if(dp[i|c][k]==INF){
                    dp[i|c][k] = dp[i][j];
                }
                else{
                    dp[i|c][k] += dp[i][j] ;
                }
            }
        }
    }
    int ans = 0;
    rep(i,n-1){
        if(dp[pow(2,n)-1][i+1]==INF) continue;
        ans += dp[(1<<n)-1][i+1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	int n;
	cin>>n;
	vector<double> arr(n);
	REP(i,0,n-1)cin>>arr[i];
	sort(arr.begin(),arr.end());
	double sum = (arr[0]+arr[1])/2;
	REP(i,2,n-1) {
		sum=(sum+arr[i])/2;
	}
	printf("%.5lf",sum);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3820
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;

// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}

void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
        #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
        #else
            #define debug(x...)
    #endif
}

const int MOD = 1e9 + 7;

int main(){

    IOS;
    OFFLINE();
    //check for corner test cases

    int n;
    cin >> n;

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

    auto f = [](int a, int b) {return (a == b);};
    for(int i = 0; i < n - 2; i++){
        if(f(VP[i].F, VP[i].S) && f(VP[i + 1].F, VP[i + 1].S) && f(VP[i + 2].F, VP[i + 2].S)){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    //check for corner test cases
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  char al='a',ans='-';
  set<char> alphabet;
  rep(i,s.size()){
    alphabet.insert(s[i]);
  }
  rep(i,26){
    if(!alphabet.count(al)){
      ans=al;
      break;
    }
    al++;
  }
  if(ans=='-'){
    cout<<"None"<<endl;
  }else{
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
   long long a,b,k; cin>>a>>b>>k;
   if(a>=k) cout<<a-k<<" "<<b<<endl;
   else if(a+b<=k) cout<<0<<" "<<0<<endl;
   else cout<<0<<" "<<b-(k-a)<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    ll pos = 0, neg = 0, sum = 0;
    FOR(i, 0, n) {
        sum += a[i];
        if (i % 2 == 1) {
            neg += max(0LL, 1 - sum);
            chmax(sum, 1LL);
        }
        else {
            neg += max(0LL, 1 + sum);
            chmin(sum, -1LL);
        }
    }
    sum = 0;
    FOR(i, 0, n) {
        sum += a[i];
        if (i % 2 == 0) {
            pos += max(0LL, 1 - sum);
            chmax(sum, 1LL);
        }
        else {
            pos += max(0LL, 1 + sum);
            chmin(sum, -1LL);
        }
    }

    cout << min(pos, neg) << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,ans=0;
  cin>>N;
  vector<ll> vec(N);
  for(ll i=0;i<N;++i){cin>>vec.at(i);}
  unordered_map<ll,ll> maxcount;
  for(ll i=0;i<N;++i){++maxcount[vec.at(i)+i];}
  for(ll i=0;i<N;++i){ans+=maxcount[i-vec.at(i)];}
  cout<<ans<<endl;
}

Measured memory_bytes: 19956
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;
string s;
int w;

int main() {
  cin >> s >> w;
  string ans;
  for (int i=0; i<s.size(); i=i+w) {
    ans.push_back(s.at(i));
  }
  cout << ans << endl;
}


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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=(c+b-1)/b;
    int y=(a+d-1)/d;
    if(y>=x)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int main(){
    int N, X; cin >> N >> X;
    vector<int> m(N);
    int sum = 0;
    for(int i=0; i<N; ++i) { cin >> m[i]; sum += m[i]; }

    sort(m.begin(), m.end());
    X -= sum;

    cout << N + X/m[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;const int N=2*1e5+10;typedef long long ll;const ll mod=1e9+7;
ll coldp[N];ll dp[N];int c[N];int n;
int main()
{
	dp[0]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if((i-1)&&c[i-1]!=c[i])
			(dp[i]+=coldp[c[i]])%=mod;
		coldp[c[i]]=dp[i];
	//	printf("%lld ",dp[i]);
	}
	printf("%lld",dp[n]);
	return 0;
}

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

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

vector <int> gr[100];
bool u[100];
int mt[100];
vector <int> gays[100][100];

bool dfs(int v) {
  if (u[v]) {
    return false;
  }
  u[v] = true;
  for (int to : gr[v]) {
    if (gays[v][to].empty()) continue;
    if (mt[to] == -1 || dfs(mt[to])) {
      mt[to] = v;
      return true;
    }
  }
  return false;
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector <int> ind(n * m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ind[i * m + j] = i;
    }
  }
  vector <vector <int> > a(n, vector <int> (m));
  for (int i = 0; i < n; i++) mt[i] = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      x--;
      a[i][j] = x;
      gr[ind[x]].push_back(i);
      gays[ind[x]][i].push_back(x);
    }
  }
  vector <vector <int> > ans(n);
  for (int it = 0; it < m; it++) {
    for (int i = 0; i < n; i++) mt[i] = -1, u[i] = 0;
    for (int i = 0; i < n; i++) {
      assert(dfs(i));
      for (int j = 0; j < n; j++) u[j] = 0;
    }
    for (int i = 0; i < n; i++) {
      ans[i].push_back(gays[mt[i]][i].back());
      gays[mt[i]][i].pop_back();
    }
  }
  vector <vector <pair <int, int> > > st(m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      st[j].push_back({ind[ans[i][j]], ans[i][j]});
      cout << ans[i][j] + 1 << ' ';
    }
    cout << '\n';
  }
  for (int i = 0; i < m; i++) {
    sort(st[i].begin(), st[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << st[j][i].second + 1 << ' ';
    }
    cout << '\n';
  }
}



Measured memory_bytes: 1244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_117
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int memCnt = line[0];
            int pointCnt = line[1];

            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Array.Sort(dataArr);
            
            List<int> lenList = new List<int>();

            for (long i = 0; i < pointCnt - 1; i++)
            {
                lenList.Add(-1 * (dataArr[i] - dataArr[i + 1]));
            }
            //昇順にソート
            lenList.Sort();

            int ret = 0;

            if (1 == pointCnt)
            {
                ret = 0;
            }
            else if ((1 < pointCnt) && (1 == memCnt))
            {
                ret = lenList.Sum();
            }
            else
            {
                for (int i = 0; i < memCnt - 1; i++)
                {
                    lenList.RemoveAt(lenList.Count - 1);
                    if (0 == lenList.Count) break;
                }
                if (0 < lenList.Count)ret = lenList.Sum();
            }

            Console.WriteLine(ret);

        }
    }
}


Measured memory_bytes: 19296
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, c, d = map(int, input().split())

    if abs(c - a) <= d:
        print("Yes")
    elif abs(c - b) <= d and abs(b - a) <= d:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <fstream>
#define rep(i,a,b) for (long long i = a; i < b ; i++)

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long sum = 0;
    rep(i,0,n){
        sum += i;
    }
    cout << sum << endl;
}

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

bool c[4];

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    c[x] = c[y] = true;
    for (int i = 1; i <= 3; ++i)
    {
        if (!c[i])
            printf("%d\n", i);
    }
    return 0;
}


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

score = 0
for idx, a in enumerate(A):
    score += B[a-1]
    if idx >= 1 and a == A[idx-1] + 1:
        score += C[A[idx-1]-1]

print(score)

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

const int INF = 2e9;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> 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;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(){
  int n,t;
  int c,tn;
  int min=1001,i;
  scanf("%d %d",&n,&t);
  for(i=0;i<n;i++){
    scanf("%d %d",&c,&tn);
    if(tn<=t&&min>c)
      min=c;
  }
  if(min==1001)
    printf("TLE\n");
  else
    printf("%d\n",min);
}

Measured memory_bytes: 128