akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

const int limit = 50;
int n, m;
int a[limit], b[limit];

bool g[limit][limit];
bool visited[limit];

void dfs(int v){
  visited[v] = true;
  rep(v2, n){
    if (visited[v2]) continue;
    if (!g[v][v2]) continue;
    dfs(v2);
  }
}

int main(){
  cin >> n >> m;
  rep(i, m){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }

  int ans = 0;

  rep(i, m){
    g[a[i]][b[i]] = g[b[i]][a[i]] = false;
    rep(j, n) visited[j] = false;
    dfs(0);
    bool bridge = false;
    rep(j, n) if (visited[j] == false) bridge = true;
    if (bridge) ans++;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
l = [a[0]]
r = [a[-1]]
for i in range(1,n):
    l.append(gcd(a[i],l[-1]))
    r.append(gcd(a[-1-i],r[-1]))
ans = max(l[-2],r[-2])
for i in range(n-2):
    ans = max(ans,gcd(l[i],r[-3-i]))
print(ans)





Measured memory_bytes: 16116
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double a = 0.0;

        while (true) {
            int n = scan.nextInt();
            int sum = 0;
            int[] students = new int[n];
            if (n == 0) break;

            for (int i = 0; i < n; i++) {
                int s = scan.nextInt();
                students[i] = s;
                sum += s;
            }
            double m = (double)sum / n;
            double sum2 = 0.0;
            for (int i = 0; i < n; i++) {
                sum2 += Math.pow(students[i] - m, 2);
            }
            a = Math.sqrt(sum2 / n);
            System.out.println(a);
        }
    }
}

Measured memory_bytes: 31044
// AtCoder Beginner Contest 126 - Problem D: Even Relation (https://atcoder.jp/contests/abc126/tasks/abc126_d)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 100010 };

vector<ii> adj[MAX];

void dfs(ll u, int color, vector<int>& cs)
{
    if (cs[u] > -1)
        return;

    cs[u] = color;

    for (auto p : adj[u])
    {
        auto v = p.first, w = p.second;

        if (w % 2 == 0)
            dfs(v, color, cs);
        else
            dfs(v, 1 - color, cs);
    }
}

