akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ans(n, -1);
    rep(i, m) {
        int s, c;
        cin >> s >> c;
        if (ans[s - 1] == -1 || ans[s - 1] == c) {
            ans[s - 1] = c;
        } else {
            puts("-1");
            return 0;
        }
    }
    if(m == 0){
        if(n == 1){
            cout << 0 << endl;
            return 0;
        }
        cout << 1;
        rep(i,n-1){
            cout << 0;
        }
        cout << endl;
        return 0;
    }


    if(n == 1 && ans[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    bool allzero = true;
    for(int i = 0; i < n; i++){
        if(ans[i] != 0){
            allzero = false;
            break;
        }
    }
    if (allzero || ans[0] == 0) {
        puts("-1");
        return 0;
    }
    
    rep(i, n) {
        if (ans[i] == -1) {
            cout << (i == 0 ? 1 : 0);
        } else {
            cout << ans[i];
        }
    }
    cout << endl;
}


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

char int_to_c(int x) {
    if(x == 0) {
        return 'A';
    } else if(x == 1){
        return 'B';
    } else {
        return 'C';
    }
}

int c_to_int(char c) {
    if(c == 'a') {
        return 0;
    } else if(c == 'b') {
        return 1;
    } else {
        return 2;
    }
}

int main() {
    string S[3];
    cin >> S[0];
    cin >> S[1];
    cin >> S[2];
    int idx[3] = {0};
    int now = 0;
    while(1) {
        //手札がなかったら勝ち
        if(idx[now] > S[now].size() - 1) {
            cout << int_to_c(now) << endl;
            break;
        } else {
        //カードを出す
            char now_char = S[now][idx[now]];
            idx[now] += 1;
            now = c_to_int(now_char);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
ll d, g, a[14], b[14];
signed main() {
	ll s = 0, q = 0, ans = 1e9 + 7;
	cin >> d >> g;
	rep(i, d)cin >> a[i] >> b[i];
	rep(i, (1 << d)) {
		s = 0, q = 0;
		rep(j, d) {
			if ((i >> j) & 1) {
				//score
				s += (j + 1) * 100 * a[j] + b[j];
				//question
				q += a[j];
			}
		}
		for (int j = d - 1; j >= 0; j--) {
			if (!((i >> j) & 1)) {
				if (s < g) {
					if ((g - s + 100 * (j + 1) - 1) / (100 * (j + 1)) <= a[j]) {
						q += ((g - s + 100 * (j + 1) - 1) / (100 * (j + 1)));
						s += ((g - s + 100 * (j + 1) - 1) / ((j + 1) * 100) * ((j + 1) * 100));
					}
				}
			}
		}
		if (g <= s)ans = min(ans, q);
	}
	cout << ans << endl;
	ggr
}


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

int main()
{
    double X1 , Y1 , X2 , Y2 ;
    cin >> X1 >> Y1 >> X2 >> Y2 ;
    double ans = sqrt((X2 - X1)*(X2 - X1) + (Y2 - Y1)*(Y2 - Y1)) ;
    printf("%.8lf\n" , ans) ;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2019/03/26/115300
int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    REP(i, N) { cin >> T[i]; }
    sort(T.begin(), T.end());
    int res = 0;
    for(int i = 0; i < N;) {
        res++;
        int start = i;
        while(i < N and T[i] - T[start] <= K and i - start < C) {
            i++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int ans=0,jishu=0;
	string a;
	cin>>a;
	for (int i=0;i<a.length();i++)
	{
		if (a[i]=='C')
		{
			jishu++;
		}
		if (a[i]=='F')
		{
			if (jishu>=1)
			{
				jishu-=1;
				ans++;
			}
		}
	}
	if (ans>0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(raw_input())
ct = Counter(map(int, raw_input().split()))
correct = True
for i,j in zip(ct.keys(), ct.values()):
    if (n % 2) == (i % 2):
        correct = False
    elif i >= n:
        correct = False
    elif i == 0:
        if j != 1:
            correct = False
    else:
        if j != 2:
            correct = False
if correct:
    print (2**(n/2)) % (10**9+7)
else:
    print 0


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

using namespace std;
using ll = long long;

int n;
array<int, 110> s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> n) {
        s.fill(0);
        for (int i = 0; i < n; ++i) {
            cin >> s[i];
        }
        int tot = accumulate(s.begin(), s.end(), 0);
        if (tot % 10 != 0) {
            cout << tot << "\n";
            continue;
        }
        sort(s.begin(), s.begin() + n);
        int mIndex = -1;
        for (int i = 0; i < n; ++i) {
            if (s[i] % 10 != 0) {
                mIndex = i;
                break;
            }
        }
        cout << (~mIndex ? tot - s[mIndex] : 0) << "\n";
#ifndef ONLINE_JUDGE
        cout.flush();
#endif
    }
}

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

using namespace std;

struct DATA{
  int x;
  int y;
  int z;
  int w;
};

int main(){
  int i, n, x1, x2, y1, y2, z1, z2, w1, w2;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
      _data.x = x1*x2 - y1*y2 - z1*z2 - w1*w2;
      _data.y = x1*y2 + y1*x2 + z1*w2 - w1*z2;
      _data.z = x1*z2 - y1*w2 + z1*x2 + w1*y2;
      _data.w = x1*w2 + y1*z2 - z1*y2 + w1*x2;
      data.push_back(_data);
    }

    for(i=0; i<data.size(); ++i)
      cout << data[i].x << " " << data[i].y << " " << data[i].z << " " << data[i].w << endl;

    data.clear();
  }

  return 0;
}

Measured memory_bytes: 0
n = int(input())
h = [int(i) for i in input().split()]
def cost(i,j):
    return abs(h[i]-h[j])

dp = [0 for _ in range(n)]
dp[1] = cost(0,1)
for i in range(2,n):
    dp[i] = min(dp[i-1]+cost(i,i-1),dp[i-2]+cost(i,i-2))

print(dp[n-1])

Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

vector<vector<int> > G(200005);

int main()
{
    int n,m;
    cin>>n>>m;
    vi h(n+1);
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        bool flg=true;
        vb vis(200005,false);
        for(int j=0;j<G[i].size();j++)
        {
            if(!vis[G[i][j]]){
                vis[G[i][j]]=true;
                if(h[G[i][j]]>=h[i]) {flg=false;break;}
            }
        }
        if(flg) cnt++;//{cout<<i<<endl;cnt++;}
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 11180
n,l=map(int,input().split())
re=[]
for i in range(1,n+1):
  re.append(l+i-1)
if 0 in re:
  print(sum(re))
else:
  if l>0:
  	print(sum(re)-min(re))
  elif(l<0):
    print(sum(re)-max(re))
#print(6+7+8+9+10+11)

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

int main()
{
  int n;
  scanf("%d", &n);
  int a[n], b[n], i;
  for(i = 0; i < n; i++){
    scanf("%d%d", &a[i], &b[i]);
  }
  int zorome = 0, frag = 0;
  for(i = 0; i < n; i++){
    if(a[i] == b[i]){
      zorome = zorome + 1;
    }else{
      zorome = 0;
    }
    if(zorome == 3){
      printf("Yes\n");
      frag = 1;
      break;
    }
  }

  if(frag == 0){
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int seg[2000005][26];
string a;
void build(int ver,int tl,int tr)
{
    if(tl>tr)
        return ;
    else if(tl==tr)
    {
        seg[ver][a[tl]-'a']=1;
    }
    else
    {
        int tm=(tl+tr)/2;
        build(2*ver,tl,tm);
        build(2*ver+1,tm+1,tr);
        for(int i=0;i<26;i++)
            seg[ver][i]=seg[2*ver][i]+seg[2*ver+1][i];
    }
}

void upd(int ver,int tl,int tr,int pos,int val,int k)
{
    if(tl>tr)
        return ;
    else if(tl==tr)
    {
        seg[ver][val]+=k;
    }
    else
    {
        int tm=(tl+tr)/2;
        if(tm>=pos)
            upd(2*ver,tl,tm,pos,val,k);
        else
            upd(2*ver+1,tm+1,tr,pos,val,k);
        for(int i=0;i<26;i++)
            seg[ver][i]=seg[2*ver][i]+seg[2*ver+1][i];
        
    }
}

int get(int ver,int tl,int tr,int l,int r,int ind)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return 0;
    else if(tl==l&&tr==r)
        return seg[ver][ind];
    else
    {
        int tm=(tl+tr)/2;
        return get(2*ver,tl,tm,l,min(tm,r),ind)+get(2*ver+1,tm+1,tr,max(tm+1,l),r,ind);
    }    
}

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;

    cout<<(n+1)/2;    

} 



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n;

	scanf("%d", &n);

	while (n)
	{
		if (n % 10 == 7)
		{
			printf("Yes\n");

			return 0;
		}

		n /= 10;
	}

	printf("No\n");

	return 0;
}


Measured memory_bytes: 1660
char a[2][204];n,m,i,j,c,p;main(s){for(;scanf(m="%d %[^\n] %[^\n]",&n,a,a+1)>2;printf(m>210?"NA\n":"%d\n",m)){for(i=2;i--;m>c?m=c:0)for(j=i,c=p=0;s=a[j][p+p]-50,c<220&&!s|n+~p;)p+=p<n&&s?~s|a[j][p+p+2]-49?j=!j,++c,2:1:-1;}exit(0);}

Measured memory_bytes: 0
from collections import deque


def main():
    S = list(input())
    dec_s = deque(S)
    flag = True  # Trueのときdec_s Falseのときre
    for _ in range(int(input())):
        t = list(input().split(' '))
        if len(t) == 1:
            flag = not flag
        else:
            if (t[1] == '1' and flag) or (t[1] == '2' and not flag):
                dec_s.appendleft(t[2])
            else:
                dec_s.append(t[2])
    if not flag: dec_s.reverse()
    print(''.join(dec_s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
n,m=map(int,input().split())

lsta=[[int(a) for a in input().split()] for i in range(n)]
lstb=[]
for j in range(m):
    b=int(input())
    lstb.append(b)

for k in range(n):
    lstc=[]
    for l in range(m):
        c=lsta[k][l]*lstb[l]
        lstc.append(c)
    print(sum(lstc))


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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define rep(i,a,b) for(i=a;i<b;i++)
#define hell 1000000007
#define mod 998244353
#define fs first
#define sc second
#define all(v) v.begin(),v.end()

int main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int n,i,j,sum=0,k;
  cin>>n;
  int a[n];
  rep(i,0,n)
  cin>>a[i];
  sort(a,a+n);
  rep(i,0,n)
  {
    rep(j,i+1,n)
    {
      rep(k,j+1,n)
      {
        if(a[i]<a[j]+a[k] && a[j]<a[i]+a[k] && a[k]<a[i]+a[j])
        {
          sum++;
        }
      }
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
def f(x, y):
    if x % y == 0:
        return y
    return f(y, x % y)
a = []
while True:
    try:
        a.append(list(map(int, input().split())))
    except EOFError:
        break
for i in a:
    g = f(i[0], i[1])
    l = (i[0] * i[1]) / g
    print(g, int(l))



Measured memory_bytes: 5600
#include<stdio.h>

int main(){
	
	int a,b,c,t;
	
	while(scanf("%d",&a)!=EOF){
		scanf("%d",&b);
		c=a+b;
		
		for(t=1;c/10!=0;t++){
			c=c/10;
		}
		printf("%d\n",t);
		
	}
	return 0;
}

Measured memory_bytes: 2572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> L[100010];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int l;
            cin >> l;
            L[l - 1].pb(i);
        }
    }
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        if(L[i].size() < 2) continue;
        int p = L[i][0];
        for (int j = 1; j < L[i].size(); j++) {
            uf.unite(p, L[i][j]);
        }
    }
    cout << (uf.size(0) == n ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 4608
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)


Measured memory_bytes: 74756
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,a,b,c;
    cin>>a>>b>>c;
    if((a==5 && b==5 && c==7) || (a==7 && b==5 && c==5) || (a==5 && b==7 && c==5))
    {
        cout<<"YES\n";
    }
    else
    {
        cout<<"NO\n";
    }
    return 0;
}


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

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, K) = Read2Longs();
            var points = new List<Point>();
            for (int i = 0; i < N; i++)
            {
                var (x, y) = Read2Longs();
                points.Add(new Point { X = x, Y = y });
            }

            points = points.OrderBy(x => x.X).ToList();
            var min = long.MaxValue;
            for (int i = 0; i < N - 1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    // 点が明らかにK個以下なので
                    if (j - i + 1 < K) continue;

                    var xPoints = points.Skip(i).Take(j - i + 1).OrderBy(x => x.Y).ToList();
                    for (int ii = 0; ii < xPoints.Count - 1; ii++)
                    {
                        for (int jj = 0; jj < xPoints.Count; jj++)
                        {
                            // 点が明らかにK個以下なので
                            if (jj - ii + 1 < K) continue;
                            {
                                var xyPoints = xPoints.Skip(ii).Take(jj - ii + 1).ToList();

                                var rec = Math.Abs(xyPoints.Max(x => x.X) - xyPoints.Min(x => x.X))
                                    * Math.Abs(xyPoints.Max(x => x.Y) - xyPoints.Min(x => x.Y));
                                min = Math.Min(min, rec);
                            }
                        }
                    }
                }
            }

            return min;
        }
        [DebuggerDisplay("{X},{Y}")]
        class Point
        {
            public long X { get; set; }
            public long Y { get; set; }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string s;cin>>s;
  // R RL LLL RL R RL L
  // 0 33 000 11 0 22 0
  
  vector<int> l;
  vector<int> r;
  for(int i=0;i<s.length();++i){
    if(s[i]=='R' && s[i+1]=='L'){
      r.push_back(i);
    }
    if(s[i]=='L' && s[i-1]=='R'){
      l.push_back(i);
    }
  }
  //for(auto i:r)cout<<i<<" ";cout<<endl;
  //for(auto i:l)cout<<i<<" ";cout<<endl;
  
  vector<int> result(s.length());
  
  for(int i=0;i<s.length();++i){
    if(s[i]=='R'){
      int index = lower_bound(r.begin(),r.end(),i)-r.begin();
      //cout<<i<<" "<<r[index]<<endl;
      if((r[index]-i)%2==1){
        result[r[index]+1]++;
      }else{
        result[r[index]]++;
      }
    }
    if(s[i]=='L'){
      int index = upper_bound(l.begin(),l.end(),i)-l.begin();
      index--;
      //cout<<i<<" "<<l[index]<<endl;
      if((i-l[index])%2==1){
        result[l[index]-1]++;
      }else{
        result[l[index]]++;
      }
    }
  }
  
  for(auto i:result){
    cout<<i<<" ";
  }cout<<endl;
  
  return 0;
}


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

int fact(int n) {
  if ( n == 0 || n == 1 ) {
    return 1;
  }
  return n * fact(n-1);
}

int calc(vector<int>& S, int start, int end) {
  int diff = end - start;
  if ( diff == 1 ) {
    return 1;
  }
  priority_queue<int,vector<int>,greater<int>> pq;
  for(int i = start; i < end; i++) {
    pq.push(S.at(i));
  }
  int start_value = S.at(start);
  int order = 0;
  while(!pq.empty()) {
    int v = pq.top();
    if ( start_value == v ) {
      break;
    }
    pq.pop();
    order++;
  }
  int offset = order > 0 ? order * fact(diff-1) : 0;
  return offset + calc(S, start+1, end);
}

int calc_order(vector<int>& S) {
  return calc(S, 0, S.size());
}

int main() {
  //input
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  rep(i,N) {
    cin >> P.at(i);
  }
  rep(j,N) {
    cin >> Q.at(j);
  }
  //calc
  int a = calc_order(P);
  int b = calc_order(Q);
//  cout << "a = " << a << "," << "b = " << b << endl;
  int answer = a > b ? a - b : b - a;
  //output
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<endl;
  }else if(b==c){
    cout<<a<<endl;
  }else if(c==a){
    cout<<b<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
using namespace std;
using ll=long long;

int main(){
  int N, M;
  map<string,int> s;
  cin >> N;
  REP(i,N){
    string e;
    cin>>e;
    if(s.find(e)==s.end()) s.emplace(e,1);
    else ++s[e];
  }
  cin >> M;
  REP(i,M){
    string e;
    cin>>e;
    if(s.find(e)==s.end()) s.emplace(e,-1);
    else --s[e];
  }

  int ans=0;
  for(map<string,int>::iterator it=s.begin(); it!=s.end(); ++it){
    pair<string,int> item=*it;
    ans=max(ans,item.second);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int a, b, q; cin >> a >> b >> q;
  vector<ll> s(a);
  //debugln(a);
  rep(i, a) cin >> s[i];
  vector<ll> t(b);
  //debugln(b);
  rep(i, b) cin >> t[i];

  while(q--) {
    ll x; cin >> x;
    auto it = lower_bound(s.begin(), s.end(), x);
    ll s1, s2;
    //debugln("hoge");
    if (it == s.begin()) {
      s1 = LLONG_MAX/4;
      s2 = (*it)-x;
    } else if (it == s.end()) {
      --it;
      s1 = x-(*it);
      s2 = LLONG_MAX/4;
    } else {
      //debugln("piyo");
      s2 = (*it)-x;
      --it;
      s1 = x-(*it);
    }
    ll t1, t2;
    it = lower_bound(t.begin(), t.end(), x);
    if (it == t.begin()) {
      t1 = LLONG_MAX/4;
      t2 = *it-x;
    } else if (it == t.end()) {
      --it;
      t1 = x-*it;
      t2 = LLONG_MAX/4;
    } else {
      t2 = *it-x;
      --it;
      t1 = x-*it;
    }

    ll ans = LLONG_MAX;
    chmin(ans, max(s1,t1));
    chmin(ans, max(s2,t2));
    chmin(ans, s1+t2+min(s1,t2));
    chmin(ans, s2+t1+min(s2,t1));
    cout << ans << '\n';
  }

}


Measured memory_bytes: 2944
#include<stdio.h>

#define FOUND 1
#define NOT_FOUND 0

int binarysearch(int *,int ,int );

int main(){
  int i,n,s[100000],q,t[50000],c=0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t[i]);
    c = c + binarysearch(s,n,t[i]);
  }

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

  return 0;
}

int binarysearch(int *a,int n,int key){
  int left,right,mid;

  left = 0;
  right = n;

  while(left < right){
    mid = (left + right) / 2;
    if(a[mid] == key){
      return FOUND;
    }
    else if(key < a[mid]){
      right = mid;
    }
    else{
      left = mid + 1;
    }
  }
  return NOT_FOUND;
}

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

int main(){
  string S;
  cin >>S;
  
  string ans = "Yes";
  int len = S.size();
  rep(i,0,len){
    if((i+1)%2==1 and S[i]=='L'){
      ans = "No";
      break;
    }else if((i+1)%2==0 and S[i]=='R'){
      ans = "No";
      break;
    }
  }
  
  cout <<ans<< endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0

if sum(a) == x:
    print(n)
    exit()

for i in range(n - 1):
    if x >= a[i]:
        ans += 1
        x -= a[i]

print(ans)

Measured memory_bytes: 3060
readline = open(0).readline
N = int(readline())
P = [readline().split() for i in range(N)]
P = [(int(v), int(w), t, int(d), s) for v, w, t, d, s in P]
P.sort()
open(1, 'w').writelines(["%d %d %s %d %s\n" % e for e in P])


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

int main() {
	int x, n,tmp,j=0;
	vector<int> p;
	cin >> x >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		p.push_back(tmp);
	}
	sort(p.begin(),p.end());
	while (1) {
		if (p.empty()) {
			cout << x << endl;
			break;
		}
		if ((find(p.begin(), p.end(), x - j)) == p.end()) {
			cout << x - j << endl;
			break;
		}
		if ((find(p.begin(), p.end(), x + j)) == p.end()) {
			cout << x + j << endl;
			break;
		}
		j++;
	}
}

Measured memory_bytes: 3632
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long  
using namespace std;
const int mod=1e9+7;
const int MAX=1e5+7;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	ll n,k,ans=0;
 	cin>>n>>k;
 	for(int i=k;i<=n+1;i++)
 	{
 		ll a=0,b=i-1,c=n-i+1,d=n;
 		ll x=(a+b)*i/2,y=(c+d)*i/2;
 		ans=(ans+y-x+1)%mod;
	 }
	 cout<<ans<<endl;
 	
}

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

