akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int f(int n){
    if(n==0 || n==1) return 0;
    else return n-1;
}

int main(void){
    string S; cin >> S;
    int K; cin >> K;
    int N = S.size();
    ll dp[N+1][2][K+1]; CLR(dp);
    dp[0][0][0] = 1;
    REP(i,N) dp[i+1][1][0] = 1;
    REP(i,N)REP(k,K){
        if(dp[i][0][k] > 0 && S[i]!='0'){
            dp[i+1][0][k+1] = 1;
        }
        else if(S[i] == '0'){
            dp[i+1][0][k+1] = dp[i][0][k+1];
        }
        dp[i+1][1][k+1] = dp[i][1][k]*9 + dp[i][1][k+1] + dp[i][0][k]*f(S[i]-'0');
        if(S[i] != '0') dp[i+1][1][k+1] += dp[i][0][k+1];
    }
    ll ans = dp[N][0][K] + dp[N][1][K];
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
const int maxn = 105;
int pre[maxn];
struct side
{
    int v1;
    int v2;
    double len;
    side(int vv1 = 0, int vv2 = 0, double ll = 0) :v1(vv1), v2(vv2), len(ll)
    {
    }
    friend bool operator <(const side&a, const side&b)
    {
        return a.len > b.len;
    }
};
vector<side>minHeap;
int Find(int x)
{
    int r = x;
    while (r != pre[r])
    {
        r = pre[r];
    }
    int c = x, p;
    while (c != r)
    {
        p = pre[c];
        pre[c] = r;
        c = p;
    }
    return r;
}
void Join(int x, int y)
{
    int f1 = Find(x), f2 = Find(y);
    if (f1 != f2) pre[f1] = f2;
}
double Kruskal()
{
    side tmp;
    int cnt = 1;
    for (int i = 0; i <= n; i++)pre[i] = i;
    double ans = 0;
    while (cnt < n)
    {
        pop_heap(minHeap.begin(), minHeap.end());
        tmp = minHeap.back();
        minHeap.pop_back();
        int u = Find(tmp.v1);
        int v = Find(tmp.v2);
        if (u != v)
        {
            Join(tmp.v1, tmp.v2);
            ans += tmp.len;
            cnt++;
        }
    }
    return ans;
}
struct node
{
    double x;
    double y;
    double z;
    double r;
}points[maxn];
int main()
{
    while (~scanf("%d", &n))
    {
        if (n == 0)break;
        minHeap.clear();
        for (int i = 0; i < n; i++)
        {
            scanf("%lf%lf%lf%lf", &points[i].x, &points[i].y, &points[i].z,&points[i].r);
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                double len = sqrt((points[i].x - points[j].x)*(points[i].x - points[j].x) + (points[i].y - points[j].y)*(points[i].y - points[j].y) + (points[i].z - points[j].z)*(points[i].z - points[j].z))-points[i].r-points[j].r;
                if (len < 0) len = 0;
                minHeap.push_back(side(i, j, len));
            }
        }
        make_heap(minHeap.begin(), minHeap.end());
        double ans = Kruskal();
        printf("%.3lf\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define rep(val,cnt) for(int (val)=0;(val)<(cnt);++(val))
#define all(v) (v).begin(),(v).end()
using namespace std;

using pint = pair<int,int>;
using tint = tuple<int,int,int>;

void Main(void);
signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
}

template<typename T>
struct edge{T to,cost;};

template<typename T>
class Graph{
	public :
	vector<vector<edge<T>>> graph;

	void add(int from,T to,int cost){
		graph[from].emplace_back((edge<T>){to,cost});
	}
	T prim(void){
		using Pi = pair<T,int>;
		T total=0;
		vector<bool> used(graph.size(),false);
		priority_queue<Pi,vector<Pi>,greater<Pi>> que;
		que.emplace(0,0);
		while(!que.empty()){
			auto p=que.top(); que.pop();
			if(used[p.second]) continue;
			used[p.second]=true;
			total+=p.first;
			for(auto &e : graph[p.second]) que.emplace(e.cost,e.to);
		}
		return total;
	}
};

void Main(void){
	int N; cin>>N;
	vector<tint> PX,PY;
	rep(i,N){
		int x,y; cin>>x>>y;
		PX.emplace_back(x,y,i),PY.emplace_back(y,x,i);
	}
	sort(all(PX)),sort(all(PY));
	Graph<int> gr; gr.graph.resize(N);
	for(int i=1;i<N;++i){
		int x1,y1,p1,x2,y2,p2,dist;
		tie(x1,y1,p1)=PX[i-1],tie(x2,y2,p2)=PX[i];
		dist=min(abs(x1-x2),abs(y1-y2));
		gr.add(p1,p2,dist),gr.add(p2,p1,dist);
		tie(x1,y1,p1)=PY[i-1],tie(x2,y2,p2)=PY[i];
		dist=min(abs(x1-x2),abs(y1-y2));
		gr.add(p1,p2,dist),gr.add(p2,p1,dist);
	}
	cout<<gr.prim()<<endl;
}

Measured memory_bytes: 24356
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);		
		int N = in.nextInt();
        int nam = 0;
        int flag = 0;
      
      for(int i = 1; i<=N; i++ ){
        nam = in.nextInt();
        if(nam!=i){flag++;}
        
      }
      if(flag<=2){
		System.out.print("YES");
      }else{System.out.print("NO");}
        
      }
	}