vector<int> solve(int N, ll u)
{
    vector<int> cs(N + 1, -1);
    
    dfs(u, 0, cs);

    return cs;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    ll u, v, w;

    for (int i = 0; i < N; ++i)
    {
        cin >> u >> v >> w;

        adj[u].push_back(ii(v, w));
        adj[v].push_back(ii(u, w));
    }

    auto ans = solve(N, u);

    for (int i = 1; i <= N; ++i)
        cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 11904
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
using namespace std;
int n, m, x;
int c[2000], a[2000][2000], vis[2000], ans=inf;
int temp[2000]={0};
void dfs(int temp_ans, int pos)
{
      if (temp_ans>=ans) return ;
      int flag=1;
      for (int i=1; i<=m; i++)
      {
            if (temp[i]<x)
            {
                  flag=0;
                  break;
            }
      }
      if (flag)
      {
            ans=min(ans, temp_ans);
                  return;
      }
      for (int i=pos+1; i<=n; i++)
      {
            if (vis[i]==0)
            {
                  for (int j=1; j<=m; j++)
                  {
                        temp[j]+=a[i][j];
                  }
                  vis[i]=1;
                  dfs(c[i]+temp_ans, i);
                  vis[i]=0;
                  for (int j=1; j<=m; j++)
                  {
                        temp[j]-=a[i][j];
                  }
            }
      }
}
int main()
{
      ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
      cin >> n >> m >> x;
      for (int i=1; i<=n; i++)
      {
            cin >> c[i];
            for (int j=1; j<=m; j++)
			cin>>a[i][j];
      }
      dfs(0, 0);
      if (ans==inf) 
	  		cout << -1 << endl;
      else cout << ans << endl;
      return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

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

int main(){

  long long int A, B;
  scanf("%lld%lld", &A, &B);

  std::cerr << "Answer: " << std::endl;
  std::cout << (A*B)/gcd(A,B) << std::endl;

  return 0;
}


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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

int main(){
  fastio;
  
  ll n;
  cin>>n;
  if(n&1)
  {   float ans=n/2+1;
    ans=(float)ans/n;
    cout<<fixed<<showpoint;
    cout<<setprecision(9)<<ans<<endl;
  }
  else
    {cout<<fixed<<showpoint;
    cout<<setprecision(9)<<0.5000000000<<endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  char next;
  set<string> SE;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (SE.count(S)) return cout << "No" << "\n", 0;
    if (i && S.front() != next) return cout << "No" << "\n", 0;
    SE.insert(S);
    next = S.back();
  }
  cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  int bit = abs(n);
  string ans = "";
  int m = n > 0 ? 1 : 0;
  for (int i = 0; i < 32; i++) {
    if (bit & (1<<i)) {
      if (i % 2 == m) {
        bit += (1 << (i+1));
      }
      ans.append("1");
    } else {
      ans.append("0");
    }
  }

  reverse(ALL(ans));
  bool flag = true;
  for (int i = 0; i < ans.size(); i++) {
    if (flag && ans[i] == '0') continue;
    flag = false;
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back

const int N = 1e6 + 5;

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

    int a[N];
    fill(a, a+N, 0);
    // fill(pre, pre+N, 0);
    vector<int> nums;

    for(int x=0, i=1; i<=n; i++){
        cin >> x;
        a[x]++;
        nums.pb(x);
    }

    int ans = 0;
    for(auto& x: nums){
        bool flag = 1;
        for(int i=1; i*i <= x; i++){
            if(x%i == 0){
                if((i == x && a[i] > 1) || (i != x && a[i] > 0)) {
                    flag = 0;
                    break;
                }
                int y = x/i;
                if(x%y == 0)
                    if((y == x && a[y] > 1) || (y != x && a[y] > 0)) {
                        flag = 0;
                        break;
                    }
            }
        }

        if(flag) ans++;
    }

    cout << ans << endl;
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 8168
class FordFulkerson:
    """max-flow-min-cut
    O(F|E|)
    """

    def __init__(self,V:int):
        """
        Arguments:
            V:num of vertex
            adj:adjedscent list(adj[from]=(to,capacity,id))
        """
        self.V = V
        self.adj=[[] for _ in range(V)]
        self.used=[False]*V

    def add_edge(self,fro:int,to:int,cap:int):
        """
        Arguments:
            fro:from
            to: to
            cap: capacity of the edge
            f: max flow value
        """
        #edge
        self.adj[fro].append([to,cap,len(self.adj[to])])
        #rev edge
        self.adj[to].append([fro,0,len(self.adj[fro])-1])

    def dfs(self,v,t,f):
        """
        search increasing path
        """
        if v==t:
            return f
        self.used[v]=True
        for i in range(len(self.adj[v])):
            (nex_id,nex_cap,nex_rev) = self.adj[v][i]
            if not self.used[nex_id] and nex_cap>0:
                d = self.dfs(nex_id,t,min(f,nex_cap))
                if d>0:
                    #decrease capacity to denote use it with d flow
                    self.adj[v][i][1]-=d
                    self.adj[nex_id][nex_rev][1]+=d
                    return d
        return 0

    def max_flow(self,s:int,t:int):
        """calculate maxflow from s to t
        """
        flow=0
        self.used = [False]*self.V
        #while no increasing path is found
        while True:
            self.used = [False]*self.V
            f = self.dfs(s,t,float("inf"))
            if f==0:
                return flow
            else:
                flow+=f


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

F = FordFulkerson(H+W+2)
for i in range(H):
    for j in range(W):
        if grid[i][j]=="S":
            sy,sx = i,j
            F.add_edge(0,i+1,float("inf"))
            F.add_edge(0,H+j+1,float("inf"))
        elif grid[i][j]=="T":
            gy,gx=i,j
            F.add_edge(i+1,H+W+1,float("inf"))
            F.add_edge(H+j+1,H+W+1,float("inf"))
        elif grid[i][j]=="o":
            F.add_edge(i+1,H+j+1,1)
            F.add_edge(H+j+1,i+1,1)

if sy==gy or sx==gx:
    print(-1)
    exit()
print(F.max_flow(0,H+W+1))


Measured memory_bytes: 81824
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toLong() }
    val storeList = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }

    val sortedStore = storeList.sortedBy { it.first()}

    // お店の最大本数よりも購入したい本数が
    // -> 少ない場合 購入したい本数*価格 を合計に足す
    // -> 多い場合 最大本数*価格を合計に足す 購入したい本数から最大本数を引く
    var wanted = m
    var total:Long = 0
    for(store in sortedStore){
        if(wanted < store[1]){
            total += store[0] * wanted
            break
        }else{
            total += store[0] * store[1]
            wanted -= store[1]
        }
    }

    println(total)
}


Measured memory_bytes: 84968
#include <cstdio>
#include <algorithm>

int x[105050];
bool vis[105050];

struct _dis
{
	int idx,dis;
	bool operator < (const _dis&o)const
	{
		return (dis>o.dis);
	}
}plx[105050];
int lplx;

int main()
{
	int N,M;scanf("%d%d",&N,&M);N--;
	for(register int i=1;i<=M;i++)
		scanf("%d",&x[i]);
	std::sort(&x[1],&x[M+1]);
	for(register int i=2;i<=M;i++)
		plx[++lplx]=(_dis){i,x[i]-x[i-1]};
	std::sort(&plx[1],&plx[lplx+1]);
	register int ans=0;
	for(register int i=1;i<=lplx;i++)
		if(N)
			vis[plx[i].idx]=true,N--;
		else
			ans+=plx[i].dis;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

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

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

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long max = Long.MIN_VALUE;
    max = Math.max(max, a * c);
    max = Math.max(max, b * c);
    max = Math.max(max, a * d);
    max = Math.max(max, b * d);
    System.out.println(max);
  }
}

