akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

int main() {
    FAST;

    ll n, k;
    cin >> n >> k;

    ll t = n % k;
    ll ans = min(t, k - t);
    println(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

ll d[300][300];

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  ll l;
  cin >> n >> m >> l;
  int a,b;
  ll c;
  REP(i,n)REP(j,n){
    if(i==j)d[i][j]=0;
    else d[i][j] = LLINF;
  }
  REP(i,m){
    cin >> a >> b >> c;
    d[a-1][b-1] = c;
    d[b-1][a-1] = c;
  }

  warshall_floyd(n);

  int q;
  cin >> q;
  REP(i,n)REP(j,n){
    if(d[i][j]==0) d[i][j]=0;
    else if(d[i][j]<=l) d[i][j]=1;
    else d[i][j]=LLINF;
  }
  warshall_floyd(n);
  int s,t;
  REP(i,q){
    cin >> s >> t;
    if (d[s-1][t-1]==LLINF)cout <<-1<<endl;
    else cout << d[s-1][t-1]-1 << endl;
  }
}


Measured memory_bytes: 1280
# -*- coding:utf-8 -*-
import sys


def tree_walk(tree, root):
    preorder_walk(tree, root)
    inorder_walk(tree, root)
    postoder_walk(tree, root)


def preorder_walk(tree, root):
    print("Preorder")
    result = []

    def preorder_walk_rec(node):
        if node == -1:
            pass
        else:
            result.append(str(node))
            preorder_walk_rec(tree[node][1])
            preorder_walk_rec(tree[node][2])

    preorder_walk_rec(root)
    print(" " + " ".join(result))


def inorder_walk(tree, root):
    print("Inorder")
    result = []

    def inorder_walk_rec(node):
        if node == -1:
            pass
        else:
            inorder_walk_rec(tree[node][1])
            result.append(str(node))
            inorder_walk_rec(tree[node][2])

    inorder_walk_rec(root)
    print(" " + " ".join(result))


def postoder_walk(tree, root):
    print("Postorder")
    result = []

    def postoder_work_rec(node):
        if node == -1:
            pass
        else:
            postoder_work_rec(tree[node][1])
            postoder_work_rec(tree[node][2])
            result.append(str(node))

    postoder_work_rec(root)
    print(" " + " ".join(result))


def get_tree():
    n = int(input())
    tree = [[-1, -1, -1] for x in range(0, n)]
    for node in sys.stdin.readlines():
        _id, left, right = [int(x) for x in node.split()]
        if left >= 0:
            tree[left][0] = _id
            tree[_id][1] = left
        if right >= 0:
            tree[right][0] = _id
            tree[_id][2] = right
    return tree


def get_root(tree):
    for i, node in enumerate(tree):
        if node[0] == -1:
            return i
    raise ValueError


if __name__ == "__main__":
    tree = get_tree()
    tree_walk(tree, get_root(tree))

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

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);
  if(x/d>=k) cout << x-k*d << endl;
  else if((k-x/d)%2==0) cout << x%d << endl;
  else if(x%d-d<=0) cout << abs(x%d-d) << endl;
  else cout << x%d+d << endl;
  
  return 0;
}