Measured memory_bytes: 23764
N,M = gets.split.map(&:to_i)
g = []
M.times do
  a,b = gets.split.map(&:to_i)
  g << [a,b]
end
g.sort_by!{|x| x[0]}

cnt = {}
ans = "IMPOSSIBLE"
g.each do |a,b|
  if a == 1
    cnt[b] = true
  elsif b == N && cnt[a]
    ans = "POSSIBLE"
  end
end
puts ans

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 500111

typedef long long ll;
typedef long double ld;

char str[maxn];
int arr[maxn];
int dp[maxn];
int n;

int main(){
	scanf("%d", &n);
	scanf("%s", str + 1);

	if(n <= 2){
		printf("0\n");
		return 0;
	}

	int l = 0;
	for(int i = 3; i <= n; i++){
		dp[i] = dp[i - 1];
		if(str[i] == '0')
			l = 0;
		else{
			if(str[i - 2] == '1' && str[i - 1] == '0' && str[i] == '1'){
				l = i;
				for(int j = i - 2; j >= 1 && str[j] == '1'; j--)
					dp[i] = max(dp[i], dp[j - 1] + (i - j + 1) - 2);	// 1...101
			}
		}

		if(l)
			dp[i] = max(dp[i], dp[l - 3] + (i - l + 1)); 	// 101...1, we add only 1 on right 
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    string X;
    cin>>X;
    
    stack<char> sta;
    REP(i,X.size()){
        if(sta.size()==0)sta.push(X[i]);
        else if(sta.top()=='S'&&X[i]=='T')sta.pop();
        else sta.push(X[i]);
    }
    
    cout<<sta.size()<<endl;
    
    return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
#define N 200005
using namespace std;

int read(){
	char c=getchar();
	int t=0,f=1;
	while(c>'9'||c<'0') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') t=t*10+c-'0',c=getchar();
	return t*f;
}

int n,Q,a[N],t[N],ans,cov[N];

struct Segment_Tree{
	int sum[N<<2],tag[N<<2];
	void pushdown(int x,int L,int mid,int R){
		if(!tag[x]) return;
		int tg=tag[x],ls=x<<1,rs=x<<1|1;
		sum[ls]+=tg*(mid-L+1),tag[ls]+=tg;
		sum[rs]+=tg*(R-mid),tag[rs]+=tg;
		tag[x]=0;
	}
	void modify(int x,int L,int R,int l,int r){
		if(L==l&&R==r) return (void)(tag[x]++,sum[x]+=(R-L+1));
		int mid=(L+R)>>1;
		pushdown(x,L,mid,R);
		if(r<=mid) modify(x<<1,L,mid,l,r);
		else if(l>mid) modify(x<<1|1,mid+1,R,l,r);
		else modify(x<<1,L,mid,l,mid),modify(x<<1|1,mid+1,R,mid+1,r);
		sum[x]=sum[x<<1]+sum[x<<1|1];
	}
	int query(int x,int L,int R,int po){
		if(L==R) return sum[x];
		int mid=(L+R)>>1;
		pushdown(x,L,mid,R);
		if(po<=mid) return query(x<<1,L,mid,po);
		return query(x<<1|1,mid+1,R,po);
	}
}T;

int main(){
	n=read(),Q=read();
	for(int i=1;i<=n;i++) t[a[i]=read()]++;
	for(int i=1;i<=n;i++)
		if(t[i]) T.modify(1,1,n,max(i-t[i]+1,1),i);
	for(int i=1;i<=n;i++){
		cov[i]=T.query(1,1,n,i);
		if(!cov[i]) ans++;
	}
	while(Q--){
		int x=read(),v1=a[x],v2=read();
		if(v1==v2){printf("%d\n",ans);continue;}
		int cg1=v1-t[v1]+1,cg2=v2-t[v2];
		if(cg1!=cg2){
			if(cg1>0&&cov[cg1]==1) ans++;
			if(cg2>0&&!cov[cg2]) ans--;
		}
		printf("%d\n",ans);
		if(cg1>0) cov[cg1]--;
		if(cg2>0) cov[cg2]++;
		t[v1]--,t[v2]++,a[x]=v2;
	}
}

Measured memory_bytes: 10112
#include<iostream>

int main(){
  long int N,H,W;
  long int A,B,count;
  std::cin>>N>>H>>W;
  for(int i=0;i<N;i++){
    std::cin>>A>>B;
    if(A>=H&&B>=W) count++;
  }
  std::cout<<count;
  return 0;
}


Measured memory_bytes: 256
//__professor_
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define test ll t;cin>>t;while(t--)
#define mod 1000000007
#define inf 1000000000000000001
const double pi=3.141592653589793238463;
using namespace std;

int main()
{
	FAST;
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	ll min=INT_MAX;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<min)
			min=arr[i];
	}

	ll ans[k+1];
	for(ll i=0;i<=k;i++)
	{
		ans[i]=-1;
	}
	for(ll i=0;i<n;i++)
	{
		ans[arr[i]]=0;
	}

	for(ll i=0;i<min;i++)
	{
		ans[i]=1;
	}

	
	for(ll i=min+1;i<=k;i++)
	{
		ll f=0;
		if(ans[i]==-1)
		{

			for(ll j=0;j<n;j++)
			{
				if((i-arr[j])>=0)
				{
					if(ans[i-arr[j]]==1)
					{
						f=1;
						break;
					}
				}
				
			}


			if(f==1)
			{
				ans[i]=0;
			}
			else
			{
				ans[i]=1;
			}

			
		}	
		
	}

	if(ans[k]==0)
	{
		cout<<"First"<<endl;
	}
	else
	{
		cout<<"Second"<<endl;
	}

	// for(ll i=0;i<=k;i++)
	// 	cout<<ans[i]<<" ";






	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  
  int n,m;
  while(cin >> n >> m,n != 0 || m != 0){
    vector<int> vec(n+m,0);
    for(int i = 0;i < n+m;i++){
      cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    int ans = vec[0] - 0;
    for(int i = 0;i < n+m-1;i++){
      ans = max(vec[i+1] - vec[i],ans);
    }
    cout << ans << endl;
    
  }
    
  return 0;
}

Measured memory_bytes: 1292
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    long[] as = [0];
    foreach (i, a; readln.split.to!(long[])) as ~= a + as[i];

    auto pq_max = new long[](N+1);
    auto pq_min = new long[](N+1);
    auto rs_max = new long[](N+1);
    auto rs_min = new long[](N+1);

    int i = 2, j = 1;
    while (i <= N) {
        while (j+1 < i && abs(as[j]*2 - as[i]) > abs(as[j+1]*2 - as[i])) ++j;
        pq_max[i] = max(as[j], as[i]-as[j]);
        pq_min[i] = min(as[j], as[i]-as[j]);
        ++i;
    }
    i = N-2, j = N-1;
    while (i >= 0) {
        while (j-1 > i && abs(as[j]*2 - as[i] - as[N]) > abs(as[j-1]*2 - as[i] - as[N])) --j;
        rs_max[i] = max(as[j]-as[i], as[N]-as[j]);
        rs_min[i] = min(as[j]-as[i], as[N]-as[j]);
        --i;
    }

    long r = long.max;
    foreach (k; 2..N-1) {
        r = min(r, max(pq_max[k], rs_max[k]) - min(pq_min[k], rs_min[k]));
    }
    writeln(r);
}

