akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
} 

vector<vector<ll> >vii;
vector<ll>vis;
queue<ll>p;

void bfs(){
   while(!p.empty()){
      ll x=p.front();
      p.pop();
      f(i,0,vii[x].size()){
         if(vis[vii[x][i]]==0){
            vis[vii[x][i]]=x;
            //cout<<vis[x]<<spc;
            p.push(vii[x][i]);
         }
      }
   }
}

int main(){
   //Fast_IO();
   ll n,m;
   cin>>n>>m;
   vii.resize(n+1);
   f(i,0,m){
      ll x,y;
      cin>>x>>y;
      vii[x].pb(y);
      vii[y].pb(x);
   }
   f(i,0,n+1){
      vis.pb(0);
   }
   p.push(1);
   bfs();
   ll no=0;
   f(i,1,n+1){
      if(vis[i]==0){
         no=1;
         break;
      }
   }
   if(no==1) cout<<"No"<<endl;
   else{
      cout<<"Yes"<<endl;
      f(i,2,n+1) {
         cout<<vis[i]<<endl;
      }
   }
   
}


Measured memory_bytes: 12852
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


typedef array<ll, 3> ar;
template <typename T, typename E>
struct SegmentTree{
  vector<T> dat;vector<E> laz;
  typedef function<T(T, T)> F;//merge
  typedef function<T(T, E)> G;//dat lazy
  typedef function<E(E, E)> H;//lazy lazy
  typedef function<E(E, int)> P;//lazy len
  int n;F f;G g;H h;
  T d1;//datの零元
  E d0;//lazyの零元
  P p;

  SegmentTree(int m,F f,G g,H h,T d1,E d0,
  	      vector<T> v=vector<T>(),P p=[](E a,int b){return a;}):
      f(f),g(g),h(h),d1(d1),d0(d0),p(p){
      init(m);
      if(m==(int)v.size()) build(m,v);
  }
  void init(int m){
    n = 1;
    while(n<m) n*=2;
    dat.clear();laz.clear();
    dat.resize(2*n-1);laz.resize(2*n-1);
  }
  void build(int m, vector<T> v){
    for(int i=0;i<m;i++) dat[i+n-1] = v[i];
    for(int i=n-2;i>=0;i--) dat[i] = f(dat[i*2+1], dat[i*2+2]);
  }
  inline void eval(int len, int k){
    if(laz[k]==d0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1], laz[k]);
      laz[k*2+2]=h(laz[k*2+2], laz[k]);
    }
    dat[k]=g(dat[k], p(laz[k], len));
    laz[k]=d0;
  }
  T update(int a, int b, E x, int k, int l, int r){
    eval(r-l, k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k] = h(laz[k], x);
      return g(dat[k], p(laz[k], r-l));
    }
    return dat[k] = f(update(a, b, x, k*2+1, l, (l+r)/2),
                      update(a, b, x, k*2+2, (l+r)/2, r));
  }
  T query(int a, int b, int k, int l, int r){
    eval(r-l, k);
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl = query(a, b, k*2+1, l, (l+r)/2);
    T vr = query(a, b, k*2+2, (l+r)/2, r);
    return f(vl, vr);
  }
  T update(int a,int b,E x){return update(a,b,x,0,0,n);}
  T query(int a,int b){return query(a,b,0,0,n);}
};

int main(){
  ll n, q;scanf("%lld %lld", &n, &q);
  vector<ar> A(n);
  for(int i=0;i<n;i++){
    ll a;scanf("%lld", &a);
    if(a==1) A[i] = ar{1, 0, 0};
    else A[i] = ar{0, 1, 0};
  }

  SegmentTree<ar, bool> seg(n,
    [&](ar l, ar r){return ar{l[0]+r[0], l[1]+r[1], l[2]+r[2]+l[0]*r[1]};},
    [&](ar l, bool flag){return ar{l[1], l[0], l[0]*l[1]-l[2]};},
    [&](bool l, bool r){return l^r;},
    ar{0, 0, 0}, false, A);

  for(int i=0;i<q;i++){
    ll t, a, b;scanf("%lld %lld %lld", &t, &a, &b);
    if(t==1) seg.update(a-1, b, true);
    else printf("%lld\n", seg.query(a-1, b)[2]);
    /*
    else{
      ar ans = seg.query(a-1, b);
      std::cout << ans[0] << " " << ans[1] << " " << ans[2] << '\n';
    }
    */
  }
}


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

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

  vector<long long> a;
  vector<long long> b;
  vector<pair<long long,long long>> anss;

  if(n==2){
    long long x,y;
    cin >> x >> y;
    cout << max(x,y)-min(x,y) << endl;
    cout << max(x,y) << " " << min(x,y) << endl; 
    return 0;
  }

  for (int i = 0; i < n; i++)
  {
    long long ab;
    cin >> ab;
    if(ab>=0) a.push_back(ab);
    else b.push_back(ab);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  if(a.size()==0){
    a.push_back(b[b.size()-1]-b[0]);
    anss.push_back(make_pair(b[b.size()-1],b[0]));
    b.erase(b.begin());
    b.erase(b.end()-1);
  }
  if(b.size()==0){
    b.push_back(a[0]-a[a.size()-1]);
    anss.push_back(make_pair(a[0],a[a.size()-1]));
    a.erase(a.begin());
    a.erase(a.end()-1);
  }

  for (int i = 0; i < a.size()-1; i++)
  {
    anss.push_back(make_pair(b[0],a[i]));
    b[0]-=a[i];    
  }

  int maxa=a[a.size()-1];
  int lenb=b.size();
  for (int i = 0; i < lenb; i++)
  {
    anss.push_back(make_pair(maxa,b[i]));
    maxa-=b[i];
  }

  cout << maxa << endl;
  for(auto p:anss){
    cout << p.first << " " << p.second << endl;
  }

}