Measured memory_bytes: 3636
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  var output = 0;
  var list = [];
  for(var i = 1; i <= N; i++){
    var tmp = input[i].split(" ").map((a)=>Number(a));
    var obj = {};
    obj["a"] = tmp[0];
    obj["b"] = tmp[1];
    list.push(obj);
  }
  list.sort(function(a,b){
  	return a["a"] - b["a"];
  });
  
  
  for(var i = 0; i < N; i++){
    output += list[i]["a"] * Math.min(M, list[i]["b"]);
    M = M - list[i]["b"];
    if(M <= 0){
       break;
       }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 53116
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            String s = in.nextString();

            if (s.length() != n + m + 1) {
                out.println("No");
                return;
            }

            for (int i = 0; i < s.length(); i++) {
                if (i == n) {
                    if (s.charAt(i) != '-') {
                        out.println("No");
                        return;
                    }
                } else {
                    if (s.charAt(i) < '0' || s.charAt(i) > '9') {
                        out.println("No");
                        return;
                    }
                }
            }

            out.println("Yes");
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

int main(void)
{
    string s;
    getline(cin, s);  // 1行読み込む
    for(int i = 0; i < s.size(); i++) {
        char c = s[i];
        if ('A' <= c && c <= 'Z') {
            //c = tolower(c);
            c = c + 32;
        }
        else if('a' <= c && c <= 'z') {
            c = c - 32;
        }
        cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int n;
string s;

int main() {
    cin >> n >> s;
    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    bool flg = true;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] !=  s[i + n/2]) flg = false;
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
def main():
    # 解説AC
    S = input()
    N = len(S)
    ans = 10**7
    for k in range(N-1):
        if S[k] != S[k+1]:
            ans = min(ans, max(k + 1, N - k - 1))
    print(ans if ans < 10**6 else N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40048
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 3e3 + 5;

int n, a[N];
int dp[N][N];

int solve(int l, int r) {
    if (l == r) {
        return a[l]; // or a[r]
    }

    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    int ans1 = a[l] - solve(l + 1, r);
    int ans2 = a[r] - solve(l, r - 1);

    return dp[l][r] = max(ans1, ans2);
}

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

    cin >> n;

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i][j] = -1;
        }
    }

    cout << solve(0, n - 1) << "\n";
    return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int c[6];
	for(int i = 0; i < 6; i++){
		cin >> c[i];
	}
	if((c[0] + c[1] * 5 + c[2] * 10 + c[3] * 50 + c[4] * 100 + c[5] * 500) / 1000)
		cout << 1 << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1160
Scanf.scanf "%d" (fun n ->
    let l = Array.make n 0 in
    let r = Array.make n 0 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d %d" (fun a b -> l.(i) <- a; r.(i) <- b + 1)
    done;

    let rec loop i p q =
        if i = n then p, q else
            let p = if l.(i) > l.(p) then i else p in
            let q = if r.(i) < r.(q) then i else q in
            loop (i + 1) p q
    in
    let p, q = loop 0 0 0 in

    let result1 =
        let rec loop j acc =
            if j = n then acc + max (r.(q) - l.(p)) 0 else
            if j = p || j = q then loop (j + 1) acc else
                loop (j + 1) (max acc (r.(j) - l.(j)))
        in
        loop 0 0
    in
 
    let result2 = (
        let work = Array.init n (fun i -> max (r.(i) - l.(p)) 0, max (r.(q) - l.(i)) 0) in
        Array.sort (fun (a0, b0) (a1, b1) -> compare (-b0, a0) (-b1, a1)) work;
        let s = Array.make (n + 1) 0 in
        let t = Array.make (n + 1) 0 in
        t.(0) <- r.(q) - l.(q);
        s.(n) <- r.(p) - l.(p);
        for i = 1 to n do
            let _, b = work.(i - 1) in
            t.(i) <- min t.(i - 1) b;
        done;
        for i = n - 1 downto 0 do
            let a, _ = work.(i) in
            s.(i) <- min s.(i + 1) a;
        done;

        let rec loop i acc =
            if i = n + 1 then acc else loop (i + 1) (max acc (s.(i) + t.(i)))
        in
        loop 0 result1
    )
    in
    Printf.printf "%d\n" result2
)

Measured memory_bytes: 12848
// Date: 2020-03-22

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

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

int a[N], b[N], n;
int main() {
    FIO;
    cin >> n;
    rep(i, 1, n) cin >> a[i], b[a[i]]++;
    LL ans = 0;
    rep(i, 1, n) ans += 1LL*b[i]*(b[i]-1)/2;
    rep(i, 1, n) {
        LL tp = ans-(b[a[i]]-1);
        cout << tp << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
def ceil10(i):
  z=int(i/10)
  z=z*10
  z=10-(i-z)
  if z==10:
    z=0
  return i+z

a=[]
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))
a.append(int(input()))

min1=(-1,9999)
for i,b in enumerate(a):
  c=int(b/10)
  c=c*10
  c=b-c
  if c==0:
    c=10
  if min1[1]>c:
    min1=(i,c)
ans=0

for i,b in enumerate(a):
  if i!=min1[0]:
    ans+=ceil10(b)
  else:
    ans+=b
print(ans)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,k;cin >>n>>k;
    vector<ll>p(n);
    for (int i = 0; i < n; ++i) {
        cin >>p[i];
        p[i]++;
    }
    ll ans=0;
    vector<ll>sum(n+1,0);
    for (int i = 0; i < n; ++i) {
        sum[i+1]=sum[i]+p[i];
    }
    for (int i = 0; i < n; ++i) {
        if(i+k>n)break;
        ans=max(ans,sum[i+k]-sum[i]);
    }
    string res=(ans%2)?".5":"";
    ans/=2;
    cout <<ans <<res<<endl;
    return 0;
}

