akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        long[] a=new long[n];
        for(int i=0;i<n;i++)
            a[i]=in.nextLong();
        long curr=a[0];
        long total=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]>=curr)
                curr=a[i];
            else
            {
                total+=(curr-a[i]);
            }
        }
        System.out.println(total);

    }
}


Measured memory_bytes: 60836
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;


vector<vector<int>> v(100010);
int r,now;

void dfs(int p,int pre,int d){
    if(now < d){
        now = d;
        r = p;
    }
    for(auto i:v[p]){
        if(pre != i){
            dfs(i,p,d+1);
        }
    }
}

bool used[100010];
vector<int> d;
bool go(int p,int pre){
    bool ret = false;
    if(p == r){
        d.push_back(p);
        used[p] = 1;
        return true;
    }
    for(auto i:v[p]){
        if(i != pre){
            ret |= go(i,p);
            if(ret)break;
        }
    }
    if(ret){
        used[p] = 1;
        d.push_back(p);
    }
    return ret;
}

int ma = 0;

void solve(int p,int pre,int d,bool wa){
    if(!wa || d!=now)ma = max(d,ma);
    else ma = max(d-1,ma);
    for(auto i:v[p]){
        if(i != pre && !used[i]){
            solve(i,p,d+1,wa);
        }
    }
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0,-1,0);
    int r1=r;
    r=-1,now=-1;
    dfs(r1,-1,0);
    int r2 = r;
    // cout << r1 << " " << r2 << endl;
    go(r1,-1);
    string ans = "";
    for(int i=0;i<n;i++){
        ans += "1";
    }
    if(now == n-1){
        cout << ans << endl;
        return 0;
    }
    // d: r2 -> r1
    for(int i=0;i<d.size();i++){
        if(v[d[i]].size() > 2){
            //cerr << "a " << i << " " << d[i] << endl;
            solve(d[i],-1,max(i,now-i),(i==(now-i)));
        }
    }
    // cerr << ma << endl;
    // ma = min(ma,now);
    for(int i=2;i<ma;i++){
        ans[i] = '0';
    }
    cout << ans << endl;



}


Measured memory_bytes: 13808
#include <bits/stdc++.h>
using namespace std;
int N, M;

vector<int> dp(100000, -1);
vector<int> coins;

int solve_dp(int n, int m) {
    if (dp[n] != -1) return dp[n];
    int count = INT_MAX;
    for (int i = 0; i < m; ++i) {
        int coin = coins[i];
        if (i == 0) {
            count = n / coin;
        } else {
            int new_n = n - coin;
            if (new_n < 0) continue;
            int coin_n = 1 + solve_dp(new_n, m);
            count = min(count, coin_n);
        }
    }
    dp[n] = count;
    return count;
}

void solve() {
    cin >> N >> M;
    coins.assign(M, 0);
    for (int i = 0; i < M; ++i) cin >> coins[i];
    sort(coins.begin(), coins.end());
    int ans = solve_dp(N, M);
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 4664
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
struct e { int a, b, c; };

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<e>> v(n), rv(n);
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		rv[b].push_back({ b,a,c });
	}
	vi b(n);
	b[n - 1] = 1;
	queue<int> q;
	q.push(n - 1);
	while (!q.empty()) {
		int p = q.front();
		q.pop();
		REP(i, rv[p].size()) {
			if (b[rv[p][i].b] == 0) {
				b[rv[p][i].b] = 1;
				q.push(rv[p][i].b);
			}
		}
	}
	REP(i, n) {
		REP(j,rv[i].size()) {
			if (b[rv[i][j].a] && b[rv[i][j].b]) {
				v[rv[i][j].b].push_back({ rv[i][j].b,rv[i][j].a,-rv[i][j].c });
			}
		}
	}
	vl d(n,INF*INF);
	d[0] = 0;
	REP(k, n) {
		REP(i, n) {
			REP(j, v[i].size()) {
				d[v[i][j].b] = min(d[v[i][j].b], d[v[i][j].a] + v[i][j].c);
			}
		}
	}
	bool updated = false;
	REP(i, n) {
		REP(j, v[i].size()) {
			if (d[v[i][j].b] > d[v[i][j].a] + v[i][j].c)updated = true;
		}
	}
	if (updated)cout << "inf" << endl;
	else cout << -d[n - 1] << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#define is(c) (c >= '0' && c <= '9')
