akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

#define pb push_back
#define mp make_pair
#define fst first
#define snd second

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(T &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) cout << " ";
    cout << *it;
  }
  cout << endl;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> C(h, vi(w)), dp(h, vi(w));
  REP(y, h) { REP(x, w) cin >> C[y][x]; }

  int max_w = 0;
  REP(y, h) {
    REP(x, w) {
      dp[y][x] = (C[y][x] + 1) % 2;
      max_w |= dp[y][x];
    }
  }
  FOR(y, 1, h) {
    FOR(x, 1, w) {
      if (C[y][x]) continue;
      dp[y][x] = min(dp[y - 1][x - 1], min(dp[y - 1][x], dp[y][x - 1])) + 1;
      max_w = max(max_w, dp[y][x]);
    }
  }

  cout << max_w * max_w << endl;
}


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

int main() {
	int n;
	int k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	
	int dp[n+1][k+1];for(int i=0;i<=n;i++)
	{
	    for(int j=0;j<=k;j++)
	    {dp[i][j]=0;}
	}
	
	dp[0][0]=1;
	int pre[k+2];
	
	for(int i=0;i<=k+1;i++)pre[i]=0;
	
	for(int i=1;i<=n;i++)
	{
	    
	    for(int j=1;j<=k+1;j++)
	    {
	        pre[j]=(pre[j-1]+dp[i-1][j-1])%1000000007;
	    }
	    
	    for(int j=0;j<=k;j++)
	    {
	      dp[i][j]+=(pre[j+1]-pre[max(0,j-a[i-1])]+1000000007)%1000000007; 
	   
        //   if(tot > j){dp[i][j]=pre[j];continue;}
        //   else
        //   {
        //       dp[i][j]=pre[j]-pre[j-tot];
        //   }
	    }
	}
	
// 		for(int i=0;i<=n;i++)
//     	{
//     	    for(int j=0;j<=k;j++)
//     	    {cout<<dp[i][j]<<" ";}cout<<endl;
//     	}
	    cout<<dp[n][k]<<endl;
	return 0;
}

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