Measured memory_bytes: 16392
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	stack<string> a; set<string> b;
	string s; cin>>s;
	bool p = 1;
	a.push(s); b.insert(s);
	while (--n){
		cin>>s;
		string t = a.top();
		if (s[0] != t[(int)t.size()-1] || b.count(s)) p=0;
		a.push(s); b.insert(s);
	}
	if (p) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long tint;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend() 
#define NACHO ios::sync_with_stdio(0); cin.tie(NULL);

const int INF = 1111122222;
const int MOD = 1e9+7;

int main(){
	int h, n; cin >> h >> n;
	int sum = 0;
	forn(i, n){
		int x; cin >> x;
		sum+=x;
	}
	if(sum >= h) cout << "Yes" << "\n";
	else cout << "No" << "\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define N 100005
using namespace std;
int nt[2*N],fs[N],dt[2*N],n,m,s[N],f[N][20],ans;
void link(int x,int y)
{
	nt[++m]=fs[x];
	dt[fs[x]=m]=y;
}
void dfs(int k,int fa)
{
	for(int i=fs[k];i;i=nt[i])
	{
		int p=dt[i];
		if(p!=fa)
		{
			dfs(p,k);
			fo(j,0,19) f[k][j]+=f[p][j];
		}
	}
	int lim=0;
	fod(j,19,0) if(f[k][j]>1)
	{
		lim=j+1;
		break;
	}
	while(f[k][lim]) lim++;
	s[k]=lim;
	fo(j,0,lim-1) f[k][j]=0;
	f[k][lim]++;
	ans=max(ans,s[k]);
}
int main()
{
	cin>>n;
	fo(i,1,n-1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		link(x,y);
		link(y,x);
	}
	dfs(1,0);
	printf("%d",ans);
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 924844033;
// head
const int maxn = 2005;
int n, k, cnt;
LL fac[maxn], f[maxn<<1][maxn][2], g[maxn], ans;
bool vis[maxn<<1];

int main() {
	cin>>n>>k;
	rep(i, 1, k) {
		for(int j = i; j <= n; j += k) 
			vis[++cnt] = (j == i);
		for(int j = i; j <= n; j += k)
			vis[++cnt] = (j == i);
	}
	f[0][0][0] = fac[0] = 1;
	rep(i, 1, n) fac[i] = i*fac[i - 1]%mod;
	rep(i, 1, n<<1)
	    rep(j, 0, min(i, n)) {
	    	f[i][j][0] = (f[i - 1][j][0] + f[i - 1][j][1])%mod;
	    	if(!vis[i]) f[i][j][1] = f[i - 1][j - 1][0];
	    }
	rep(i, 0, n) {
		int op = (i&1) ? -1:1;
		g[i] = (f[n<<1][i][0] + f[n<<1][i][1])%mod;
		ans = (ans + op*g[i]*fac[n - i]%mod + mod)%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 105088
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const A = s[0];
  const B = s[1];
  const C = s[2];

  let modSet = new Set();

  for (let i = 0; i <= A * B; i++) {
    modSet.add((A * i) % B);
  }

  const answer = modSet.has(C) ? 'YES' : 'NO';
  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
void solve()
{
   ll n,ans=(ll)(1e12+2);
   
   cin>>n;
 
   for(ll i=1;i<=ceil(sqrt(n));i++)
   {
       ll a=i;
       ll b=n/i;
       
       if(a*b==n)
       ans=min(ans,a+b-2);
       
   }
    
    cout<<ans;
    return;
   
   
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

double a,b;

int main()
{
	in>>a>>b;
	out<<(int)((a+b)/2+0.5)<<std::endl;
	return 0;
}


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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


const int N = 1e5 + 5;
int freq[N][2];
int arr[N];
int n;

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int E = 0 , O = 0;
    cin >> n;
    loop(i,n){
        cin >> arr[i] , freq[arr[i]][i&1]++;
        if(i&1)O++;
        else E++;
    }

    set<pii> even , odd;
    range(i,1,N-1){
        even.insert({E - freq[i][0] , i});
        odd.insert({O - freq[i][1] , i});
    }

    int t = 0;
    int ans = n;
    for(auto p : even){
        t++;
        if(t == 100)break;
        int x = 0;
        for(auto po : odd){
            x++;
            if(x == 5)break;
            if(p.sc != po.sc)ans = min(ans , p.fr + po.fr);
        }
    }

    cout << ans << endl;



    return 0;
}


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

const int maxn = 105;
int n, m;	
int lq[maxn][maxn], fx[8][2] = {{1,0},{0,1},{1,1},{-1,0},{0,-1},{-1,-1},{1,-1},{-1,1}};
char s[maxn];
struct node { int x, y; };

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s", s);
		for (int j = 0; j <= m; ++j)
			if (s[j] == '#')
				lq[i][j + 1] = -1; 
			else lq[i][j + 1] = 0;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			if (lq[i][j] == -1)
				continue;
			node now;
			now.x = i;
			now.y = j;
			for (int k = 0; k < 8; ++k)
			{
				node newn;
				newn.x = now.x + fx[k][0];
				newn.y = now.y + fx[k][1];
				if (newn.x > 0 && newn.x <= n && newn.y > 0 && newn.y <= m && lq[newn.x][newn.y] == -1)
					lq[now.x][now.y]++;
			}
		}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
			if (lq[i][j] == -1)
				printf("#");
			else printf("%d", lq[i][j]);
		printf("\n");
	}
	
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N); //A[i]はiの上司を指す。
    A.at(0) = 0;
    for (int i = 1; i < N; i++) cin >> A.at(i); // [(0), 1, 1, 2, 2] 

    // 各上司について部下を求める。これには2次配列を用いる
    // 5人で、1 1 2 2 の場合、2と3の上司が1、4と5の上司は2となる。
    // [[2,3], [4,5], [], [], []]のような物を得たい。
    vector<vector<int>> B(N, vector<int>(0));

    /* for (int i = 1; i < N; i++){ 
(*_*; これでもできるがTLE ちょっとの改善でO(N)にできる!
        for (int j = 1; j <= N; j++){
            if (A.at(i) == j) B.at(j-1).push_back(i+1);
        }} */
    
    for (int i = 1; i < N; i++){ // iはAの添え字
        int boss = A.at(i);  // i+1番目の上司の番号はboss
        B.at(boss-1).push_back(i+1);  // こうすれば、O(N) !!
    }

    for (int i = 0; i < N; i++)
        cout << B.at(i).size() << endl;
}

