akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],dp[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	printf("%d\n",dp[n]);
	return 0;
}


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

char board[2020][2020];
int dp_h[2020][2020] = {0};
int dp_w[2020][2020] = {0};

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h,w;
    cin >> h >> w;
    

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> board[i][j];
        }
    }
    
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(board[i][j] == '.'){
                if(dp_w[i][j-1] == 0) dp_w[i][j] = 1;
                else dp_w[i][j] = dp_w[i][j-1] + 1;
            } else {
                dp_w[i][j] = 0;
            }
        }
    }
    
    for(int i = 1; i <= w; i++){
        for(int j = 1; j <= h; j++){
            if(board[j][i] == '.'){
                if(dp_h[j-1][i] == 0) dp_h[j][i] = 1;
                else dp_h[j][i] = dp_h[j-1][i] + 1;
            } else {
                dp_h[j][i] = 0;
            }
        }
    }
    
    for(int i = 1; i <= h; i++){
        for(int j = w - 1; j >= 1; j--){
            if(dp_w[i][j]) dp_w[i][j] = max(dp_w[i][j], dp_w[i][j+1]);
        }
    }
    
    for(int i = 1; i <= w; i++){
        for(int j = h - 1; j >= 1; j--){
            if(dp_h[j][i]) dp_h[j][i] = max(dp_h[j][i], dp_h[j+1][i]);
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            ans = max(ans,dp_w[i][j] + dp_h[i][j] - 1);
        }
    }
    cout << ans << endl;
}
 



Measured memory_bytes: 36096
/*BINH :))*/
#include<bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(cc,a,b) for (int cc=a,x,y,z;cc<=b;cc++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL cout<<endl
#define maxn 1005
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#pragma GCC optimize("Ofast")
ll n,m,f[101][100001],w[3000],v[3000];
int main(){
    IO
    cin>>n>>m;
    FOR(i,1,n){
        cin>>w[i]>>v[i];
    }
    FOR(i,1,n){
        FOR(j,1,m){
            int k = j - w[i];
            if(k<0) f[i][j] = f[i-1][j];
            else f[i][j] = max(f[i-1][j], v[i] + f[i-1][k]);
        }
    }
    cout<<f[n][m];
}
    

Measured memory_bytes: 78464
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
        
    vector<int>v(3);

    repa(i,0,2)
        cin>>v[i];

    sort(all(v));
    int ans = v[0]*v[1];
    ans/=2;
    cout<<ans<<endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
struct SegmentTree {
private:
  int N, uni = 0;vector<int>  node;
public:
  SegmentTree(){}
  int look(int x, int y){
    return max(x,y);
  }
  void init(vector<int> v){
    int sz = v.size();
    N = 1;while(N < sz)N *= 2;
    node.resize(2*N-1, uni);

    rep(i,sz)node[i+N-1] = v[i];//最下段に値を入れる
    for(int i=N-2;i >= 0;i--)node[i] = look(node[2*i+1], node[2*i+2]);//上げていく
  }
  void update(int x, int val){
    x += (N-1);//最下段へ
    node[x] += val;
    while(x > 0){//上げていく
      x = (x-1)/2;
      node[x] = look(node[2*x+1], node[2*x+2]);
    }
  }
  int get(int a, int b, int k=0, int l=0, int r=-1){
    if(r < 0)r = N;
    if(r <= a || b <= l)return uni;
    if(a <= l && r <= b)return node[k];
    int vl = get(a, b, 2*k+1, l, (l+r)/2);
    int vr = get(a, b, 2*k+2, (l+r)/2, r);
    return look(vl, vr);
  }
};

////////////////////////////////////////////////////////////////////

int n,h[210000],a[210000];
SegmentTree s;
signed main(){
  cin>>n;
  rep(i,n)cin>>h[i];rep(i,n)cin>>a[i];
  s.init(vector<int>(n));
  rep(i,n)h[i]--;
  rep(i,n){
    s.update(h[i], s.get(0,h[i]) + a[i]);
  }
  cout << s.get(0, n) << endl;
}


Measured memory_bytes: 9088
#B - たてなが
H,W = map(int,input().split())
C = []
for _ in range(H):
    Ci = input()
    C.append(Ci)

C_ans = []
for j in range(H):
    C_ans.append(C[j])
    C_ans.append(C[j])

for k in C_ans:
    print(''.join(k))

Measured memory_bytes: 9128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

const int mod = 1000000007;

//エラトステネスの篩
const int N = 1010;
vector<bool> prime(N, true);
void Eratosthenes() {
	prime[0] = false;
	prime[1] = false;
	rep(i, N)
		if (prime[i])
			for (int j = i * 2; j < N; j += i)
				prime[j] = false;
}