Measured memory_bytes: 5104
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {1, 0, -1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 2e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

ll a,b;
void solve() {
    cin>>a>>b;
    ll x = gcd(a,b);
    cout<<a*b/x<<endl;
}
  
int main()
{   
    //freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
    solve();
    return 0;
 
}
 

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


int main(void)
{
  int n, x;
  vector<int>a;
  
  cin >> n >> x;
  
  long long count = 0;
  int before = 0;
  for(int i=0; i<n; i++){
      int tmp;
      cin >> tmp;
      
      if(before + tmp > x){
          count += (before + tmp) - x;
          before = x - before;
      }
      else
          before = tmp;
      //cout << before << " ";
  }
  //cout << endl;
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  ca = n.times.map{ gets.to_i }
  cm = ca.each_cons(k).map{ |cards| cards.reduce(:*) }
  cs = ca.sort.reverse
  ci = ca.map{ |card| cs.index(card) }
  v = cm.max
  ans = 0
  (0..n-k).each do |i|
    min = cs[ci[i,k].max]
    max = cs[((0...n).to_a - ci[i,k]).min]
    ans = cm[i] * max / min - v if ans < cm[i] * max / min - v
  end
  puts ans
end

Measured memory_bytes: 11612
let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main({ input, load, yesno, math_sum, math_max, math_min, log_json }) {
    const [N] = load()
    const A = load(N,1,BigInt)
 
    if(A.includes(0n)) return 0
    
    let result = 1n
    for(const a of A) {
        result *= a
        if(result > 1e18) return -1
    }
    
    return result.toString()
}



let inputs = input.split(/[\s\n]/)
let result = main({
    input,
    yesno: value => value ? 'Yes' : 'No',
    math_sum: numbers => numbers.reduce((acc, cur) => acc + cur, 0),
    load(rows = 1, cols = 1, type = Number) {
        const length = rows * cols
        let result = inputs.splice(0, length)
        if(type !== String) result = result.map(type)
        if(cols > 1) {
            const arrays = new Array(cols)
            for(let col = 0; col < cols; col++) {
                arrays[col] = new Array()
                for(let row = 0; row < rows; row++) {
                    arrays[col].push(result[row * cols + col])
                }
            }
            result = arrays
        }
        return result
    },
    inifinite_loop_preventer() {
        throw new Error("Infinite loop")
    },
    math_max,
    math_min,
    log_json(value) {
        console.log(JSON.stringify(value))
    },
})

if(result === undefined) {
    console.warn("result is undefined")
} else {
    console.log(result)
}

function math_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

function math_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}


Measured memory_bytes: 46072
import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toInt()}

    fun func(a: List<Int>): Array<IntArray> {
        val dp = Array(N + 1) { IntArray(K + 1) { 0 } }

        dp[0][0] = 1

        for (i in a.indices) {
            for (j in dp[i].indices) {
                dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j])

                val k = Math.min(K, j + a[i])
                dp[i + 1][k] = Math.max(dp[i + 1][k], dp[i][j])
            }
        }

        for (i in a.indices) {
            for (j in 1 .. K) {
                dp[i][j] += dp[i][j - 1]
            }
        }

        return dp
    }

    val dp = IntArray(K + 1)
    dp[0] = 1

    val rdp = func(a.reversed())

    var cnt = 0

    for (i in a.indices) {
        if (a[i] >= K) {
            cnt++
            continue
        }

        var r = false

        for (j in 0 .. K - 1) {
            if (dp[j] == 0)
                continue
            val l = Math.max(K - a[i] - j, 0)
            val u = K - j - 1

            r = r || (l == 0 && rdp[N - i - 1][l] > 0) || (rdp[N - i - 1][u] - rdp[N - i - 1][Math.max(l - 1, 0)] > 0)

            if (r) break
        }

        if (r) {
            cnt++
        }


        for (j in dp.indices.reversed()) {
            if (j - a[i] >= 0) {
                dp[j] = Math.max(dp[j], dp[j - a[i]])
            }
        }
    }

    println(N - cnt)
}


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