int main() {
	bool cards[4][14];
	int n, rank;
	char suit;

	for (int s = 0; s < 4; s++) {
		for (int r = 1; r <= 13; r++) {
			cards[s][r] = 0;
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> suit >> rank;
		if (suit == 'S')cards[0][rank] = 1;
		if (suit == 'H')cards[1][rank] = 1;
		if (suit == 'C')cards[2][rank] = 1;
		if (suit == 'D')cards[3][rank] = 1; 
	}

	for (int s = 0; s < 4; s++) {
		for (int r = 1; r <= 13; r++) {
			if (cards[s][r])continue;
			if (s == 0)suit = 'S';
			if (s == 1)suit = 'H';
			if (s == 2)suit = 'C';
			if (s == 3)suit = 'D';
			cout << suit << " " << r << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int dp[80][220000];

int main(){cout<<fixed<<setprecision(20);
		   ll n,k;
           cin>>n>>k;
           vin a(n);
           rep(i,0,n){
             cin>>a[i];
             a[i]--;
           }
           rep(i,0,n)dp[0][i]=a[i];
           rep(i,1,80){
            rep(j,0,n){
             dp[i][j]=dp[i-1][dp[i-1][j]]; 
            }
           }
           int ans=0;
           int cnt=0;
           while(k){
            if(k&1)ans=dp[cnt][ans];
             cnt++;
             k>>=1;
           }
           cout<<ans+1<<endl;
}

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

int main() {
    int N, K;
    cin >> N >> K;
 
    vector<int> D;
    for(int i = 0; i < K; i++) {
        int temp;
        cin >> temp;
        D.push_back(temp);
    }

    int result = 0;

    for(int i = N; i < 100000; i++) {
        int current_num = i;
        bool find = true;
        while(current_num != 0) {
            int digit = current_num % 10;
            for(int k = 0; k < D.size(); k++) {
                if(digit == D.at(k)) {
                    find = false;
                    break;
                }
            }
            current_num /= 10;
        }
        if(find) {
            result = i;
            break;
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define N -1
struct Node{int p, l, r;};
struct Node T[MAX];
int n, D[MAX];
 
void print(int x){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",x,T[x].p,D[x]);
  if(T[x].p==N)
    printf("root, ");
  else if(T[x].l==N)
    printf("leaf, ");
  else
    printf("internal node, ");
  printf("[");
  for(i=0,c=T[x].l;c!=N;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}
 
int rec(int x, int p){
  D[x]=p;
  if(T[x].r!=N)
    rec(T[x].r,p);
  if(T[x].l!=N)
    rec(T[x].l,p+1);
}
 
int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=N;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==N) r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}

Measured memory_bytes: 5300
N=int(input())
T=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
if N==1:
  if A[0]==T[0]:
    print(1)
  else:
    print(0)
  exit()
  
ans=1
mod=10**9+7
for i in range(N):
  if i==0:
    if A[i]!=A[i+1] and T[i]!=A[i]:
      print(0)
      exit()
  elif i==N-1:
    if T[i]!=T[i-1] and T[i]!=A[i]:
      print(0)
      exit()
  else:
    if T[i]==T[i-1] and A[i]==A[i+1]:
      ans=(ans*min(T[i],A[i]))%mod
    elif T[i]!=T[i-1] and A[i]<T[i]:
      print(0)
      exit()
    elif A[i]!=A[i+1] and A[i]>T[i]:
      print(0)
      exit()
print(ans)
    
      

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

int main() {
	string s;
	cin >> s;
  int ans = 0;
	for (const char& c: s) {
        ans += (c - '0');
        ans %= 9;
	}
	cout << (ans ? "No" : "Yes") << endl;
};

Measured memory_bytes: 3692
package main
 
import (
	"fmt"
)

func main() {
	var a int
	var b int
	var o int
	fmt.Scanf("%d %d", &a, &b)
	target := []int{1, 2, 3}
	result := 0
	for _, v := range target {
		if v == a {
			if v == 1 {
				result += 300000
			}
			if v == 2 {
				result += 200000
			}
			if v == 3 {
				result += 100000
			}
		}
		if v == b {
			if v == 1 {
				result += 300000
			}
			if v == 2 {
				result += 200000
			}
			if v == 3 {
				result += 100000
			}
		}
	}
	if a == 1 && b == 1 {
		result += 400000
	}
	o = result
	fmt.Print(o)
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

int gcd(int x, int y) {
	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>k(m);
	int s[11][11];
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		//cout << k[i] << endl;
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			//cout << s[i][j] << endl;
		}
	}
	vector<int>p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
		//cout << p[i] << endl;
	}
	
	int ans = 0;
	for (int bits = 0; bits < (1 << n); bits++) {
		bool ok = true;
		for (int i = 0; i < m; i++) {
			int count = 0;
			for (int j = 0; j < k[i]; j++) {
				if (bits & (1 << (s[i][j]-1))) {
					count++;
				}
			}
			//cout << count << endl;
			if (count % 2 != p[i]) {
				ok = false;
			}
		}
		if (ok) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;


int main() {
	int W, H, x, y; cin >> W >> H >> x >> y;
	cout << ((double)W * (double)H) * 0.5 << " ";
	if (x * 2 == W && y * 2 == H) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


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

int dfs(int p, int q)
{
    if (p > q)
    {
        return 0;
    }
    if (dp[p][q] != -1)
    {
        return dp[p][q];
    }
    dp[p][q] = dfs(p, q - 1) + dfs(p + 1, q) - dfs(p + 1, q - 1) + v[p][q];
    return dp[p][q];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    memset(dp, -1, sizeof dp);
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        v[x][y]++;
    }
    rep(i, q)
    {
        int p, q;
        cin >> p >> q;
        cout << dfs(p, q) << endl;
    }
}

Measured memory_bytes: 2944
a, b = map(int, input().split())

if a >= 1:
    print('Positive')
elif a == 0 or b == 0:
    print('Zero')
elif a <= -1 and b >= 1:
    print('Zero')
elif (b-a) % 2 == 0:
    print('Negative')
else:
    print('Positive')


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

struct P { int v, n; };

int main() {
  int N;
  cin >> N;
  map<int, int> ma;
  for (int i; i < N; ++i) {
    int a;
    cin >> a;
    ++ma[a];
  }
  bool ans{};

  vector<P> va;
  for (const auto &p : ma) {
    va.push_back({p.first, p.second});
  }
  sort(va.begin(), va.end(), [](P l, P r) { return l.n > r.n; });
  switch (va.size()) {
    case 1:
      if ((va[0].v ^ va[0].v) == va[0].v) {
        ans = true;
      }
      break;
    case 2:
      if (va[0].n == va[1].n * 2 &&
          (va[0].v ^ va[0].v) == va[1].v && (va[0].v ^ va[1].v) == va[0].v) {
        ans = true;
      }
      break;
    case 3:
      if (va[0].n == va[1].n && va[1].n == va[2].n &&
          (va[0].v ^ va[1].v) == va[2].v && (va[1].v ^ va[2].v) == va[0].v && (va[2].v ^ va[0].v) == va[1].v) {
        ans = true;
      }
      break;
    default:break;
  }

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


Measured memory_bytes: 4988
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> D;
typedef pair<D, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<D> g[334];
D dist[334][334];
priority_queue<P, vector<P>, greater<P> > pq;

int main(void){
	int n,m,i,a,b,q,s,t;
	ll l,c;
	D da,db;
	fill(dist[0],dist[334],D(INFLL,INFLL));
	cin >> n >> m >> l;
	for(i=0; i<m; ++i){
		cin >> a >> b >> c; --a; --b;
		g[a].push_back(D(c,b));
		g[b].push_back(D(c,a));
	}
	for(s=0; s<n; ++s){
		dist[s][s] = D(0ll,0ll);
		pq.push(P(dist[s][s],s));
		while(!pq.empty()){
			a = pq.top().second;
			da = pq.top().first;
			pq.pop();
			if(dist[s][a] < da){
				continue;
			}
			for(i=(g[a].l_ength()-1); i>=0; --i){
				b = g[a][i].second;
				c = g[a][i].first;
				if(c>l){
					continue;
				}
				db = D(da.first,da.second + c);
				if(db.second > l){
					++db.first;
					db.second = c;
				}
				if(dist[s][b]>db){
					dist[s][b] = db;
					pq.push(P(dist[s][b],b));
				}
			}
		}
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> s >> t; --s; --t;
		cout << ((dist[s][t].first<INFLL)?(dist[s][t].first):(-1ll)) << endl;
	}
	return 0;
}


Measured memory_bytes: 5508
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const uint64_t INF = static_cast<uint64_t>(-1);

struct VectorItem
{
  uint64_t len;
  pair<uint64_t, uint64_t> prev;

  VectorItem(uint64_t len = 0, const pair<uint64_t, uint64_t> &prev = make_pair(INF, INF))
    : len(len), prev(prev) {}

  bool operator<(const VectorItem &item) const {
    return len < item.len;
  }

  VectorItem operator+(uint64_t v) const {
    return VectorItem(this->len + v, this->prev);
  }
};

int main()
{
  string S, T;
  cin >> S >> T;

  vector<vector<VectorItem>> dp(S.size() + 1, vector<VectorItem>(T.size() + 1));
  // dp[i][j] ; Sのi文字目までとTのj文字目までとで作れるLCSの長さ

  N_TIMES(i, S.size()) {
    N_TIMES(j, T.size()) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        dp[i + 1][j + 1].prev = make_pair(i, j);
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }

  string U = "";
  uint64_t i = S.size(), j = T.size();
  while (true) {
    if ((i == INF) || (j == INF)) { break; }

    VectorItem item = dp[i][j];
    if ((i < S.size()) && (j < T.size()) && (S[i] == T[j])) { U += S[i]; }

    i = item.prev.first;
    j = item.prev.second;
  }
  reverse(U.begin(), U.end());
  cout << U << endl;

  return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long[] dd = sc.LongArray();
        long m = sc.NextLong();
        long[] tt = sc.LongArray();

        Dictionary<long, long> dic = new Dictionary<long, long>();
        foreach (var d in dd)
        {
            if (dic.ContainsKey(d))
            {
                dic[d]++;
            }
            else
            {
                dic.Add(d, 1);
            }
        }

        string answer = "YES";

        foreach (var t in tt)
        {
            if (!dic.ContainsKey(t))
            {
                answer = "NO";
                break;
            }
            else
            {
                if (dic[t] == 0)
                {
                    answer = "NO";
                    break;
                }
                else
                {
                    dic[t]--;
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

def get_shortest_distance(field,locations,current_HP):
	is_visit = [[False for _ in range(len(field[0]))] for __ in range(len(field))]
	frontier = list([locations[current_HP-1]])
	for step in range(len(field)*len(field[0])):
		next_frontier = set()
		for cx,cy in frontier:
			for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
				nx, ny = cx+dx, cy+dy
				if (nx,ny)==locations[current_HP]: return step+1
				if not (0<=nx<len(field)):		continue
				if not (0<=ny<len(field[nx])):	continue
				if field[nx][ny]=='X':			continue
				if is_visit[nx][ny]: 			continue
				next_frontier.add((nx,ny))
				is_visit[nx][ny] = True
		frontier = next_frontier

def solve(field,locations):
	total_step=0
	for current_HP in range(1,len(locations)):
		total_step += get_shortest_distance(field,locations,current_HP)
	return total_step

def main():
	line=input().strip()
	H,W,N=list(map(int,line.split(' ')))
	field,locations=list(),dict()
	for i in range(H):
		field.append(list(input().strip()))
		for j,x in enumerate(field[-1]):
			if x=='S':
				locations[0] = (i,j,)
			if x.isdigit():
				x = int(x)
				field[-1][j] = x
				locations[x] = (i,j,)
	print(solve(field,locations))

if __name__=='__main__':
	main()

Measured memory_bytes: 25392
#include <iostream>
#include <algorithm>

using namespace std;

#define INF (1 << 30)

int dp[401][401];

int main() {
	int n, ma, mb, a, b, c;

	fill(dp[0], dp[401], INF);
	dp[0][0] = 0;

	cin >> n >> ma >> mb;
	while (n--) {
		cin >> a >> b >> c;
		int temp[401][401];
		for (int i = 0; i < 401; ++i) {
			for (int j = 0; j < 401; ++j) {
				temp[i][j] = dp[i][j];
			}
		}
		for (int i = 0; i < 401; ++i) {
			for (int j = 0; j < 401; ++j) {
				if (temp[i][j] != INF && i + a < 401 && j + b < 401) {
					dp[i + a][j + b] = min(temp[i + a][j + b], temp[i][j] + c);
				}
			}
		}
	}

	int ans = INF;
	for (int i = 1; i <= 400; ++i) {
		for (int j = 1; j <= 400; ++j) {
			if (dp[i][j] != INF&& i * mb == j * ma) {
				ans = min(ans, dp[i][j]);
			}
		}
	}
	if (ans == INF) ans = -1;

	cout << ans << endl;

	return 0;
}

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

int ary[15];
char str[7][12]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int main(){
	ary[1]=2;
	for(int i=1;i<12;i++){
		if(i==4||i==6||i==9||i==11){
			ary[i+1]=(ary[i]+30)%7;
		}
		else if(i==2){
			ary[i+1]=(ary[i]+29)%7;
		}
		else{
			ary[i+1]=(ary[i]+31)%7;
		}
	}
	int x,y;
	while(scanf("%d %d",&x,&y)!=EOF){
		if(x==0&&y==0) break;
		cout<<str[(ary[x]+y)%7]<<endl;
	}
	return 0;
}

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

void solve(long long N, long long L, long long T, std::vector<long long> X, std::vector<long long> W){
    ll count = 0;    
    for (int i=1;i<N;i++){
        ll init_pos;
        if (W[0] ==1 &&  W[i] == 2){
            init_pos = X[i]-X[0];
            if (2*T >= init_pos){
                count += 1 + (2*T - init_pos)/L;
            }
        }else if (W[0] ==2 &&  W[i] == 1){
            init_pos = L - (X[i]-X[0]);
            if (2*T >= init_pos){
                count += 1 + (2*T - init_pos)/L;
            }
        }else{
                // pass
        } 
    }
    int number = (W[0]==1)? count%N : (N +(-count %N))%N;
    vector<ll> final_pos(N,0);
    for (int i=0;i<N;i++){
        ll increment = (W[i]==1)? T%L:-T%L + L;
        final_pos[i] = (X[i] + increment) %L;
    }
    ll pos_number = final_pos[0]; // ゼッケンがnumberの蟻が final_pos[0]にいるはず
    sort(final_pos.begin(),final_pos.end());
    int p;
    if (W[0] == 2){//もし同じ場所に複数の蟻がいる場合、そこでそれぞれスワップするので
        p = lower_bound(final_pos.begin(),final_pos.end(),pos_number) -final_pos.begin();
    }else{
        p = upper_bound(final_pos.begin(),final_pos.end(),pos_number) -final_pos.begin() -1;
    }
    // ゼッケンがnumberの蟻が
    for (int i=0;i<N;i++){
        printf("%lld\n",final_pos[(2*N+p-number+i)%N]);
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> X(N);
    std::vector<long long> W(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&W[i]);
    }
    solve(N, L, T, std::move(X), std::move(W));
    return 0;
}


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

int main() {
    ll m, n;
    cin >> m >> n;
    string g[m];
    ll dp[m][n];
    memset(dp, 0, sizeof(dp));
    for (int j = 0; j < m; j++) {
        cin >> g[j];
    }
    for (int j = 0; j < m; j++) {
        if (g[j][0] == '.') {
            dp[j][0] = 1LL;
        } else {
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        if (g[0][i] == '.') {
            dp[0][i] = 1LL;
        } else {
            break;
        }
    }
    for (int j = 1; j < m; j++) {
        for (int i = 1; i < n; i++) {
            if (g[j][i] != '#') {
                if (g[j][i] == '.') {
                    dp[j][i] += dp[j][i-1];
                    dp[j][i] %= M;
                    dp[j][i] += dp[j-1][i];
                    dp[j][i] %= M;
                }
            }
        }
    }
    cout << dp[m-1][n-1] % M;
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
/**
AHMED;HASSAN;SAEED
*/
using namespace std;
long long gcd(long long a,long long b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b){
    return a*b/gcd(a,b);
}
long long num(long long A,long long B,long long M){
     // Add 1 explicitly as A is divisible by M
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long x=1;
    long long nms=0;
    nms=num(a,b,c)+num(a,b,d)-num(a,b,lcm(c,d));
    cout << (b-a+1)-nms << endl;
    return 0;
}


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

using namespace std;

int a[123];
int main()
{
    int n,m;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int x,y;
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        int summ = sum + y - a[x - 1];
        cout << summ << endl;
    }
    return 0;
}


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

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);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	static int MAX = 1000001;

	static class Query {
		int l, r, idx;

		public Query(int l, int r, int idx) {
			this.l = l;
			this.r = r;
			this.idx = idx;
		}
		static void update(int idx, int val, int bit[], int n) {
			for (; idx <= n; idx += idx & -idx)
				bit[idx] += val;
		}
		
		static int query(int idx, int bit[], int n) {
			int sum = 0;
			for (; idx > 0; idx -= idx & -idx)
				sum += bit[idx];
			return sum;
		}
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int n = in.ni(), q = in.ni();
			int[] colors = in.readArray(n);
			Query[] qs = new Query[q];
			for (int i = 0; i < q; ++i)
				qs[i] = new Query(in.ni() - 1, in.ni() - 1, i);
			Arrays.sort(qs, (x, y) -> {
				if (x.r < y.r)
					return -1;
				else if (x.r == y.r)
					return 0;
				else
					return 1;
			});
			int[] bit = new int[n + 1];
			Arrays.fill(bit, 0);
			int[] last_visit = new int[MAX];
			Arrays.fill(last_visit, -1);
			int[] ans = new int[q];
			int query_counter = 0;
			for (int i = 0; i < n; i++) {
				if (last_visit[colors[i]] != -1)
					Query.update(last_visit[colors[i]] + 1, -1, bit, n);
				last_visit[colors[i]] = i;
				Query.update(i + 1, 1, bit, n);
				while (query_counter < q && qs[query_counter].r == i) {
					ans[qs[query_counter].idx] = Query.query(qs[query_counter].r + 1, bit, n)
							- Query.query(qs[query_counter].l, bit, n);
					query_counter++;
				}
			}

			for (int i = 0; i < q; i++)
				out.println(ans[i]);
		}
	}

	private static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		private int ni() {
			return Integer.parseInt(n());
		}

		private int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; ++i)
				a[i] = ni();
			return a;
		}
	}
}

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

int main()
{
	const int s[24][3] = { {1, 2, 3}, {1, 3, 5}, {1, 5, 4}, {1, 4, 2},
				{2, 1, 4}, {2, 4, 6}, {2, 6, 3}, {2, 3, 1},
				{3, 1, 2}, {3, 2, 6}, {3, 6, 5}, {3, 5, 1},
				{4, 1, 5}, {4, 5, 6}, {4, 6, 2}, {4, 2, 1},
				{5, 1, 3}, {5, 3, 6}, {5, 6, 4}, {5, 4, 1},
				{6, 2, 4}, {6, 4, 5}, {6, 5, 3}, {6, 3, 2} };
	
	int a[100][6] = { 0 }, n = 0, f = 0;

	cin >> n;

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

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n - i; j++) {
			for (int k = 0; k < 24; k++) {
				if (a[i][0] == a[j][s[k][0] - 1]) {
					if (a[i][1] == a[j][s[k][1] - 1]) {
						if (a[i][2] == a[j][s[k][2] - 1]) {
							if (a[i][3] == a[j][6 - s[k][2]]) {
								if (a[i][4] == a[j][6 - s[k][1]]) {
									if (a[i][5] == a[j][6 - s[k][0]]) {
										f = 1;
									}
								}
							}
						}
					}
				}
			}
		}
	}

	if(f == 1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3092
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)

N, K = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(N, MOD)
for i in range(1, K+1):
    blue = com.binom(K-1, i-1)
    red = com.binom(N - K + 1, i)
    ans = (blue * red) % MOD
    print(ans)

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

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	char c;
	c = getchar();
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')cout << "vowel\n";
	else cout << "consonant\n";
}


Measured memory_bytes: 256
// やったぜ！！！！！
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll mod = 1e9 + 7;

vector<string> s(1000);

using Vec = vector<ll>;
using Mat = vector<Vec>;

Mat mul(Mat a, Mat b) {
  int n = a.size();
  Mat r(n, Vec(n));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      for(int k = 0; k < n; k++) {
        (r[i][j] += a[i][k] * b[k][j] % mod) %= mod;
      }
    }
  }
  return r;
}

Mat pow(Mat a, ll k) {
  int n = a.size();
  Mat r(n, Vec(n));
  for(int i = 0; i < n; i++) r[i][i] = 1;
  while(k) {
    if(k & 1) r = mul(r, a);
    a = mul(a, a);
    k >>= 1;
  }
  return r;
}

ll modpow(ll a, ll b) {
  ll r = 1;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

ll solve() {
  ios::sync_with_stdio(false), cin.tie(0);
  int h, w;
  ll k;
  cin >> h >> w >> k;
  if(k == 0) return 1;
  for(int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int hroll = 0, wroll = 0;
  for(int i = 0; i < h; i++)
    if(s[i][0] == s[i][w - 1] && s[i][0] == '#') { wroll = 1; break; }
  for(int j = 0; j < w; j++)
    if(s[0][j] == s[h - 1][j] && s[0][j] == '#') { hroll = 1; break; }
  if(wroll && hroll) {
    return 1;
  }
  if(hroll) {
    vector<string> rev = s;
    s = vector<string>(1000, string(1010, ' '));
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)
      s[j][i] = rev[i][j];
    swap(h, w);
  }
  ll l = 0, r = 0, n = 0;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(s[i][j] == '#') {
        n++;
        if(j == 0) {
          l++;
        } else {
          if(s[i][j - 1] != '#') l++;
        }
        if(s[i][(j - 1 + w) % w] != '#') r++;
      }
    }
  }
  k--;
  if(!wroll && !hroll) return modpow(n, k);
  Mat A(2, Vec(2));
  A[0][0] = l; A[0][1] = n - l;
  A[1][0] = r; A[1][1] = n - r;
  A = pow(A, k);
  return A[0][0];
}

int main() {
  cout << solve() << endl;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

signed main(){
  string s;
  int k;
  cin>>s>>k;
  set<string> st;
  rep(i,s.size()){
    loop(j,1,6){
      string t=s.substr(i,j);
      st.insert(t);
    }
  }
  int cnt=0;
  for(auto x:st){
    if(cnt==k-1){
      cout<<x<<endl;
      return 0;
    }
    cnt++;
  }



  return 0;
}


Measured memory_bytes: 1664
// 2020-08-23 22:59:31
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hc(h, 0), wc(w, 0);
  vector<P> t;
  int hm = 0, wm = 0;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    chmax(hm, ++hc[a]);
    chmax(wm, ++wc[b]);
    t.emplace_back(a, b);
  }
  sort(ALL(t));
  int hmc = 0, wmc = 0;
  rep(i, h) hmc += (hc[i] == hm);
  rep(i, w) wmc += (wc[i] == wm);
  ll rem = hmc * wmc;
  for(const auto& e : t) {
    if(hc[e.first] == hm && wc[e.second] == wm) rem--;
  }
  int ans = hm + wm;
  if(rem == 0) ans--;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 9756
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
	int N; cin >> N;
	vector<double> dp(N + 1, 0); dp[0] = 1;			//dp[i] = prob to have i heads
	double ans = 0;

	for (int i = 0; i < N; i++) {
		double curP; cin >> curP;
		for (int j = N; j >= 0; j--) {
			dp[j] = (j == 0 ? 0 : dp[j - 1] * curP) + dp[j] * (1 - curP);
		}
	}

	for (int i = (N + 1) / 2; i <= N; i++) { ans += dp[i]; }

	cout << setprecision(9) << fixed << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var market = new List<int>();
            market.Add(A[0]);
            for (int i = 1; i < N; i++)
            {
                if (A[i] == A[i - 1]) continue;
                market.Add(A[i]);
            }

            if (market.Count <= 1) return 1000;

            var infection = new List<int>();
            if (market[0] < market[1]) infection.Add(market[0]);
            for (int i = 1; i < market.Count - 1; i++)
            {
                if (((market[i] > market[i - 1]) && (market[i] > market[i + 1])) || ((market[i] < market[i - 1]) && (market[i] < market[i + 1])))
                {
                    infection.Add(market[i]);
                }
            }
            if (market[market.Count - 1] > market[market.Count - 2]) infection.Add(market[market.Count - 1]);

            if (infection.Count == 0) return 1000;

            long money = 1000;
            long stock = 0;
            for (int i = 0; i + 1 < infection.Count; i += 2)
            {
                long purchase = money / infection[i];
                money -= purchase * infection[i];
                stock += purchase;

                money += stock * infection[i + 1];
                stock = 0;
            }
            return money;
        }
    }
}


