akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

const double eps = 1e-10;
inline bool eq(double a, double b) { return fabs(a - b) < eps; }
const double pi = acos(-1);

struct Point {
    double x, y;
    Point() {}
    Point(double x, double y) : x(x), y(y) {}
    Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
    Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
    Point operator*(double k) { return Point(x * k, y * k); }
    Point operator/(double k) { return Point(x / k, y / k); }
};
Point rotate(double theta, const Point &p) {
    return Point(cos(theta) * p.x - sin(theta) * p.y, sin(theta) * p.x + cos(theta) * p.y);
}
double radian_to_degree(double r) { return (r * 180.0 / pi); }
double degree_to_radian(double d) { return (d * pi / 180.0); }

struct Line {
    Point a, b;
    Line() {}
    Line(Point a, Point b) : a(a), b(b) {}
    Line(double A, double B, double C) { // Ax + By = C
        if (eq(A, 0))
            a = Point(0, C / B), b = Point(1, C / B);
        else if (eq(B, 0))
            a = Point(C / A, 0), b = Point(C / A, 1);
        else
            a = Point(0, C / B), b = Point(C / A, 0);
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(Point p, double r) : p(p), r(r) {}
};
double norm(const Point &a) { return a.x * a.x + a.y * a.y; }
double abs(const Point &a) { return sqrt(norm(a)); }
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }

Point projection(Line l, Point p) {
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}
Point reflection(Line l, Point p) { return p + (projection(l, p) - p) * 2; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Point p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    Line base(p1, p2);
    int q;
    cin >> q;
    vector<Point> r(q);
    for (int i = 0; i < q; ++i) {
        cin >> r[i].x >> r[i].y;
    }
    cout << fixed << setprecision(10);
    for (int i = 0; i < q; ++i) {
        Point ret = reflection(base, r[i]);
        cout << ret.x << " " << ret.y << "\n";
    }
}


Measured memory_bytes: 3316
////////////////////////////////////////////    _LeMur_
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
string s;

int answ[N];
int dp[N][102];

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> s;
    for(int i=0;i<(int)s.size();i++){
        int x = i;
        int k = 10;
        while(k--){
            if(s[x] == 'L')
                --x;
            else
                ++x;
        }
        dp[i][0] = x;
    }
    for(int j=1;j<=100;j++){
        for(int i=0;i<(int)s.size();i++){
            int x = i;
            int k = 10;
            while(k--){
                x = dp[x][j - 1];
            }
            dp[i][j] = x;
        }
    }
    for(int i=0;i<(int)s.size();i++){
        answ[ dp[i][100] ]++;
    }
    for(int i=0;i<(int)s.size();i++){
        printf("%d ",answ[i]);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 40896
def main():
    arr = []
    for i in range(3):
        arr.append(list(map(int, input().split())))
    b1 = arr[0][0] - arr[0][1]
    b2 = arr[0][1] - arr[0][2]
    a1 = arr[1][0] - arr[0][0]
    a2 = arr[2][0] - arr[1][0]
    for i in range(3):
        if arr[i][0] - arr[i][1] != b1 or arr[i][1] - arr[i][2] != b2 or arr[1][i] - arr[0][i] != a1 or arr[2][i] - \
                arr[1][i] != a2:
            print("No")
            return
    print("Yes")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>

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

  int sum = 0;
  int max = 0;
  for (int i = 0; i < N; ++i) {
    int L;
    scanf("%d", &L);
    sum += L;
    max = std::max(max, L);
  }
  if (max < sum-max) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
    int  N;
    int sen;


    scanf("%d",&N);

    sen=(int )N/1000;

    if(N%1000==0){
        printf("%d",1000*(sen)-N);
    }else{
        printf("%d",1000*(sen+1)-N);
    }




    return 0 ;

}

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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2){
			cout<<"first"<<endl;
			return 0;
		}
	}
	cout<<"second"<<endl;

	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int days[12]={31,60,91,121,152,182,213,244,274,305,335,366};
  int m,d,total;
  char a[7][10] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
  while(1){
    scanf("%d %d",&m,&d);
    total = 0;
    if(m==0 && d==0) break;
    if(m != 1){
      total += days[m-2];
    }
    total += d;
    while(total > 7){
      total = total - 7;
    }
    printf("%s\n",a[total-1]);
  }
  return 0;
}
    

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define ill long long
#define rep(i, a, b) for(ill i = (ill)(a); i < (ill)(b); i++)
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(b-a == c-b) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 3636
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void) {

    int N; cin>>N;
    int maximum=0;
    map<string, int> mp;
    for (int i = 0; i < N; ++i) {
        string tmp; cin>>tmp;
        if(!mp.count(tmp)){
            mp[tmp] = 1;
            maximum = max(maximum,1);
        }else{
            mp[tmp]++;
            maximum = max(maximum,mp[tmp]);
        }
    }

    for (auto i:mp) {
        if(i.second == maximum) cout<<i.first<<endl;
    }

}