Measured memory_bytes: 6404
n,a,b=list(map(int,input().split()))
t=n//(a+b)
amari=n%(a+b)
if a+b==n:
    print(a)
if a >= n:
    print(n)
if a < n < a+b:
    print(a)
if a+b<n:
    if amari==0:
        print(t*a)
    elif amari<=a:
        print(t*a+amari)
    else:
        print(t*a+a)
   

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int d = y - (2 * x);
    if( d >= 0 && d % 2 == 0 && (d / 2) <= x){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35712
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll a,b;
  cin >> a >> b;
  b++;
  ll ans = 0;
  REP(i,40){//iビット目は2^iで0と1が交互、周期は2^(i+1)
    ll quo_a = a/(1LL<<(i+1));
    ll rem_a = a%(1LL<<(i+1));
    ll cnt_a = (1LL<<i)*quo_a + max(0LL,rem_a-(1LL<<i));
    ll quo_b = b/(1LL<<(i+1));
    ll rem_b = b%(1LL<<(i+1));
    ll cnt_b = (1LL<<i)*quo_b + max(0LL,rem_b-(1LL<<i));
    if((cnt_b-cnt_a)%2==1) ans += (1LL<<i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
(defun record (str ht)
  (let ((h (gethash str ht)))
    (setf (gethash str ht) (if h (1+ h) 1))))

(defun read-record(N ht)
  (if (<= N 0) ()
    (progn
      (record (read) ht)
      (read-record (1- N) ht))
    ))

(defun ht2alist (table)
  (let ((alist nil))
    (maphash (lambda (k v)
	       (push (cons k v) alist))
	     table)
    alist))


(let ((ht (make-hash-table :test #'equal)))
  (read-record (read) ht)
  (setq alist (sort (ht2alist ht) #'> :key #'cdr))
  (setq alist (remove-if (lambda (x) (< (cdr x) (cdr (car alist)))) alist))
  (setq alist (sort (mapcar 'car alist) #'string<))

  (format t "~{~A~^~%~}" (mapcar 'string-downcase alist)))

Measured memory_bytes: 114660
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main()
{
   /* vector<int>v;
    vector<int>v1;
    vector<int>v2;
    set <char>s;
    int t,coun1=0,a,ans3,coun2=0,x,y=0,ans1=0,b,sum=0,flag=0,ans2;*/




    long long ai,t,n,a,b,c=0;
    string str;
    string str1;

    getline(cin,str);
    getline(cin,str1);

    b=str1.size() -1;

    a=str1.size()-1;

    str1=str1.substr(0,a);





    if( str.compare(str1) == 0 && b == str.size() )
    {


     cout << "Yes" << endl;


    }
    else
    {
        cout << "No" << endl;
    }



return 0;
}


Measured memory_bytes: 3612
/***
*  author  :_shamim
*  created : 06.05.2020
*
***/

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--)          

using namespace std;

ll i,j,temp;

int main()
{_
  
  int x,y;
  cin>>x>>y;

  char arr[x+2][y+2];
  for(i=0;i<x+2;i++){
    for(j=0;j<y+2;j++){
      if(i==0|| j==0 || i==(x+1) || j==(y+1)){
        arr[i][j]='#';
      }
      else{
      	arr[i][j] = '0';
      }
    }
    
  }
  

  for(i=1;i<x+1;i++){
    for(j=1;j<y+1;j++){
      cin>>arr[i][j];
    }
  }
  for(i=0;i<x+2;i++){
    for(j=0;j<y+2;j++){
      cout<<arr[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;

const int MAX_V = 100010;
using Capacity = int;
using Cost = int;
const auto inf = numeric_limits<Capacity>::max() / 8;
struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};
struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // ?????????
		g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
		g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		// vector<Cost> h(g.size()), dist(g.size());
		// vector<int> prevv(g.size()), preve(g.size());
		static Cost h[MAX_V], dist[MAX_V];
		static int prevv[MAX_V], preve[MAX_V];
		for(int i = 0; i < n; i++) {
			h[i] = 0;
		}
		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.emplace(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.emplace(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t ????????????????????£??????????????????
			int d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// ??????????????????=???????????????-?????¨??????????????¨???
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};


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

	int V, E, F;
	cin >> V >> E >> F;

	PrimalDual pd(V);

	for(int i = 0; i < E; i++) {
		int u, v, c, d;
		cin >> u >> v >> c >> d;
		pd.add_edge(u, v, c, d);
	}

	int res = pd.solve(0, V - 1, F);
	if(res == inf) {
		cout << -1 << endl;
	}
	else {
		cout << res << endl;
	}
}

Measured memory_bytes: 3320
def func(x):
    return int(x)-1
N, K = list(map(int, input().split()))
A = list(map(func, input().split()))



now = 0
past = []
past_set = set()

for i in range(N):
    if now in past_set:
        break
    past.append(now)
    past_set.add(now)
    now = A[now]


i_loop = past.index(now)
loop = past[i_loop:]
if K >= i_loop:
    print(loop[(K-i_loop) % len(loop)] +1)
else:
    print(past[K] +1)



Measured memory_bytes: 32360
#include <stdio.h>

#define N 8

int main(void){
    int dt[N];
    char str[N];
    long max,min;
    int n,tmp;
    
    scanf("%d",&n);
    for (int i=0; i<n; i++){
        max = min = 0;
        // input
        scanf("%s", str);
        for (int j=0; j<N; j++) dt[j]=str[j]-'0';
        // sort
        for (int j=0; j<N; j++){
            for (int k=N-2; k>=j; k--){
                if (dt[k] >dt[k+1]){
                    tmp = dt[k];
                    dt[k] = dt[k+1];
                    dt[k+1] = tmp;
                }
            }
        }
        for (int j=0; j<N; j++){
            max *= 10;
            max += dt[N-1-j];
            min *= 10;
            min += dt[j];
        }
        printf("%d\n", max-min);
    }
    return 0;
}

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

int w,h;
int field[51][51];

// 現在地(x,y)
void dfs(int x, int y){
    // 今いるところを-1に置き換える
    field[y][x] = -1;

    // 移動する8方向をループ
    for(int dx = -1 ; dx <= 1 ; dx++ ){
        for(int dy = -1 ; dy <= 1 ; dy++ ){
            // x方向にdx, y方向にdy, 移動した場所を(mx,my)とする
            int mx = x + dx;
            int my = y + dy;
            // 範囲外に出たときは次の処理へ
            if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
            // 陸地だったら再帰呼び出し
            if( field[my][mx] == 1 ){
                dfs( mx , my );
            }
        }
    }
}

int main(){
    while( cin >> w >> h , w||h ){
        for(int y=0 ; y < h ; y++ ){
            for(int x=0 ; x < w ; x++ ){
                cin >> field[y][x];
            }
        }

        int ans = 0;
        for(int y=0 ; y < h ; y++ ){
            for(int x=0 ; x < w ; x++ ){
                if( field[y][x] == 1 ){ // 陸地があったら再帰関数を呼び出す
                    dfs( x , y );
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class Info {
    public:
    int n, m;
    Info(int n, int m):
    n(n), m(m) {}
    bool operator < (const Info &f) const {
        return n < f.n;
    }
    bool operator > (const Info &f) const {
        return n > f.n;
    }
};
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    map<int, int> mp1, mp2;
    for (int i = 0; i < N; i++) {
        if (i % 2) mp1[a[i]]++;
        else mp2[a[i]]++;
    }

    vector<Info> v;
    for (auto m : mp1) { v.push_back(Info(m.second, m.first)); }
    for (auto m : mp2) { v.push_back(Info(m.second, m.first)); }
    v.push_back(Info(0, 0));
    sort(v.begin(), v.end(), greater<Info>());
    int cnt = 0;
    int num = -1;
    for (int i = 0; i < v.size(); i++) {
        if (num == -1) {
            cnt += v[i].n;
            num = v[i].m;
        }
        else {
            if (num == v[i].m) continue;
            cnt += v[i].n;
            break;
        }
    }

    cout << N - cnt << '\n';

}


Measured memory_bytes: 6520
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int ans;
bool FLG;

void recursive(short table[30],int count){

	if(count >= ans)return;

	FLG = true;
	for(int i = 1; i <= 8; i++){
		if(table[0] != table[i]){
			FLG = false;
			break;
		}
	}
	if(FLG){
		if(table[9] != table[10] || table[9] != table[11]){
			FLG = false;
		}
	}
	if(FLG){
		if(table[12] != table[13] || table[12] != table[14]){
			FLG = false;
		}
	}
	if(FLG){
		if(table[15] != table[16] || table[15] != table[17]){
			FLG = false;
		}
	}
	if(FLG){
		if(table[18] != table[19] || table[18] != table[20]){
			FLG = false;
		}
	}
	if(FLG){
		for(int i = 22; i <= 29; i++){
			if(table[21] != table[i]){
				FLG = false;
				break;
			}
		}
	}

	if(FLG){
		ans = min(ans,count);
		return;
	}

	short new_table[4][30];

	for(int i = 0; i < 4; i++){
		for(int k = 0; k < 30; k++)new_table[i][k] = table[k];
	}

	new_table[0][15] = table[17];
	new_table[0][17] = table[15];
	new_table[0][0] = table[23];
	new_table[0][23] = table[0];
	new_table[0][3] = table[26];
	new_table[0][26] = table[3];
	new_table[0][6] = table[29];
	new_table[0][29] = table[6];
	new_table[0][9] = table[20];
	new_table[0][20] = table[9];
	recursive(new_table[0],count+1);


	new_table[1][14] = table[12];
	new_table[1][12] = table[14];
	new_table[1][2] = table[21];
	new_table[1][21] = table[2];
	new_table[1][5] = table[24];
	new_table[1][24] = table[5];
	new_table[1][8] = table[27];
	new_table[1][27] = table[8];
	new_table[1][11] = table[18];
	new_table[1][18] = table[11];
	recursive(new_table[1],count+1);


	new_table[2][18] = table[20];
	new_table[2][20] = table[18];
	new_table[2][0] = table[27];
	new_table[2][27] = table[0];
	new_table[2][1] = table[28];
	new_table[2][28] = table[1];
	new_table[2][2] = table[29];
	new_table[2][29] = table[2];
	new_table[2][14] = table[15];
	new_table[2][15] = table[14];
	recursive(new_table[2],count+1);


	new_table[3][9] = table[11];
	new_table[3][11] = table[9];
	new_table[3][6] = table[21];
	new_table[3][21] = table[6];
	new_table[3][7] = table[22];
	new_table[3][22] = table[7];
	new_table[3][8] = table[23];
	new_table[3][23] = table[8];
	new_table[3][12] = table[17];
	new_table[3][17] = table[12];
	recursive(new_table[3],count+1);
}

int main(){

	int N;
	short table[30];
	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		ans = 9;

		for(int k = 0; k < 30; k++){
			scanf("%hd",&table[k]);
		}

		recursive(table,0);

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2760
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n,a,b;cin>>n>>a>>b;
	cout<<min(n*a,b);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#include<utility>
#define int long long
using namespace std;
const int MaxN = 200005;
int n, k, head, tail, a[MaxN];
signed main(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	head = k, tail = 1;
//	printf("%lld",a[head]);
	for(int i=k+1;i<=n;i++){
		head++;
		if(a[head] > a[tail]) printf("Yes\n");
		else printf("No\n");
		tail++;
	}
	return 0;
}

Measured memory_bytes: 4656
n,k = map(int,input().split())
pl = list(map(int,input().split()))

import itertools
pl_ac = [0] + list(itertools.accumulate(pl))

ans = 0
for i in range(n-k+1):
    tmp = pl_ac[i+k] - pl_ac[i]
    ans = max(tmp, ans)
print((ans+k)/2)


Measured memory_bytes: 25060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


#define ll long long


//gcdやり直す

void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}




/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}





/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n;
  scanf("%d",&n);
  /*
  y=1,z=1のときを考えると，与式はx^2+2x+3=nとなるので，
  x,y,zのそれぞれについて1~sqrt(n)までの全探索を考える．

  n<=10^4より，計算量はO(nsqrt(n))となり実行時間制限には十分間に合います．
  */

  int A[n+10];
  for(int i=0;i<n+10;i++){
    A[i]=0;
  }
  for(int x=1;x<110;x++){
    for(int y=1;y<110;y++){
      for(int z=1;z<110;z++){
        int now=x*x+y*y+z*z+x*y+y*z+z*x;
        if(now<=n){
          A[now]++;
        }
      }
    }
  }

  for(int i=1;i<=n;i++){
    printf("%d\n",A[i]);
  }
}

Measured memory_bytes: 1664
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,K = map(int,input().split())
arrH = [int(input()) for _ in range(N)]
arrH.sort()

ans = 10**9+1
for i in range(N-K+1):
    num = arrH[i+K-1] - arrH[i] 
    ans = min(ans,num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 3030;
const ll M = 1e9+7;
const ll H = 500000004;
ll nv[MN][MN],eq[MN][MN];
ll w[MN];
ll to[MN][2];
inline ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(ac,b);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll norm(ll v) {
	ll res = v%M;
	return res>=0?res:res+M;
}
int main() {
	ll n,q;
	cin >> n >> q;
	memset(nv,0,sizeof(nv));
	memset(eq,0,sizeof(eq));
	for(int i=0;i<n;i++) {
		cin >> w[i];
	}
	for(int i=0;i<n;i++) {
		for(int j=i;j<n;j++) {
			if(w[i] > w[j]) {
				nv[i][j] = 1;
			}
			if(w[i] == w[j]) {
				eq[i][j] = 1;
			}
		}
	}
	for(int i=0;i<q;i++) {
		int a,b;
		cin >> a >> b;
		a--;b--;
		int p[2] = {min(a,b),max(a,b)};
		for(int id=0;id<2;id++) {
			for(int j=0;j<n;j++) {
				int u = min(j,p[id]);
				int v = max(j,p[id]);
				if(j >= p[0] && j <= p[1]) {
					to[j][id] = norm(1-eq[u][v]-nv[u][v]);
				}  else {
					to[j][id] = nv[u][v];
				}
			}
		}
		swap(to[p[0]][0],to[p[1]][0]);
		swap(to[p[0]][1],to[p[1]][1]);
		for(int id=0;id<2;id++) {
			for(int j=0;j<n;j++) {
				int u = min(j,p[id^1]);
				int v = max(j,p[id^1]);
				if(j == p[id]) {
					if(id == 0) {
						u = p[0];
						v = p[1];
					} else {
						continue;
					}
				}
				nv[u][v] += to[j][id];
				if(nv[u][v] >= M) {nv[u][v] -= M;}
				nv[u][v] = mul(nv[u][v],H);
			}
		}
		for(int id=0;id<2;id++) {
			for(int j=0;j<n;j++) {
				int u = min(j,p[id]);
				int v = max(j,p[id]);
				to[j][id] = eq[u][v];
			}
		}
		swap(to[p[0]][0],to[p[1]][0]);
		swap(to[p[0]][1],to[p[1]][1]);
		for(int id=0;id<2;id++) {
			for(int j=0;j<n;j++) {
				int u = min(j,p[id^1]);
				int v = max(j,p[id^1]);
				if(j == p[id]) {
					if(id == 0) {
						u = p[0];
						v = p[1];
					} else {
						continue;
					}
				}
				eq[u][v] += to[j][id];
				if(eq[u][v] >= M) {eq[u][v] -= M;}
				eq[u][v] = mul(eq[u][v],H);
			}
		}
	}
	ll res = 0;
	ll pu = bp(2,q);
	for(int i=0;i<n;i++) {
		for(int j=i+1;j<n;j++) {
			res += mul(pu,nv[i][j]);
		}
	}
	res %= M;
	cout << res << '\n';
}


Measured memory_bytes: 147180
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N, W[110];
int sum;
int S1, S2;
int ans;
int MIN = 1000; 

int main(){
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> W[i];
		sum += W[i];
	}
	for (int i = 0; i < N; i++){
		if(i==0)S1 = sum - W[i];
		else S1 -= W[i];
		S2 = sum - S1;
		ans = abs(S1 - S2);
		if (MIN > ans)MIN = ans;
	}
	
	cout << MIN << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 


// ll Arr[105];
// ll Size[105];


// ll root (ll i)
// {
//     while(Arr[ i ] != i)
//     {
//         Arr[ i ] = Arr[ Arr[ i ] ] ; 
// i = Arr[ i ]; 
//     }
// return i;
// }


// void initialize(ll N)
// {
//     for(ll i = 0;i<N;i++)
//     {
//         Arr[ i ] = i ;
//         Size[ i ] = 1;
//     }
// }
// void weighted_union(ll A,ll B)
// {
//     ll root_A = root(A);
//     ll root_B = root(B);
//     if(Size[root_A] < Size[root_B ])
//     {
// Arr[ root_A ] = Arr[root_B];
// Size[root_B] += Size[root_A];
// }
//     else
//     {
// Arr[ root_B ] = Arr[root_A];
// Size[root_A] += Size[root_B];
// }

// }

ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll c)
{
    ll x=1,y=a;
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y)%c;
        }
        y = (y*y)%c;
        b /= 2;
    }
    return x%c;
}
 
double sqdist(double a,double b,double c,double d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}


ll check(ll i)
{
    ll p = 0;
    while(i)
    {
        if(i%2)p++;
        i/=2;
    }
    // cout<<i<<' '<<p<<endl;
    return p;
}


void solve()
{
    int n;
    cin>>n;
    vector<int> arr(n,0);
    for(auto &i:arr)cin>>i;
    vector<int> dp(n,INT_MAX);
dp[0]=0;
    for(int i=0;i<n;i++)
    {
        if(i+1<n)
            dp[i+1]=min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
        if(i+2<n)
            dp[i+2]=min(dp[i+2],dp[i]+abs(arr[i]-arr[i+2]));
    }
    cout<<dp[n-1];
}   
 
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    solve();
}

Measured memory_bytes: 3944
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	long long int  N;
	scanf("%lld", &N);
	long long int i;
	long long int ans = 1;
	for (i = 1; i <= N; i++)
	{
		ans *= i;
		ans %= 1000000007;
	}
	printf("%lld\n", ans);



#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> da(n);
  for(int i=0;i<n;i++){
    cin >> da[i];
  }
  cout << (n+k-3)/(k-1) << endl;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
write = sys.stdout.write
 
n, q = map(int, input().split())
INF = 2**31-1
 
LV = (n-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
 
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1
 
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None
 
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)
 
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])
 
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
 
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s
 
 
ans = []
for i in range(q):
    t, *cmd = map(int, readline().split())
    if t:
        s, t = cmd
        ans.append(str(query(s, t+1)))
    else:
        s, t, x = cmd
        update(s, t+1, x)
 
write("\n".join(ans))
write("\n")


Measured memory_bytes: 17756
#include<bits/stdc++.h>
using namespace std;
using u64 = uint_fast64_t;
using i64 = int_fast64_t;
#define rep(i, n) for(u64 i = 0; i < n; ++i)
#define dump(x) cout << #x << " = " << x << endl
template<class T>
bool chmin(T &a, const T &b){
  if(b < a){
    a = b;
    return true;
  }
  return false;
}

int main(){
  u64 n, m;
  cin >> n >> m;
  u64 dpsiz = u64(1) << n;
  vector<u64> dp(dpsiz, u64(1) << 32);
  dp[0] = 0;
  rep(l, m){
    u64 a, b;
    cin >> a >> b;
    u64 s = 0;
    rep(i, b){
      u64 c;
      cin >> c;
      --c;
      s |= u64(1) << c;
    }
    for(u64 t = dpsiz; t;){
      t = t - 1 & s;
      chmin(dp[t], a);
    }
  }
  rep(s, dpsiz){
    for(u64 t = dpsiz; t;){
      t = t - 1 & s;
      chmin(dp[s], dp[t] + dp[s - t]);
    }
  }
  const u64 ans = dp.back();
  if(ans >= (u64(1) << 32)){
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from pprint import pprint

S = list(input())
MOD = 10**9 + 7

dp = [[0 for _ in range(4)] for _ in range(len(S)+1)]

dp[len(S)][0] = 0
dp[len(S)][1] = 0
dp[len(S)][2] = 0
dp[len(S)][3] = 1

for i in reversed( range(len(S))):
    dp[i][0] = dp[i+1][0]
    if S[i] == 'C':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] + dp[i+1][3]
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'B':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2]
        dp[i][1] = dp[i+1][1] + dp[i+1][2]
        dp[i][0] = dp[i+1][0]
    elif S[i] == 'A':
        dp[i][3] = dp[i+1][3]
        dp[i][2] = dp[i+1][2] 
        dp[i][1] = dp[i+1][1] 
        dp[i][0] = dp[i+1][0] + dp[i+1][1]
    elif S[i] == '?':
        dp[i][3] = 3*dp[i+1][3]
        dp[i][2] = 3*dp[i+1][2] + dp[i+1][3]
        dp[i][1] = 3*dp[i+1][1] + dp[i+1][2]
        dp[i][0] = 3*dp[i+1][0] + dp[i+1][1]

    dp[i][3] %= MOD
    dp[i][2] %= MOD
    dp[i][1] %= MOD
    dp[i][0] %= MOD


# pprint(dp)
print(dp[0][0]%MOD)


Measured memory_bytes: 28844
#include <stdio.h>

main(){
  unsigned int s=100000, temp;
  int n, i;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    s=s*105/100;
    if(s%1000!=0){
      temp=s/1000;
      s=(temp+1)*1000;
    }
  }

  printf("%d\n", s);

  return 0;
}

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

constexpr int MAX_N = 2000;
int solve(int n, const vector<bitset<MAX_N> > & wins) {
    vector<bitset<MAX_N> > dpl(n);
    vector<bitset<MAX_N> > dpr(n);
    REP_R (l, n) REP3 (r, l, n) {
        if (l == r) {
            dpl[r][l] = true;
            dpr[l][r] = true;
        } else {
            dpl[r][l] = (wins[l] & dpr[l + 1] & dpl[r]).any();
            dpr[l][r] = (wins[r] & dpr[l] & dpl[r - 1]).any();
        }
    }
    return (dpr[0] & dpl[n - 1]).count();
}

int main() {
    int n; cin >> n;
    assert (n <= MAX_N);
    vector<bitset<MAX_N> > wins(n);
    REP (i, n) {
        REP (j, i) {
            char c; cin >> c;
            wins[i][j] = c - '0';
            wins[j][i] = not wins[i][j];
        }
    }
    cout << solve(n, wins) << endl;
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()


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

    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    vector<vector<int>> dist(n,vector<int>(n, -1));
    for(int i=0; i<n; i++){
        queue<int> que;
        que.push(i);
        dist[i][i] = 0;
        while(!que.empty()){
            int v = que.front(); que.pop();
            vector<int> nvs;
            if(v > 0) nvs.push_back(v-1);
            if(v < n+1) nvs.push_back(v+1);
            if(v == x) nvs.push_back(y);
            if(v == y) nvs.push_back(x);
            for(int nv: nvs){
                if(dist[i][nv] == -1){
                    dist[i][nv] = dist[i][v] + 1;
                    que.push(nv);
                }
            }
        }
    }
    vector<int> res(n, 0);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            res[dist[i][j]]++;
        }
    }
    for(int d=1; d<n; d++){
        cout << res[d] << ln;
    }
}

Measured memory_bytes: 16000
import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val worldBTimeSum = scanner.nextInt().toFloat()
    val worldBSpeedTime = scanner.nextInt().toFloat()

    val worldAElapsedTime: Float = worldBTimeSum / worldBSpeedTime

    println(worldAElapsedTime)
}

Measured memory_bytes: 31528
import itertools

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            j = 2 * i
            while j <= n:
                is_prime[j] = False
                j += i
    return is_prime

a = sieve(10**5)
b = [0] * (10**5 + 1)
for i in range(10**5+1):
  if a[i] and a[(i+1)//2]:
    b[i] = 1

b = list(itertools.accumulate(b))
ans = []
Q = int(input())
for i in range(Q):
  l, r = map(int, input().split())
  ans.append(b[r] - b[l-1])

print(*ans, sep='\n')

Measured memory_bytes: 13188
import numpy as np
N = int(input())
A = [int(s)-1 for s in input()]
#print(A)
if 1 in A:
  factor = 1
else:
  factor = 2
  A = [a//2 for a in A]

n = len(A) - 1
s = 0
for i, a in enumerate(A):
  s += a * (n == ( i | (n - i) ))
print((s%2)*factor)


Measured memory_bytes: 29324
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod= 1e9+7;

int main(){
  ll X,A,B;
  cin>>X>>A>>B;
  if (B-A>X){
    cout << "dangerous" << endl;
  }else if (B-A>0&& B-A<=X){
    cout << "safe" << endl;
  }else{
    cout << "delicious" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
int n, a;
long long s[200000];
char c[11];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			c[j] = 'a' - 1;
		}
		scanf(" %s", c);
		for (int j = 0; j < 11; j++) {
			if (c[j] == NULL)c[j] = 'a' - 1;
			s[i] += c[j] - ('a' - 1);
			s[i] *= 27;
		}
	}
	std::sort(s, s + n);
	for (int i = 1; i < n; i++) {
		if (s[i] != s[i - 1])a++;
	}
	printf("%d\n", a + 1);
}

Measured memory_bytes: 3292