Measured memory_bytes: 27744
from bisect import insort

S=input()
K=int(input())

T=[]
N=len(S)
for  i in range(N):
    V=""
    for j in range(i,min(i+K,N)):
        V+=S[j]
        if V not in T:
            insort(T,S[i:j+1])
            T=T[:K]
print(T[-1])


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

#define MAX_INT 0x3f3f3f3f 
#define precision(x) setprecision(x)
#define boost ios_base::sync_with_stdio(false); 	cin.tie(NULL);

int main()
{
	boost;
	int n;
	cin >> n;
	map<string,int> mp;
	mp["AC"]=mp["TLE"]=mp["WA"]=mp["RE"]=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << "AC x " << mp["AC"] << "\n";
	cout << "WA x " << mp["WA"] << "\n";
	cout << "TLE x " << mp["TLE"] << "\n";
	cout << "RE x " << mp["RE"] << "\n"; 
}

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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


typedef pair<int,int> pii;
class Line{
public:
  vector<pii> x;
  Line(){};
  Line(vector<pii> s){
    reps(i,0,s.size()){
      x.push_back(pii(s[i].first-s[0].first, s[i].second-s[0].second));
    }
    while(!rotateOk())rotate();
  }
  bool rotateOk(){
    return x[0].first < x[1].first;
  }
  void rotate(){
    rep(i,x.size()){
      int f = -x[i].second;
      int s = x[i].first;
      x[i] = pii(f,s);
    }
  }
  bool ok(Line& line){
    if(line.x.size() != x.size())return false;
    rep(i,x.size()){
      if(line.x[i] != x[i])return false;
    }
    return true;
  }
};