int cnt(int n, int p) {
	VI a;
	for (int i = p; i <= n; i *= p)a.pb(i);

	int re = 0;
	rep(i, sz(a)) {
		re += n / a[i] % mod;
		//cout << n << "/" << a[i] << endl;
	}
	//cout << p << " " << re << endl;
	return re;
}


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

	LL ans = 1;
	rep(i, 1005) {
		if (prime[i] && i <= n) {
			ans = (1 + cnt(n, i))*ans%mod;
			//cout << i << " : " << cnt(n, i) << endl;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 300100;

ll T,N,a,b,c,d,e,f,K,M;
ll A[MAXN];

int main(){
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<' '<<b<<' '<<c;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int M = 81*81*2;
int main(void){
    int H, W;
    int A[81][81],B[81][81];
    cin >> H >> W;
    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
        }
    }
    rep(i,H){
        rep(j,W){
            cin >> B[i][j];
        }
    }
    
    bool dp[80][80][81*81*2+1];
    rep(i,H){
        rep(j,W){
            rep(k,81){
                dp[i][j][k] = false;
            }
        }
    }
    dp[0][0][abs(A[0][0]-B[0][0])] = true;
    rep(i,H){
        rep(j,W){
            rep(k,M){
                if(dp[i][j][k]){
                    if(j<W-1){
                        if(k+abs(A[i][j+1]-B[i][j+1]) < M)
                        dp[i][j+1][k+abs(A[i][j+1]-B[i][j+1])] = true;
                        if(abs(k-abs(A[i][j+1]-B[i][j+1])) < M)
                        dp[i][j+1][abs(k-abs(A[i][j+1]-B[i][j+1]))] = true;
                    }
                    
                    if(i<H-1){
                        if(k+abs(A[i+1][j]-B[i+1][j]) < M)
                        dp[i+1][j][k+abs(A[i+1][j]-B[i+1][j])] = true;
                        if(abs(k-abs(A[i+1][j]-B[i+1][j])) < M)
                        dp[i+1][j][abs(k-abs(A[i+1][j]-B[i+1][j]))] = true;
                    }
                }
            }
        }
    }
    int min = 100;
    rep(i,M){
        if(dp[H-1][W-1][i]) {
            min = i;
            break;
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;

int main() {

	int N;
	cin >> N;
	map<string, int> memo;

	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;

		memo[str] += 1;


	}
	int max = 0;
	for (auto i = memo.begin(); i != memo.end(); i++) {
		if (max < i->second) {
			max = i->second;
		}

	}
	for (auto i = memo.begin(); i != memo.end(); i++) {
		if (max == i->second) {
			cout << i->first << endl;
		}

	}

	return 0;

}

Measured memory_bytes: 25216
/* Author : Pranav Deshmukh
            PICT,Pune
   Purpose: Practice B Codeforces Round #653 (Div. 3)
*/

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int             long long
#define dip(type,var)   type var; cin>>var;
#define dipi(x)			int x; cin>>x;
#define w(x)            int x; cin>>x; while(x--)
#define mka(arr,n,type) type *arr=new type[n];
#define foi(i,n)		for(int i=0;i<n;i++)
#define mod             pow(10,9)+7
#define inf             1e18
#define endl			"\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	dipi(s);
	dipi(w);
	if (w>=s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}

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

signed main(){
	string S; cin>>S;
	int ans=100000;
	for(int i=0;i<S.size()-2;i++){
		int X=stoi(S.substr(i,3));
		ans=min(ans,abs(X-753));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, a, tmp_min = 1000001, tmp_max = -1000001;
    long sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += a;
        tmp_min = min(tmp_min, a);
        tmp_max = max(tmp_max, a);
    }
    cout << tmp_min << " " << tmp_max << " " << sum << endl;
    return 0;
}


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

const long long mod=1000000007;
int du[1010];

struct EE
{
    int to,ne;
}e[10010];
int L,head[1010];
void adde(int u,int v)
{
    e[L].to=v;
    e[L].ne=head[u];
    head[u]=L++;
}
long long dp[1010][2];
bool vis[1010];
long long ans;
bool dfs(int u,int fa,int root)
{
    bool fg=false;
    dp[u][0]=dp[u][1]=1;
    vis[u]=true;
    for (int i=head[u];i!=-1;i=e[i].ne)
    {
        int v=e[i].to;
        if (v==root) {
            fg=true;
            continue;
        }
        if (v==fa) continue;
        if (!vis[v])
        {
            if (dfs(v,u,root))
            {
                dp[u][0]=dp[u][0]*dp[v][0]%mod;
                dp[u][1]=dp[u][1]*dp[v][1]%mod;
                fg=true;
            }
            else
            {
                dp[u][1]=dp[u][1]*(dp[v][0]+dp[v][1])%mod;
                dp[u][0]=dp[u][0]*dp[v][0]%mod;
            }
        }
        else
        {
            dp[u][1]=dp[u][1]*(dp[v][0]+dp[v][1])%mod;
            dp[u][0]=dp[u][0]*dp[v][0]%mod;
        }
    }
    if (u==root && du[u]==0) ans=ans*(dp[u][0]+dp[u][1])%mod;
    if (fg && u==root) ans=ans*(dp[u][0]+dp[u][1])%mod;
    return fg;
}
int main()
{
    int n,m;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        L=0;
        for (int i=1;i<=n;i++)
        {
            du[i]=0;
            head[i]=-1;
            vis[i]=false;
        }
        for (int i=1;i<=m;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            adde(v,u);
            du[u]++;
        }
        ans=1;
        for (int i=1;i<=n;i++)
        if (!vis[i])
        {
            dfs(i,-1,i);
          //  cout<<ans<<endl;
        }
        for (int i=1;i<=5;i++)
        {
         //    cout<<i<<" "<<dp[i][0]<<' '<<dp[i][1]<<endl;
        }
        printf("%d\n",(int)ans);
    }
}
/*
5 5
1 2
2 3
3 4
4 2
5 4
*/

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	string d1="maerd",d2="remaerd",e1="esare",e2="resare";
	reverse(s.begin(),s.end());
	int n=s.size();
	rep(i,n){
		if(i+6<n && s.substr(i,7)==d2){
			i+=6;
		}
		else if(i+5<n && s.substr(i,6)==e2){
			i+=5;
		}
		else if(i+4<n && (s.substr(i,5)==d1 || s.substr(i,5)==e1)){
			i+=4;
		}
		else{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 512
S=input()

count=0     #R
now="R"
idx=[[],[]]

def goukei(left,right):
    l=0
    r=0
    if left%2==0:
        l+=int(left/2)
        r+=int(left/2)
    else:
        l+=int(left/2)+1
        r+=int(left/2)
    if right%2==0:
        l+=int(right/2)
        r+=int(right/2)
    else:
        l+=int(right/2)
        r+=int(right/2)+1
    return l,r

for i in range(len(S)-1):
    s_left=S[i]
    s_right=S[i+1]
    if s_left=="R" and s_right=="L":
        idx[0].extend([i,i+1])
        left=i-count+1
        count=i+1   #L

        if i==len(S)-2:
            right=i+1-count+1
            l,r=goukei(left, right)
            idx[1].extend([l,r])


    elif s_left=="L" and s_right=="R":
        right=i-count+1
        count=i+1   #R

        l,r=goukei(left, right)
        idx[1].extend([l,r])

    elif i==len(S)-2:
        right=i+1-count+1
        l,r=goukei(left, right)
        idx[1].extend([l,r])

ans=["0" for i in range(len(S))]
for i,j in zip(idx[0],idx[1]):
    ans[i]=str(j)
print(" ".join(ans))

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

#define INDEXED_SET 0

#if INDEXED_SET
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using indexed_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
//find_by_order(i) - iterator to i-th element
//order_of_key(x) - x's index in the set
#endif

#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define leading_0s(x) __builtin_clz(x)  //left 0s
#define trailing_0s(x) __builtin_ctz(x) //right 0s
#define count_1s(x) __builtin_popcount(x)
#define parity_1s(x) __builtin_parity(x) // 0 = even, 1 = odd
#define FORI(i,a,b) for (int i = int((a)); i <= int((b)); i++)
#define FORD(i,a,b) for (int i = int((a)); i >= int((b)); i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define endl '\n'
#define MAX 200005

using ll = long long;
using pi = pair<int,int>;
using pll = pair<long,long>;
using vi = vector<int>;
using vll = vector<ll>;
using vpi = vector<pi>;
using vpll = vector<pll>;

const int mod = 1e9 + 7;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    FAST_IO;

    string s;
    cin >> s;
    map<char,int> f;
    FORI(i,0,3) {
        f[s[i]]++;
    }
    if (f.size() != 2) {
        cout << "No" << endl;
    } else {
        for (auto e:f) {
            if (e.S != 2) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}

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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-7;
// const ld PI = acos(-1.0);

const int N = 1e6 + 66;

int _div (ll x) {
	int res = 0;
	for (ll i = 1 ; i * i <= x ; ++ i) {
		if (x % i == 0) {
			res++;
			res += i * i != x;
		}
	}
	return res;
}

bool okay (ll x, ll y) {
	while (y % x == 0) y /= x;
	y %= x;
	// cout << x << " " << y << "\n";
	// if (y == 1) cout << x << " is okay\n";
	return y == 1;
}

void solve () {
	ll n;
	cin >> n;
	ll res = _div (n - 1) - 1; // because of 1
	for (ll i = 1 ; i * i <= n ; ++ i) {
		if (n % i == 0) {
			if (i != 1)
				res += okay (i, n);
			if (i * i != n)
				res += okay (n / i, n);
		}
	}
	cout << res;
}

int main () {
	ios;
	// double start_time = clock();
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
	// cerr << (clock() - start_time) / CLOCKS_PER_SEC;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int x = 111;
    while (n > x)
    {
        x += 111;
    }
    cout << x << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD = 1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,x[100000],y[100000],xsum = 0,ysum = 0;
	cin >> n >> m;
	for(int i = 0;i < n;i++) {
		cin >> x[i];
		if(i) x[i - 1] = x[i] - x[i - 1];
	}
	for(int j = 0;j < m;j++) {
		cin >> y[j];
		if(j) y[j - 1] = y[j] - y[j - 1];
	}
	int now = n - 1,d = n - 3;
	for(int i = 0;i < n - 1;i++){
		xsum = (xsum + x[i] * now % MOD) % MOD;
		now += d;
		d -= 2;
	}
	now = m - 1;
	d = m - 3;
	for(int i = 0;i < m - 1;i++){
		ysum = (ysum + y[i] * now % MOD) % MOD;
		now += d;
		d -= 2;
	}
	cout << xsum * ysum % MOD << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    int f[10][10];
    int h, w;
    cin>>h>>w;
    for (int i=0; i<10; i++) {
        for (int j=0; j<10; j++) {
            cin>>f[i][j];
        }
    }
    for (int k=0; k<10; k++) {
        for (int i=0; i<10; i++) {
            for (int j=0; j<10; j++) {
                if (f[i][k] + f[k][j] < f[i][j]) {
                    f[i][j] = f[i][k] + f[k][j];
                }
            }
        }
    }
    int sum = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            int a;
            cin>>a;
            if (a > -1) sum += f[a][1];
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9003372036854775807LL
#define mod 1000000007
#define fixed fixed<<setprecision(12)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii=pair<int, int > ;
lol a[300010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  lol n,m,k,r,x,y;
  cin >>n>>k;
  lol sum1=0;
  for(int i=1;i<k;i++) sum1+=i;
  lol sum2=0;
  for(int i=n;i>n-k;i--) sum2+=i;
  lol ans=sum2-sum1+1;
  for(int i=k;i<=n;i++){
    sum1+=i;
    sum2+=n-i;
    sum1%=mod;
    sum2%=mod;
    ans+=sum2-sum1+1;
    ans%=mod;
  }
  while(ans<0) ans+=mod;
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 3640
import math

n = int(input())
x=[0]*n
y=[0]*n
sum = 0.0

for i in range(n):
    x[i],y[i] = map(int, input().split())

for i in range(n):
    for j in range(n):
        sum += math.sqrt(pow((x[i]-x[j]),2) + pow((y[i]-y[j]),2))
        #print(x[i],y[i],x[j],y[j],sum)
print(sum/n)

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> coin(m);
    int max = 0;
    for(int i = 0; i < m; i++){
        cin >> coin[i];
    }
    sort(coin.begin(), coin.end());

    vector<unsigned int> coin_nums(n+1, -1);
    coin_nums[0] = 0;
    unsigned int min;

    for(int i = max+1; i <= n; i++){
        min = -1;
        for(int j = 0; j < m && coin[j] <= i; j++){
            if(min > coin_nums[i-coin[j]]) min = coin_nums[i-coin[j]];
        }
        coin_nums[i] = min+1;
    }
    
    cout << coin_nums[n] << endl;
    return 0;
}

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

ll count(ll H){
	ll res = 0;
	while(H > 1){
		H /= 2;
		res++;
	}
	
	return res;
	
}

//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x;
		x = x*x;
		n  = n >> 1;
	}
	return ans;
}


int main(){
	ll H;
	cin >> H;
	
	ll val = count(H);
	
	
	cout << mpow(2,val+1) - 1 << endl;
	
    return 0;
}



Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[51],ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=k;++i) ans+=a[n-i+1];
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC";
    } else if (r < 2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] arg) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] arr = line.split(" ");
		int first = 0;
		int sec = 0;
		//System.out.println(Arrays.toString(arr));
		Stack<Integer> st = new Stack<Integer>();
		for(int i = 0; i < arr.length; i++) {
			try {
				st.push(Integer.parseInt(arr[i]));
			}
			catch(Exception e){
				if(arr[i].equals("+")) {
					sec = st.pop();
					first = st.pop();
					st.push(first + sec);
				}
				else if(arr[i].equals("-")) {
					sec = st.pop();
					first = st.pop();
					st.push(first - sec);
				}
				else if(arr[i].equals("*")) {
					sec = st.pop();
					first = st.pop();
					st.push(first * sec);
				}
			}
		}
		if(arr[arr.length-1].equals("+")) {
			System.out.println(first+sec);
		}
		else if(arr[arr.length-1].equals("-")) {
			System.out.println(first-sec);
		}
		else if(arr[arr.length-1].equals("*")) {
			System.out.println(first*sec);
		}
	}
}