Measured memory_bytes: 14860
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
double pi=3.14159265;

int main(){
    while(1){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if(op == '?') return 0;
        if(op == '+') cout << a+b << endl;
        if(op == '-') cout << a-b << endl;
        if(op == '*') cout << a*b << endl;
        if(op == '/') cout << a/b << endl;
    }
}


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


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

    int count = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
        count = count + vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    double a = ((double)count)/(4.0*M);


    int OK = 0;
    for (int j = 0; j < M;j++) {
        if (vec.at(j)>= a) {
            OK = OK + 1;
        }

    }
    if (OK == M) {
        cout << "Yes" << endl;

    }
    else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	float time5,time10;

	while(scanf("%f %f",&time5,&time10)!=EOF){
		if(time5<35.5 && time10<71.0)printf("AAA\n");
		
		else if(time5<37.5 && time10<77.0)printf("AA\n");
		
		else if(time5<40.0 && time10<83.0)printf("A\n");
		
		else if(time5<43.0 && time10<89.0)printf("B\n");
		
		else if(time5<50.0 && time10<105.0)printf("C\n");
		
		else if(time5<55.0 && time10<116.0)printf("D\n");
		
		else if(time5<70.0 && time10<148.0)printf("E\n");
		
		else printf("NA\n");
		
	}

	return 0;
}

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