vector<Line> lines;
Line base;

void init(){
  lines.clear();
}

Line getLine(){
  vector<pii> x;
  int a;
  cin>>a;
  rep(i,a){
    int c,d;
    cin>>c>>d;
    x.push_back(pii(c,d));
  }
  return Line(x);
}
bool input(){
  int n;
  cin>>n;
  if(n==0)return false;

  base = getLine();
  rep(i,n){
    lines.push_back(getLine());
  }
  return true;
}


int solve(){
  vector<pii> copy = base.x;
  reverse(copy.begin(),copy.end());

  Line base2(copy);

  int sum = 0;
  rep(i,lines.size()){
    if(base.ok(lines[i]) || base2.ok(lines[i])){
      printf("%d\n",i+1);
    }
  }
  puts("+++++");
  return sum;
}


int main(){
  while(init(),input())solve();
}

Measured memory_bytes: 1196
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
        String s=in.nextLine();
        String p=in.nextLine();
    	boolean m=false;
    	for(int i=0;i<s.length();i++){
        	if(s.charAt(i)==p.charAt(0)){
        		if(p.length()>1){
            		int k=i+1;
            		for(int j=1;j<p.length();j++){
        				if(k>=s.length()) k=0;
            			if(s.charAt(k)==p.charAt(j)){
            				m=true;
            				k++;
            			}else{
            				m=false;
            				break;
            			}
            		}
        		}else{
        			m=true;
        		}
        		if(m) break;
        	}
    	}
    	if(m){
    		System.out.println("Yes");
    	}else{
        	System.out.println("No");
    	}        
	}
}