int main() {
    
    long long N, A, B;
    cin >> N >> A >> B;
    
    long long sho = N / (A + B);
    long long amari = N % (A + B);
    
    if(A == 0){
        cout << 0 << endl;
        return 0;
    }
    
    sho *= A;
    
    if(amari >= A){
        cout << sho + A << endl;
    }
    else{
        cout << sho + amari << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int a;
	string s;

	cin >> a;
	cin >> s;
	if (a >= 3200)
		cout << s << endl;
	else
		puts("red");
}



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

#define R (long long)(1e9 + 7)
#define INF (long long)(1e16L + 5)
#define ll long long
#define grid vector<vector<ll>>
#define L 26

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

struct graph
{
    int n;
    vector<vector<pair<int, int>>> adj;
    graph(int n)
    {
        this -> n = n;
        adj.resize(n);
    }
    
    void add_edge(int u, int v, int w)
    {
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin >> x;
    if(x == 0)
        cout << 1 << '\n';
    else
        cout << 0 << '\n';

    // cout << "        __.....__\n";
    // cout << "     .-'         '-.\n";
    // cout << "   .'               '.\n";
    // cout << "  /                   \\\n";
    // cout << " /        |\\           \\\n";
    // cout << ";        |V \\_          ;\n";
    // cout << "|        |  ' \\         ;\n";
    // cout << ";        )   ,_\\        |\n";
    // cout << ";       /    |          ;\n";
    // cout << " \\     /      \\         /\n";
    // cout << "  \\    |       \\       /\n";
    // cout << "   '.   \\       \\    .'\n";
    // cout << "     '-._|       \\.-'\n";
    // cout << "         | |\\     |    \n";
    // cout << "_________/ |_'.   /_______  \n";
    return 0;
    
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1) cout << 1 << endl;
    else cout << (h*w+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,count = 0,N_c=0;
  cin >> N;
  N_c = N;
  
  while(N>0){
    count += N % 10;
    N = N /10;
  }
  if(N_c % count == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		//System.out.println(a);
		if (a.equals("Sunny")) {
			System.out.println("Cloudy");
		} else if (a.equals("Cloudy")) {
			System.out.println("Rainy");
		} else if (a.equals("Rainy")) {
			System.out.println("Sunny");
		}
	}

}


Measured memory_bytes: 21204
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()
hand = [str()] * n
ans = 0
for i in range(n):
    if i < k:
        if t[i] == "r":
            ans += p
            hand[i] = "r"
        elif t[i] == "s":
            ans += r
            hand[i] = "s"
        else:
            ans += s
            hand[i] = "p"
    else:
        if t[i] == t[i-k]:
            if hand[i-k] == t[i]:
                continue
            else:
                if t[i] == "r":
                    ans += p
                    hand[i] = "r"
                elif t[i] == "s":
                    ans += r
                    hand[i] = "s"
                else:
                    ans += s
                    hand[i] = "p"
                
        else:
            if t[i] == "r":
                ans += p
                hand[i] = "r"
            elif t[i] == "s":
                ans += r
                hand[i] = "s"
            else:
                ans += s
                hand[i] = "p"

print(ans)

Measured memory_bytes: 4084
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nm[0];
        int m = nm[1];
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (a.Distinct().Count() != n || b.Distinct().Count() != m)
        {
            Console.WriteLine(0);
            return;
        }
        HashSet<int> fixedPos = new HashSet<int>();
        List<int> e = new List<int>();
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                //確定ポイントは確定リストに入れて飛ばす
                //全ての点について最大値を
                if(a[i] == b[j])
                {
                    fixedPos.Add(a[i]);
                }
                else
                {
                    e.Add(Min(a[i], b[j]));
                }
            }
        }
        var stack = new Stack<Tuple<int, int>>(e.GroupBy(x => x).Select(x => new Tuple<int, int>(x.Key, x.Count())).OrderBy(x => x.Item1));
        long choices = 0;
        long res = 1;
        Debug.WriteLine(stack.Peek());
        for (int i = n * m; i > 0; i--)
        {
            if (fixedPos.Contains(i)) continue;
            bool flag = true;
            while (stack.Count > 0 && stack.Peek().Item1 >= i)
            {
                var item = stack.Pop();
                var num = item.Item2;
                if(item.Item1 == i)
                {
                    flag = false;
                    res *= num;
                    res %= 1000000007;
                    num--;
                }
                choices += num;
            }
            if (flag)
            {
                if(choices == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
                res *= choices;
                res %= 1000000007;
                choices--;
            }
        }
        Console.WriteLine(res);
    }
}