const ll INF = 1e18;

// aの約数を全て返すもののアレンジ
ll divisor(ll a){
	ll res = INF;
	for(ll i = 1; i*i <= a; i++){
		if(a%i == 0){
			/*
			res.push_back(i);
			if(i != a/i) res.push_back(a/i);
			*/
			res = min( res, (i - 1) + (a/i - 1));
		}
	}
	return res;
}


int main(){
	
	ll n;
	cin >> n;
	
	cout << divisor(n) << endl;

	return 0;
}

Measured memory_bytes: 256
import heapq
X,Y,Z,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
B=[int(i) for i in input().split(" ")]
C=[int(i) for i in input().split(" ")]

AB=[]
for a in A:
    for b in B:
        AB.append(a+b)

AB=heapq.nlargest(K,AB)
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)

for cake in heapq.nlargest(K,ABC):
    print(cake)


Measured memory_bytes: 160848
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int[][] A = new int[N][M];
        int[] B = new int[M];
        for(int i=0; i<M; i++) {
            B[i] = Integer.parseInt(sc.next());
        }
        int sum = 0;
        int count = 0;
        for(int i=0; i<N; i++) {
            sum = C;
            for(int j=0; j<M; j++) {
                A[i][j] = Integer.parseInt(sc.next());
                sum += A[i][j] * B[j];
            }
            if(sum > 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n;
  cin >> n;
  vector<string> vec(n),ans;
  rep(i,n){
    cin >> vec[i];
  }
  sort(all(vec));
  string str = "";
  ll maxs = 0;
  t1 = 0;
  //cout << endl;
  rep(i,n){
    //cout << vec[i] << endl;
    if(str == vec[i]){
      t1++;
    }else{
      //cout << str << " " << vec[i] << endl;
      str = vec[i];
      t1 = 1;
    }
    //cout << t1 << endl;
    if(t1 > maxs){
      maxs = t1;
      ans.clear();
      ans.push_back(vec[i]);
    }else if(t1 == maxs){
      ans.push_back(vec[i]);
    }
  }

  ull len = ans.size();
  rep(i,len){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 15988
#include<stdio.h>
long check(long n,long a,long b){
	if(n>1e9||n<=1||a>b||a<1||b>1e9||b<1||a>1e9)
	{
		if(n==1&&a==b){
			return 1;
		}else return 0;

	}	long o=0;	long p=0;
	 o=(n-2);p=b-a;
	 long sum=o*p+1;

	return sum;
	
}
int main(){
long n;long a;long b;
	scanf("%ld %ld %ld",&n,&a,&b);
	
	printf("%ld\n",check(n,a,b));
	return 0;
}

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

using namespace std;

int abs(int x) {
	return x > 0 ? x : -x;
}
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

int main() {
	int N, X;
	vector<int> x;
	cin >> N >> X;
	int a;
	cin >> a;
	int ans = abs(X - a);
	int bef=a;
	for (int i = 1; i < N; i++) {
		int b;
		cin >> b;
		ans = gcd(ans, abs(b-bef));
			bef = b;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
int main()
{
	int A, B, K;
	std::cin >> K >> A >> B;
	if ((A + K - 1) / K * K <= B) {
		std::cout << "OK" << std::endl;
	}
	else {
		std::cout << "NG" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3620
a,b = map(int, input().split())
if a < 0:
    if b >= 0:
        print("Zero")
    else:
        if (b-a) % 2 == 0:
            print("Negative")
        else:
            print("Positive")
elif a == 0:
    print("Zero")
else:
    if b <= 0:
        print("Zero")
    else:
        print("Positive")


Measured memory_bytes: 2940
N = int(input())
S = input()
ls = ['SS','SW','WS','WW']
ok = -1
for ind,i in enumerate(S):
    if(ind==0):continue
    if(ind==N-1):break
    for indj,j in enumerate(ls):
        if(i=='o'):
            if(j[ind]=='S'):
                ls[indj] += j[ind-1]
            else:
                ls[indj] += 'W' if j[ind-1]=='S' else 'S'
        else:
            if(j[ind]=='S'):
                ls[indj] += 'W' if j[ind-1]=='S' else 'S'

            else:
                ls[indj] += j[ind-1]
for num,l in enumerate(ls):
    flag = True
    for ind,i in enumerate(S):
        if(ind==0):
            a = l[-1]
            b = l[1]
        elif(ind==N-1):
            a = l[-2]
            b = l[0]
        else:
            a = l[ind-1]
            b = l[ind+1]
        if(i=='o'):
            if(l[ind]=='S'):
                flag&=(a==b)
            else:
                flag&=(a!=b)
        else:
            if(l[ind]=='S'):
                flag&=(a!=b)
            else:
                flag&=(a==b)
        if(not flag):
            break
    if(flag):
        ok = num
        break
if(ok==-1):
    print(-1)
else:
    print(ls[ok])


Measured memory_bytes: 3936
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int num_days, num_assignments;
    cin >> num_days >> num_assignments;
    int total_loads = 0;
    for(int i=0; i<num_assignments; i++){
        int load;
        cin >> load;
        total_loads += load;
    }
    int free_days = num_days - total_loads;
    cout << (free_days >= 0 ? free_days : -1);
}

Measured memory_bytes: 3636
s = input()
K = int(input())

x = [[s[j:j+i+1] for j in range(len(s)-i)] for i in range(5 if len(s)>=5 else len(s))]

s_set = []
for i in x:
	s_set.extend(i)

s_set = list(set(s_set))
s_set.sort()
print(s_set[K-1])

Measured memory_bytes: 5232
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

typedef vector<int> vec;
//a*b
vec multi(vec a, vec b) {
	int n = a.size();
	vec ret(n);
	rep(i, n) {
		ret[i] = a[b[i] - 1];
	}
	return ret;
}
vec inv(vec a) {
	int n = a.size();
	vec ret(n);
	rep(i, n) {
		ret[a[i] - 1] = i + 1;
	}
	return ret;
}
int n, k; vec p, q;
int main() {
	cin >> n >> k;
	p.resize(n), q.resize(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> q[i];
	int r = k % 6, d = k / 6;
	if (r == 0) {
		r=6; d--;
	}
	vec b(n);
	if (r == 1) {
		b = p;
	}
	else{
		vec c = p, d = q;
		rep(i, r - 2) {
			vec mem = inv(c); c = d; d = multi(d, mem);
		}
		b = d;
	}
	vec u = multi(multi(q, inv(p)), multi(inv(q), p));
	vec v = inv(u);
	vec u2[30], v2[30];
	u2[0] = u, v2[0] = v;
	rep1(i, 29) {
		u2[i] = multi(u2[i - 1], u2[i - 1]);
		v2[i] = multi(v2[i - 1], v2[i - 1]);
	}
	rep(i, 30) {
		if (d&(1 << i)) {
			b = multi(multi(u2[i], b), v2[i]);
		}
	}
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << b[i];
	}
	cout << endl;
	//stop
	return 0;
}


Measured memory_bytes: 28212
"use strict";

const main = arg => {
    const X = parseInt(arg.split("\n")[0].split(" ")[0]);
    const A = parseInt(arg.split("\n")[0].split(" ")[1]);
    const B = parseInt(arg.split("\n")[0].split(" ")[2]);
    
    if((B - A) >= X + 1) {
        console.log("dangerous");
    } else if((B - A) <= X && (B - A) > 0) {
        console.log("safe");
    } else {
        console.log("delicious");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

char a[100010];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	scanf("%s",a+1);int n=strlen(a+1);
	int s1=0,s2=0,s3=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]=='a') s1++;
		if (a[i]=='b') s2++;
		if (a[i]=='c') s3++;
	}
	if (abs(s1-s2)>1||abs(s2-s3)>1||abs(s3-s1)>1) puts("NO"); else puts("YES");
	return 0;
}



Measured memory_bytes: 764
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int p[] = new int[n];
        int data[] = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            data[i] = i + 1;
        }

        for (int i = 0; i < m; i++) {
            int x = root(sc.nextInt(), data);
            int y = root(sc.nextInt(), data);
            if (x != y) {
                data[x - 1] = y;
            }
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (isSame(p[i], i + 1, data)) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    public boolean isSame(int x, int y, int data[]) {
        return root(x, data) == root(y, data);
    }

    public int root(int p, int data[]) {
        if (data[p - 1] == p) {
            return p;
        }

        return data[p - 1] = root(data[p - 1], data);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int q;
  cin >> q;
  bool rev = 0;
  vector<char> v, w;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
    } else {
      int f;
      cin >> f;
      char c;
      cin >> c;
      if ((f == 1 && rev == 0) || (f == 2 && rev == 1)) {
        v.push_back(c);
      } else {
        w.push_back(c);
      }
    }
  }

  debug(rev, v, w);
  string ans;
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    ans += v[i];
  }
  ans += s;
  for (char c : w) {
    ans += c;
  }
  if (rev) reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4336
#include<stdio.h>
#include<algorithm>
int main() {
	
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

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

	if (N == 1) {
		printf("Hello World");
	}
	else {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d", a + b);
	}
}

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

using namespace std;

int main() {
	int N; cin >> N;
	vector<int> p(N),a(N),b(N);
	for(auto&e:p) cin >> e;
	for(int i=0;i<N;++i) a[i]=i*N+1,b[i]=(N-i)*N+1;
	for(int i=0;i<N;++i) a[p[i]-1]+=i;
	for(int i=0;i<N;++i) {
		if(i) cout << " ";
		cout << a[i];
	}
	cout << endl;
	for(int i=0;i<N;++i) {
		if(i) cout << " ";
		cout << b[i];
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}

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

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << c+(b-d) << " "  << d-(a-c) << " "  << a+(b-d)  << " " << b-(a-c) << endl;
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    Int A, B, N; cin >> A >> B >> N;
    auto f = [&](Int x) {
        return A * x / B - A * (x / B);
    };
    cout << f(min(B - 1, N)) << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
    ll n, m; cin >> n >> m;
    ll x[m];
    ll cnt = 0;
    rep(i, m){
        cin >> x[i];
    }
    if(m == 1 || n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(x, x+m);
    ll dif[m-1] = {0};
    rep(i, m-1){
        dif[i] = x[i+1]-x[i];
    }
    ll ans = x[m-1]-x[0];
    sort(dif, dif+m-1);
    rep(i, n-1){
        ans -= dif[m-2-i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
N=int(input())
S=input()

numb=[0]
numw=[0]
cond="b"
for i in range(N):
    numb.append(numb[-1])
    numw.append(numw[-1])
    if S[i]=="#":
        numb[-1]+=1
    else:
        numw[-1]+=1

ans=[0 for _ in range(N+1)]
for j in range(N+1):
    ans[j]=numb[j]+(numw[-1]-numw[j])
print(min(ans))

Measured memory_bytes: 20984
#include<iostream>
#include<string>
using namespace std;
string S,T,U,V;
bool solve(string a1,string a2){
    int H=0;
    for(int i=0;i<a2.size();i++){
        if(a1[H]==a2[i])H++;
        if(H==a1.size())return true;
    }
    return false;
}
int main(){
    cin>>S>>T;
    for(int i=0;i<S.size();i++){
        if(i%2==0)U+=S[i];
        if(i%2==1)V+=S[i];
    }
    bool OK=false;
    if(solve(U,T)==true || solve(V,T)==true)OK=true;
    if(OK==true)cout<<"Yes"<<endl;
    else{cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 3196
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# しゃくとり法
N = ir()
A = lr()
answer = 0
left = 0
right = 0

temp = A[left]
while left < N:
    while right < N-1:
        num = A[right+1]
        if temp ^ num != temp + num:
            break
        temp += num
        right += 1
    right = max(right, left)
    answer += right - left + 1
    temp -= A[left]
    left += 1

print(answer)


Measured memory_bytes: 23560
#include<iostream>
using namespace std;
//????????????
void swap(int idx1, int idx2, int *node)
{
	int f = node[idx1];
	node[idx1] = node[idx2];
	node[idx2] = f;
}
//??????????????????????????????????????nlogn
void quickSort(int left, int right , int *node)
{
	int pl = left;
	int pr = right;
	int pivot_f = node[(pl + pr) / 2];
	do
	{
		while (node[pl] < pivot_f)
		{
			pl++;
		}
		while (node[pr]> pivot_f)
		{
			pr--;
		}
		if (pl <= pr)
		{
			swap(pl++, pr-- , node);
		}
	} while (pl <= pr);
	if (left < pr) quickSort(left, pr , node);
	if (pl <= right) quickSort(pl, right , node);
}

int main() {
	int num[10];
	for (int i = 0; i < 10; i++)
	{
		cin >> num[i];
	}
	quickSort(0, (10-1), num);
	for (int i = 1; i <= 3; i++)
	{
		cout << num[10-i] << endl;
	}
	return 0;
}

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

int n, x[50], y[50];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", x+i, y+i);
	}
	int ans = n;
	for (int i = 0; i < n; ++i) {
		for (int j = i; j < n; ++j) {
			int p = x[i]-x[j], q = y[i]-y[j];
			if (p == 0 && q == 0) continue;
			int cost = n;
			for (int k = 0; k < n; ++k) {
				for (int l = 0; l < n; ++l) {
					if (x[k]-x[l] == p && y[k]-y[l] == q) {
						cost--;
						break;
					}
				}
			}
			ans = min(ans, cost);
		}
	}
	printf("%d\n", ans);
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    REP(i, m) cin >> a[i];

    vector<LL> dp(n+5, 0);
    map<int, bool> mp;
    REP(i, m) mp[a[i]] = true;
    dp[0] = 1;
    REP(i, n)
    {
        if(!mp[i+1]) dp[i+1] = (dp[i] + (i >= 1 ? dp[i-1] : 0)) % MOD;
        //cout << dp[i] << " " << dp[i-1] << " " << dp[i+1] << endl;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    int ans = c - (a - b);
    if(ans < 0){
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256