bool g[2005][2005];
int n, m, q;
int a[2005][2005], b[2005][2005], c[2005][2005];

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

    cin >> n >> m >> q;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j) {
            char x;
            cin >> x;
            g[i][j] = (x-'0');
        }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j) {
            a[i][j] = (g[i][j] + a[i-1][j] + a[i][j-1] - a[i-1][j-1]);
        }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m-1; ++j) {
            bool t = (g[i][j]&g[i][j+1]);
            b[i][j] = (t + b[i-1][j] + b[i][j-1] - b[i-1][j-1]);
        }

    for (int i = 1; i <= n-1; ++i)
        for (int j = 1; j <= m; ++j) {
            bool t = (g[i][j]&g[i+1][j]);
            c[i][j] = (t + c[i-1][j] + c[i][j-1] - c[i-1][j-1]);
        }

    for (int i = 0; i < q; ++i) {
        int a1, b1, a2, b2;
        cin >> a1 >> b1 >> a2 >> b2;
        a1--; b1--;
        int v1 = a[a2][b2] - a[a1][b2] - a[a2][b1] + a[a1][b1];
        int v2 = b[a2][b2-1] - b[a1][b2-1] - b[a2][b1] + b[a1][b1];
        int v3 = c[a2-1][b2] - c[a1][b2] - c[a2-1][b1] + c[a1][b1];
        cout << v1 - v2 - v3 << "\n";
    }
}

Measured memory_bytes: 52864
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
using namespace std ;

#define MOD 998244353

long long n ;
string s ;

int f ( int x ) {
    if ( ( x & 1 ) == 0 ) { x = ( x >> 1 ) + (1<<(n-1)) ; }
    else { x >>= 1 ; }
    return x ;
}


string get_shift ( string aux ) {
    string ret = "" ;
    for ( int i = 1 ; i < n ; ++ i ) {
        ret += aux[ i ] ;
    }
    ret += aux[ 0 ] ;
    return ret ;
}

void input ( ) {
    cin >> n >> s ;
    /**
    n = 200000 ;
    s = "" ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        s += (char) ( '0' + (i%2) ) ;
    }
    **/
}