Measured memory_bytes: 26164
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
    I = i*500
    if X<i*500:
        break
        
    for j in range(B+1):
        J =I + j*100
        if X<J:
            break
        if X<=J + C*50:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
import { readFileSync } from 'fs'
function main() {
  const input = readFileSync('/dev/stdin', 'utf8')
  const [n, a, b, c] = input.trim().split('\n').map(v => v.trim().split(' ').map(string => parseInt(string))) 
  let result = 0  
  for (let i = 0; i < a.length; i++) {
    const number = a[i] - 1
    result += b[number]
    if (number !== a.length && i + 1 !== a.length && a[i] + 1 === a[i + 1]) {
      result += c[number]
    }
  }
  console.log(result)
}
main()

Measured memory_bytes: 7372
import math
time = [int(input()) for _ in range(5)]
bad = 9
def swap(i):
  time[i],time[-1] = time[-1],time[i]
for i in time:
  if i % 10 == 0:
    continue
  else:
    if bad % 10 > i % 10:
      bad = i
if bad in time:
  index = time.index(bad)
  swap(index)
for i in range(4):
  if time[i] % 10 != 0:
    time[i] = time[i] + (10 - time[i] % 10)
print(sum(time))

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  unsigned long long A;
  double B;
  cin>>A>>B;
  unsigned long long C=B*100+0.000001;
  cout<<A*C/100LL<<endl;
  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	int h, a;
	cin >> h >> a;
	if(h%a == 0)cout << h/a << endl;
	else cout << h/a + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define INF (0x3f3f3f3f)