static class Writer
{
    public static void WriteLine<T>(this T item) => Console.WriteLine(item);

    public static void WriteLog<T>(this T item) => Debug.WriteLine(item);
}

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

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

    int S, W;
    cin >> S >> W;

    if(W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 100005
using namespace std;
typedef long long ll;
int n,m;char x[MN],y[MN];
int gcd(int x,int y){return !y?x:gcd(y,x%y);}
int main(){
	scanf("%d%d%s%s",&n,&m,x,y);ll ans=1ll*n*m/gcd(n,m);int tmp=gcd(n,m);
	for(int i=0,j=0;i<n;i+=n/tmp,j+=m/tmp){
		if(x[i]!=y[j])return 0*puts("-1");
	}printf("%lld\n",ans);
}

Measured memory_bytes: 384
using System;

namespace AizuOnLine
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
     
            int i = 1;
            int x = 0;
            while (true)
            {
                x = i;
                if (x % 3 == 0 || -1 < x.ToString().IndexOf("3"))
                {
                    Console.Write(" " + i);
                }

                if (n < ++i)
                {
                    break;
                }
            }
            Console.WriteLine(string.Empty);
        }

    }
}

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

int main(){

  int n,k;
  int s[1000];
  int b;

  while(true){

    memset(s,0,sizeof(s));

    cin >> n >> k;
    if(!n && !k) break;

    for(int i=0;i<k;i++) cin >> s[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++){
	cin >> b;
	s[j] -= b;
      }
    }

    bool d = true;

    for(int i=0;i<k;i++){
      if(s[i] < 0) d = false;
    }

    if(!d) cout << "No" << endl;
    else cout << "Yes" << endl;

  }
}

Measured memory_bytes: 1152
from itertools import chain

while True:
    n = int(input())
    if not n:
        break
    dp = [[0]*(n+1) for _ in [0]*(n+1)]
    for y, (l_u, l_c) in enumerate(zip(dp, dp[1:]), start=1):
        for x, (c, ul, u, left) in enumerate(zip(input(), l_u, l_u[1:], l_c), start=1):
            dp[y][x] = min(ul, u, left)+1 if c == "." else 0

    print(max(chain.from_iterable(dp)))


Measured memory_bytes: 38936
#include<stdio.h>
#include<string.h>
int main()
{
    char a[15],b[15],c[15];
    char ph1,ph2;
    scanf("%s",a);
    int len,flag=0;
    len=strlen(a);
    ph1=a[len-1];
    scanf("%s",b);
    ph2=b[0];
    len=strlen(b);
    if(ph1!=ph2)
    {
        printf("NO");
        flag=1;
    }
    ph1=b[len-1];
    scanf("%s",c);
    ph2=c[0];
    if(ph1!=ph2&&flag==0)
    {
        printf("NO");
        flag=1;
    }
    if(flag==0)
        printf("YES");
    return 0;
}



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

ll dp[1000010][2]; //dp[i][j] = i桁目まで決め打った時に条件を満たすものの通り数、ただしj = 0の時はi桁目まで決め打った時にLと一緒、j = 1の時はそれ未満

int main() {
    string S;
    cin >> S;
    dp[1][0] = 2;
    dp[1][1] = 1;
    for(int i = 1;i < S.size();i++) {
        if(S.at(i) == '0') {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1] * 3 % MOD;
        }
        else {
            dp[i + 1][0] = dp[i][0] * 2 % MOD;
            dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD;
        }
    }
    cout << (dp[S.size()][0] + dp[S.size()][1]) % MOD << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#define SS(i) scanf("%s",i)
#define SC(i) scanf("%d",&i)
#define SCC(i,j) scanf("%d%d",&i,&j)
#define SCCC(i,j,z) scanf("%d%d%d",&i,&j,&z)
#define PR(i) printf("%d\n",i)
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define CL(i,x) memset(i,x,sizeof(i))
#define IN freopen("in.txt","r",stdin)
#define OUT  freopen("out.txt","w",stdout)
#define PB(i) push_back(i)
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define ll rt<<1
#define rr rt<<1|1
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define eq(x, y) (fabs(x-y) < eps)
#define forv(x, y) FF(y, 0, (int)x.size()-1)
using namespace std;