Measured memory_bytes: 26752
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
using namespace std;
int ans[2020];
int n,x,y;
int main()
{
    cin>>n>>x>>y;
    for(int  i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            ans[min(i-j,abs(x-j)+abs(y-i)+1)]++;
        }
    }
    for(int i=1;i<=n-1;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
N = int(input())
count = 0
flg = 0
for i in range(N):
  D = list(map(int, input().split()))
  if D[0] == D[1]:
    count += 1
    if count >= 3:
      flg = 1
      break
  else:
    count = 0
    
if flg:
  print('Yes')
else:
  print('No') 
  

Measured memory_bytes: 62332
#include <bits/stdc++.h>
using namespace std;
void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 + 10;
int n, a; long long res; map<int, int> c;
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i)
        read (a), res += c[i - a], ++c[i + a];
    return printf ("%lld\n", res), 0;
}


Measured memory_bytes: 20724
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int numSwitch = sc.nextInt();
		int numLight = sc.nextInt();
		int needSwitch[] = new int[numLight];
		for(int i = 0; i < numLight; i ++) {
			int tmp = sc.nextInt();
			for(int j = 0; j < tmp; j ++) {
				needSwitch[i] |= 1 << (sc.nextInt() - 1);
			}
		}
		long need[] = new long[numLight];
		for(int i = 0; i < numLight; i ++) {
			need[i] = sc.nextLong();
		}

		long ans = 0;
		for(int state = 0; state < Math.pow(2, numSwitch); state ++) {
			boolean ok = true;
			for(int i = 0; i < numLight; i ++) {
				if(Integer.bitCount(needSwitch[i] & state) % 2 != need[i]) {
					ok = false;
					break;
				}
			}
			if(ok) { ans ++; }
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.hh", "r", stdin);
	vector < map < string, pair < int, int > > > t;
	string str = "";

	while (getline (cin, str ) ){

		string classname = "";
		int am = 0;
		int pm = 0;

		stringstream ss(str);
		ss >> classname >> am >> pm;
		map <string, pair < int, int > > tt;
		tt.insert (make_pair (classname, make_pair (am, pm ) ) );
		t.push_back (tt);

	} // end loop

	for (int i = 0; i < t.size(); ++i){

		map<string, pair<int, int> >::iterator it = t[i].begin();

		for (; it != t[i].end(); ++it){

			string cn = (*it).first;
			int am = (*it).second.first;
			int pm = (*it).second.second;
			int sum = am + pm;
			int total = 200*am + 300*pm;

			cout << cn << ' ';
			cout << sum << ' ' << total << endl;
		} // end for
	} // end for	

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
    int p,q,r,ans;
    
    scanf("%d %d %d",&p,&q,&r);
    ans=q+p+r;
    if( q >=p && q >=r){ans-=q;}
    else if(p <=r && r >=q){ans-=r;}
    else{ans -=p;}
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(K)]

MOD = 998244353
class Mint:
    __slots__ = ('value')

    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

LR.sort(key=lambda x: x[1])
pl = pr = -1
LR2 = []
for l, r in LR:
    if LR2:
        pl, pr = LR2.pop()
        if l <= pl:
            LR2.append((l, r))
        elif l <= pr:
            LR2.append((pl, r))
        else:
            LR2.append((pl, pr))
            LR2.append((l, r))
    else:
        LR2.append((l, r))

dp = [Mint() for _ in range(N + 5)]
dp[1] += 1
dp[2] -= 1
for i in range(1, N):
    dp[i] += dp[i - 1]
    for l, r in LR2:
        nl = min(i + l, N + 1)
        nr = min(i + r, N + 1)
        dp[nl] += dp[i]
        dp[nr + 1] -= dp[i]
dp[N] += dp[N - 1]
print(dp[N])