void solve ( ) {
    /**
    for ( int i = 0 ; i < (1<<n) ; ++ i ) {
        int x = f ( i ) ;
        int cnt = 1 ;
        while ( x != i ) {
            x = f ( x ) , ++ cnt ;
        }
        if ( cnt != 2 * n ) { printf ( "%d --> %d\n" , , x , cnt ) ; }
        if ( cnt == 12 ) { break ; }
    }
    **/
    long long ans = 0 ;
    for ( int i = 0 ; i < n ; ++ i ) {
        if ( s[ i ] == '0' ) { ans *= 2 ; }
        else { ans = ans * 2  + 1 ; }
        while ( ans >= MOD ) { ans -= MOD ; }
    }
    ans = ( ans + 1 ) % MOD ;
    ans = ( ans * n * 2 ) % MOD ;


    long long pat = 1 ;
    vector < pair < long long , long long > > v ;
    for ( pat = 1 ; pat < n ; ++ pat ) {
        if ( ( n % pat ) == 0 && ( n / pat ) % 2 == 1 ) {
            long long cnt = 0 ;
            for ( int i = 0 ; i < pat ; ++ i ) {
                if ( s[ i ] == '0' ) { cnt *= 2 ; }
                else { cnt = cnt * 2  + 1 ; }
                while ( cnt >= MOD ) { cnt -= MOD ; }
            }
            ///cout << cnt << "\n" ;
            bool fl = false ;
            int st = pat ;
            while ( st < n ) {
                int i ;
                for ( i = st ; i < st + pat ; ++ i ) {
                    if ( s[ i - pat ] == '1' && s[ i ] == '1' ) { break ; }
                    if ( s[ i - pat ] == '0' && s[ i ] == '0' ) { fl = true ; break ; }
                }
                if ( i < st + pat ) { break ; }
                st += pat ;
            }
            if ( fl == false ) { ++ cnt ; }
            while ( cnt >= MOD ) { cnt -= MOD ; }
            for ( int j = 0 ; j < v.size ( ) ; ++ j ) {
                if ( pat % v[ j ].first == 0 && ( pat / v[ j ].first ) % 2 == 1 ) {
                    cnt = ( cnt - v[ j ].second + MOD ) % MOD ;
                }
            }
            ans = ( ans - ( cnt * ( 2 * n - 2 * pat ) ) % MOD + MOD ) % MOD ;
            v.push_back ( { pat , cnt } ) ;
        }
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}



Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <list>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>
#include <random>
#include <fstream>


using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>m(H, vector<char>(W));
	vector<vector<bool>>m_b(H, vector<bool>(W, true));
	vector<vector<int>>m_i(H, vector<int>(W, 0));
	int black = 0;

	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> m[i][j];
			if (m[i][j] == '#') {
				m_b[i][j] = false;
				m_i[i][j] = -1;
				black++;
			}
		}
	}
	
	list<pair<int, int>>q;
	q.push_front(pair<int,int>(0,0));
	pair<int, int>now;
	pair<int, int>next;
	vector<pair<int, int>>arrow(4);
	arrow[0] = pair<int, int>(-1, 0);
	arrow[1] = pair<int, int>(0, 1);
	arrow[2] = pair<int, int>(1, 0);
	arrow[3] = pair<int, int>(0, -1);
	
	while (q.size() != 0) {
		now = q.front();
		q.pop_front();
		
		rep(i, 0, arrow.size()) {
			next.first = now.first + arrow[i].first;
			next.second = now.second + arrow[i].second;
			
			if (next.first < 0 || next.second < 0)continue;
			if (H <= next.first)continue;
			if (W <= next.second)continue;
			if (m_b[next.first][next.second] == false)continue;
			if (m[next.first][next.second] == '#')continue;

			q.push_back(next);
			m_b[next.first][next.second] = false;
			m_i[next.first][next.second] = m_i[now.first][now.second] + 1;
		}
	}
	if (m_i[H - 1][W - 1] == 0)cout << "-1" << endl;
	else cout << H*W - black - (m_i[H - 1][W - 1] + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
n, leg = map(int,input().split())

turtle_foreleg = leg - n*2 # all crane ?
if turtle_foreleg < 0:
    print('No')
    exit()

if turtle_foreleg % 2: # odd leg ?
    print('No')
    exit()

turtle = turtle_foreleg//2
crane = n - turtle
if crane < 0:
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 9168
import sys
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from copy import deepcopy 

def main():
    n = int(input())
    s = input()
    flag = False  
    
    for bit in range(4):
        ani0 = (bit>>0)&1
        ani1 = (bit>>1)&1

        if ani0 == 0:
            ans = ['S']
        else:
            ans = ['W']

        if ani1 == 0:
            ans.append('S')
        else:
            ans.append('W')
        
        before2 = ani0
        before1 = ani1
        for i in range(n - 1):
            if s[i + 1] == 'o':
                tmp = before2^before1
            else:
                tmp = before2^before1^1
            
            before1,before2 = tmp,before1

            if i != n - 2:
                if before1:
                    ans.append('W')
                else:
                    ans.append('S')
        
        if s[0] == 'o':
            tmp = before2^before1
        else:
            tmp = before2^before1^1
        
        before1,before2 = tmp,before1

        if before1 == ani1 and before2 == ani0:
            flag = True
            break
    
    if flag:
        print(''.join(ans))
    else:
        print(-1)

if __name__=='__main__':
    main() 

Measured memory_bytes: 4696
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
int N, M, a, b;

bool dfs(int src, vector<vector<bool>> &graph, vector<bool> &is_reeach){
  is_reeach[src] = true;

  for(int i = 0; i < N; i++){
    if(is_reeach[i]) continue;
    if(graph[src][i]) {
      dfs(i, graph, is_reeach);
    }
  }

  bool ret = true;
  for(bool b: is_reeach){
    ret = ret && b;
  }
  return ret;

}

int main() {
  //
  cin >> N >> M;
  vector<pair<int, int>> edges(M);
  vector<vector<bool>> graph(N, vector<bool>(N, false));
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;
    a--; b--;
    graph[a][b] = true;
    graph[b][a] = true;
    edges[i] = make_pair(a, b);
  }

  //
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    a = edges[i].first, b = edges[i].second;
    graph[a][b] = false;
    graph[b][a] = false;

    vector<bool> is_reeach = vector<bool>(N, false);
    if(!dfs(0, graph, is_reeach)) ans++;
//    cout <<  << endl;

    graph[a][b] = true;
    graph[b][a] = true;
  }

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



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