#define Mod (1000000007)
using namespace std;
typedef long long LL;

template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; }
template <typename T> inline bool chkmin(T &a , T b) { return b < a ? (a = b , 1) : 0; }

int _ , __;
char c_;
inline int read()
{
	for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1;
	for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
	return _ * __;
}


const int maxn = 100010 , maxm = 200010;

int v[maxm] , nex[maxm] , beg[maxn] , e , n , m , b[maxn] , w[maxn] , uu , vv , isin[maxn];
LL cntw , cntb , cntbw;
 
queue<int> q;

void add(int uu , int vv)
{
	v[++ e] = vv;
	nex[e] = beg[uu];
	beg[uu] = e;
}

void dfs(int u , int type)
{
	if (type == 1)
	{
		for (int i = beg[u] ; i ; i = nex[i])
		{
			if (!w[v[i]])
			{
				w[v[i]] = 1;
				dfs(v[i] , 2);
			}
		}
	}
	if (type == 2)
	{
		for (int i = beg[u] ; i ; i = nex[i])
		{
			if (!b[v[i]])
			{
				b[v[i]] = 1;
				dfs(v[i] , 1);
			}
		}
	}
}

void BFS()
{
	q.push(1);
	b[1] = 1;
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		isin[u] = 0;
		if (b[u])
		{
			for (int i = beg[u] ; i ; i = nex[i])
			{
				if (!w[v[i]])
				{
					w[v[i]] = 1;
					if (!isin[v[i]])
					{
							q.push(v[i]),
							isin[v[i]] = 1;
					}
				}
			}
		}
		if (w[u])
		{
			for (int i = beg[u] ; i ; i = nex[i])
			{
				if (!b[v[i]])
				{
					b[v[i]] = 1;
					if (!isin[v[i]])
					{
							q.push(v[i]),
							isin[v[i]] = 1;
					}
				}
			}
		}
	}
}