Measured memory_bytes: 17320
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let (n, x) = {
        let line = get_input();
        let mut split = line.split_whitespace();
        let n:i32 = split.next().unwrap().parse().unwrap();
        let x:i32 = split.next().unwrap().parse().unwrap();
        (n, x)
    };

    // let mut l:Vec<i32> = Vec::new();
    let mut ans = 1;
    let mut d = 0;
    {
        let line = get_input();
        let mut split = line.split_whitespace();
        for _ in 0..n {
            let l:i32 = split.next().unwrap().parse().unwrap();
            d = d + l;
            if d > x {
                break;
            }
            ans += 1;

        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  string s;cin>>s;
  int c=0;
  for(int i=0;i<s.size();++i)
	if(s[i]=='0')++c;
  cout<<min(c,(int)s.size()-c)*2<<endl;
  return 0;
}


Measured memory_bytes: 512
dirs = [(-1,0), (0,1), (1,0), (0,-1)]

while True:
	n = int(input())
	if n == 0:
		break
	x, y = 0, 0
	nd = [[0, 0, 0, 0]]
	for i in range(n-1):
		n, d = map(int, input().split())
		nd.append([n, d, 0, 0])
	for i in range(1, len(nd)):
		nd[i][2] = nd[nd[i][0]][2] + dirs[nd[i][1]][0]
		nd[i][3] = nd[nd[i][0]][3] + dirs[nd[i][1]][1]
	w = max(nd, key=lambda x:x[2])[2] - min(nd, key=lambda x:x[2])[2]
	h = max(nd, key=lambda x:x[3])[3] - min(nd, key=lambda x:x[3])[3]
	print('{} {}'.format(w+1, h+1))

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

using namespace std;

const int MAXN = 2000 + 10;
const int MOD = 924844033;

vector<int> a;
long long f[MAXN][MAXN][2], C[MAXN][MAXN];
long long fact[MAXN];
int n, k;

int main()
{
    cin >> n >> k;
    a.push_back(0);
    for(int i = 1; i <= min(n, k + k); i++)
        for(int j = i; j <= n; j += k + k)
            a.push_back(j);
    f[0][0][0] = 1; f[0][0][1] = 0;
    for(int i = 1; i <= n; i++) {
        int v = a[i];
        if (v <= k + k) {
            for(int j = 0; j <= i - 1; j++) {
                f[i - 1][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) % MOD;
                f[i - 1][j][1] = 0;
            }
        }
        for(int j = 0; j <= i; j++) {
            f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1]) % MOD;
            f[i][j][1] = 0;
            if (j > 0) {
                if (v > k) f[i][j][0] = (f[i][j][0] + f[i - 1][j - 1][0]) % MOD;
                if (v + k <= n) f[i][j][1] = (f[i][j][1] + f[i - 1][j - 1][0] + f[i - 1][j - 1][1]) % MOD;
            }
        }
    }

    for(int i = 0; i <= n; i++) {
        C[0][i] = C[i][i] = 1; C[1][i] = i;
    }
    for(int i = 3; i <= n; i++)
        for(int j = 2; j < i; j++) C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % MOD;

    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % MOD;

    long long res = fact[n];
    for(int i = 1; i <= n; i++) {
        long long x = (fact[n - i] * (f[n][i][0] + f[n][i][1])) % MOD;
        //cout << i << " " << (f[n][i][0] + f[n][i][1]) << " " << fact[i] << endl;
        if (i % 2 == 1) res = (res - x + MOD) % MOD;
        else res = (res + x) % MOD;
    }

    cout << res << endl;
}