Measured memory_bytes: 102092
// 5/13 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    rep(i, N) {
        int A;
        cin >> A;
        H -= A;
    }

    if (H <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for(int i = 0; i < N; i++){
        if(i == 0){
            ans *= K;
        }
        else{
            ans *= (K - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
// void deepu()
// {
// 	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// 	#ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// 	freopen("error.txt","w",stderr);
// 	#endif
// }

int main() 
{ 
	// deepu();
	lld a,b,k;
	cin>>a>>b>>k;
	if(k>=a)
		{
	    k=k-a;
	    a=0;}
	    else
	    {
	        a=a-k;
	        k=0;}

	  if(k>=b)
		{
	    k=k-b;
	    b=0;}
	    else
	    {
	        b=b-k;
	        k=0;}

	        cout<<a<<" "<<b;



 	return 0;
}



Measured memory_bytes: 256
const solve = (s) => {
  let w = []
  let wc = 0
  let b = []
  let bc = 0
  s.split("").map((c, i) => {
    if (c == ".") {
      wc++
    } else {
      bc++
    }
    w[i] = wc
    b[i] = bc
  })
  let r = []
  let res = s.length
  for (var i = 0; i < w.length; i++) {
    let bb = b[i - 1] || 0
    let ww = w[w.length - 1] - w[i]
    let rr = bb + ww
    res = Math.min(res, rr)
  }
  return res
}
const main = (input) => {
  const [n, s] = input.split("\n")
  return solve(s)
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}


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

int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll ans = (a * (ll)(b * 100 + 0.00001)) / 100;
    cout << ans << endl;

    return 0;
} 

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;


int main(){
  int n; cin >> n;
  bool s1 = false;
  bool s2 = false;
  bool s3 = true;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
    if(s1 == false && v[i] % 2 == 1){s1 = true;}
    if(s2 == false && v[i] % 2 == 0){s2 = true;}
    if(s3 == true && i > 0){
      if(v[i] != v[i-1]){s3 = false;}
    }
  }
  sort(v.begin(), v.end());
  if(s3){cout << v[0] << endl;}

  else{
    ll subst = v[0];
    while(v[1] != 0){
      for(int i = 1; i < n; i++){
        v[i] %= subst;
        if(v[i] != 0 && v[i] < subst){subst = v[i];}
      }
     sort(v.begin(), v.end()); 
    } 
    cout << subst << endl;
  }
}


Measured memory_bytes: 640
#
# agc025 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """15"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100000"""
        output = """10"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    ans = float('inf')
    for a in range(1, N):
        b = N - a
        A = str(a)
        B = str(b)
        t = 0
        for i in range(len(A)):
            t += int(A[i])
        for i in range(len(B)):
            t += int(B[i])
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16228
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;
ll MOD;

int n, m;
vector<int> eds[MAXN];
ll dp[MAXN];

void dfs1(int v, int p) {
	ll now = 1;
	for (int u: eds[v]) {
		if (u == p)
			continue;
		dfs1(u, v);
		now = (now * dp[u]) % MOD;
	}
	now = (now + 1) % MOD;
	dp[v] = now;
}

ll ans[MAXN];

void dfs2(int v, int p, ll up) {
	ll cur = up;
	for (int u: eds[v])
		if (u != p)
			cur = (cur * dp[u]) % MOD;
	ans[v] = cur;
	vector<ll> lb(eds[v].size());
	vector<ll> rb(eds[v].size());
	ll now = 1;
	for (int i = 0; i < eds[v].size(); ++i) {
		lb[i] = now;
		int u = eds[v][i];
		if (u == p)
			continue;
		now = (now * dp[u]) % MOD;
	}
	now = 1;
	for (int i = (int)eds[v].size() - 1; i >= 0; --i) {
		rb[i] = now;
		int u = eds[v][i];
		if (u == p)
			continue;
		now = (now * dp[u]) % MOD;
	}
	for (int i = 0; i < eds[v].size(); ++i) {
		int u = eds[v][i];
		if (u == p)
			continue;
		ll go = (up * lb[i]) % MOD * rb[i] % MOD;
		go = (go + 1) % MOD;
		dfs2(u, v, go);
	}
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> MOD;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	dfs1(0, -1);
	dfs2(0, -1, 1);
	for (int i = 0; i < n; ++i)
		cout << ans[i] << "\n";
	return 0;
}




Measured memory_bytes: 21120
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    int a=0;
    REP(i,4){
        if(S[i]=='+')a++;
        else a--;
    }
    cout<<a<<endl;
}

Measured memory_bytes: 256
s = input()
ans = 0
flag = 0
temp = 0
for i in range(len(s)):
    if s[i] == 'R':
        flag = 1
    else:
        flag = 0
    if flag:
        temp += 1
    else:
        temp = 0
    ans = max(ans, temp)

print(ans)


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

using namespace std;

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

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

    int n;

    cin >> n;

    long long ans = 0;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                int a = gcd(i, j);
                a = gcd(a, k);
                ans += a;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)

func main() {
	s.Split(bufio.ScanWords)
	n := nextInt(s)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(s)
	}

	q := partition(a, 0, n-1)
	for i := range a {
		if i == q {
			fmt.Printf("[%d] ", a[i])
			continue
		} else if i == len(a)-1 {
			fmt.Printf("%d\n", a[i])
			break
		}
		fmt.Printf("%d ", a[i])
	}
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func partition(A []int, p, r int) int {
	x, y, i := A[r], A[:r], p-1
	for j := p; j < len(y); j++ {
		if t := A[j]; t <= x {
			i++
			A[j] = A[i]
			A[i] = t
		}
	}
	A[r] = A[i+1]
	A[i+1] = x

	return i + 1
}



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

int main(){
	

	int t = 1;
//	cin >> t;
	while(t--){
		int n;
		cin >> n;
		if(n >= 400 && n < 600) cout << "8\n";
		if(n >= 600 && n < 800) cout << "7\n";
		if(n >= 800 && n < 1000) cout << "6\n";
		if(n >= 1000 && n < 1200) cout << "5\n";
		if(n >= 1200 && n < 1400) cout << "4\n";
		if(n >= 1400 && n < 1600) cout << "3\n";
		if(n >= 1600 && n < 1800) cout << "2\n";
		if(n >= 1800 && n < 2000) cout << "1\n";

	}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
const ll INF = 1e10;
int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int dp[n+1][m+1] = {0};
    rep(i,n+1)dp[i][0] = 0;
    rep(i,m+1)dp[0][i] = 0;
    rep(i,n){
        rep(j,m){
            if(s[i] == t[j])dp[i+1][j+1] = dp[i][j] + 1;
            else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }
    //rep(i,n+1)rep(j,m+1)cout << dp[i][j] << ((j < m)?" ":"\n");
    
    int x = n, y = m;
    string r;
    while(dp[x][y] != 0 && x > 0 && y > 0){
        //cout << x << " " << y << endl;
        if(dp[x][y] == dp[x-1][y-1] + 1 && dp[x-1][y] != dp[x][y] && dp[x][y-1] != dp[x][y]){
            r += s[x-1];
            //cout << s[x-1] << endl;
            x--; y--;
        }else {
            if(dp[x][y] == dp[x-1][y])x--;
            else y--;
        }
    }
    reverse(r.begin(), r.end());
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const lli mod = 1e9+7;
lli h, w;
char a[1001][1001];
lli memo[1001][1001];

lli dfs(lli x, lli y) {
  if (memo[y][x] >= 0) return memo[y][x];
  lli res = 0;
  if (a[y][x] == '.') res = (dfs(x+1, y) + dfs(x, y+1)) % mod;
  return memo[y][x] = res;
}

int main() {
  cin >> h >> w;
  read_n(a, h);
  for (lli i=0; i<h; ++i) fill(&memo[i][0], &memo[i][w], -1);
  memo[h-1][w-1] = 1;
  cout << dfs(0, 0) << '\n';
  return 0;
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, x, ans = 1, c;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> x;
	for(Int i=0; i<n; ++i){
		Int l; cin >> l;
		c += l;
		if(c <= x) ++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 500000
#define SENTINEL 2000000000
int L[(MAX/2)+2], R[(MAX/2)+2];
int cnt = 0;
void merge(int*,int,int,int,int);
void mergeSort(int*,int,int,int);
int main(){
  int *S;
  int n, i;
  scanf("%d",&n);
  if(n > MAX)
    exit(1);
  S = (int*)malloc(sizeof(int) * n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
    if(S[i] < 0 || S[i] > (SENTINEL/2))
      exit(1);
  }

  mergeSort(S,n,0,n);

  for(i = 0; i < n; i++){
    printf("%d",S[i]);
    if(i != n-1)
      printf(" ");
  }
  printf("\n%d\n",cnt);
  
  return 0;
}

void merge(int S[],int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int i,j,k;
  for(i = 0; i < n1; i++)
    L[i] = S[left+i];
  for(i = 0; i < n2; i++)
    R[i] = S[mid+i];
  L[n1] = R[n2] = SENTINEL;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    cnt++;
    if(L[i] <= R[j])
      S[k] = L[i++];
    else
      S[k] = R[j++];
  }
}

void mergeSort(int S[],int n, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(S,n,left,mid);
    mergeSort(S,n,mid,right);
    merge(S,n,left,mid,right);
  }
}




Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

//Union-Find Tree
class UnionFindTrees{
	public:
		//　_n : ノード数
		UnionFindTrees(int _n){
			n = _n;
			root = vector<int>(_n);
			tree_size = vector<int>(_n,1);
			rep(i,_n) root[i] = i;
		}
		//　xの根っこ（属する木）を見つける
		int find(int x){
			if(root[x]==x) return x;
			else return root[x]=find(root[x]);			
		}
		//　xとyの属する木が同じかどうか判定する
		bool same(int x, int y){
			return find(x)==find(y);
		}
		//　xとyの属する木を統合する
		void merge(int x, int y){
			if(same(x,y)) return;
			x = find(x);
			y = find(y);
			if(tree_size[x]<tree_size[y]) swap(x,y);			
			root[y] = x;
			tree_size[x] += tree_size[y];
			n--;			
		}
		//　xが属する木のサイズを出力する
		int get_tree_size(int x){
			return tree_size[find(x)];
		}
		//　木の数を出力する
		int get_forest_size(){return n;}
	private:
		vector<int> root;
		vector<int> tree_size;
		int n;
};

int main(void) {
	int n; cin >> n;
	vi x(n),y(n);
	rep(i,n) cin >> x[i] >> y[i];
	int ans = INF;
	rep(i,n)rep2(j,i+1,n){
		int p,q;
		p = x[i]-x[j];
		q = y[i]-y[j];
		UnionFindTrees uft(n);
		rep(ni,n)rep2(nj,ni+1,n){
			int dx,dy;
			dx = x[ni]-x[nj];
			dy = y[ni]-y[nj];
			if( (p==dx&&q==dy) || (-p==dx&&-q==dy) )
				uft.merge(ni,nj);
		}
		ans = min(ans,uft.get_forest_size());
	}
	if(n==1) ans = 1;
	cout << ans << endl;
}




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

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for(ll i = 1; i*i <= n; ++i){
    if(n%i!=0) continue;
    ll j = n/i;
    ans = min (ans, i+j-2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		int cnt = 0;
		while (a % 2 == 0) {
			cnt++;
			a /= 2;
		}
		ans += cnt;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = [input() for _ in range(h)]
right_limit = [0]*h
for j in range(w):
    if a[0][j] == "#":
        right_limit[0] = j

for i in range(1, h):
    for j in range(w):
        if right_limit[i-1] > j and a[i][j] == "#":
            print("Impossible")
            exit()
        if a[i][j] == "#":
            right_limit[i] = j
print("Possible")

Measured memory_bytes: 61796
#include <cstdio>
#include <algorithm>
using namespace std;

int dp[101][10001];

int main(){
    int N,W;
    int v[1001],w[1001];
    scanf("%d%d",&N,&W);
    for(int i = 0;i < N;i++){
        scanf("%d%d",v+i,w+i);
    }
    for(int i = 0;i <= W;i++){
        dp[0][i] = 0;
    }
    for(int i = 1;i <= N;i++){
        for(int j = 0;j <= W;j++){
            if(j - w[i-1] < 0){
                dp[i][j]  = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-w[i-1]] + v[i-1]);
            }
        }
    }
    printf("%d\n",dp[N][W]);

}


Measured memory_bytes: 6660
//Coded by tzc_wk
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
ÍüÎÄ¼þ²Ù×÷£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
map<string,bool> mp;
int n=read();
signed main(){
	int ans=0;
	while(n--){
		string s;cin>>s;
		if(!mp[s])	ans++;
		mp[s]=1;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int ans=0;
	int N,A,B;
	scanf("%d%d%d",&N,&A,&B);
	for(int i=0;i<N;i++){
		int T;
		scanf("%d",&T);
		if(T<A||T>=B)ans++;
	}
	printf("%d\n",ans);
	return 0;
	
}


Measured memory_bytes: 256
import itertools

# 引数のリストの全ての順列リストを返す
def fact_list(seq:list):
    return list(itertools.permutations(seq))


n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

x = fact_list(range(1, n+1))
a = 0
b = 0
for i, xi in enumerate(x):
    if list(xi) == P:
        a = i+1
    if list(xi) == Q:
        b = i+1
print(abs(a-b))

Measured memory_bytes: 8436
#define ll long long int
#include <bits/stdc++.h>
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff               first
#define ss               second
#define mp               make_pair
#define pb               push_back
#define pf               push_front
#define vi               vector<ll>
#define pii              pair<ll,ll>
#define qi               queue<ll>
#define mem(a,b)         memset(a,b,sizeof(a))
#define print(a)         cout<<a<<'\n'
#define sorted(arr)      sort(arr.begin(),arr.end())
#define gcd(a,b)         gcd((a),(b))
#define lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define all(v)           v.begin(),v.end()
#define read(a)          scanf("%d", &a)
#define f(a,n)           for(ll i=a;i<n;i++)
#define in(a,n,arr)      for(ll i=a;i<n;i++)cin>>arr[i];
#define in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define debug(a)         cerr<<a<<" ";
#define debug1(a)        cerr<<a<<'\n'

const unsigned ll mod= (ll)1e9 + 7;
const ll inf = (ll)1e18 + 42;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin >> t;
    while(t --)
    {
        string s;
        cin >> s;
        ll k;
        cin >> k;
        ll f = 0 , ans = 0 , h = 0;
        ll j = 1 , count = 1;
        while(s[j] == s[j-1] && j < s.size())
            count ++ , j ++;
        //fill(arr,arr+s.size(),0);
        /*string str = s;
        for(ll i = 0;i<k-1;i++)str += s;
        ll ans1 = 0;
        for(ll i=0;i<str.size();i++)
        {
           if(str[i] == str[i-1])
            {
                str[i] = '#';
                if( i == str.size() - 1)
                    h = 1;
                ans1 ++;
            }
        }
        cout<<ans1<<'\n';*/
        for(ll i=1;i<s.size();i++)
        {
            if(s[i] == s[i-1])
            {
                s[i] = '#';
                if( i == s.size() - 1)
                    h = 1;
                ans ++;
            }
            else
                f = 0;
        }
        
        
        //cout << count <<'\n';
        if(count == s.size())
        {
            ll oo = s.size() * k ;
            oo /= 2;
            cout << oo <<'\n';
            return 0;
        }
        ll temp = 0;
        if(s[0] == s[s.size() - 1 ])
        {if(h == 0 && count&1)temp = k - 1;}
        print((ans * k)+temp);
    }
    /*
     aaaaaaaaa
     ababababa
      */
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
          ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    string s;
    cin >> s;
    ll now = 0;
    char prev;
    prev = s[now];
    ll ans = 1;
    now++;
    while(now < s.length()){
//        cout << now <<" ";
        if(s[now] == prev){
            now += 1;
            prev = {};
        }else{
            prev = s[now];
        }
        ans++;
        now++;
        if(now == s.length()+1){
            ans--;
        }
//        cout << ans << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc164D
    {
        public static void Main()
        {
            var s = Console.ReadLine().Select(i => i - '0').ToArray();
            var n = s.Length;
            long r = 0;
            long d = 1;
            var count = new long[2019];
            for (int i = 1; i <= n; i++)
            {
                r = (d * s[n - i] + r) % 2019;
                count[r]++;
                d = d * 10 % 2019;
            }
            var ans = count[0];
            for (int i = 0; i < 2019; i++)
                ans += count[i] * (count[i] - 1) / 2;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 20320
def list_add(li1, li2):
    return list(map(sum, zip(li1, li2)))


def dfs(price, knowledge, depth):
    if (min(knowledge) >= X):
        ansList.append(price)
    if depth == N:
        return
    dfs(price, knowledge, depth + 1)
    dfs(price+priceList[depth], list_add(KnowList[depth], knowledge), depth+1)


N, M, X = map(int, input().split(" "))
KnowList = [[] for i in range(N)]
priceList = [0] * N
for i in range(N):
    tmp = [int(i) for i in input().split(" ")]
    priceList[i] = tmp[0]
    KnowList[i] = tmp[1:]
price = 0
ansList = []
knowledge = [0] * M
dfs(price, knowledge, 0)
if (len(ansList) == 0):
    ansList.append(-1)
print(min(ansList))

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

using namespace std;

bool erased[1000];

using Weight=long long;
struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

pair<Weight,int>sweep(int p,int v,const Graph &g){
    pair<Weight,int> r(0,v);
    for(auto e:g[v]){
        if(e.dst!=p && !erased[e.dst]){
            pair<Weight,int> t=sweep(v,e.dst,g);
            t.first+=e.weight;
            if(r.first<t.first)r=t;
        }
    }
    return r;
}

Weight double_sweep(const Graph &g,int s){
    pair<Weight,int> r=sweep(-1,s,g);
    pair<Weight,int> t=sweep(-1,r.second,g);
    return t.first;// (r.second, t.second) is farthest pair.
}

int main(){
    int n;
    while(cin>>n,n){
        for(int i=0;i<1000;++i)erased[i]=false;
        vector<int>p(n),d(n);
        Weight ans=0;
        for(int i=1;i<n;++i){
            cin>>p[i];
            --p[i];
        }
        for(int i=1;i<n;++i){
            cin>>d[i];
        }
        Graph g(n);
        for(int i=1;i<n;++i){
            g[i].emplace_back(i,p[i],d[i]);
            g[p[i]].emplace_back(p[i],i,d[i]);
            ans+=3*d[i];
        }
        int start;
        for(int i=0;i<n;++i){
            if(g[i].size()==1){
                ans-=2*g[i][0].weight;
                erased[i]=true;
            }
            else start=i;
        }
        ans-=double_sweep(g,start);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3240
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


							  //変数
string s;






//サブ関数
//入力
void input()
{
	cin >> s;
}


//計算
void calc()
{
	int N = s.size();

	// rightest one find
	if (s.back() == '1' || s.front() == '0') {
		cout << -1 << endl;
		return;
	}
	REP(i, N / 2 + 1)if (s[i] != s[N - 2 - i]) {
		cout << -1 << endl;
		return;
	}
	cout << "1 2" << endl;

	int id = 2;
	FOR(i, 1, N-1) {
		if (s[i] == '0') {
			cout << id << " " << i + 2 << endl;
		}
		else {
			cout << id << " " << i + 2 << endl;
			id = i + 2;
		}
	}
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin >> N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;cin>>n;
	vector<ll> x(n+10),lo(n+10);
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=1;i<n;i++){
		lo[i]=x[i]-x[i-1];
	}
	int m;ll k;cin>>m>>k;
	vector<vector<int>> v(70,vector<int>(n+10));
	for(int i=1;i<n;i++)v[0][i]=i;
	for(int i=0;i<m;i++){
		int a;cin>>a;
        swap(v[0][a],v[0][a-1]);

	}
	for(int i=0;i<=60;i++){
		for(int j=1;j<n;j++){
			v[i+1][j]=v[i][v[i][j]];
		}
	}
	vector<int> s(n);
    for(int i=1;i<n;i++)s[i]=i;
	for(ll i=0;i<=61;i++){
        if(k&(1LL<<i)){
            for(int j=1;j<n;j++){
                s[j]=v[i][s[j]];
            }
        }
    }
	vector<ll> ans(n);
	ans[0]=x[0];
	for(int i=1;i<n;i++){
		ans[i]=ans[i-1]+lo[s[i]];
	}
	assert(ans[n-1]==x[n-1]);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
}


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

i = a// x
j = b// x
p = i* x
q = j* x
while i* x < a:
  i+= 1
  p = i* x
while j* x < b:
  j+= 1
  q = (j- 1)* x

ans = int((q- p)// x)+ 1

if(ans<= 0):
  print(0)
else:
  print(ans)

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

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>


using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod


int n, m;
vector<vector<int>> g(1000000 + 6), rg(1000000 + 6);
vector<int> vs;
bool visited[1000000 + 6];
int cmp[1000000 + 6];

void add_edge(int from , int to) {
    g[from].push_back(to);
    rg[to].push_back(from);
}

void dfs(int now) {
    visited[now] = true;
    for (auto nx : g[now]) {
        if (!visited[nx]) {
            dfs(nx);
        }
    }
    vs.push_back(now);
    return; 
}

void rdfs(int now, int cnt) {
    visited[now] = true;
    cmp[now] = cnt;
    for (auto nx : rg[now]) {
        if (!visited[nx]) {
            rdfs(nx, cnt);
        }
    }
    return;
}

int scc(int n) {
    fill(visited, visited + n, false);
    vs.clear();
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(i);
        }
    }

    fill(visited, visited + n, false);
    int cnt = 0;
    vector<int> comp(n, -1);
    for (int i = vs.size() - 1; i >= 0; i--) {
        if (!visited[vs[i]]) {
            rdfs(vs[i], cnt++);
        }
    }
    return cnt;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> m;
    rep(i, m) {
        int s, t;
        cin >> s >> t;
        add_edge(s, t);
    }

    int cnt = scc(n);

    int q;
    cin >> q;
    rep(i, q) {
        int u, v;
        cin >> u >> v;
        cout << (cmp[u] == cmp[v] ? '1' : '0') << endl; 
    }
}

Measured memory_bytes: 51272
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

h1,m1,h2,m2,k=map(int,input().split())


print(((h2-h1)*60+(m2-m1))-k)

Measured memory_bytes: 9176
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		String T = scan.next();
		String X = scan.next();

		System.out.println(X+T);
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const int mod = 1e9 +7;
int N, M, Q, K;
int cnt[MAX];
int A[MAX];
int main()
{
    int i, j, k, num;
    scanf("%d", &N);
    for(i = 1; i<= N; ++i) scanf("%d", &A[i]);
    int maxi1, maxi2, maxnum1, maxnum2;
    maxi1 = maxi2 = 0;
    for(i = 1; i<= N; i += 2){
        cnt[A[i]]++;
        if(maxi1 < cnt[A[i]]){
            maxi1 = cnt[A[i]];
            maxnum1 = A[i];
        }
    }
    memset(cnt, 0, sizeof(cnt));
    for(i = 2; i<= N; i += 2){
        cnt[A[i]]++;
        if(maxi2 < cnt[A[i]] && maxnum1 != A[i]){
            maxi2 = cnt[A[i]];
            maxnum2 = A[i];
        }
    }

    int res1 = N/2 - maxi1 + N/2 - maxi2;

    memset(cnt, 0, sizeof(cnt));
    maxi1 = maxi2 = 0;
    for(i = 2; i<= N; i += 2){
        cnt[A[i]]++;
        if(maxi1 < cnt[A[i]]){
            maxi1 = cnt[A[i]];
            maxnum1 = A[i];
        }
    }
    memset(cnt, 0, sizeof(cnt));
    for(i = 1; i<= N; i += 2){
        cnt[A[i]]++;
        if(maxi2 < cnt[A[i]] && maxnum1 != A[i]){
            maxi2 = cnt[A[i]];
            maxnum2 = A[i];
        }
    }

    int res2 = N/2 - maxi1 + N/2 - maxi2;

    printf("%d", min(res1, res2));
}


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

int main(){
  bool f = true;
  int N, m = 0, ans = 0;
  cin >> N;
  vector<int> s(N);
  for (int i = 0; i < N; i++){
    cin >> s[i];
  }
  
  sort(s.begin(), s.end());
    
  for (int i = 0; i < N; i++){
    if (s[i] % 10 != 0 && f){
      f = false;
      m = s[i];
    }
    ans += s[i];
  }
  if (ans % 10 == 0){
    if (f) {
      cout << 0 << endl;
    }else{
    cout << ans - m << endl;
    }
  }else{
    cout << ans << endl;
  }
}

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

using namespace std;

int main(){
	long long n;
	scanf("%lld", &n);
	long long ans = 0;
	long long cur = 1;
	while (n > 0LL){
		ans += cur;
		cur <<= 1;
		n >>= 1;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    int i = 1;
    bool ans = true;
    while(ans){
        int a;
        cin >> a;
        if(a != 0){
            cout <<"Case "<< i <<": "<< a << endl;
        }if(a == 0){
            ans = false;
        }
        i++;
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair

int main(){
   int i,j;
   int n,x;
   cin>>n>>x;
   int a[n];
   for(i=0;i<n;i++)
   	  cin>>a[i];
   	sort(a,a+n);
   	int ans=0;
   	for(i=0;i<n;i++)
   		if(x>=a[i])
   			{ans++;
   				x=x-a[i];

   			}
   			else
   				break;
   			if(i==n&&x>0)
   				ans--;

    cout<<ans<<endl;



	return 0;
}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if((A+B)>(C+D)){
        cout << "Left";
    }
    else if((A+B)<(C+D)){
        cout << "Right";
    }
    else{
        cout << "Balanced";
    }
    return 0;
}

Measured memory_bytes: 256
e = 0
s = 0
n = int(input())
a = list(map(int,input().split()))

for i in range(n): 
    s += a[i]
    if i % 2 == 1:
        e += a[i]

b = []
for i in range(n):
    if (i == 0):
        b.append(s-2*e)
    else:
        b.append(2*a[i-1]-b[i-1])

print(" ".join(map(str,b)))

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

int main(){
	int  n;
	while(cin >> n, n){
		int ans = 0;
		long long m = 5;
		while(m <= n){
			ans += n/m;
			m *= 5;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3056