akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}



class Program
{
    static int MAX_V = 100 * 100;
    
    struct Edge {
	public int to, cap, rev;
	public Edge(int _to, int _cap, int _rev)
	{
	    to = _to; cap = _cap; rev = _rev;
	}
    }

    static List<Edge>[] G;
    static bool[] used;

    static void AddEdge(int from, int to, int cap)
    {
	G[from].Add(new Edge(to, cap, G[to].Count));
	G[to].Add(new Edge(from, 0, G[from].Count - 1));
    }

    static int dfs (int v, int t, int f)
    {
	if (v == t) return f;
	used[v] = true;
	for (int i = 0; i < G[v].Count; i++)
	{
	    Edge e = G[v][i];
	    if (!used[e.to] && e.cap > 0)
	    {
		int d = dfs(e.to, t, Math.Min(f, e.cap));
		if (d > 0)
		{
		    e.cap -= d;
		    G[v][i] = e;
		    var et = G[e.to][e.rev];
		    et.cap += d;
		    G[e.to][e.rev] = et;
		    return d;
		}
	    }
	}
	return 0;
    }

    static int MaxFlow(int s, int t)
    {
	int flow = 0;
	while (true)
	{
	    used = new bool[MAX_V];
	    int f = dfs(s, t, 1000000000);
	    if (f == 0) return flow;
	    flow += f;
	}
    }
    
    public static void Main()
    {
	G = new List<Edge>[MAX_V];
	for (int i = 0; i < MAX_V; i++)
	    G[i] = new List<Edge>();

	int n = int.Parse(ReadLine());
	int[] a = new int[n];
	int[] b = new int[n];
	int[] c = new int[n];
	int[] d = new int[n];

	for (int i = 0; i < n; i++)
	{
	    var tmp = ReadIntArray();
	    a[i] = tmp[0]; b[i] = tmp[1];
	}
	for (int i = 0; i < n; i++)
	{
	    var tmp = ReadIntArray();
	    c[i] = tmp[0]; d[i] = tmp[1];
	}

	// node#
	//  red : 1 .. n
	//  blue: n+1 .. 2n
	//  s:0, t: 2n+1
	for (int i = 0; i < n; i++)
	{
	    for (int j = 0; j < n; j++)
	    {
		if (a[i] < c[j] && b[i] < d[j])
		{
		    AddEdge(i+1, n+j+1, 1);
		}
	    }
	}

	for (int i = 1; i <= n; i++)
	{
	    AddEdge(0, i, 1);
	    AddEdge(n+i, 2*n+1, 1);
	}

	WriteLine(MaxFlow(0, 2*n+1));
    }
}


Measured memory_bytes: 14516
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    sa: [String; n]
  };
  let mut ans = vec![0;4];
  for s in sa {
    let s = &s;
    match s {
      _ if s == "AC" => ans[0] += 1,
      _ if s == "WA" => ans[1] += 1,
      _ if s == "TLE" => ans[2] += 1,
      _ if s == "RE" => ans[3] += 1,
      _ => {}
    }
  }
  println!("AC x {}", ans[0]);
  println!("WA x {}", ans[1]);
  println!("TLE x {}", ans[2]);
  println!("RE x {}", ans[3]);
}


Measured memory_bytes: 7832
import java.util.Scanner;

public class Main {
  private static boolean isMonth(String ns) {
    int n = Integer.parseInt(ns);
    return n >= 1 && n <= 12;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    sc.close();
    boolean first = isMonth(s.substring(0, 2));
    boolean second = isMonth(s.substring(2));
    String result = "NA";
    if (first && second) result = "AMBIGUOUS";
    else if (first) result = "MMYY";
    else if (second) result = "YYMM";
    System.out.println(result);
  }
}