void calc()
{
	For(i , 1 , n)
	{
		if (w[i] && !b[i])
			++ cntw;
		if (b[i] && !w[i])
			++ cntb;
		if (w[i] && b[i])
			++ cntbw;
	}
	printf("%lld\n" , cntw * cntb + cntb * cntbw + cntbw * cntw + cntbw * (cntbw - 1) / 2 - m);
}

int main()
{
	n = read();
	m = read();
	For(i , 1 , m)
	{
		uu = read(),
		   vv = read(),
		   add(uu , vv),
		   add(vv , uu);
	}
		dfs(1 , 1);
//	BFS();
	calc();
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

#define N_MAX 10

typedef struct {
	char name[32];
	int w,s;
} food_t;

static int n;
static food_t foods[N_MAX];
static int ans_index[N_MAX];
static int ans_buffer[N_MAX];
static int ans_score;

void search(int pos,int left,int cur_weight) {
	int i;
	if(pos<=0) {
		int cur_score=0;
		for(i=0;i<n;i++) {
			cur_score+=(i+1)*foods[ans_buffer[i]].w;
		}
		if(ans_score<0 || cur_score<ans_score) {
			ans_score=cur_score;
			for(i=0;i<n;i++)ans_index[i]=ans_buffer[i];
		}
	} else {
		for(i=0;i<n;i++) {
			if((left&(1<<i))!=0) {
				if(cur_weight<=foods[i].s) {
					ans_buffer[pos-1]=i;
					search(pos-1,left&~(1<<i),cur_weight+foods[i].w);
				}
			}
		}
	}
}

int main(void) {
	int i;
	while(scanf("%d",&n)==1 && n!=0) {
		for(i=0;i<n;i++) {
			if(scanf("%s%d%d",foods[i].name,&foods[i].w,&foods[i].s)!=3)return 1;
		}
		ans_score=-1;
		search(n,(1<<n)-1,0);
		for(i=0;i<n;i++)puts(foods[ans_index[i]].name);
	}
	return 0;
}

Measured memory_bytes: 584
N,M = map(int,input().split(" "))
pair = []
for i in range(M):
    a,b = map(int,input().split(" "))
    pair.append((a,b))
pair.sort(key=lambda x:x[1])

cur = (-1)
cnt = 0
for i in range(M):
    if pair[i][0] <= cur and cur < pair[i][1]:
        pass
    else:
        cur = pair[i][1] - 1
        cnt += 1

print(cnt)


Measured memory_bytes: 18192
S = input()
N = len(S)
X = [i-1 if S[i]=='L' else i+1 for i in range(N)]

for i in range(20):
    X = [X[X[j]] for j in range(N)]

ans = [0] * N
for i in range(N):
    ans[X[i]] += 1

print(*ans)


Measured memory_bytes: 110324
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  rep(i, 0, s.size())
  {
    if (s.substr(i, 1) == "A" || s.substr(i, 1) == "G" || s.substr(i, 1) == "C" || s.substr(i, 1) == "T")
    {
      count++;
      ans = max(ans, count);
    }
    else
    {
      count = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
    int x,y;
    char op;


    while(scanf("%d %c %d", &x, &op, &y)!=EOF)
    {
        if(op=='?')
        {
            break;
        }

        switch(op)
       {
        case'+':
        printf("%d\n", x+y);
        break;

        case'-':
        printf("%d\n", x-y);
        break;

        case'*':
        printf("%d\n", x*y);
        break;

        case'/':
        printf("%d\n", x/y);
        break;

    }
}

    return 0;



}


Measured memory_bytes: 2020
#include <stdio.h>

int main()
{
  int i,n,k;
  int a[100000];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &k);
    a[k-1]=i;
  }
  for(i=0;i<n;i++)
    printf("%d ",a[i]+1);
  printf("\n");
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int count_around_mine(vector<string> &s, int center_row, int center_col){
  int result = 0;
  for(int row = center_row - 1; row < center_row + 2; row++){
    for(int col = center_col - 1; col < center_col + 2; col++){
      if(row == center_row && col == center_col) continue;
      try{
        if(s.at(row).at(col) == '#') result += 1;
      }catch(out_of_range e){
        // 無視
      }
    }
  }
  return result;
}

int main(){
  int h, w;
  std::cin >> h >> w;
  vector<string> s(h);
  for(int row = 0; row < h; row++){
    std::cin >> s[row];
  }

  for(int row = 0; row < h; row++){
    for(int col = 0; col < w; col++){
      if(s[row][col] == '#'){
        std::cout << "#";
        continue;
      }
      int result = count_around_mine(s, row, col);
      std::cout << result;
    }
    std::cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(1000):
  chk = str(i).zfill(3)
  a = s.find(chk[0])
  b = s.find(chk[1],a+1)
  c = s.find(chk[2],b+1)
  if a!=-1 and b!=-1 and c!=-1:
    ans += 1
print(ans)

Measured memory_bytes: 38384
package main

import (
	"fmt"
)

func main() {
	var a,b,c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Println(sub(a, b, c))
}

func sub(n int, a int, b int) int {
	res := 0
	for i:=1; i<=n; i++ {
		s := sumOfEachDigit(i)
		if a<=s && s<=b {
			res += i
		}
	}
	return res
}

func sumOfEachDigit(n int) int {
	res := 0
	for ;n>=10; {
		res += n % 10
		n = n/10
	}
	res += n
	return res
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int N, K;
    cin>>N>>K;

    int cnt = 0;
    while (N > 0) {
        cnt++;
        N /= K;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import math
import itertools
import sys
n = int(input())
c = input()
wcnt = 0
for i in range(n):
    if(c[i] == 'W'):
        wcnt += 1
sw = 0
for i in range(len(c)-wcnt):
    if(c[i] == 'W'):
        sw += 1
print(min(min(wcnt, len(c)-wcnt), sw))


Measured memory_bytes: 9396
def ri():
    return int(input())


def rii():
    return [int(v) for v in input().split()]


def solve():
    N = ri()
    m = int(1e9 + 7)
    ans = 10 ** N % m
    ans = (ans - 9 ** N) % m
    ans = (ans - 9 ** N) % m
    ans = (ans + 8 ** N) % m

    print(ans)


if __name__ == "__main__":
    solve()

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

int main() {
  int s;
  cin >> s;
  int count = 0;
  
  if (s == 1 || s == 2){
    cout << 4 << endl;
  }
  else {
  
   while (s != 4) {
     if (s % 2 == 0){
       s = s / 2;
       count++;
     }
     else {
       s = s * 3 + 1;
       count++;
     }
   }
   
   cout << count + 4 << endl;
  }
}

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

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
   cin >> x >> y >> k;
    ans = x * 10 + y + k;
    lnt = y * 10 + x + k;
    cnt = k * 10 + x + y;
    cout << max(ans, max(lnt, cnt));
}


Measured memory_bytes: 6400
#include <iostream>
using namespace std;
int main()
{
	int n, m, h[100], i, j, r;
	char s[100][9], t[9];
	bool f;
	while (cin >> n >> m, n)
	{
		for (i = r = 0; i < n; i++)
			cin >> s[i] >> h[i];
		for (; m > 0; m--)
		{
			cin >> t;
			for (i = 0; i < n; i++)
			{
				f = 1;
				for (j = 7; j >= 0 && f; j--)
				{
					if (s[i][j] == '*')
						break;
					if (s[i][j] != t[j])
						f = 0;
				}
				if (f)
				{
					r += h[i];
					break;
				}
			}
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 0
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, L, T;
int x[100010], w[100010];
int calc(int a, int b) {
    int s = x[a], t = x[b];
    int dist = (w[a] == 1 ? (t-s+L)%L : (s-t+L)%L);
    if(2*T < dist) return 0;
    return (2*T - dist) / L + 1;
}

signed main() {
    vector<pii> pos;
    cin >> N >> L >> T;
    rep(i,0,N) {
        cin >> x[i] >> w[i];
        if(w[i] == 1) pos.push_back(make_pair( (x[i]+T)%L, i ));
        if(w[i] == 2) pos.push_back(make_pair( (x[i]-(T%L)+L)%L, -i ));
    }
    sort(pos.begin(), pos.end());
    
    int diff = 0, idx = 0;
    rep(i,1,N) if(w[0] != w[i]) diff += calc(0, i);
    diff %= N;
    if(w[0] == 2) diff *= -1;
    while(pos[idx].second != 0) idx++;

    rep(i,0,N) printf("%lld\n", pos[(idx+i-diff+N)%N].first);
    return 0;
}

Measured memory_bytes: 4464
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll H;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H;
  // A.resize(N);
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   A[i] = tmp;
  // }

  ll ans = 0;
  ll m = 1;
  while (H > 0) {
    ans += m;
    m *= 2;
    H /= 2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a[3];
	int i,j,max,sum,x;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	max=-1;
	x=0;
	for(i=0;i<3;i++){
		for(i=0;i<3;i++){
			if(a[i]>a[j]){
				x=a[i];
				a[i]=a[j];
				a[j]=x;
			}
		}
	}
	sum=a[0]*10+a[1]+a[2];
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define ll long long

class FIO
{
public:
    template<typename T>FIO& operator >>(T& x){ _R(x);return *this; }
    template<typename T>FIO& operator <<(T x){ _W(x);return *this; }
private:
    char f,c,a[25],i;
    template<typename T>inline void _R(T& x)
    {
        for(f=0;(c=getchar())<48;c==45&&(f=1));
        for(x=c^48;(c=getchar())>47;x=(x<<3)+(x<<1)+(c^48));
        if(f)x=-x;
    }
    template<typename T>inline void _W(T x)
    {
        if(sizeof(x)==1){ putchar(x);return; }
        if(x<0)putchar(45),x=-x;
        if(x>99) {
            for(i=0;x;x/=10)a[i++]=x%10;
            while(i--)putchar(a[i]+48);
        } else if(x>9) putchar(x/10+48),putchar(x%10+48);
        else putchar(x+48);
    }
}io;

int main()
{
    int n;
    io>>n;
    ll ans=0;
    for(int i=0,a;i<n;++i) {
        io>>a;
        ans+=a;
    }
    io<<ans-n;
    return 0;
}

Measured memory_bytes: 2908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		long m = n;

		for (int i = n - 1; i > 0; i--) {
			m *= i;
		}
		System.out.println(m);

	}

}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> Field(H+2),Ans(H);
  string unta="";
  for (int j=-1;j<W+1;j++){
    unta+=".";
  }
  Field.at(0)=unta;
  Field.at(H+1)=unta;
  for (int i=0;i<H+1;i++){
    cin >> Field.at(i+1);
    Field.at(i+1)="."+Field.at(i+1)+".";
  }
  for(int h=0;h<H;h++){for(int w=0;w<W;w++){
    int c=0;
    if (Field.at(h+1).at(w+1)=='#'){
      Ans.at(h)+="#";
    }
    else{
      for(int i=-1;i<2;i++){for(int j=-1;j<2;j++){
        if (i==0 and j==0){
          continue;
        }else{
          if (Field.at(1+h+i).at(1+w+j)=='#'){
            c++;
          }
        }
      }}Ans.at(h)+=to_string(c);
    }
  }cout << Ans.at(h) << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int, int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(long long i = l;i<r;i++)

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

mt19937 mt('O' + '4' + 'K' + 'O');

void kekek()
{
    
    mt();
    #ifdef EB_UG
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
    #ifndef EB_UG
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #endif
}

vector<vector<pii>> gr(100228);
vector<bool> used(100228);
vector<int> color(100228);

int max_sz = 0;

void dfs(int st, int cur_col) {
    used[st] = true;
    int cnt = 1;
    for (auto it: gr[st]) {
        if (!used[it.first]) {
            // printf("i: %d, edge: %d %d, cur_col: %d, color to: %d\n",i,  st, gr[st][i - 1].first, cur_col, (cur_col + i) % (max_sz));
            color[it.second] = (cur_col + cnt) % (max_sz);
            dfs(it.first, (cur_col + cnt) % (max_sz));
            cnt++;
        }
    }
}

int main() {
    kekek();
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        gr[u].push_back({v, i});
        gr[v].push_back({u, i});
    }
    for (int i = 1; i <= n; i++) {
        max_sz = max(max_sz, (int)gr[i].size());
    }
    // cout << max_sz << endl;
    dfs(1, -1);
    cout << max_sz << endl;
    for (int i = 0; i < n - 1; i++) {
        cout << color[i] +1 << endl;
    }
}

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

int main(){
  int n,r=0,s=0; cin >>n;
  vector<int>v(n);
  for(int i=0; i<n; i++){cin >>v[i];}

  for(int i=1; i<=n; i++)
  {
    for(int j=r; j<n; j++)
    {
    if(v[j]!=i){r++; s++;}
    else{r++; break;}
    }
  }
  
  if(r>s) cout <<s;
  else cout <<"-1";
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif

using namespace std;
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int n;
ll k;
int a[maxn];

bool check(int x)
{
	ll res = 0;
	for(int i = 0; i < n; ++i)
	{
		if(a[i] <= x) continue;
		/*
		ll cnt = 1;
		double y = a[i];
		while((int)y > x)
		{
			y = y / 2.0;
			res += cnt;
			cnt *= 2ll;
		}
		*/
		res += a[i] / x;
	}
	//cout << x << " " << res << endl;
	return res <= k;
}

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

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

	int l = 0, r = 1e9 + 1;
	while(r - l > 1) 
	{
		int mid = (l + r) >> 1;
		if(mid != 0 && check(mid)) r = mid;
		else l = mid;
	} 
	cout << r << endl;
	return 0;
}

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

int main() {
  int D, N;
  cin >> D >> N;
  if (D == 0 && N <= 99) {
    cout << N;
  }else if (D == 1 && N <= 99) {
    cout << N * 100;
  }else if (D == 2 && N <= 99){
    cout << N * 10000;
  }else{
     if (D == 0) {
      cout << N + 1;
    }else if (D == 1) {
      cout << (N + 1) * 100;
    }else if (D == 2){
      cout << (N + 1) * 10000;
    }
  }
} 

Measured memory_bytes: 256