#define p 1000000007
using namespace std;
int n;
long long ans;
int read()
{
	int s = 0, f = 1;
	char c = getchar();
	while(!is(c))
	{
		if(c == '-')
			f--;
		c = getchar();
	}
	while(is(c))
	{
		s = (s << 3) + (s << 1) + (c ^ 48);
		c = getchar();
	}
	return f ? s : -s;
}
int main()
{
	n = read();
	ans = 1;
	for(int i = 1; i <= n; i++)
		ans = ans * i % p;
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
  int n,i,j;
  scanf("%d",&n);
  int V[100][100];
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      V[i][j]=0;
    }
  }
  int u,k,v;
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      V[u-1][v-1]=1;
    }
    for(j=0;j<n;j++){
      printf("%d",V[i][j]);
if(j!=n-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2100
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}

int fact[2000005];
int infact[2000005];

int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}

int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}

void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}

int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}
void q1(){
  string s; cin>>s;
  if(s>="a" && s<="z") cout<<"a";
  else cout<<"A";
}
void q2(){
  int n,k; cin>>n>>k;
  int a[n]; f(i,0,n) cin>>a[i];
  sort(a,a+n);
  int s=0;
  f(i,0,k)s+=a[i];
  cout<<s;
}
void q3(){
  string ret="";
  int a; cin>>a;
  while(a!=0){
    a--;
    ret+=(a%26 +'a');
    a/=26;
  }
  reverse(ret.begin(),ret.end());
  cout<<ret;
}
void q4(){
  int n; cin>>n;
   int a[100005]={0};
   int s=0;
  f(i,0,n){
    int x; cin>>x;
    s+=x;
    a[x]++;
  }
  int q; cin>>q;
  while(q--){
    int b,c; cin>>b>>c;
    s-=a[b]*b;
    s+=a[b]*c;
    a[c]+=a[b];
    a[b]=0;
    cout<<s<<"\n";
  }
 
}
void q5(){
  int n; cin>>n;
  int x=0;
  int a[n]; f(i,0,n){
    cin>>a[i];
    x^=a[i];
  } 
   f(i,0,n) cout<<(x^a[i])<<" ";
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  q5();
  return 0;
  facto();
  int k; cin>>k;
  string s; cin>>s;
  int l=k+s.size();
  int xp=s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret=1;
  f(i,0,l){
    ret*=26; ret%=mod;
  }
  int sub=0;

  f(i,0,xp){
    // l choose i
    sub+= (nck(l,i)*po(25,l-i));
    sub%=mod; 
  }

  cout<<((ret-sub)%mod + mod) %mod <<"\n";
  return 0;
}


Measured memory_bytes: 5220
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int N=1e5+5,M=N<<2;
int ans,s,t,tot,now,n,m,head[N],nex[M],to[M];
int d[N];
bool vv[N];
void add(int u,int v)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;
}
struct node
{
    int u,x;
    node(int u,int x):u(u),x(x){}
    bool operator<(const node&o)const
    {
        return x>o.x;
    }
};
int vis[N][3];
priority_queue<node>q;
pair<int,int>st[N*3];
int top;
void dfs(int u,int p)
{
    if(p==0)
    {
        if(d[u]>d[now]+1)
        {
            d[u]=d[now]+1;
            vv[u]=false;
            q.push(node(u,d[u]));
        }
        return;
    }
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(vis[v][p-1]) continue;
        vis[v][p-1]=true;
        st[++top]=make_pair(v,p-1);
        dfs(v,p-1);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
    }
    memset(d,inf,sizeof(d));
    scanf("%d%d",&s,&t);
    d[s]=0;
    memset(vv,true,sizeof(vv));
    vv[s]=false;
    q.push(node(s,d[s]));
    while(!q.empty())
    {
        now=q.top().u;q.pop();
        if(vv[now]||d[now]>=d[t]) continue;
        vv[now]=true;
        dfs(now,3);
        if(now==d[t]) break;
    }
    if(d[t]!=d[0]) printf("%d\n",d[t]);
    else printf("-1\n");
} 

Measured memory_bytes: 6784
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int dp[100010] = {0};
    int N;
    int height[100010];

    cin >> N;
    for(int i=0; i<N; i++)  cin >> height[i];

    dp[1] = abs(height[1] - height[0]);

    for(int j=2;j<N;j++){
        dp[j] = min(dp[j-1] + abs(height[j] - height[j-1]), dp[j-2] + abs(height[j-2] - height[j]));
    }

    cout << dp[N-1];

}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#define SIZE 1005
#define MOD 1000000007