Measured memory_bytes: 23252
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll a, b, c, d;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> a >> b >> c >> d;
	while(true){
		c -= b;
		if(c <= 0){
			puts("Yes");
			return 0;
		}
		a -= d;
		if(a <= 0){
			puts("No");
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector<set<int>>v(200001);
int visited[200001];

int dfs(int i , int p)
{
    if(visited[i]) return 0;
    visited[i]=1;
    int ans = 1;
    for(auto x:v[i])
    {
        if(x == p) continue;
        ans += dfs(x , i);

    }
    return ans;
}



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

    while(m--)
    {
        int a , b;
        cin>>a>>b;
        v[a].insert(b);
        v[b].insert(a);
    }
    int ans = 0;
    for(int i=1; i <= n; i++)
    {
        if(!visited[i]) ans = max(ans , dfs(i , -1));
    }
    cout<<ans<<"\n";

}


Measured memory_bytes: 42276
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa[3][3];
	for(int64 ii = 0;ii < 3;ii++)
	{
		for(int64 jj = 0;jj < 3;jj++)
		{
			cin >> aa[ii][jj];
		}
	}
	int64 nn, tmp;
	cin >> nn;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		for(int64 jj = 0;jj < 3;jj++)
		{
			for(int64 kk = 0;kk < 3;kk++)
			{
				if(aa[jj][kk] == tmp)
				{
					aa[jj][kk] = -1;
				}
			}
		}
	}
	for(int64 ii = 0;ii < 3;ii++)
	{
		tmp = 1;
		for(int64 jj = 0;jj < 3;jj++)
		{
			if(aa[ii][jj] != -1)
			{
				tmp = 0;
			}
		}
		if(tmp)
		{
			puts("Yes");
			return 0;
		}
	}
	for(int64 ii = 0;ii < 3;ii++)
	{
		tmp = 1;
		for(int64 jj = 0;jj < 3;jj++)
		{
			if(aa[jj][ii] != -1)
			{
				tmp = 0;
			}
		}
		if(tmp)
		{
			puts("Yes");
			return 0;
		}
	}
	tmp = 1;
	for(int64 ii = 0;ii < 3;ii++)
	{
		if(aa[ii][ii] != -1)
		{
			tmp = 0;
		}
	}
	if(tmp)
	{
		puts("Yes");
		return 0;
	}
	tmp = 1;
	for(int64 ii = 0;ii < 3;ii++)
	{
		if(aa[ii][2-ii] != -1)
		{
			tmp = 0;
		}
	}
	if(tmp)
	{
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	char c;
	cin >> c;
	
	printf("%c", c + 1);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume0
{
    public class SurfSmeltFishingContest2
    {
        public static int Main()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                int num = int.Parse(input.Substring(0, input.IndexOf(' ')));
                int ev = int.Parse(input.Substring(input.IndexOf(' ') + 1));

                var record = new int[num + 1];
                // 参加者番号1が暫定一位
                int reader_id = 1;
                int reader_val = 0;
                for (int i = 0; i < ev; i++)
                {
                    input = Console.ReadLine();
                    int id = int.Parse(input.Substring(0, input.IndexOf(' ')));
                    int val = int.Parse(input.Substring(input.IndexOf(' ') + 1));
                    record[id] += val;

                    // トップの数値が変わったら選び直しの可能性あり
                    if (id == reader_id)
                    {
                        reader_val += val;
                        if (val < 0)
                        {
                            reader_id = 1;
                            reader_val = 0;
                            for (int j = 1; j <= num; j++)
                            {
                                if (reader_val < record[j])
                                {
                                    reader_id = j;
                                    reader_val = record[j];
                                }
                            }
                        }
                    }
                    else
                    {
                        if (reader_val < record[id])
                        {
                            reader_id = id;
                            reader_val = record[id];
                        }
                        else if (reader_val == record[id])
                        {
                            reader_id = Math.Min(reader_id, id);
                        }
                    }

                    Console.WriteLine(string.Format("{0} {1}", reader_id, reader_val));
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 16676
n, k = map(int, input().split())
x = list(map(int, input().split()))
m = 2 * (abs(x[n - 1]) + abs(x[0]))
for i in range(n - k + 1):
  if x[i] > 0:
    p = x[i + k - 1]
  elif x[i + k - 1] < 0:
    p = - x[i]
  else:
    q = min(x[i + k - 1], - x[i])
    p = x[i + k - 1] - x[i] + q
  if p < m:
    m = p
print(m)

Measured memory_bytes: 14224
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <bitset>
using namespace std;

int main() {
        string s;
        cin >> s;
        int x, y;
        scanf("%d %d", &x, &y);
        int cnt = 0;
        vector<int> lr, ud;
        int p = 0;
        while (s[p] == 'F') {
                p ++;
                x --;
        }
        bool is_lr = true;
        for (; p < s.size(); p ++) {
                if (s[p] == 'F') { 
                        cnt ++;
                } else {
                        if (cnt) (is_lr ? lr : ud).push_back(cnt);
                        cnt = 0;
                        is_lr = !is_lr;
                }
        }
        if (cnt) (is_lr ? lr : ud).push_back(cnt);
        auto calc = [&](int target, const vector<int> &a) {
                const int MID = 20000;
                bitset<MID * 2> cur, prev;
                prev[MID] = 1;
                for (int i = 0; i < a.size(); i ++) {
                        cur |= prev << a[i];
                        cur |= prev >> a[i];
                        prev = cur;
                        cur.reset();
                }
                return prev[target + MID];
        };
        bool ans = calc(x, lr) && calc(y, ud);
        puts(ans ? "Yes" : "No");
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
int N,i,mini,j,swap=0,a;
scanf("%d\n",&N);
int array[N];
for(i=0;i<N;i++) scanf("%d ",&array[i]);
for(i=0;i<N-1;i++)
{
mini=i;
for(j=i+1;j<N;j++)
{
if(array[j]<array[mini]) mini=j;
}
if(mini!=i){
swap++;
a=array[i];
array[i]=array[mini];
array[mini]=a;
}
}
for(i=0;i<N-1;i++) printf("%d ",array[i]);
printf("%d\n%d\n",array[N-1],swap);
return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll x, y;
  cin >> x >> y;
  vll v(13);
  v[1] = v[3] = v[5] = v[7] = v[8] = v[10] = v[12] = 1;
  v[4] = v[6] = v[9] = v[11] = 4;
  v[2] = 2;
  if (v[x] == v[y]) Yes();
  else No();
}

Measured memory_bytes: 256
#include <cstdio>
#define MN 101000

int n, a[MN];
int main()
{
	scanf("%d", &n);
	long long l = 2, r = 2;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = n; i >= 1; i--)
	{
		long long L = l / a[i] * a[i];
		if(L < l) l = L + a[i]; else l = L;
		r = r / a[i] * a[i] + (a[i] - 1);
		if(l > r) return 0 * puts("-1");
	}
	printf("%lld %lld\n", l, r);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 10005
using namespace std;

queue<int> S;// ??\???????????????????????¨???????????????
vector<int> in[N];// ??\??????
vector<int> out[N];// ?????????
vector<int> G[N];// ??\?????????????????????????????\???

void init(int V){// ?????°??????????????°
  for(int i=0;i<V;i++)in[i].clear();
  for(int i=0;i<V;i++){
    out[i]=G[i];
    for(int j=0;j<G[i].size();j++)
      in[G[i][j]].push_back(i);
  }
  for(int i=0;i<V;i++)
    if(!in[i].size())S.push(i);
}

vector<int> Topological_Sort(int V){
  vector<int> res;
  while(!S.empty()){
    int pos=S.front(); S.pop();
    res.push_back(pos);
    for(int i=0;i<out[pos].size();i++){
      int nx=out[pos][i];
      if(in[nx].size()==1)S.push(nx);
      for(int j=0;j<in[nx].size();j++)
	if(pos==in[nx][j]){
	  in[nx].erase(in[nx].begin()+j);
	  break;
	}
      out[pos].erase(out[pos].begin()+i);
      i--;
    }
  }
  for(int i=0;i<V;i++)
    if(in[i].size()||out[i].size())
      res.clear();
  return res;
}

int main(){
  int v,e,s,t;
  cin>>v>>e;
  for(int i=0;i<e;i++){
    cin>>s>>t;
    G[s].push_back(t);
  }
  init(v);
  vector<int> ans=Topological_Sort(v);
  for(int i=0;i<ans.size();i++)
    cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 4828
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;

string str,str2;
long long int n,m,res=0,res2=0,sum,now=1;

int main() {
	cout << fixed << setprecision(10);
    cin>>str>>n;
    str2=str+str;
    if(str.length()==1){cout<<n/2;return 0;}
    for(int i=1;i<str.length();i++){
        if(str[i]==str[i-1]){}
        else{goto next;}
    }
    cout<<str.length()*n/2;
    return 0;
    next:
    now=1;
    str.push_back('#');
    
    str2.push_back('#');
    for(int i=1;i<str.length();i++){
        if(str[i]==str[i-1]){now++;}
        else{res+=now/2;now=1;}
    }
    now=1;
    for(int i=1;i<str2.length();i++){
        if(str2[i]==str2[i-1]){now++;}
        else{res2+=now/2;now=1;}
    }
    //cout<<str<<str2;
    cout<<(n-1)*(res2-res)+res;
} 


Measured memory_bytes: 256
def solve():
    N, K, *V = map(int, open(0).read().split())
    
    AB_MAX = min(N, K)
    val = []
    for left in range(AB_MAX+1):
        for right in range(AB_MAX-left+1):
            get = V[:left] + V[-right:] if right != 0 else V[:left]
            get.sort()
            i = K - left - right
            if get:
                while get[0] < 0 and 0 < i:
                    get = get[1:]
                    i -= 1
                    if not get:
                        break
            val.append(sum(get))
    print(max(val))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s,t,u;
int a,b,f;
int main(){
    cin>>s>>t>>a>>b>>u;
    for(int i=0;i<s.size();i++)
        if(s[i]!=u[i]) f=1;
    if(f==1) b--;
    else a--;
    cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
// Your code here!
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
      .map(|e| e.parse().ok().unwrap()).collect()
}
fn main(){
  let mut a :Vec<usize> = read_vec();
  let n = a[0];
  let rating:usize = if n >= 10{ 
  0 } else{
  100 * (10 - n)};
  let answer = a[1] + rating;
  println!("{}", answer)
}

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

int main(){
  int n;
  string up,un;
  cin >> n;
  while(n--){
    cin >> up >> un;
    if(up.size() > 80 || un.size() > 80){
    exit:
      cout << "overflow\n";
      continue;
    } 
    if(up.size() < un.size()) swap(up,un);
    for(int i=up.size()-1,j=un.size()-1;i>=0;i--,j--){
      if(j >= 0) up[i] += un[j]-'0';
      if(up[i] > '9'){
	up[i] -= 10;
	if(i == 0) up = "1" + up;
	else up[i-1]++;
      }
    }
    if(up.size() > 80) goto exit;
    cout << up << endl;
  }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct BellmanFord {
private:
    struct Edge {
        int from, to;
        T cost;
    };
    
    int n;
    vector<vector<int>> graph;
    vector<bool> used;
    vector<Edge> edges;
    
    void dfs(int v) {
        if (used[v]) return;
        used[v] = true;
        for(auto u : graph[v]) {
            dfs(u);
        }
    }
    
public:
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    
    BellmanFord(){};
    BellmanFord(int _n) {
        n = _n;
        graph.resize(n);
        used.resize(n);
        dist.resize(n);
    }
    
    void add_edge(int from, int to, T cost) {
        edges.push_back((Edge){from, to, cost});
        graph[from].push_back(to);
    }
    
    bool get_distance(int from, int to = -1) {
        vector<bool> reach(n, true);
        for(int i = 0; i < n; i++) {
            fill(used.begin(), used.end(), false);
            dfs(i);
            if (to != -1) reach[i] = used[to];
        }
        fill(dist.begin(), dist.end(), inf);
        dist[from] = 0;
        for(int i = 0; i < n; i++) {
            bool update = false;
            for(auto e : edges) {
                if ((!reach[e.from]) || (!reach[e.to]) || (dist[e.from] == inf)) continue;
                if (dist[e.to] > (dist[e.from] + e.cost)) {
                    dist[e.to] = dist[e.from] + e.cost;
                    update = true;
                }
            }
            if (!update) break;
            if (i == (n - 1)) {
                return true;
            }
        }
        return false;
    }
};

int main(){
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> bf(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        bf.add_edge(a, b, p - c);
    }
    if (bf.get_distance(0, n - 1)) {
        cout << -1 << endl;
    }
    else {
        cout << max(0LL, -bf.dist[n - 1]) << endl;
    }
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
bool a[15][15];
int arr[15][15];
int b[15];

int main()
{
    _FastIO;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> arr[i][j];
        }
    }
    cin >> n;
    for(int k = 0; k < n; k++){
        cin >> b[k];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(b[k] == arr[i][j]){
                    a[i][j] = true;
                }
            }
        }
    }
    bool ans = false;
    if(a[0][0] && a[0][1] && a[0][2])   ans = true;
    if(a[1][0] && a[1][1] && a[1][2])   ans = true;
    if(a[2][0] && a[2][1] && a[2][2])   ans = true;
    if(a[0][0] && a[1][0] && a[2][0])   ans = true;
    if(a[0][1] && a[1][1] && a[2][1])   ans = true;
    if(a[0][2] && a[1][2] && a[2][2])   ans = true;
    if(a[0][0] && a[1][1] && a[2][2])   ans = true;
    if(a[0][2] && a[1][1] && a[2][0])   ans = true;
    if(ans){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
    
   string s;cin>>s;
   ll q;cin>>q;
   int rev=0;
   
   char next[200000],prv[200000];
   int nx=0,pr=200000-1;
   
   while(q--)
   {
       int t;cin>>t;
       if(t==1)
       {
           if(rev==0) rev=1;
           else rev=0;
       }
       else
       {
           int f;char ch;cin>>f>>ch;
           if(f==1)
           {
               if(rev==0) {//s=ch+s;
                   prv[pr]=ch;pr--;
               }
               else
               {//s=s+ch;
               next[nx]=ch;nx++;
                }
           }
           else
           {
               if(rev==0)
               {//s=s+ch;
                  next[nx]=ch;
                  nx++;
               }
               else 
               {//s=ch+s;
               
                   prv[pr]=ch;
                   pr--;
               }
           }
           
       }
       
   }
   
   if(rev==1)
   {
       for(int i=nx-1;i>=0;i--) cout<<next[i];
       for(long long int i=s.length()-1;i>=0;i--)
       cout<<s[i];
       for(int i=200000-1;i>pr;i--) cout<<prv[i];
   }
   else
   {
       for(int i=pr+1;i<200000;i++)
       cout<<prv[i];
       cout<<s;
       for(int i=0;i<nx;i++) cout<<next[i];
   }
   
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 976
package main

import (
	"fmt"
	"sort"
)

type pair struct {
	idx  int
	name string
	val  int
}

type Int64Slice []pair

func (p Int64Slice) Len() int           { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i].name < p[j].name }
func (p Int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

type Slice []pair

func (p Slice) Len() int           { return len(p) }
func (p Slice) Less(i, j int) bool { return p[i].val > p[j].val }
func (p Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func main() {
	var n int
	fmt.Scan(&n)

	all := make(Int64Slice, 0, n)

	for index := 0; index < n; index++ {
		var st string
		fmt.Scan(&st)

		var n int
		fmt.Scan(&n)

		all = append(all, pair{idx: index + 1, name: st, val: n})
	}
	sort.Sort(all)

	p := Slice{}
	now := all[0].name

	for _, item := range all {
		if now == item.name {
			p = append(p, item)
		} else {
			sort.Sort(p)
			for _, it := range p {
				fmt.Println(it.idx)
			}
			p = Slice{item}
			now = item.name
		}
	}
	sort.Sort(p)
	for _, it := range p {
		fmt.Println(it.idx)
	}

	// var re int
	// fmt.Println()
}


Measured memory_bytes: 512
M = int(input())
c = []
d = []
for i in range(M):
    di,ci = map(int,input().split())
    c.append(ci)
    d.append(di)

s = 0#各桁の和
for i in range(M):
    s += c[i] * d[i]

if s % 9 == 0:
    x = s//9 - 1
else:
    x = s//9

n = sum(c)#桁数

print(x + n - 1)

Measured memory_bytes: 12568
s = gets.chomp.split("")
flag = 1

s.size.times do |i|
    if (i + 1) % 2 == 0 && s[i] == "R"
        flag = 0
        break
    elsif (i + 1) % 2 == 1 && s[i] == "L"
        flag = 0
        break
    end
end

if flag == 0
    puts "No"
else
    puts "Yes"
end


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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int>p(n);

  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());

  int ans = 0;

  for (int i = 0; i < k; i++) {
    ans += p.at(i);
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n), B(n), C(n);
    REP(i, n) cin >> A[i];
    REP(i, n) cin >> B[i];
    REP(i, n) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    long long ans = 0;
    REP(i, n){
        long long tmp = 0;
        tmp = lower_bound(A.begin(), A.end(), B[i]) - A.begin();   //Aの中でB[i]以上で一番左の要素番号 -> Aの中でB[i]までの個数
        tmp *= n - (upper_bound(C.begin(), C.end(), B[i]) - C.begin());   //Cの中でB[i]より大きい一番左の要素番号を出しnで引くとCのB[i]より大きい数の個数が出せる
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
main=do
 getLine
 a<-map read.words<$>getLine
 print$min(f True 0 a)(f False 0 a)
f w s[]=0
f w s(a:as)=if(if w then s+a>0 else s+a<0)then f(not w)(s+a)as else if w then 1-s-a+(f(not w)1 as)else s+a+1+(f(not w)(-1)as)

Measured memory_bytes: 53628
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	string s;
	cin >> s;
	ll a = 0;
	for (int i = 0; i < s.size(); i++)
	{
		a += (ll)(s[i] - '0');
		a %= 9;
	}
	if (a % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3764
N = gets.to_i
W = gets.split.map(&:to_i)

ans = W.max
(1..N-1).each do |i|
  s_1 = W.slice(0..i-1).sum
  s_2 = W.slice(i..N).sum
  ans = [ans, (s_1-s_2).abs].min
end
p ans

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

int main() {
    string s;
    cin >> s;
    int count = 0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=s.at(s.size()-1-i)){
            count++;
        }
    }
    cout << count/2;
}

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

int main(){
    int x,y;cin>>x>>y;
    
    cout<<x+y/2<<endl;
    return 0;
}


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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv( maxN+5, 1 );
vcL fac( maxN+5, 1 );

void ADD(lli &x, lli y) {
	x += y;
	if ( x >= mod ) x -= mod;
	if ( x < 0 ) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = ( x%mod + mod ) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if ( e&1 ) MUL( ans, b );
		MUL( b, b );
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow( n, mod-2 );
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod-mod/i) * inv[ mod%i ] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[ i-1 ] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if ( a < b ) return 0;

	MUL( ans, inv[ fac[ a-b ] ] );
	MUL( ans, inv[ fac[b] ] );
	MUL( ans, fac[a] );

	return ans;
}

lli Lucas(lli n, lli m) {
	if ( m == 0 ) return 1;
	return cm( n%mod, m%mod ) * Lucas( n/mod, m/mod ) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas( n, m );
}

/// coding area ///

const lli maxn = 1E5;

void precal() {

	return;
}

void solve() {
	lli n = 1, m, sum = 0, ans = 0, cnt = 0, cnt0 = 0, ext = 0;
	string s;
	cin >> n;

	vcL num(n);
	for (auto &x : num) cin >> x;
	
	sort( ALL(num) );
	
	cout << num[ n/2 ]-num[ n/2-1 ] << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}




Measured memory_bytes: 4224
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	string S;
	while(N!=0){
		int val = N/(-2);
		if(N<0){
			if(abs(N)%2){
				val++;
				S.push_back('1');
			}
			else{
				S.push_back('0');
			}
		}
		else{
			if(abs(N)%2){
				S.push_back('1');
			}
			else{
				S.push_back('0');
			}
		}
		N = val;
	}
	if(S.empty()) S.push_back('0');
	reverse(S.begin(),S.end());
	cout << S <<endl;
	return 0;
}


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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,t;
    cin >> n >> t;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> b(n);
    int mn=a[0];
    for(int i = 0; i < n; i++) {
        if(a[i]<mn){
            mn=a[i];
            b[i]=0;
        }
        else{
            b[i]=a[i]-mn;
        }
    }
//    for(auto &e : b) {
//        cout << e << " ";
//    }
//    cout << "\n";
    sort(b.rbegin(),b.rend());
    int cnt=0;
    while(b[cnt]==b[0] && cnt!=n) {
        cnt++;
    }
    cout << cnt << "\n";

    return 0;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, int> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


int main() {
    int k;
    cin >> k;
    vector<int> numbers = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4,
                           1, 51
    };
    cout << numbers[k-1] << endl;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = 0
dp[1] = abs(arr[1] - arr[0])
for i in range(2, n):
    dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1], abs(arr[i] - arr[i - 2]) + dp[i - 2])
print (dp[-1])
# print (dp)

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

long GCD(long n,long m) {
  long r = n % m;
  while(r!=0){
    n = m;
    m = r;
    r = n % m;
  }
  return m;
}

int main() {
	long N,X,D;
	vector<long> x;
	cin >> N >> X;
	for (int i=0; i<N; i++) {
		long tmp;
		cin >> tmp;
		if (i==0) D=abs(tmp-X); 
		else {
			long gcd = GCD(D, abs(tmp-X));
			if (gcd<D) D=gcd;
		}
	}
	cout << D << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int h;
	while(cin>>h){
		if(h==0) break;
		int a[h][5];
		for(int i=0;i<h;i++){
			for(int j=0;j<5;j++){
				cin>>a[i][j];
			}
		}
		int now,ct=0,tp=0,p=1;
		while(p>0){
			p=0;
			for(int i=0;i<h;i++){
				ct=0;
				now=0;
				for(int j=0;j<5;j++){
					if(a[i][j]==now){
						ct++;
					}
					else if(a[i][j]!=now&&ct>=2){
						for(int k=0;k<j;k++){
							if(a[i][k]==now){
								a[i][k]=0;
								p=p+now;
							}
						}
						now=a[i][j];
						ct=0;
					}
					else{
						ct=0;
						now=a[i][j];
					}
				}
				if(ct>=2){
					for(int j=4-ct;j<=4;j++){
						a[i][j]=0;
						p=p+now;
					}
				}
			}
			tp=tp+p;
			for(int i=0;i<=h-1;i++){
				for(int j=0;j<5;j++){
					if(a[i][j]==0){
						for(int k=i-1;k>=0;k--){
							a[k+1][j]=a[k][j];
						}
						a[0][j]=0;
					}
				}
			}
		}
		cout<<tp<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {
		String result = "No";
		
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		sc.close();
		Set<String> nsweExistSet = new HashSet<String>();
		for(int i=0;i<input.length();i++){
			String tmpS = String.valueOf(input.charAt(i));
			nsweExistSet.add(tmpS);
			if(nsweExistSet.size() == 4){
				break;
			}
		}
		
		if(nsweExistSet.contains("N")&&nsweExistSet.contains("S")
				&&nsweExistSet.contains("W")&&nsweExistSet.contains("E")){
					result = "Yes";
		}
		else if(nsweExistSet.contains("N")&&nsweExistSet.contains("S")
				&&!nsweExistSet.contains("W")&&!nsweExistSet.contains("E")){
			result = "Yes";
		}
		else if(!nsweExistSet.contains("N")&&!nsweExistSet.contains("S")
				&&nsweExistSet.contains("W")&&nsweExistSet.contains("E")){
			result = "Yes";
		}
		
		System.out.print(result);
	}
}

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

int     main() {
        int N, X;
        cin >>N >>X;
        int m=1000;
        for (int i=0; i<N; i++) {
                int mm;
                cin >>mm;
                m = min(m, mm);
                X -=mm;
        }
        N += X/m;
        cout <<N <<endl;
        return 0;
};

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
H, A, D, S = map(int, raw_input().split())
ans = 0
flag = False
ls = []
for i in range(n):
    h, a, d, s = map(int, raw_input().split())
    a -= D
    if s < S:
        ans -= max(0, a)
    if A <= d and a > 0:
        flag = True
    elif a > 0:
        turn = h / (A - d)
        if h % (A - d) != 0:
            turn += 1
        ls.append((turn / float(a), turn, a))
if flag:
    print -1
    exit()
ls.sort()
S = 0
for p in ls:
    S += p[1]
    ans += S * p[2]
if ans < H:
    print ans
else:
    print -1



Measured memory_bytes: 12224
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, k = LI()
p = [(i + 1)/2 for i in LI()]
ans = ret = sum(p[:k])
for i in range(n - k):
    ret = ret + p[k + i] - p[i]
    ans = max(ans, ret)


print(ans)



Measured memory_bytes: 67820
#include <stdio.h>
int main (void)
{
	int a, b, men, syu;

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

	men = a * b;
	syu = (2 * a) + (2 * b);

	printf("%d %d\n", men, syu);
	
	
	
	return 0;


}

Measured memory_bytes: 1028
// abc096_b
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void) {
	int A, B, C, K;
	cin >> A >> B >> C;
	cin >> K;
	int max = std::max({ A, B, C });
	int sum = (A + B + C) - max;
	for (int i = 0; i < K; i++) {
		max *= 2;
	}
	sum += max;
	cout << sum << endl;
	return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main() {
    //preparation
    ll n, m;
    vector<bool> f(10, 0);
    VE cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    cin >> n >> m;
    REP(i, m) {
        ll A;
        cin >> A;
        f[A] = true;
    }
    VE dp(n + 1, -1 * mod);
    VE par(n + 1, -1 * mod);
    // dp for count digit
    dp[0] = 0;
    REP(i, n + 1) {
        RREP(j, 10) {
            if (!f[j] || i - cost[j] < 0)continue;
            if (dp[i] >= dp[i - cost[j]] + 1)continue;
            dp[i] = dp[i - cost[j]] + 1;
            par[i] = i - cost[j];
        }
    }
    VE cnt(10, 0);
    ll res = n;
    while (res != 0) {
        cnt[res - par[res]]++;
        res = par[res];
    }
    jkl;
    RREP(i, 10) {
        if (!f[i] || cnt[cost[i]] < 0)continue;
        while (cnt[cost[i]]--)cout << i;
    }
}


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

void print(){}
template<class Head,class... Tail>
void print(Head&& head, Tail&&... tail){
  cout<<head<<endl;
  print(forward<Tail>(tail)...);
}

void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}

int main(){

  double a,b,c,d;
  input(a,b,c,d);
  cout<<fixed<<setprecision(10);
  cout<<(a*b/2)<<" "<<(a==2*c&&b==2*d)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

int main(){
    init;
    int n,i,j,k,l;
    cin>>n>>k;
    vector<int>h(n);
    for(i=0;i<n;i++)
        cin>>h[i];
    int dp[n+1];
    fill(dp,dp+n+1,1e9);
    dp[1] = 0;
    dp[2] = abs(h[1]-h[0]);
    for(i=3;i<=n;i++)
        for(j=1;j<=k;j++)
            if(i-j > 0)
                dp[i] = min(dp[i-j] + abs(h[i-1] - h[i-j-1]), dp[i]);
            else break;
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
def solve(data):
    data = sorted(data, key=lambda x:-x[2])

    for cx in range(101):
        for cy in range(101):
            d0 = data[0]
            x,y,h = d0
            H = abs(x-cx)+abs(y-cy)+h
            flag = True
            for d in data[1:]:
                x,y,h = d
                if(max(H-abs(x-cx)-abs(y-cy),0) != h):
                    flag = False
                    break
            if(flag==True):
                return cx,cy,H

n = int(input())
data = [list(map(int,input().split())) for _ in range(n)]
# x, y, h

# print(data)
cx,cy,H = solve(data)
print(cx,cy,H)

Measured memory_bytes: 3064
/*input
3 2
1 2 1
2 3 1
*/

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

void dijkstra(int target, vector<vector<pair<int, int>>> &node,
	vector<int> &result, set<pair<int, int>> &route){

	int num_node = node.size();
	vector<int> distance(num_node, INT_MAX);
	vector<int> distance_from(num_node, 0);
	// vector<int> result(num_node, INT_MAX);
	fill(result.begin(), result.end(), INT_MAX);
	vector<int> decided;

	result[target] = 0;
	distance[target] = 0;
	decided.push_back(target);
	int min_index = target;

	while(true){

		for(auto pa:node[min_index]){
			int d = pa.second;
			if(distance[min_index] + d < distance[pa.first]){
				distance_from[pa.first] = min_index;
			}
			distance[pa.first] = min(distance[pa.first], distance[min_index] + d);
		}
		for(auto d:decided){
			distance[d] = INT_MAX;
		}

		vector<int>::iterator min_itr = min_element(distance.begin(), distance.end());
		min_index = std::distance(distance.begin(), min_itr);

		int a = min_index;
		int b = distance_from[min_index];
		// cout << "from:" << a << " to:" << b << endl;
		if(a > b) swap(a,b);
		route.insert(make_pair(a,b));

		result[min_index] = distance[min_index];
		decided.push_back(min_index);

		if(decided.size() == num_node) break;
	}
}

int main()
{
	int N, M;
	cin >> N >> M;

	vector<vector<pair<int, int>>> node(N);
	set<pair<int, int>> route;

	for(int i=0;i<M;i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		node[a].push_back(make_pair(b, c));
		node[b].push_back(make_pair(a, c));
	}

	vector<int> result(N);

	for(int i=0;i<N;i++){
		dijkstra(i, node, result, route);
	}

	cout << (M - route.size()) << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
int n;
cin>>n;
int a[n];
int s=0,ans=0;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    int z=(a[i]*s)%hell;
    ans=(ans+z)%hell;
    s=(s+a[i])%hell;
}
cout<<ans<<endl;


}

int32_t main()
{
   IOS;
    int t;
    t=1;
    //cin>>t;
    
    while(t--)
    {
       
        
        solve();
    }
    return 0;
}






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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    f1(i,0,n)
    cin>>a[i];
    int lar=a[0];
    int ans=1;
    f1(i,1,n)
    {
    	if(a[i]>=lar)
    	{
    		ans++;
    		lar=a[i];
    	}
    }
    cout<<ans;
    return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	int c[m];
	for(int i=0; i<m; i++)
		cin >> c[i];

	int dp[n+1];
	for(int i=0; i<=n; i++)
		dp[i] = i;

	for(int j=0; j<m; j++){
		for(int i=1; i<=n; i++){
			if(i/c[j] != 0)
				dp[i] = min(dp[i], dp[i-c[j]]+1);
		}
	}

	cout << dp[n] << endl;
}


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>

using namespace std;

#define int long long




signed main() {
	int n;

	cin >> n;

	int ans = 0;

	for (int i = 1; i < n; i++) {
		ans += i;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
  L=list(map(int,input().split()))
  C.append(L[0])
  A.append(L[1:])
ans=-1
for i in range(1<<N):
  cost=0
  tmp=[0]*M
  for j in range(N):
    if (i>>j)&1==0:
      continue
    cost+=C[j]
    for k in range(M):
      tmp[k]+=A[j][k]
    if min(tmp)>=X:
      if ans==-1:
        ans=cost
      else:
        ans=min(ans,cost)
print(ans)

Measured memory_bytes: 9220
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0 for i in range(9)]
red = 0
for i in a:
	if i < 400:
		b[0] += 1
	elif i < 800:
		b[1] += 1
	elif i < 1200:
		b[2] += 1
	elif i < 1600:
		b[3] += 1
	elif i < 2000:
		b[4] += 1
	elif i < 2400:
		b[5] += 1
	elif i < 2800:
		b[6] += 1
	elif i < 3200:
		b[7] += 1
	else:
		red += 1
c = 0
for i in b:
	if i > 0:
		c += 1
if c == 0:
	mn = 1
else:
	mn = c
mx = c + red
print (mn, mx)

Measured memory_bytes: 3064
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(n):
        t += (min(abs(x[i]), abs(k - x[i])) * 2)
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256