const int N = 5000 + 15;

int main()
{


    int n, m;
    SCC(n, m);
    int ci = pow(2, m);
    int ans = (1900 * m + (n-m) * 100) * ci;
    PR(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin >>S;
    if(S=="ABC") cout <<"ARC" << endl;
    else cout <<"ABC" <<endl;



}


Measured memory_bytes: 3636
#include <stdio.h>
int main(){   
  int i,j,v,N,n;
    int A[1000];   
    scanf("%d",&N);  
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    for(n=0;n<N-1;n++){
        printf("%d ",A[n]);
        
    }
	printf("%d",A[N-1]);
	printf("\n");
    for(i=1;i<=N-1;i++){
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j--;
            A[j+1]=v;
        }
        for(n=0;n<N-1;n++){
        printf("%d ",A[n]);
        
    }
	printf("%d",A[N-1]);
printf("\n");
    }
}



Measured memory_bytes: 2124
N, M = gets.chomp.split().map(&:to_i)

danger = []
M.times do
  danger << gets.chomp.to_i
end

dp = [0] * (N+1)
dp[0] = 1
if danger[0] == 1
  dp[1] = 0
  danger.shift
else
  dp[1] = 1
end

for i in 2..N do
  if i == danger[0]
    dp[i] = 0
    danger.shift
  else
    dp[i] = dp[i-1] + dp[i-2]
  end
end

puts dp[-1] % 1000000007