Measured memory_bytes: 32824
from collections import deque


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    
    ans = deque([])
    for i in range(n):
        if i % 2 == 0:
            ans.append(a[i])
        else:
            ans.appendleft(a[i])
    if n % 2 == 1:
        ans.reverse()
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 29124
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////

int main() {
	int cnt[100010] = {};
	int n; cin >> n;
	for (int i = 1; i <= 100; ++i) {
		for (int j = 1; j <= 100; ++j) {
			for (int k = 1; k <= 100; ++k) {
				int key = i * i + j * j + k * k + i * j + i * k + j * k;
				cnt[key]++;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (3e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 100;
const int SQRT = BUCK+9;

ll fact[N], ifact[N];

void pre()
{
	int i;
	fact[0] = ifact[0] = 1;
	fo(i,1,N)
	{
		fact[i] = (fact[i-1] * 1LL * i)%mod;
		ifact[i] = inmodx(fact[i]);
	}
	return;
}

ll choose(int n, int r)
{
	if(n < 0 || r < 0 || n < r)
		return 0;
	ll ans = (fact[n]*ifact[r])%mod;
	ans = (ans * ifact[n-r])%mod;
	return ans;
}

void solve()
{
	ll n, a, b, k, x, ans = 0, y, d;
	pre();
	cin >> n >> a >> b >> k;
	fo(x,0LL,n+1LL)
	{
		d = k - a*x;
		if(d % b == 0LL)
		{
			y = d/b;
			ans = (ans + choose(n,x)*choose(n,y))%mod;
		}
	}
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;
typedef unsigned long long        ull;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

string str;
int n;
vvi dp;

int solve( int l, int r, int k){
  if( l > k or r >= n ) return 0;
  if( dp[l][r] != -1 ) return dp[l][r];
  trace(l,r);
  if(str[l] == str[r]){
    dp[l][r] = 1+solve(l+1,r+1, k);
  }else{
    dp[l][r] = 0;
  }
  return dp[l][r];
}

int main( int argc, char * argv[] ){
  cin >> n; 
  cin >> str;
  int ans = 0;
  dp.resize(n);
  for(auto & v : dp) v.resize(n,-1);
  forall(i,0,n){
    forall(j,i+1,n){
      ans = max(ans, solve(i,j,j-1));
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

void forceInComp(int x, map<int, int> &comp) {
	if (comp.count(x) == 0) {
		int ita = comp.size();
		comp[x] = ita;
	}
}

int main() {
	int n; scanf("%d", &n);
	vector<int> x(n), y(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &x[i], &y[i]);
	}
	map<int, int> xcomp, ycomp;
	for (int i = 0; i < n; ++i) {
		forceInComp(x[i], xcomp);
		forceInComp(y[i], ycomp);
	}
//	for (auto pp : xcomp) printf("x %d %d\n", pp.first, pp.second);
//	for (auto pp : ycomp) printf("y %d %d\n", pp.first, pp.second);
	int a = xcomp.size(), b = ycomp.size();
	vector<vector<int>> graph(a + b);
	for (int i = 0; i < n; ++i) {
//		printf("adding edge %d %d\n", xcomp[x[i]], ycomp[y[i]] + a);
		graph[xcomp[x[i]]].push_back(ycomp[y[i]] + a);
		graph[ycomp[y[i]] + a].push_back(xcomp[x[i]]);
	}
	vector<int> compid(a + b, -1);
	int curcc = 0;
	for (int i = 0; i < a + b; ++i) {
		queue<int> q;
		if (compid[i] == -1) {
			q.push(i);
			compid[i] = curcc;
			while (!q.empty()) {
				int cur = q.front(); q.pop();
				for (int next : graph[cur]) {
					if (compid[next] == -1) {
						compid[next] = curcc;
						q.push(next);
					}
				}
			}
			++curcc;
		}
	}
	vector<int> cxct(curcc), cyct(curcc);
//	for (int i = 0; i < a + b; ++i) printf("in comp %d %d\n", compid[i], i);
	for (int i = 0; i < a; ++i) ++cxct[compid[i]];
	for (int i = a; i < a + b; ++i) ++cyct[compid[i]];
	vector<int> cect(curcc);
	for (int i = 0; i < n; ++i) ++cect[compid[xcomp[x[i]]]];
	ll ans = 0;
	for (int i = 0; i < curcc; ++i) {
//		printf("comp %d x y e %d %d %d\n", i, cxct[i], cyct[i], cect[i]);
		ans += (ll)cxct[i] * cyct[i] - cect[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int L=0;
  int R=0;
  rep(i,N){
    if(S[i]=='(') L++;
    else if(L) L--;
    else R++;
  }
  rep(i,R) cout<<"(";
  cout<<S;
  rep(i,L) cout<<")";
  cout<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:10:49 2020

@author: Aruto Hosaka
"""


H,W,K = map(int,input().split())
C = [input() for i in range(H)]

# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']

# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]

Cn = [[0 for w in range(W)] for h in range (H)]

for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            Cn[h][w] = 0
        else:
            Cn[h][w] = 1

counter1 = 0

ii = 0

for i in range(2**H):
# for i in range(2):
    for j in range(2**W):
    # for j in range(2):
        i = ii
        for h in reversed(range(H)):
            if i >= 2**h:
                for w2 in range(W):
                    Cn[h][w2] = 0
                i += -2**h
        for w in reversed(range(W)):
            if j >= 2**w:
                for h2 in range(H):
                    Cn[h2][w] = 0
                j += -2**w
        counter = 0
        for h in range(H):    
            counter += sum(Cn[h])
        
        if counter == K:
            counter1 += 1
        
        for h in range(H):
            for w in range(W):
                if C[h][w] == '.':
                    Cn[h][w] = 0
                else:
                    Cn[h][w] = 1
    ii += 1
print(counter1)

Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll N,M,Q;
vector<ll>a,b,c,d;

ll score(const vector<ll> &A){
  ll res=0;
  for(ll i=0;i<Q;i++){
    if(A[b[i]]-A[a[i]]==c[i])res+=d[i];
  }
  return res;
}

ll dfs(vector<ll> &A){
  if(A.size()==N){
    return score(A);
  }
  ll res=0;
  ll prev_last=(A.empty()?0:A.back());
  for(ll i=prev_last;i<M;i++){
    A.push_back(i);
    res=max(res,dfs(A));
    A.pop_back();
  }
  return res;
}

int main(){
  cin>>N>>M>>Q;
  a.resize(Q),b.resize(Q),c.resize(Q),d.resize(Q);
  for(ll i=0;i<Q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--,b[i]--;
  }
  vector<ll>A;
  cout<<dfs(A)<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef long double ld;
char s[100050],t[100050];
int n,m;
ll ans;
vector <int> v[30+'a'];

int main(){
	scanf("%s",s);
	scanf("%s",t);
	n=strlen(s),m=strlen(t);
	for(int i=0;i<n;++i){
		v[s[i]].push_back(i);
	}
	int p1=-1;
	for(int i=0;i<m;++i){
		char c=t[i];
		if(v[c].empty())return puts("-1"),0;
		auto it=upper_bound(v[c].begin(),v[c].end(),p1);
		if(it==v[c].end()){
			it=v[c].begin();
			ans++;
		}
		p1=*it;
	}
	cout<<ans*1LL*strlen(s)+p1+1<<endl;
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	 long long int n,s=0;
 	cin>>n;
 	while(n>0)
 	{
 		if((n%3!=0)&&(n%5!=0))
 			s=s+n;
 		n--;
	 }
		cout<<s<<endl;		
 	return 0;
 }

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

int main() {
  int N;
  cin >> N;
  int L[N];
  for (int i{}; i < N; ++i) {
    cin >> L[i];
  }
  sort(L, L+N, greater<int>());
  int l1 = L[0];
  int l2{};
  for (int i{1}; i < N; ++i) {
    l2 += L[i];
  }

  cout << (l1 < l2 ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int a, b, k; cin >> a >> b >> k;
	vector<int>v;
	for (int i = 1; i <= 100; i++) {
		if (a%i == 0 && b%i == 0) {
			v.push_back(i);
		}
	}
	cout << v[v.size() - k] << endl;
	cin >> k;
}

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

public class Main {
    public static void main(String[] args) throws Exception{
        final long MOD = 1000000007;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        long sum = 0, sqSum = 0;

        for(int i=0; i<n; i++){
            int k = Integer.parseInt(st.nextToken());
            sum += (long)k;
            sqSum += (long)((long)(k)*(long)(k));

            sum %= MOD;
            sqSum %= MOD;
        }
        long ans = sum * sum;
        ans -= sqSum;
        ans = (ans%MOD + MOD) %MOD;
        if(ans %  2 == 1) ans+=MOD;
        ans /= 2;
        out.println(ans);
        out.close();
    }
}

Measured memory_bytes: 54636
#include <cstdio>
#include<iostream>
#include<cmath>
typedef long long ll;
const ll INF=1e10;

using namespace std;
char s[410];
bool vis[410]={0};
int len=0;

void hou(int x){
	for(int i=len;i>=x;i--){
		s[i+1]=s[i];
		vis[i+1]=vis[i];
	}
}
int main() {
	int n,be=0,en=0;
	cin>>n;
	len=n;
	int left=150,right=150+n-1; 
	for(int i=150;i<=150+n-1;i++){
		cin>>s[i];
	}
	int j=left;
	while(j<=n+149){
		bool f=1; 
		if(vis[j]==1){
			j++;
			continue;
		}
		if(s[j]=='('){//到后面找） 
			for(int i=j+1;i<=n+149;i++){
				if(s[i]==')'&&vis[i]==0){
					vis[j]=1;
					vis[i]=1;
					f=0;
					break;
				}
			}
			if(f){//如果没有匹配的，就在最后插入 ) 
				vis[j]=1;
				s[++right]=')';
				vis[right]=1;
			}
		}
		else{//到前面找（ 
			for(int i=j-1;i>=150;i--){
				if(s[i]=='('&&vis[i]==0){
					vis[j]=1;
					vis[i]=1;
					f=0;
					break;
				}
			}
			if(f){//如果没有匹配的，就在最前面插入 
				vis[j]=1;
				s[--left]='(';
				vis[left]=1;
			}
		} 
		j++;
	}
	for(int i=left;i<=right;i++){
		cout<<s[i];
	}
	return 0;
}





Measured memory_bytes: 256
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])#reverse
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    z=wv[i][0]-w0
    k=wv[i][1]+x[z][-1]
    l=len(x[z])
    if l*wv[i][0]<=w:
        x[z].append(k)
ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    for j in range(l2):
        if w-i*(w0+3)-j*(w0+2)>=0:
            for k in range(l1):
                d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                if d>=0:
                    ma_sub=x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,l0-1)]
                    ma=max(ma,ma_sub)
                else:
                    break
        else:
            break

print(ma)


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn=200005;


int main() {
    //freopen("in.cpp","r",stdin);
    string s;
    cin>>s;
    for(int i=0;i<4;i++)cout<<s[i];
    cout<<" ";
    for(int i=4;i<s.size();i++)cout<<s[i];
    cout<<endl;
    return 0;
}


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

const int MAX_V = 100010;
int par[MAX_V];
int treerank[MAX_V];

void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    treerank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(treerank[x] < treerank[y]){
    par[x] = y;
  }
  else{
    par[y] = x;
    if(treerank[x] == treerank[y]) treerank[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n, m; cin >> n >> m;
  init(n);
  for(int i=0; i<m; i++){
    int s, t; cin >> s >> t;
    unite(s, t);
  }
  int q; cin >> q;
  for(int i=0; i<q; i++){
    int s, t; cin >> s >> t;
    cout << (same(s, t) ? "yes" : "no") << endl;
  }
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int p[100010];
signed main()
{
    int n, m;
    cin >> n >> m;
    vector<string> s(m);
    for (int i = 0; i < m; i++)
    {
        cin >> p[i] >> s[i];
    }
    map<int, int> mp_ac,mp_wa;
    int ac = 0;
    for (int i = 0; i < m; i++)
    {
        if(s[i]=="AC" && mp_ac[p[i]]==0){
            ac++;
        }
        if(s[i]=="AC"){
            mp_ac[p[i]]++;
        }
        else{
            if(mp_ac[p[i]]==0){
            mp_wa[p[i]]++;
            }
        }
    }
    int wa = 0;
    for (int i = 1; i <= n; i++)
    {
        if(mp_ac[i]!=0) wa += mp_wa[i];
    }
    cout << ac << " " << wa << endl;

    return 0;
}

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

#define int long long

int a[1009];

int32_t main () {
	int k; cin>>k; int n=50;
	int x=k/n;
	int foo=k%n;
	a[1]=n-1+x;

	for(int i=2; i<=50; i++) {
		a[i]=a[i-1]-1;
	}

	for(int i=50, o=1;  i>0 && o<=foo; i--, o++) {
		a[i]+=n;
		for(int j=1; j<i; j++) a[j]--;
		for(int j=i+1; j<=n; j++) a[j]--;
	}
    cout<<"50"<<endl;
	for(int i=1; i<=n; i++) cout<<a[i]<<' '; cout<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    int N; cin >> N;
    vector<vector<int>> to(N),cot(N);
    int i,j,w;
    rep(r,N-1){
        cin >> i >> j >> w;
        w %= 2; i--; j--;
        to[i].push_back(j);
        cot[i].push_back(w);
        to[j].push_back(i);
        cot[j].push_back(w);
    }
    vector<int> ans(N,-1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        rep(r,to[v].size()){
            int u = to[v][r];
            if (ans[u] == -1){
                ans[u] = (ans[v] + cot[v][r])%2;
                q.push(u);
            }
        }
    }
    
    rep(i,N) cout << ans[i] << endl;
    rn 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N + 1);
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    int ans = 1, D = 0;
    for (int i = 0; i < N; i++)
    {
        D = D + L[i];
        if (D <= X)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define int LL
const LL inf=0x3f3f3f3f;
using namespace std;
template<typename tp> inline void read(tp &x)
{
	x=0; char c=getchar(); bool f=0;
	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
	if(f) x=-x;
}
int n,m;
signed main()
{
	read(n),read(m);
	printf("%d\n",n-m+1);
	return 0;
}

Measured memory_bytes: 256
module Main where

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

solve :: Int -> [[Int]] -> Int
solve target points = if null master_cost then -1 else minimum master_cost
  where
    table = to_table points
    allcase = filter (not . null). pattern $ table
    master_cost = map get_cost . filter (correct target) . map result $ allcase

result :: [(Int, [Int])] -> (Int, [Int])
result ((c, p):ps) = (c + cc, zipWith (+) p pp)
  where
    (cc, pp) = result ps

result [] = (0, repeat 0)


to_table :: [[Int]] -> [(Int, [Int])]
to_table = map (\p -> (head p, tail p))


pattern :: [a] -> [[a]]
pattern (p:ps) = concat . map (\pp -> [pp, p:pp] ) $ pattern ps
pattern [] = [[]]


correct :: Int -> (Int, [Int]) -> Bool
correct target (_, ps) = all (>= target) ps

get_cost :: (Int, [Int]) -> Int
get_cost (c, _) = c


Measured memory_bytes: 5040
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;
typedef bitset<12801> BS;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) {
    REP(j, W) {
      cin >> A[i][j];
    }      
  }
  REP(i, H) {
    REP(j, W) {
      int B;
      cin >> B;
      A[i][j] = abs(A[i][j] - B);
        
    }      
  }
  vector<BS> v(W);
  v[0].set(6400);
  REP(i, H) {
    vector<BS> nv(W);
    REP(j, W) {
      BS tb = j == 0 ? v[j] : (v[j] | nv[j-1]);
      nv[j] = (tb >> A[i][j]) | (tb << A[i][j]);
    }
    v = nv;
  }
  for(int i=0; i<=6400;++i) {
    if(v[W-1][6400-i] | v[W-1][6400+i]) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = getString(sc);
		String[] arr = s.split("");

		boolean isStepable = true;
		for (int i = 0; i < arr.length; i++) {
			String step = arr[i];
			if (step.equals("U") || step.equals("D")) {
				continue;
			}
			if (i % 2 == 0 && step.equals("R")) {
				continue;
			}
			if (i % 2 == 1 && step.equals("L")) {
				continue;
			}
			isStepable = false;
			break;
		}
		if (isStepable) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
int main(void){
    string s;
    vector<int> V(3);
    for(int i=0;i<3;i++) cin >> V[i];
    sort(V.begin(),V.end(),greater<int>());
    
    s = to_string(V[0]) + to_string(V[1]);
    cout<<atoi(s.c_str())+V[2];
    
    
    
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'


void solve()
{
 int n,k;
 cin>>n>>k;
  int a[n],dp[n];
 for (int i = 0; i < n; ++i)
 {
   cin>>a[i];
 }
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
  
  for(int i=2;i<n;i++)
  { int min=INT_MAX;
    for(int j=i-1;j>=i-k && j>=0;j--) 
      min=std::min(dp[j]+abs(a[i]-a[j]),min);

    dp[i]=min;
  }

  cout<<dp[n-1];

}

int main() 
{ IOS
    
    solve();
  

  return  0;

}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, A, B;
std::string S;
int all_cou, fore_rank = 1;

int main()
{
	in >> N >> A >> B >> S;
	for (auto c : S)
	{
		if (c == 'a')
		{
			if (all_cou < A + B)
			{
				out << "Yes" << std::endl;
				++all_cou;
			}
			else { out << "No" << std::endl; }
		}
		if (c == 'b')
		{
			if (all_cou < A + B && fore_rank <= B)
			{
				out << "Yes" << std::endl;
				++all_cou; ++fore_rank;
			}
			else { out << "No" << std::endl; }
		}
		if (c == 'c') { out << "No" << std::endl; }
	}
	return 0;
}

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

int main()
{
  int r, c;
  cin >> r >> c;
  vector<vector<int> > A(r + 1, vector<int>(c + 1));
  for (int i = 0; i < r; i++)
  {
    int sum = 0;
    for (int j = 0; j < c; j++)
    {
      cin >> A.at(i).at(j);
      sum += A.at(i).at(j);
    }
    A.at(i).at(c) = sum;
  }
  for (int j = 0; j < c + 1; j++)
  {
    int sum = 0;
    for (int i = 0; i < r; i++)
    {
      sum += A.at(i).at(j);
    }
    A.at(r).at(j) = sum;
  }

  for (int i = 0; i < r + 1; i++)
  {
    for (int j = 0; j < c + 1; j++)
    {
      if (j)
      {
        cout << " ";
      }
      cout << A.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a, z;
  for(int i = 0; i < s.size(); i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int i = s.size()-1; i >= 0; i--){
    if(s[i]=='Z'){
      z=i;
      break;
    }
  }
  cout << z-a+1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
#define int long long
#define deb(x) cout<<#x <<" = "<<x<<"\n";
using namespace std; 
signed main() 
{
	//freopen("input.txt", "r", stdin);
	int n; cin >> n;
    cout << (n + 1)/2 << "\n";
	
	
	
	
	
}

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

using namespace std;

const int MX = 3000, md = 1000000007;

int f[MX][MX], g[MX][MX], p2[MX + 1];

int get(int x, int y, int t) {
	return f[x][y] * 1ll * p2[g[x][y] - t - 1] % md;
}

int a[MX], x[MX], y[MX];

int main() {
	p2[0] = 1;
	for (int i = 1; i <= MX; i++) p2[i] = p2[i - 1] * 2 % md;
	
	int n, q;
	ignore = scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) ignore = scanf("%d", a + i);
	for (int i = 0; i < q; i++) {
		ignore = scanf("%d %d", x + i, y + i);
		x[i]--;
		y[i]--;
	}
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			f[i][j] = i < j ? 1 : 0;
			g[i][j] = q;
		}
	
	for (int i = q - 1; i >= 0; i--) {
		vector<tuple<int, int, int>> changes;
		changes.reserve(4 * n);
		changes.emplace_back(x[i], y[i], get(y[i], x[i], i));
		changes.emplace_back(y[i], x[i], get(x[i], y[i], i));
		for (int z = 0; z < n; z++) {
			if (z == x[i] || z == y[i]) continue;
			changes.emplace_back(x[i], z, get(y[i], z, i));
			changes.emplace_back(y[i], z, get(x[i], z, i));
			changes.emplace_back(z, x[i], get(z, y[i], i));
			changes.emplace_back(z, y[i], get(z, x[i], i));
		}
		
		for (auto& t : changes) {
			int x, y, v;
			tie(x, y, v) = t;
			
			f[x][y] = (get(x, y, i) + v) % md;
			g[x][y] = i;
		}
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] > a[j])
				ans = (ans + get(i, j, -1)) % md;
			
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


// https://atcoder.jp/contests/colopl2018-final/submissions/4341467
template <typename T> class ConvexHullTrick{
public:
	deque<pair<T,T>> lines;
	bool is_needless(pair<T,T> a, pair<T,T> b, pair<T,T> c){
		return (a.second-b.second)*(a.first-c.first) >= (a.second-c.second)*(a.first-b.first);
	}
	void add(T a, T b){
		if(!lines.empty()){
			auto l = lines.back();
			if(l.first == a){
				if(l.second < b) return;
				else lines.pop_back();
			}
		}
		while(lines.size()>=2 && is_needless(make_pair(a,b), lines.back(), *(lines.end()-2))){
			lines.pop_back();
		}
		lines.push_back(make_pair(a,b));
	}
	T apply(pair<T,T> f, T x){
		return f.first*x + f.second;
	}
	T query(T x){
		while(lines.size()>=2 && apply(lines[0],x)>apply(lines[1],x)){
			lines.pop_front();
		}
		return apply(lines[0],x);
	}
};


int main(){
	ll N,C;
	cin >> N >> C;
	vector<ll> h(N+1),dp(N+1,INF);
	FOR(i,1,N+1)cin >> h[i];
	ConvexHullTrick<ll> cht;
	dp[1] = 0;
	cht.add(-2*h[1],dp[1]+h[1]*h[1]);
	FOR(i,2,N+1){
		dp[i] = h[i]*h[i] + C + cht.query(h[i]);
		cht.add(-2*h[i],dp[i]+h[i]*h[i]);
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string S; cin >> S;
	int n = (int)S.length();
	set<char> same; same.clear();
	rep (i, n){
		char c = S[i];
		same.insert(c);
	} // end rep

	bool ok = ((int)same.size() == 4);
	if ((int)same.size() == 2){
		char c[2] = {0};
		set<char>::iterator it = same.begin();
		for (int i = 0; it != same.end(); ++it,++i){
			c[i] = (*it);
		} // end for
		ok |= (c[0] == 'S' && c[1] == 'N') || (c[0] == 'N' && c[1] == 'S');
		ok |= (c[0] == 'E' && c[1] == 'W') || (c[0] == 'W' && c[1] == 'E');
	} // end if

	cout << (ok ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256