using namespace std;
typedef long long int ll;

ll mpow(ll m,ll t)
{
	if(t==0) return 1LL;
	ll ret=mpow(m,t/2);
	ret=ret*ret%MOD;
	if(t%2==1) ret=ret*m%MOD;
	return ret;
}
ll inv(ll x)
{
	return mpow(x,MOD-2);
}
char mp[SIZE][SIZE];

int main()
{
	int n,m;
	ll K;
	scanf("%d %d %lld",&n,&m,&K);
	bool A=false,B=false;
	for(int i=0;i<n;i++) scanf("%s",&mp[i]);
	ll S=0,T=0;
	for(int i=0;i<n;i++) if(mp[i][0]=='#'&&mp[i][m-1]=='#') A=true,S++;
	for(int i=0;i<m;i++) if(mp[0][i]=='#'&&mp[n-1][i]=='#') B=true,T++;
	if(A&&B) puts("1");
	else if(K<=1) puts("1");
	else
	{
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(mp[i][j]=='#') cnt++;
			}
		}
		if(!A&&!B) printf("%lld\n",mpow(cnt,K-1));
		else
		{
			ll mn=0;
			if(A)
			{
				for(int i=0;i<n;i++)
				{
					for(int j=0;j+1<m;j++)
					{
						if(mp[i][j]=='#'&&mp[i][j+1]=='#') mn++;
					}
				}
				mn=mn%MOD;
			}
			else
			{
				S=T;
				for(int i=0;i+1<n;i++)
				{
					for(int j=0;j<m;j++)
					{
						if(mp[i][j]=='#'&&mp[i+1][j]=='#') mn++;
					}
				}
				mn=mn%MOD;
			}
			//f(K)=f(K-1)*cnt-mn*S^(K-2) , f(1)=1
			//printf("%lld %lld %lld\n",cnt,mn,S);
			cnt=cnt*inv(S)%MOD;
			mn=mn*inv(S*S)%MOD;
			ll ans;
			if(cnt==1) ans=inv(S)+(MOD-mn)*(K-1)%MOD;
			else
			{
				ll ap=mn*inv(cnt-1)%MOD;
				ans=mpow(cnt,K-1)*(inv(S)-ap+MOD)%MOD;
				ans+=ap;
				ans%=MOD;
			}
			ans=ans*mpow(S,K)%MOD;
			printf("%lld\n",ans);
		}
	}
	return 0;
}


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