int main( void ) {
    int n;
    std::cin >> n;

    std::vector< int > ss;

    for( size_t i = 0; i < n; ++i ) {
        int s;
        std::cin >> s;
        ss.push_back( s );
    }

    std::sort(ss.begin(), ss.end());

    std::vector< int > mods;
    for( size_t i = 0; i < 10; ++i ) {
        mods.push_back( 0 );
    }

    for( size_t i = 0; i < n; ++i ) {
        std::vector< int > next_mods = mods;
        for( size_t j = 0; j < mods.size(); ++j ) {
            const int sum = mods[ j ] + ss[ i ];
            next_mods[ sum % 10 ] = std::max( next_mods[ sum % 10 ], sum );
        }
        mods = next_mods;
    }

    int max_sum = 0;
    for( size_t i = 1; i < mods.size(); ++i ) {
        max_sum = std::max( max_sum, mods[ i ] );
    }

    std::cout << max_sum << std::endl;

    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeMaximum(Node x){
 while(x->right!=NIL)x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL){
    x=y->left;
  }
  else x=y->right;

  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL)root=x;
  else{
    if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z)z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else{
    if(z->key<y->key)y->left=z;
    else y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25208
#include <cstdio>
#include <cstring>

#define MAX (1000000)

using namespace std;

typedef long long lint;

int eulerPhi(int n) {
	int ans;
	int x;
	if (n == 0){
		return (0);
	}
 	ans = n;
	for (x = 2; x * x <= n; ++x){
		if (n % x == 0) {
			ans -= ans / x;
			while (n % x == 0){
				n /= x;
			}
		}
	}
	if (n > 1){
		ans -= ans / n;
	}
	return (ans);
}
int main(void)
{
        int n, m;
	int i, j;
	static lint euler[MAX + 1];
	
	for (i = 1; i <= MAX; i++){
		euler[i] = eulerPhi(i);
	}
	
	for (i = 1; i <= MAX; i++){
		euler[i] += euler[i - 1];
	}
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d", &m);
		printf("%lld\n", euler[m] + 1);
	}
	
	return (0);
}

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