Measured memory_bytes: 61696
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
typedef long long ll;
typedef pair<int,int> pii;
typedef double lf; const lf err=1e-7;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define qwq {cout<<"qwq"<<endl;}
#define orz(x) {cout<<#x": "<<x<<endl;}
const int N=110;
const int inf=1e9;
const int mod=1e9+7;
#define int ll
int cantor(int a[],int n){
	int f=1,ans=1; //假设答案最小值是1
	repeat_back(i,0,n){
		int cnt=0;
		repeat(j,i+1,n)
			cnt+=a[j]<a[i];
		ans=(ans+f*cnt%mod)%mod; //ans+=f*cnt;
		f=f*(n-i)%mod; //f*=(n-i);
	}
	return ans;
}
int n,a[N],b[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	repeat(i,0,n)cin>>a[i];
	repeat(i,0,n)cin>>b[i];
	cout<<abs(cantor(a,n)-cantor(b,n))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N, M;
    int A[51], B[51], C[51], D[51];
    int i, j;
    int d, t;
    int ans;

    scanf("%d %d", &N, &M);

    for(i = 0; i < N; i++)
        scanf("%d %d", &A[i], &B[i]);

    for(j = 0; j < M; j++)
        scanf("%d %d", &C[j], &D[j]);

    for(i = 0; i < N; i++){
        for(j = 0; j < M; j++) {

            d = abs(A[i]-C[j]) + abs(B[i]-D[j]);

            if (j == 0) {
                t = d;
                ans = 1;
            }
            else if (t > d){
                t = d;
                ans = j+1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
void maxheap(int* , int , int);
void insert(int*, int, int);
int main(){
  int value,array[2000000],size=0,max;
  char command[10];
  while(1){
    scanf("%s",command);
    if(command[0]=='e' && command[1]=='n') break;  /* It means end*/
    if(command[0]=='e'){           /* It means extract*/
      if(size==0) break;
      max=array[1];
      array[1]=array[size];
      size--;
      
      
      maxheap(array,1,size);
      printf("%d\n",max);
     
    }
    if(command[0]=='i'){    /* It means insert */
      size++;
      scanf("%d",&value);
      insert(array,size,value);
    }
  }
  return 0;
}
      
void maxheap(int *array, int i, int num){
  int left,right,max,value;
  left=i*2;
  right=i*2+1;
  if(left<=num &&  array[left]>array[i]) max=left;
  else max=i;
  if(right<=num && array[right]>array[max]) max=right;
  if(max!=i){
    value=array[i];     /* exchange array[i] and array[max] */
    array[i]=array[max];
    array[max]=value;
    maxheap(array,max,num);
  }
}

void insert(int *array, int size, int value){
  int change;
  array[size]=value;
  while(size>1 && array[size/2] < array[size]){
    change=array[size];
    array[size]=array[size/2];
    array[size/2]=change;
    size=size/2;
  }
}




Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n,x;cin>>n>>x;
    vector<int> l(n);
    rep(i,n)cin>>l[i];

    vector<int> d(n+1);

    d[0] = 0;
    int count = 0;
    rep(i,n+1){
        if(d[i] > x) break;
        d[i+1] = d[i] + l[i];
        count ++;
    }
    cout <<count <<endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0, c = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I')
      c++;
    else
      c--;
    ans = max(c, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int i, n;
    short a[101];
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    if (n >= 1) printf("%d", a[n - 1]);
    for (i = n - 2; i >= 0; i--) printf(" %d", a[i]);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2624
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int cost1, cost2, cost3,cost4;
	cost1 = a + c;
	cost2 = a + d;
	cost3 = b + c;
	cost4 = b + d;
	int ans = cost1;
	if (ans >= cost2) {
		ans = cost2;
	}
	if (ans >= cost3) {
		ans = cost3;
	}
	if (ans >= cost4) {
		ans = cost4;
	}
	cout << ans << endl;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int sum = a+b;
  int dif = a-b;
  int mlt = a*b;
  set <int> ans;
  ans.insert(sum);
  ans.insert(dif);
  ans.insert(mlt);
  cout << *rbegin(ans) << endl;
}

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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = c-a, y = d-b;
  for (int i = 0; i < d-b; i++) {
    cout << 'U';
  }
  for (int i = 0; i < c-a; i++) {
    cout << 'R';
  }
  for (int i = 0; i < d-b; i++) {
    cout << 'D';
  }
  for (int i = 0; i < c-a; i++) {
    cout << 'L';
  }
  cout << 'L';
  for (int i = 0; i <= d-b; i++) {
    cout << 'U';
  }
  for (int i = 0; i <= c-a; i++) {
    cout << 'R';
  }
  cout << 'D' << 'R';
  for (int i = 0; i <= d-b; i++) {
    cout << 'D';
  }
  for (int i = 0; i <= c-a; i++) {
    cout << 'L';
  }
  cout << 'U' << endl;
}

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

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
	if (u == -1) {
		return;
	}
		cout <<" "<< u;
		preParse(T[u].l);
		preParse(T[u].r);
	
}

void inParse(int u) {
	if (u == -1) {
		return;
	}
	inParse(T[u].l);
	cout <<" "<< u;
	inParse(T[u].r);
}
void postParse(int u) {
	if (u == -1) {
		return;
	}
	postParse(T[u].l);
	postParse(T[u].r);
	cout <<" "<< u;
}

int main() {
	int n, i, v, l, r,root;
	cin >> n;
	for (i = 0; i < n; i++) {
		T[i].p = -1;
	}
	for (i = 0; i < n; i++) {
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if (l != -1) {
			T[l].p = v;
		}
		if (r != -1) {
			T[r].p = v;
		}
	}
	for (i = 0; i < n; i++) {
		if (T[i].p == -1) {
			root = i;
		}
	}
		cout << "Preorder" << endl;
		preParse(root);
		cout << endl;
		cout << "Inorder" << endl;
		inParse(root);
		cout << endl;
		cout << "Postorder" << endl;
		postParse(root);
		cout << endl;

		return 0;

	}




Measured memory_bytes: 3116