int main(){
  int h, w;
  while (true){
    cin >> h >> w;
    if (h == 0 && w == 0){
      break;
    }
    
    for (int i = 0; i < h; i++){
      for (int a = 0; a < w; a++){
        if (i == 0 || i == h - 1){
          cout << "#";
        }else{
          if (a == 0 || a == w - 1){
            cout << "#";
          }else{
            cout << ".";
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

const int N=200005;
char s[N];int n,k,c;
int pre[N],nxt[N];
bool f1[N],f2[N];
int main()
{
	rd(n);rd(k);rd(c);
	scanf("%s",s+1);
	pre[0]=0;F(i,1,n) pre[i]=s[i]=='o'?i:pre[i-1];
	nxt[n+1]=n+1;UF(i,n,1) nxt[i]=s[i]=='o'?i:nxt[i+1];
	//F(i,1,n) cout<<pre[i]<<' ';cout<<endl;
	//F(i,1,n) cout<<nxt[i]<<' ';cout<<endl;
	int mx=0,t=1;
	while(1<=t&&t<=n)
	{
		t=nxt[t];
		if(1<=t&&t<=n) {f1[t]=true;t+=c+1;}
	}
	//F(i,1,n) cout<<f1[i]<<' ';cout<<endl;
	mx=0,t=n;
	while(1<=t&&t<=n)
	{
		t=pre[t];
		if(1<=t&&t<=n) {f2[t]=true;t-=c+1;++mx;}
	}
	//F(i,1,n) cout<<f2[i]<<' ';cout<<endl;
	if(mx!=k) return 0;
	F(i,1,n) if(f1[i]&&f2[i]) printf("%d\n",i);
	return 0;
}
///////////////////

Measured memory_bytes: 3712
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    D = list(map(int, readline().rstrip().split()))
    nums = [str(i) for i in range(10)]
    for d in D:
        nums.remove(str(d))
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e not in nums:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import Data.List

solve cards = [ s ++ " " ++ show r | s <- ["S","H","C","D"], r <- [1..13], (s,r) `notElem` cards]

main = getContents >>= mapM_ putStrLn . solve . sort . map ((\[x,y] -> (x,read y :: Int)).  words) . tail . lines

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

# from numba import njit

from collections import Counter
# input = stdin.readline

# @njit
def solve(n,s):
  flag = False
  d = Counter(s)
  whiteCount = d["W"]
  redCount   = d["R"]
  res = min(s[:redCount].count("W"),s[redCount:].count("R"))
  
  return res



def main():
  N = int(input())
  s = input()
  print(solve(N,s))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9708
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    lenA = len(A)

    tmp = []
    path = []
    setpath = set([])
    cnt = 0
    i = 1
    for _ in range(1, N+10):
        setpath.add(i)
        path.append(i)
        if len(setpath) != len(path):
            path.pop()
            itmp = path.index(i)
            break
        i = A[i-1]

    lenpath = len(path)
    if K >= lenpath:
        jtmp = (K-itmp)%(lenpath-itmp)
        ans = path[itmp+jtmp]
    else:
        ans = path[K]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32180
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

int main()
{
	fastio
	lld k;
	cin>>k;

	lld init=7,ans=1;
	set<lld>s;
	while(init%k!=0)
	{
		init = init%k;
		if(s.find(init)!=s.end())
		{
			ans=-1;
			break;
		}
		s.insert(init);
		init = (10*init+7);
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 50512
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

vector<vector<int>> G;
vector<bool> visited;
ll ans = 0;

void dfs(int cur) {
	bool f = true;
	for (int i = 0; i < sz(visited); i++) {
		if (!visited[i] && i != cur) {
			f = false;
		}
	}
	if (f) {
		ans++;
		return;
	}

	visited[cur] = true;
	for (auto g : G[cur]) {
		if (!visited[g]) {
			dfs(g);
		}
	}
	visited[cur] = false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, m;
	cin >> n >> m;

	G.resize(n);

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	visited.resize(n, false);

	dfs(0);

	out(ans);

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
vector<int> prime(){
    vector<bool> a(100050,true);
    a[0] = a[1] = false;
    for(int i=2;i<=100000;++i)if(a[i]){
        for(int j=i+i;j<=100000;j+=i)a[j] = false;
    }
    vector<int> ret;
    for(int i=100000;i>0;--i)if(a[i]){
        if(i%2 and a[(i+1)/2])ret.push_back(i);
    }
    reverse(ret.begin(),ret.end());
    return ret;
}
int main(){
    auto p = prime();
    int q;
    cin>>q;
    for(int i=0;i<q;++i){
        int l,r;
        cin>>l>>r;
        auto lnum = lower_bound(p.begin(),p.end(),l-1);
        auto rnum = lower_bound(p.begin(),p.end(),r+1);
        cout << rnum - lnum << endl;
    }
    return 0;
}



Measured memory_bytes: 768
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    cout << n*n*n << "\n";
    
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
  int n, stair[31];
  while (cin >> n, n) {
    memset(stair, 0, sizeof(int) * 31);
    stair[0] = 1;

    for (int i = 1; i <= n; i++) {
      stair[i] += stair[i-1];
      if (i - 2 >= 0)
        stair[i] += stair[i-2];
      if (i - 3 >= 0)
        stair[i] += stair[i-3];
    }
    cout << stair[n] / 3650 + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		k := make([]int, n)
		for i := 0; i < n; i++ {
			k[i] = io.NextInt()
		}
		const st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		s := io.NextLine()
		for i, cnt := 0, 0; i < len(s); i, cnt = i+1, (cnt+1)%n {
			idx := strings.IndexRune(st, rune(s[i]))
			c := st[(idx-k[cnt]+52)%52]
			io.Printf("%c", c)
		}
		io.Println()
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1300
#coding: utf-8

p = [0,0]
n = int(input())
for i in range(n):
    c1 = input().split(" ")
    c2 = sorted(c1)

    if c1[0] == c1[1]:
        p[0] += 1
        p[1] += 1

    elif c1[0] == c2[0]:
        p[1] += 3
    else:
        p[0] += 3

print(str(p[0]) + " " + str(p[1]))


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

int main() {
  int Z=0;
  int saikou=0;
  string S;
  cin >> S;
  for (int X=0; X<S.size(); X++){
    Z=1;
    if (S.at(X)=='A' || S.at(X)=='T' || S.at(X)=='G' || S.at(X)=='C'){
      for (int Y=X+1; Y<S.size(); Y++){
        if (Z==0){
          Z=1;
        }
        if (S.at(Y)=='A' || S.at(Y)=='T' || S.at(Y)=='G' || S.at(Y)=='C'){
          Z+=1;
          if (Z>saikou){
            saikou=Z;
          }
        }
        else{
          break;
        }
      }
      if(X+1==S.size() && saikou==0){
        saikou=1;
      }
    }
  }
  cout << saikou << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A,B,C,D;
int main(){
	scanf("%d%d%d%d",&A,&B,&C,&D);
	cout<<max(A*B,C*D)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
string n;
int K;
ll dp[110][2][4];
/*
dp[i][smaller][k]:=i桁目以降で0以外の数を使用できるのが残りk個である数の個数
i桁目までの部分について, smallerがtrueならnより小さく, falseならnと等しいとする.
*/

ll rec(int i=0,bool smaller=false,int k=K){
    if(k==0)return 1;
    if(i>=(ll)n.size())return 0;
    ll &ret=dp[i][(int)smaller][k];
    if(ret>0)return ret;
    ret=0;
    if(smaller){
        ret+=rec(i+1,true,k);
        ret+=rec(i+1,true,k-1)*9LL;
    }else {
        if(n[i]=='0')ret+=rec(i+1,false,k);
        else {
            ret+=rec(i+1,true,k);
            ret+=rec(i+1,true,k-1)*(n[i]-'1');
            ret+=rec(i+1,false,k-1);
        }
    }
    return ret;
}
int main(){
    cin>>n;cin>>K;
    cout<<rec()<<endl;
}

Measured memory_bytes: 3560
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a[100005];
int main()
{
	int n; cin >> n;
	for(int i=0;i<n;i++){
		int x; scanf("%d",&x); a[x]++;
	}
	int ret = 0,cnt = 0;
	for(int i=1;i<=100005;i++){
		if(a[i]) ret++;
		if(a[i]&&a[i]%2 == 0) cnt++;
	}
	if(cnt%2 == 1) ret--;
	cout << ret << endl;
}

Measured memory_bytes: 640
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"
#define inf 1e18
#define mm 998244353

void solve(){
	int n; cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		ff(j,1,n){
			for(int u=1;u<=n;u++){
				int f1 = __gcd(i,j);
				int h = __gcd(f1,u);
				ans += h;
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

using namespace std;

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

    int r , d , cur;
    cin >> r >> d >> cur;

    for (int i = 0 ;i < 10 ;i++) {
        cur = r * cur - d;
        cout << cur << '\n';
    }
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $str);
$cnt = strlen($str);
for ($i = 1; $i < $cnt; $i++) {
  $str = substr($str, 0, strlen($str)-1);
  if (strlen($str)%2 == 1){
    continue;
  }
  $half_str = substr($str, 0, strlen($str)/2);
  if ($str == $half_str . $half_str) {
    echo strlen($str);
    break;
  }
}

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

int main(){
  ll x;
  cin >> x;
  ll u1 = x / 500;
  ll u2 = (x - (500 * u1)) / 5;
  cout << u1 * 1000 + u2 * 5 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll n, a, b;
	cin >> n >> a >> b;
	vi x(n);
	for (auto &i : x) cin >> i;
	ll ans = 0;
	REP(i, n - 1)
	{
		ans += min(a * (x[i + 1] - x[i]), b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
// Allah amader korona virus theke rokkha korun.Amin.

//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp> //order_of_key return number of elements less than x, find_by_order return index (pointer use kora lgbe)

using namespace std;
using namespace __gnu_pbds;

#define ull    unsigned long long
#define ll    long long
#define ios    ios::sync_with_stdio(0);cin.tie(0);
#define ses   "\n"
#define all(x) (x).begin(), (x).end()
//#define INF   ((int)2e18)
#define ii pair<ll, ll>

string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

const int N=1e6+5;
const ll M=1e18;

typedef tree< ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

struct Edge
{
    int u, vv;
    bool operator<(Edge const& other)
    {
        return vv > other.vv;
    }
}; // eta joss jinis.krsukal er jnno and sort 1 out of 3 or more er jnno better

/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//main function is here.........
int main()
{
       //ios
ll n,m,mn=0;
cin>>n>>m;
ll arr[m];
for(ll i=0;i<m;i++){
     cin>>arr[i];
}
for(ll i=0;i<m-1;i++){
                mn=max(abs(arr[i]-arr[i+1]),mn);
}
mn= max(mn,abs(n-arr[m-1]+arr[0]));
cout<<n-mn;
}


/*
*/



//Alhamdulillah


Measured memory_bytes: 1792
n = gets.chomp.to_i
s = gets.chomp.split("")
ans = 0

(1..n-1).each do |i|
  cnt = 0
  l = s.slice(0, i).uniq
  r = s.slice(i, n).uniq
  l.each do |j|
    if r.include?(j)
      cnt += 1
    end
  end
  if ans < cnt
    ans = cnt
  end
end

puts ans

Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b;
    cin >> a>>b;

    int ret = a*b;
    if(a>9||b>9) ret = -1;

    cout << ret << endl;
   return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
//use std::num;

fn main() {
    input! {
        n:usize,
        xy:[(i32,i32);n]
    }
    // 各町の間の距離 d[i][j]とする。(0<i,j<n)
    let mut d: Vec<Vec<f64>> = vec![vec![0f64; n]; n];
    for i in 0..n {
        for j in 0..n {
            d[i][j] = (((xy[i].0 - xy[j].0).pow(2) + (xy[i].1 - xy[j].1).pow(2)) as f64).sqrt();
        }
    }
    let mut values: Vec<usize> = (0..n).collect();
    let mut distance = 0_f64;
    while {
        for i in 0..values.len() - 1 {
            distance += d[values[i]][values[i + 1]];
        }

        values.next_permutation()
    } {}
    // 合計distanceは、高々3000万
    let mut p = 1;
    for i in 2..n + 1 {
        p *= i;
    }
    let ans = distance / (p as f64);

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


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

int main() {
	int n;
	cin>>n;
	vector<int>x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	
	auto dist=[&](int i,int j){
		double dx=x[i]-x[j];
		double dy=y[i]-y[j];
		return sqrt(dx*dx+dy*dy);
	};
	
	//初期順列
	vector<int>p(n);
	rep(i,n)p[i]=i;
	
	double len=0;
	int cnt=0;
	
	do{
		rep(i,n-1)len+=dist(p[i],p[i+1]);//iはn-1までで全部計算される
		cnt++;
	}while(next_permutation(p.begin(),p.end()));
	
	double ans=len/cnt;
	
	cout<<fixed<<setprecision(10)<<ans<<endl;
}


//ラムダ式
//do-while文
//next_permutationの使い方(順列全探索)

//写経のはずが3WA

Measured memory_bytes: 256
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
string s;
cin >> s;
if ( s == string(s.rbegin(),s.rend()))cout << "Yes" ;
else cout << "No";

return 0 ;
}


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

int main()
{
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    int count = 0;
    if (a == b && c == d && a != c)
    {
        cout << "Yes";
    }
    else if (a == c && b == d && a != b)
    {
        cout << "Yes";
    }
    else if (a == d && b == c && a != b)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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

int main () {
    int64_t x;
    cin >> x;
    int64_t a = (x / 11LL) * 2LL;
    int64_t b = x % 11LL;
    if (b == 0) ;
    else if (b <= 6) a++;
    else a+=2LL;
    cout << a << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import defaultdict


def main():
    n = int(input().strip())
    s = input().strip()

    pos = defaultdict(set)
    for i, c in enumerate(s):
        pos[c].add(i)

    # ありえるくみあわせを求める
    base = len(pos["R"]) * len(pos["G"]) * len(pos["B"])

    # 条件2にあてはまる分を求める
    sk = sorted(["R", "G", "B"], key=lambda k: len(pos[k]))
    for p1 in pos[sk[0]]:
        for p2 in pos[sk[1]]:
            p_min, p_max = (p1, p2) if p1 < p2 else (p2, p1)
            if p_min - (p_max - p_min) in pos[sk[2]]:
                base -= 1
            if p_max + (p_max - p_min) in pos[sk[2]]:
                base -= 1
            if (p_max + p_min) % 2 == 0 and (p_max + p_min) // 2 in pos[sk[2]]:
                base -= 1

    print(base)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9772
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define int long long
#define MAX         2000000000000000000
#define re(i,x,n) for(i=x;i<=n;i++)
typedef long long ll;
using namespace std;
void c_p_c()
{
	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);
#endif
}
vi graph[200001];
int vis[200001] = {0};
int cost[100001];
int parent = -1;
int costi ;
void dfs(int i)
{
	vis[i] = 1;
	costi = min(cost[i], costi);
	//cout << costi << endl;
	for (auto &it : graph[i])
	{
		if (vis[it] == 0) {

			dfs(it);

		}
	}

}
int pp[100001];
bool isPrime(int n)
{
	int i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
//
int32_t main()
{
	//c_p_c();
	int n, k;
	cin >> n >> k;
	int a[n];
	int i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int sum = 0;
	for (i = 0; i < k; i++)
		sum += a[i];
	cout << sum << endl;
}

Measured memory_bytes: 8324
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    if B[i] > A[i]:
        ans += A[i]
        B[i] -= A[i]
        
        ans += min(B[i], A[i + 1])
        if B[i] > A[i + 1]:
            A[i + 1] = 0
        else:
            A[i+1] -= B[i]    
    else:
        ans += B[i]
        B[i] = 0

print(ans)

Measured memory_bytes: 18396
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int n = nextInt();
        List<Integer> p = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {
            int input = nextInt();
            p.add(input);
        }

        long swapCount = 0L;

        for (int i = 0; i < n; i++) {
            int pi = p.get(i);

            if (pi == i + 1) {
                // 最後以外は右を見る
                if (i < n - 1) {
                    int piRight = p.get(i + 1);

                    // 右隣もpi = i ならそこで入れ替える
                    if (piRight == i + 1) {
                        Collections.swap(p, i, i + 1);
                    } else if (piRight == i) {
                        // 右隣が今の位置の番号なら左と入れ替える
                        Collections.swap(p, i, i - 1);
                    } else {
                        Collections.swap(p, i, i + 1);
                    }
                } else {
                    // 最後は左を見る
                    Collections.swap(p, i, i - 1);
                }

                swapCount++;
            }
        }

        out(swapCount);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}

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

using namespace std;

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++)
        cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n-1; i++){
        if((p[i] < p[i-1] && p[i] > p[i+1])||(p[i]>p[i-1] && p[i]<p[i+1]))
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

int main() {
    int coins[]{500, 100, 50, 10, 5, 1};
    while(true) {
        int p; cin >> p;
        if (p == 0) break;
        int change = 1000 - p;
        int ans = 0;
        for (int c : coins) {
            int v = change / c;
            ans += v;
            change -= v * c;
        }
        cout << ans << "\n";
    }

    return 0;
}


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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

ll n, m, d;

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

  while (cin >> n >> m >> d) {
    ll p = (n - d) * (2 * (m - 1));
    ll q = n * n;
    double ans = (double)p / q;

    if (d == 0) {
      ans /= 2;
    }

    printf("%.10f\n", ans);
  }

  //   (n - d) * (2 * (m - 1)) * (n ^ (m-2)) / (n ^ m)
  // = (n - d) * (2 * (m - 1)) / (n ^ 2)
}


Measured memory_bytes: 256
package MyApp;
use utf8;
use 5.016;

print func(map { chomp; $_ } <>);

sub func {
    my @result;
    while (my $line = shift) {
        my ($n1, $n2) = split / /, $line;
        push @result, func2($n1, $n2);
    }
    return join("\n", @result, '');
}

sub func2 {
    my ($n1, $n2) = @_;
    return $n2 if $n1 >= 13;
    return $n2 / 2 if $n1 >= 6;
    return 0;
}

1;
__END__


Measured memory_bytes: 512
scores = [0, 0]
for i in range(int(input())):
    cards = input().split()
    if cards[0] == cards[1]:
        scores = [score+1 for score in scores]

    else:
        sorted_cards = sorted(cards)
        if sorted_cards == cards:
            scores[1] += 3
        else:
            scores[0] += 3

print(scores[0], scores[1])


Measured memory_bytes: 5604
#include<cstdio>
#include<cstring>
#include<cstring>
#include<algorithm>
using namespace std;
const int md=1000000007;
int n,x,i,j,k,a[205],f[205][100005],s[100005],C[205][205],jc[205],rjc[205],inv[205];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	scanf("%d%d",&n,&x);
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	sort(a+1,a+1+n,cmp);
	for(j=0;j<=100000;++j)
		f[n+1][j]=j;
	inv[1]=1;
	for(i=2;i<=n;++i)
		inv[i]=1ll*inv[md%i]*(md-md/i)%md;
	jc[0]=rjc[0]=1;
	for(i=1;i<=n;++i)
	{
		jc[i]=1ll*jc[i-1]*i%md;
		rjc[i]=1ll*rjc[i-1]*inv[i]%md;
	}
	for(i=n;i>=1;--i)
	{
		for(j=0;j<=100000;++j)
		{
			s[j]=(s[j]+1ll*f[i+1][j%a[i]]*rjc[n-i])%md;
			//for(k=i;k<=n;++k)
				//f[i][j]=(f[i][j]+1ll*f[k+1][j%a[k]]*rjc[n-k])%md;
			f[i][j]=1ll*s[j]*jc[n-i]%md;
		}
	}
	printf("%d",f[1][x]);
	return 0;
}


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

m = 0
min_m = 0

for c in S:
    if c == '(':
        m += 1
    else:
        m -= 1
    min_m = min(min_m, m)

ans = '('*(-min_m) + S + ')'*(m-min_m)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  
  while(k>0) {
    if(a<b) break;
    b*=2;
    k--;
  }
  while(k>0) {
    if(b<c) break;
    c*=2;
    k--;
  }
  
  cout << (a<b and b<c ? "Yes" : "No") << newl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=17005,mo=998244353;
int poww(int x,int y){
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%mo)if(y&1)ans=1ll*ans*x%mo;
	return ans;
}
struct NTT{
	int b[N],l,invl,wn[N];
	inline void ini(int n){
		for(l=1;l<=n;l<<=1);
		int i,j,k,m;static int c[N];
		for(i=0;i<l;++i)b[i]=i;
		for(i=l;i>1;i>>=1)
			for(j=0,m=i>>1,memcpy(c,b,l<<2);j<l;j+=i)
				for(k=0;k<m;++k)b[j+k]=c[j+(k<<1)],b[j+k+m]=c[j+(k<<1|1)];
		wn[0]=1;wn[1]=poww(3,(mo-1)/l);
		for(i=2;i<=l;++i)wn[i]=1ll*wn[i-1]*wn[1]%mo;
		invl=poww(l,mo-2);
	}
	inline void DFT(int*a,int key){
		static int c[N],w[N];memcpy(c,a,l<<2);
		int i,j,k,m;
		for(i=0;i<l;++i)a[b[i]]=c[i];
		for(i=2;i<=l;i<<=1){
			m=i>>1;
			if(key==1)for(j=0,k=0;j<m;++j,k+=l/i)w[j]=wn[k];
				else for(j=0,k=l;j<m;++j,k-=l/i)w[j]=wn[k];
			for(j=0;j<l;j+=i)
				for(k=0;k<m;++k){
					int u=1ll*w[k]*a[j+k+m]%mo;
					a[j+k+m]=(a[j+k]+mo-u)%mo;
					a[j+k]=(a[j+k]+u)%mo;
				}
		}
		if(key==-1)for(i=0;i<l;++i)a[i]=1ll*a[i]*invl%mo;
	}
}F;
int vf[N],fac[N],inv[N];
inline int C(int n,int m){return n>=m?1ll*vf[m]*vf[n-m]%mo*fac[n]%mo:0;}
int n,m,i,j,k,l,f[205][N],A[N];
int main(){
	for(int i=*vf=*fac=1;i<N;++i)
		inv[i]=i==1?1:1ll*(mo-mo/i)*inv[mo%i]%mo,
		vf[i]=1ll*vf[i-1]*inv[i]%mo,fac[i]=1ll*fac[i-1]*i%mo;
	scanf("%d%d",&n,&m);
	for(i=0;i<=n;++i)f[m][i]=C(n,i);
	F.ini(n*2);
	for(i=0;i<=n;++i)A[i]=vf[i+2];F.DFT(A,1);
	for(i=m;i;--i){
		for(j=0;j<=n;++j)f[i-1][j]=mo-1ll*j*f[i][j]%mo,f[i][j]=1ll*fac[j+2]*f[i][j]%mo;
		reverse(f[i],f[i]+n+1);F.DFT(f[i],1);for(j=0;j<F.l;++j)f[i][j]=1ll*f[i][j]*A[j]%mo;F.DFT(f[i],-1);
		for(j=0;j<=n;++j)f[i-1][j]=(f[i-1][j]+1ll*vf[j]*f[i][n-j])%mo;
	}
	printf("%d\n",f[0][0]);
	return 0;
}

Measured memory_bytes: 14080