int main(){
  int f[10] = {};
  char c;
  
  for(int i=0; i<4; i++){
    cin >> c;
    c -= '0';
    f[c] = 1;
  }
  
  cout << (f[1] && f[9] && f[7] && f[4]? "YES": "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

size_t ceil_pow2(size_t n) {
  --n;
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  n |= n >> 32;
  return n+1;
}

constexpr int INF = 1000000000;

class SegmentTree {
 public:
  SegmentTree(const size_t n)
    : size(ceil_pow2(n)), data(2*size, INF), sum(2*size) {}
  // [l, r)
  void query_update(const size_t l, const size_t r, const int x) {
    update_impl(1, 0, size, l, r, x);
  }
  int query_sum(const size_t l, const size_t r) const {
    return sum_impl(1, 0, size, l, r);
  }
 private:
  void update_impl(const size_t idx, const size_t rngl, const size_t rngr,
      const size_t l, const size_t r, const int x) {
    if (r <= rngl || rngr <= l) return;
    if (idx >= size) {
      data[idx] = x;
      sum[idx] = x;
      return;
    }
    const auto mid = (rngl + rngr) / 2;
    if (l <= rngl && rngr <= r) {
      data[idx] = x;
      sum[idx] = x * (rngr - rngl);
    } else {
      if (data[idx] != INF) {
        update_impl(2*idx,   rngl, mid,  rngl, rngr, data[idx]);
        update_impl(2*idx+1, mid,  rngr, rngl, rngr, data[idx]);
      }
      data[idx] = INF;
      update_impl(2*idx,   rngl, mid,  l, r, x);
      update_impl(2*idx+1, mid,  rngr, l, r, x);
      sum[idx] = sum[2*idx] + sum[2*idx+1];
    }
  }
  int sum_impl(const size_t idx, const size_t rngl, const size_t rngr,
      const size_t l, const size_t r) const {
    if (r <= rngl || rngr <= l) return 0;
    if (idx >= size) return sum[idx];
    const auto mid = (rngl + rngr) / 2;
    if (data[idx] != INF) {
      return data[idx] * (min(r, rngr) - max(l, rngl));
    }
    if (l <= rngl && rngr <= r) {
      return sum[idx];
    } else {
      return sum_impl(2*idx,   rngl, mid,  l, r)
        +    sum_impl(2*idx+1, mid,  rngr, l, r);
    }
  }
  const size_t size;
  vecint data;
  vecint sum;
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,q;
  cin>>n>>q;
  SegmentTree st(n);
  st.query_update(0, n, 0);
  REP(i,q) {
    int a;
    cin>>a;
    if (a == 0) {
      int s,t,x;
      cin>>s>>t>>x;
      st.query_update(s, t+1, x);
    } else {
      int s,t;
      cin>>s>>t;
      cout<<st.query_sum(s, t+1)<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4916
K=int(input())
if K==32:
  print(51)
elif K==24:
  print(15)
elif K==16:
  print(14)
elif K==8 or K==12 or K==18 or K==20 or K==27:
  print(5)
elif K==28 or K==30:
  print(4)
elif K==4 or K==6 or K==9 or K==10 or K==14 or K==21 or K==22 or K==25 or K==26:
  print(2)
else:
  print(1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 100005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m;ll k;
int b[maxn],to[70][maxn],c[maxn];
double a[maxn],d[maxn];
int main()
{
    n=read();reg int i,j;
    for(i=1;i<=n;++i)a[i]=read();
    for(i=2;i<=n;++i)d[i]=a[i]-a[i-1];
    m=read(),k=read();
    for(i=1;i<=m;++i)b[i]=read();
    for(i=1;i<=n;++i)to[0][i]=i,c[i]=i;
    for(i=1;i<=m;++i)swap(to[0][b[i]],to[0][b[i]+1]);
    for(j=1;j<=62;++j)for(i=2;i<=n;++i)
        to[j][i]=to[j-1][to[j-1][i]];
    for(j=62;j>=0;--j)if(k>=(1ll<<j))
    {
        for(i=2;i<=n;++i)c[i]=to[j][c[i]];
        k^=(1ll<<j);
    }
    for(i=2;i<=n;++i)a[i]=d[c[i]]+a[i-1];
    for(i=1;i<=n;++i)printf("%.9lf\n",a[i]);
	return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    pll ans(100 * A, 0);
    REP(a, 31) {
        if (100 * A * a > F)
            break;
        REP(b, 31) {
            ll n = 100 * A * a + 100 * B * b;
            if (n > F)
                break;
            REP(c, 301) {
                if (c * C + n > F || c * C > (n / 100) * E)
                    break;
                REP(d, 301) {
                    ll m = c * C + d * D;
                    if (n + m > F || m > (n / 100) * E)
                        break;

                    if (ans.second * (n + m) <= m * ans.first) {
                        ans = pll(n + m, m);
                    }
                }
            }
        }
    }
    cout << ans.first << " " << ans.second << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N)cin >> A[i];
    bool frag = 1;
    REP(i,N){
        if(A[i] % 2 == 0){
            if(A[i] % 3 != 0 && A[i] % 5 != 0)frag = 0;
        }
    }
    if(frag){
        cout <<"APPROVED"<< "\n";
    }else{
        cout <<"DENIED"<< "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265

int main()  
{     
    IOS;
    string s;
    cin>>s;
    ll n=s.length();
    for(ll i=0;i<n-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2;
            return 0;
        }
        if(i+2<n&&s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3;
            return  0;
        }
    }
    cout<<-1<<" "<<-1;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int n;
int a[1010];

signed main()
{
    while (true) {
        cin >> n;
        if (n == 0) break;

        REP(i,n) cin >> a[i];
        sort(a, a + n);

        int minSa = INT_MAX;
        REP(i,n-1) {
            minSa = min(minSa, a[i+1] - a[i]);
        }

        cout << minSa << endl;
    }
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

vector<ii> e;
ll ans[MAXn];
ll dsu[MAXn],sz[MAXn];
ll fd(ll x){
  if (dsu[x] == x) return x;
  return dsu[x] = fd(dsu[x]);
}
void mrg(ll x,ll y){
  if (sz[x] > sz[y]) swap(x,y);
  dsu[x] = y;
  sz[y] += sz[x];
}
int main(){
  IOS();
  ll n,m;
  cin >> n >> m;
  REP (i,n) dsu[i] = i,sz[i] = 1;
  REP (i,m) {
    ll u,v;
    cin >> u >> v;
    u--,v--;
    e.eb(u,v);
  }
  ll tmp = n*(n-1)/2;
  for (ll i=m-1;i>=0;i--) {
    ans[i] = tmp;
    ll u = fd(e[i].X), v = fd(e[i].Y);
    if (u != v) {
      tmp -= sz[u] * sz[v];
      mrg(u,v);
    }
  }
  REP (i,m) cout << ans[i] << endl;
}


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

typedef long long LL;

void solve(long long N, std::vector<long long> A) {
  vector<LL> data = {0};
  for (auto elem : A) data.push_back(elem);
  data.push_back(0);
  LL ans = 0;
  for (int i = 0; i <= N; i++) ans += abs(data[i] - data[i + 1]);
  for (int i = 1; i <= N; i++) {
    LL tmp = ans + abs(data[i - 1] - data[i + 1]);
    tmp -= abs(data[i - 1] - data[i]) + abs(data[i] - data[i + 1]);
    cout << tmp << endl;
  }
}

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


Measured memory_bytes: 2932
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    ll N,M;
    cin >> N >> M;
    if(N==1 || M==1){
        if(N==M){
            cout << 1 << endl;
        }else{
            cout << N*M-2 << endl;
        }
    }else{
        cout << (N-2)*(M-2) << endl;
    }
    
    return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  int snk[N]={0};
  for(int i=0;i<K;i++){
    int d;
    cin >> d;
    for(int k=0;k<d;k++){
      int a;
      cin>>a;
      snk[a-1]=1;
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(snk[i]==0) count++;
  }
  cout<<count<<endl;
  return 0;
}

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int main()
{
	int n;
	cin >> n;
	int N = n;
	int t = 0;
	for (;n > 0; n /= 10) {
		t += n % 10;
	}
	if (N % t) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256