Measured memory_bytes: 445208
#include<stdio.h>
int main (){
  char ch;

  scanf("%s",&ch);

  if (ch == 'A') printf("T\n");
  else if(ch == 'T') printf("A\n");
  else if(ch == 'C') printf("G\n");
  else if(ch == 'G') printf("C\n");
  else printf("error\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int dfs (int i, vector<bool> &vis, vector<vector<int>> &adj, vector<int> &dp) {
  if (vis[i] == true)
    return dp[i];
  vis[i] = true;
  //cout<<i<<" ";
  for (auto a: adj[i]) {
    //cout<<a<<" ";
    if(!vis[a]) 
      dfs(a, vis, adj, dp);
    dp[i] = max(dp[i], 1+dp[a]);
   }
   return dp[i];
}
                
                
int main() {
  int n, m;
  cin>>n>>m;
  int ma = 0;
  vector<vector<int>> adj(n, vector<int>());
  while (m--) {
	int x,y;
    cin>>x>>y;
    adj[x-1].push_back(y-1);
  }
  vector<int> dp(n, 0);
  vector<bool> vis(n, false);
  for (int i=0;i<n;i++) {
    if (!vis[i]) {
      dfs(i, vis, adj, dp);
    }
    ma = max(ma, dp[i]);
  }
  cout<<ma<<endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> data(h, vector<char>(w));
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cin >> data.at(i).at(j);
        }
    }
    
    for(int i=0; i<h; i++) {
        for(int k=0; k<2; k++) {
            for(int j=0; j<w; j++) {
                cout << data.at(i).at(j);
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
counter = 0;

for i in range(N):
    d1, d2 = list(map(int, input().strip().split()))
    if d1 == d2:
        counter += 1
    else:
        counter = 0
    if counter >= 3:
        print("Yes")
        break;
if counter < 3:
    print("No")

Measured memory_bytes: 9176
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

#参考:https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-03-22abc-159

n,s = LI()
a = LI()
ans = 0
dp = [[0]*(s+1) for _ in range(n)]
dp[0][0] = 1
if s >= a[0]:
    dp[0][a[0]] = 1
for i in range(1,n):
    b = a[i]
    for j in range(s+1):
        if j == 0:
            dp[i][j] = dp[i-1][j] + 1
        else:
            dp[i][j] = dp[i-1][j]
    for j in range(s+1):
        if dp[i-1][j]:
            if j + b <= s:
                if j == 0:
                    dp[i][j+b] += dp[i][j]
                    dp[i][j+b] %= mod
                else:
                    dp[i][j+b] += dp[i-1][j]
                    dp[i][j+b] %= mod
for i in dp:
    ans += i[-1]
    ans %= mod
print(ans)




Measured memory_bytes: 113372
function Main(input) {
input = input.split("\n");
const a =Number(input[0]);
const b =Number(input[1]);
const c =Number(input[2]);
const d =Number(input[3]);
const result1 = Math.min(a,b)
const result2 = Math.min(c,d)
console.log(result1+result2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using ll = long long;

class Stream{
public:
    Stream(){

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

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

int main(){
    Stream io;

    string s, t;
    io.read(s, t);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t) cout << "Yes";
    else cout << "No";
    return 0;
}

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

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

using namespace std;
// using namespace __gnu_pbds;

#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define MAX 500005
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))

typedef long long ll;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int memo[MAX], arr[MAX];
int k = 2;
int solve(int i){
	if (memo[i] !=-1) return memo[i];
	if (i==1) return memo[i] = 0;
	int dp = 100000000000000;
	for (int j =i-1; j>=i-k && j>0;j--){
		dp = min(dp,solve(j) + abs(arr[i]-arr[j]));
	}
	return memo[i] = dp;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
		
	
	int n;
	cin>>n>>k;
	initialize(memo,-1);
	For(i,1,n+1) cin>>arr[i];
	cout<<solve(n)<<endl;
	// For(i,1,3) cout<<memo[i]<<" ";



	return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,p) for(int i=l;i<=p;i++)
using namespace std;
const int maxN = 1e5+5;


int a[maxN],b[maxN],c[maxN];
int N;
int cnt_b[maxN],cnt_c[maxN];
long long sum[maxN];
bool cmp(const int &a,const int &b){
	return a>b;
}

void input(){
	int t;
	rep(i,1,N) cin >> a[i];
	rep(i,1,N) cin >> b[i];
	rep(i,1,N) cin >> c[i]; 
	sort(a+1,a+1+N,cmp);
	sort(b+1,b+1+N,cmp);
	sort(c+1,c+1+N,cmp);
	int bt = 0,ct = 0;
	rep(i,1,N){
		
		rep(j,bt+1,N){
			if ( b[j] > a[i] ) bt++;
			else break;	
		}
		cnt_b[i] = bt;
	
		rep(j,ct+1,N){
			if ( c[j] > b[i] ) ct++;
			else break;
		}
		
		cnt_c[i] = ct;
	}
	rep(i,1,N) sum[i] = sum[i-1] + cnt_c[i];
//	rep(i,1,N) printf("cntb: %d  cntc: %d\n",cnt_b[i],cnt_c[i]);
}
void solve(){
	long long res = 0;

	rep(i,1,N){
		int a = i,b = cnt_b[i];
		res += sum[b];
	
	}
	printf("%lld\n",res);
}
int main(){
	scanf("%d",&N);
	
	input();
	solve();
	
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s,t,u;
    cin >> s;
    cin >> t;

    for(int i = 0;i < s.size();i++){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

int main() {
  int H, M, h, m, k;
  cin >> H >> M >> h >> m >> k;

  int x1 = H * 60 + M;
  int x2 = h * 60 + m;
  x2 -= k;

  int ans = max(0, x2 - x1);
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3624
//for ( auto &i: a ){
//		cin >> i;
//}
#include <bits/stdc++.h>
# define ll      long long 
# define in      freopen("input.txt", "r", stdin);
# define out     freopen("output.txt", "w", stdout);
# define all(vc) vc.begin(),vc.end()
# define fi      first
# define se      second
# define str     string 
# define pb      push_back
# define speed   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
ll a,b,c,d,e,f,mn=1e9,mx,cnt,bnt,sum,seven,four; str jul,s,cal,kcal;bool ok=false;
set <int> st; map <char, int> mp; vector <ll> vc1;
void botsolve(){
	for (int i = 0; i < a; ++i){
		if(s[i]=='I') cnt++;
		else if(s[i]=='D') cnt--;
		mx=max(mx,cnt);
	}
	cout<<mx<<'\n';
}
int main(){
	speed;
	//in out
    cin>>a>>s;
    botsolve();

	time;
	return 0;
}

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

int K, n, m, ans;
char A[12], B[12], C[12];

int toInt(){
  int res = 0;

  for(int i = n - 1; i >= 0; i--){
    res *= 10;
    res += C[i];
  }

  return res;
}

void solve(int idx, int borrow, int rem){
  if(idx == n){
    ans = max(ans, toInt());
    return;
  }

  if(A[idx] - borrow >= B[idx]){
    C[idx] = A[idx] - borrow - B[idx];
    solve(idx + 1, 0, rem);
  }
  else{
    C[idx] = A[idx] - borrow + 10 - B[idx];
    solve(idx + 1, 1, rem);
    if(rem > 0) solve(idx + 1, 0, rem - 1);
  }
}

int main(){
  while(cin >> A >> B >> K){
    n = strlen(A);
    m = strlen(B);
    reverse(A, A + n);
    reverse(B, B + m);

    for(int i = m; i < n; i++){
      B[i] = '0';
    }

    for(int i = 0; i < n; i++){
      A[i] -= '0';
      B[i] -= '0';
    }

    ans = 0;
    solve(0, 0, K);
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
from collections import defaultdict

N = int(input())
S = input()
A, B = S[:N], S[N:]
D = defaultdict(int)
ans = 0

def paint(X, i):
    r = ""
    b = ""
    for j, k in enumerate(format(i, "b").zfill(N)):
        if k == "1":
            r += X[j]
        else:
            b += X[j]
    return r, b

for i in range(2**N):
    r, b = paint(A, i)
    D[(r, b)] += 1

for i in range(2**N):
    r, b = paint(B, i)
    ans += D[(b[::-1], r[::-1])]

print(ans)

Measured memory_bytes: 166652
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>
#include<limits>
#include<type_traits>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int gcd(int a,int b) {
	if (a < b)gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int n, x;
	int cd, pre;
	bool f = 1;
	cin >> n >> x;
	int ans;
	rep(i, n) {
		if (f) {
			f =0 ;
			cin >> pre;
			ans = abs(pre - x);
		}
		else {
			cin >> cd;
			if (ans > gcd(abs(pre-x), abs(cd-x)))ans = gcd(abs(pre-x), abs(cd-x));
			pre = cd;
		}

	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <std::uint_fast64_t mod>
class ModInt {
    using u64 = std::uint_fast64_t;

   public:
    u64 x;
    ModInt(const ll x = 0) : x(x < 0 ? (mod - (-x % mod)) % mod : x % mod) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod;
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod) x %= mod;
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod - 2;
        while (p > 0) {
            if (p & 1) *this *= r;
            r *= r;
            p >>= 1;
        }
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod; }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        ll a;
        in >> a;
        if (a < 0) a = mod - (-a % mod);
        if (a >= mod) a %= mod;
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }
};
constexpr std::uint_fast64_t mod = 1e9 + 7;
using mint = ModInt<mod>;

template <typename T, typename U>
T pow(T x, U n, T e = 1) {
    T res = e;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    mint ans = 0;
    vector<mint> f(K + 1);
    for (int x = K; x >= 1; x--) {
        f[x] = pow<mint, int>(K / x, N);
        int y = 2 * x;
        while (y <= K) {
            f[x] -= f[y];
            y += x;
        }
        ans += f[x] * x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int W, H;
bool cool[100][100];
int dfs(int y, int x) {
  if(y < 0 || x < 0 || y >= H || x >= W || !cool[y][x]) return 0;
  cool[y][x] = 0;
  int ret = 0;
  ret = max(ret, dfs(y + 1, x));
  ret = max(ret, dfs(y - 1, x));
  ret = max(ret, dfs(y, x + 1));
  ret = max(ret, dfs(y, x - 1));
  cool[y][x] = 1;
  return ret + 1;
}
int main()
{
  while(cin >> W >> H, W||H) {
    CLR(cool);
    FOR(h,0,H) FOR(w,0,W) cin >> cool[h][w];
    int ans = 0;
    FOR(h,0,H) {
      FOR(w,0,W) {
        ans = max(ans, dfs(h, w));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A1(N), A2(N);
    for (int i = 0; i < N; i++)
        cin >> A1[i];
    for (int i = 0; i < N; i++)
        cin >> A2[i];

    vector<int> cnt(N);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            cnt[i] += A1[j];
        }
        for (int j = i; j < N; j++) {
            cnt[i] += A2[j];
        }
    }

    int res = 0;
    for (int i = 0; i < N; i++)
        res = max(res, cnt[i]);

    cout << res << endl;
    return 0;
}

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

#define debug(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n,Q;
    cin>>n>>Q;
    vector<int> a(n+2), pre(n+2), nxt(n+2), q(Q);
    rep1(i,n){
        cin>>a[i];
    }
    rep(i,Q) cin>>q[i];
    a[0] = 0;
    a[n+1] = n+1;
    rep1(i,n){
        pre[a[i]] = a[i-1];
        nxt[a[i]] = a[i+1];
    }
    nxt[0] = a[1];
    pre[n+1] = a[n];

    rep(j,Q){
        int p = q[j];
        int v1 = nxt[0];
        int v2 = pre[p];
        int v3 = nxt[p];
        int v4 = pre[n+1];


        if(v3 == n+1){
            nxt[0] = p;
            pre[p] = 0;
        }else{
            nxt[0] = v3;
            pre[v3] = 0;

            nxt[v4] = p;
            pre[p] = v4;
        }

        if(v2 == 0){
            pre[n+1] = p;
            nxt[p] = n+1;
        }else{
            nxt[p] = v1;
            pre[v1] = p;

            nxt[v2] = n+1;
            pre[n+1] = v2;
        }

    }

    int cur = nxt[0];
    int i = 0;
    while(cur != n+1){
        cout<<cur<<(i < n-1 ? " " : "\n");
        cur = nxt[cur];
        i++;
    }
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

struct position
{
  int x;
  int y;
};

int main()
 {
  int n,gx,gy,nm,*m,k;
  bool Vert[16][16],Horiz[16][16];
  
  cin>>n;
  m = new int[n];
  for(k=0;k<n;k++)
    {
      cin>>gx>>gy>>nm;
      int XY[16][16];
	  for (int j = 0; j < 16; j++)
		  for (int i = 0; i < 16; i++)
		  {
			  if (i != 0 && j != 0){
				  Vert[i][j] = true;
				  Horiz[i][j] = true;
			  }
			  else if (i == 0)
			  {
				  Vert[j][i] = true;
				  Horiz[j][i] = false;
			  }
			  else if (j == 0)
			  {
				  Vert[j][i] = false;
				  Horiz[j][i] = true;
			  }
		  }
      if(gx>15||gy>15) return 0;
	  position *p1=new position[nm];
	  position *p2=new position[nm];
      for(int i=0;i<nm;i++)
	{
		cin >> p1[i].x >> p1[i].y >> p2[i].x >> p2[i].y;
	  if(p1[i].x==p2[i].x)
		  Vert[p1[i].y > p2[i].y ? p1[i].y:p2[i].y][p1[i].x] = false;
	  else
		  Horiz[p1[i].y][p1[i].x>p2[i].x ? p1[i].x : p2[i].x ] = false;
	}     
	  XY[0][0] = 1;
	  for (int i = 1; i <= gx; i++)
	  {
		  if (Horiz[0][i] && gx > 0 && gy > 0) XY[0][i] = XY[0][i-1];
		  else XY[0][i] = 0;
	  }
	  for (int i = 1; i <= gy; i++)
	  {
		  if (Vert[i][0] && gx > 0 && gy > 0) XY[i][0] = XY[i-1][0];
		  else XY[i][0] = 0;
	  }
    for(int i=1;i<=gy;i++)
	  for(int j=1;j<=gx;j++)
	  {
		if(!Horiz[i][j]&&!Vert[i][j])
		  XY[i][j]=0;
		else if(!Horiz[i][j])
		  XY[i][j]=XY[i-1][j];
		else if(!Vert[i][j])
		  XY[i][j]=XY[i][j-1];
		else
		  XY[i][j]=XY[i-1][j]+XY[i][j-1];
	  }
	m[k] = XY[gy][gx];
    }
  for (int i = 0; i < k; i++)
  {
	  if (m[i])
		  cout << m[i] << endl;
	  else
		  cout << "Miserable Hokusai!" << endl;
  }
  //system("pause");
  
}

Measured memory_bytes: 3084
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int main() {
    int nums[3], cnt = 0;
    scnd3( nums[0], nums[1], nums[2]);
    
    while ( true ){
        
        int m = min(nums[0],min(nums[1],nums[2]));
        rep(i,3) nums[i] -= m;
        
        int z = 0;
        rep(i,3) if ( nums[i]==0 ) z++;
        
        if ( z==3) break;
        if ( z==2) {rep(i,3) if( nums[i]==0) nums[i]++; }
        if ( z==1) {rep(i,3) if( nums[i]==0) nums[i]=2;}
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int, input().split())) for _ in range(n)]

ans=0

for j in range(n):
    x=0
    for i in range(m):
        x+=a[j][i]*b[i]
    if x > -1 * c:
        ans+=1
print(ans)    




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    string s;
    cin>>s;
    int ans=0;
    for(auto &it:s)
    {
        if(it=='+')
        ans++;
        else
        ans--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int s = 0;
        for(int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
            boolean che = false;
            while(che == false){
                if(a[i] % 2 == 0){
                    a[i] /= 2;
                    s++;
                }else{
                    che = true;
                }
            }
        }
        System.out.println(s);
        sc.close();
    }
}

Measured memory_bytes: 47612
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int dp[3005][3005];
void solve() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	dp[a][b]=1;
	fr(i,a,c)
		fr(j,b,d)
			if(i!=a||j!=b)
				dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1))%mod;
	if(dp[c][d]<0)
		dp[c][d]+=mod;
	cout<<dp[c][d]<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 74008