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

double dist(int a, int b);
int x[10], y[10];
int main(){
	int n;
	double sum = 0.0;
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i];
	vector<int> v(n);
	rep(i,n) v[i] = i + 1;
	do{
		rep(i, n-1) sum += dist(v[i], v[i+1]);
		
		}while(next_permutation(v.begin(), v.end()));
		
	int p=1;
	for(int i = 2; i <= n; ++i) p *= i;
	//cout << p << endl;
	double ans = sum/p;
	cout << fixed << setprecision(10) << ans << endl;
 	return 0;
}

double dist(int a, int b){
	double dx = x[a] - x[b];
	double dy = y[a] - y[b];
	return pow(dx*dx + dy*dy, 0.5);
}
 


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<char>r;
    for(int i = 0,j=0; i<n ; i++)
    {
        if(s[i+1] == s[i])
        {
            continue;
        }
        else
        {
            r.push_back(s[i]);
        }
    }
    int l = r.size();
    cout<<l<<endl;
    return 0;
}




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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ar[100];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,h,p,mn,i,c,v,t;
	cin >> n;
	h = 0;
	for(i=1;i<=n;++i)
	{
		cin >> t;
		if(t != ar[h])
			ar[++h] = t;
	}
	mn = 200;
	p = 1000;
	ar[0] = 1000;
	for(i=1;i<=h;++i)
	{
		if(ar[i]>ar[i-1] && ar[i]>ar[i+1])
		{
			c = p%mn;
			v = p/mn;
			p = c+v*ar[i];
			mn = 200;
		}
		else
			mn = min(mn,ar[i]);
	}

	cout << p << "\n";
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int A = 1;
  for(int i=0; i<N; i++){
    if(A < K){
      A *= 2;
    }else{
      A += K;
    }
  }
  cout << A << endl;
}

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

int main(){
  int N,x=0,y=0;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin >> a.at(i);
  sort(a.begin(),a.end());
  for(int i=1;i<=N;i+=2){
    x+=a.at(N-i);
    if(N-i-1>=0)y+=a.at(N-i-1);
  }
  cout << x-y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
int cnt[10];
string good = "keyence";
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    string s;
    cin>>s;
    bool ok = false;
    owo(i, 0, 7) {
        if(s.substr(0, i) + s.substr(s.size()-7+i, 7-i)==good)ok = true;
    }
    cout<<(ok ? "YES\n" : "NO\n");
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	long i,j,ans=1;
	for(i=0; i<s.size(); i++){
		if(s[i]=='A'){
			ans-=i; break;
		}
	}
	for(j=s.size()-1; j>=0; j--){
		if(s[j]=='Z'){
			ans+=j; break;
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
// Try Exawizards 2019
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    let c = get!();
    
    if a == b && b == c {
    	println!("Yes");
    } else {
    	println!("No");
    }
}

Measured memory_bytes: 4352
def insertionSort(_A, _N)
  printf "%s\n", _A.join(" ")
  for i in 1.._N-1
    v = _A[i]
    j = i - 1
    while j >= 0 && _A[j] > v do
      _A[j+1] = _A[j]
      j -= 1
    end
    _A[j+1] = v
    printf "%s\n", _A.join(" ")
  end
end

n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
insertionSort(arr, n)

Measured memory_bytes: 8828
#include <iostream>
using namespace std;
int H, W, DP[1001][1001]={{0}};
char A[1000][1000];

int main(){
    cin >> H >> W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) cin >> A[i][j];
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) {
            if(A[i][j]=='#') continue;
            else if(i+j==0) DP[i+1][j+1] = 1;
            else DP[i+1][j+1] = (DP[i][j+1]%1000000007 + DP[i+1][j]%1000000007)%1000000007;
        }
    }
    cout << DP[H][W] << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
int main()
{
while(true)
{
char c;
int a, b;
scanf("%d %c %d", &a, &c, &b);
if( c == '?') break;
int ans = 0;
switch(c)
{
case '+': ans = a+b; break;
case '-': ans = a-b; break;
case '*': ans = a*b; break;
case '/': ans = a/b; break;
}
printf("%d\n", ans);
}
return 0;
}

Measured memory_bytes: 1028
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
//USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN THE RESPECTIVE DATA STRUCTURE
//NOTE THAT MEMSET CANNOT ASSIGN A VALUE OF 10^18 IT WILL ASSIGN A LOWER VALUE THAN THAT!!!
//NOTE THAT MEMSET CANT FILL THE DOUBLE VALUES;
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long

 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>

 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}




void solve()
{
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    vi v1,v2,ans;ll xx;
    for(ll i=0;i<a;i++)
    {
        cin>>xx;v1.pb(xx);
    }
    for(ll i=0;i<b;i++)
    {
        cin>>xx;v2.pb(xx);
    }
    for(ll i=0;i<c;i++)
    {
        cin>>xx;ans.pb(xx);
    }
    sort(v1.begin(),v1.end(),greater<ll>());
     sort(v2.begin(),v2.end(),greater<ll>());
     
    for(ll i=0;i<x;i++)
    {
        ans.pb(v1[i]);
    }
    for(ll i=0;i<y;i++)
    {
        ans.pb(v2[i]);
    }
    sort(ans.begin(),ans.end(),greater<ll>());ll p=0;
    for(ll i=0;i<x+y;i++)
    {
        p+=ans[i];
    }
   
    cout<<p<<endl;
}

signed main()
{
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//   }
   
    solve();
    return 0;
}


Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int dp[50][1<<17];
int ans=1;
ll S,fow;
int main(){
    int n;scanf("%d",&n);
    int x,y,z;scanf("%d%d%d",&x,&y,&z);
    for(int i=0;i<n;i++){
        ans=1ll*ans*10%mod;
    }
    S=(1<<x+y+z)-1;
    fow=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=S;j++){
            for(int k=1;k<=10;k++){
                int T=(j<<k)|(1<<k-1);
                T&=S;
                if((T&fow)!=fow)
                    dp[i][T]=(dp[i][T]+dp[i-1][j])%mod;
            }
        }
    }
    for(int i=0;i<=S;i++){
        ans=(ans-dp[n][i]+mod)%mod;
    }
    printf("%d\n",ans);
    //system("pause");
    return 0;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} 

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  rep(i,N) cin >> T.at(i);
  
  ll res = 1;
  rep (i,N) res = lcm(res, T.at(i));
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int max=0,k;
  int n,count=0,ans=1;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    k=i;
    while(k>=1){
      if(k%2==0){
      count++;
      }
      k=k/2;
    }
    if(max<count){
    max=count;
    ans=i;
    }
    count=0;
  }
printf("%d",ans);
 return 0;
}

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

int main()
{
  ll A; cin >> A;
  ll B; cin >> B;

  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll c = A;
  ll cnt = 1;
  while (c < B) {
    c += A-1;
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

int A, B, M;

int main() {
  cin >> A >> B >> M;
  int a[A], b[B];
  for (int i = 0; i < A; ++i) cin >> a[i];
  for (int i = 0; i < B; ++i) cin >> b[i];
  
  int ans = 200000;
  for (int i = 0; i < M; ++i) {
    int x, y, c; cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  
  // 割引券を使わない場合の最小値
  sort(a, a + A);
  sort(b, b + B);
  ans = min(ans, a[0] + b[0]);
  
  cout << ans << endl;
   
  return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#include <ctime>
#include <set>
#define endl '\n'
#define ll unsigned long long
#define mod 1000000007
#define NCONS 100001
#define MACRO(a) for(int a = 1; a < 1001; a++)

using namespace std;
bool prime[100001];
bool _2017[100001];
int prefix[100001];

bool is_prime(int a)
{
	if (a == 1) return false;
	if (a == 2) return true;
	for (int i = 2; i * i <= a; i++)
		if (a % i == 0) return false;
	return true;
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	for (int i = 1; i < 100001; i++)
		if (is_prime(i)) prime[i] = true;
	for (int i = 1; i < 100001; i++)
		if (prime[i] && prime[(i + 1) / 2]) _2017[i] = true;
	for (int i = 1; i < 100001; i++)
	{
		int offset = 0;
		if (_2017[i]) offset = 1;
		prefix[i] = prefix[i - 1] + offset;
	}
	int Q; cin >> Q;
	while (Q--)
	{
		int l, r; cin >> l >> r;
		cout << prefix[r] - prefix[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
decks = $<.gets.to_i.times.map {$<.gets.split.map(&:to_i)}
L = decks.size
memo = Array.new(L) {[]}

minimum = ->(left, right) {
  return memo[left][right] if memo[left][right]
  result = if left == right
    0
  else
    (right - left).times.map do |i|
      decks[left][0] * decks[left + i][1] * decks[left + i + 1][0] * decks[right][1] +
        minimum.(left, left + i) + minimum.(left + i + 1, right)
    end.min
  end
  memo[left][right] = result
}
puts minimum.(0, L - 1)


Measured memory_bytes: 7340
package main

import (
        "fmt"
)

func main() {
        N := 0
        isOk := false
        fmt.Scan(&N)
FOR_LABEL:
        for i := 1; i <= 9; i++ {
                for j := 1; j <= 9; j++ {
                        if N == i*j {
                                isOk = true
                                break FOR_LABEL
                        }
                }
        }
        if isOk {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

Measured memory_bytes: 512
#include <stdio.h>

#define STR_LENGTH (3)
int main(int argc, char* argv[])
{
	//ABC158 A
	int i;
	char param;
	char s[STR_LENGTH + 1];
	int isDiff = 0;

	scanf("%s", &s[0]);

	param = s[0];
	for (i = 1; i < STR_LENGTH; i++) {
		if (param != s[i]) {
			isDiff = 1;
		}
		
	}

	if (isDiff == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}



Measured memory_bytes: 128
# GaussJordan
module GaussJordan
  def self.calc(a)
    a.length.times do |k|
      pivot = a[k][k]
      i = k

      i.upto(a[k].length - 1) do |j|
        a[k][j] /= pivot
      end

      a.length.times do |j|
        if j != k
          d = a[j][k]
          l = k
          l.upto(a[k].length - 1) do |m|
            a[j][m] -= d * a[k][m]
          end
        end
      end
    end

    a
  end
end

while line = gets
  a, b, c, d, e, f = line.chomp.split.map(&:to_f)
  g = [[a, b, c], [d, e, f]]
  answer = GaussJordan.calc(g)
  puts sprintf('%.3f %.3f', answer[0][2] + 0.0, answer[1][2] + 0.0)
end

Measured memory_bytes: 8672
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int l=sc.nextInt();
		int[] apple = new int[n];
		for(int i=0;i<n;i++) {
			apple[i]=l+i;
		}
		Arrays.parallelSort(apple);
		int sum=0;
		for(int i=0;i<n;i++) {
			sum+=apple[i];
		}
		int min=Integer.MAX_VALUE;
		int index=0;
		for(int i=0;i<n;i++) {
			int temp=Math.abs(apple[i]);
			if(min>temp) { min=temp; index=i;}
		}
		System.out.println(sum-apple[index]);
	}
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

inline ll check(ll b,ll n){
	ll ret=0LL;
	while(n) ret+=n%b,n/=b;
	return ret;
}


int main(void){
	ll n,s;
	cin >> n >> s;

	ll ans=n+2;
	
	for(ll b=2;b*b<=n;++b){
		ll res=check(b,n);
		if(res==s) chmin(ans,b);
	}


	for(ll x=1;x*x<=n;++x){
		ll y=s-x;
		if(y<0||n-y<0) continue;
		if((n-y)%x==0){
			ll b=(n-y)/x;
			if(x<b&&y<b) chmin(ans,b);
		}
	}

	if(n==s) ans=n+1;
	if(ans==n+2) ans=-1;
	cout << ans << endl;
	return 0;
}

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

using namespace std;


#define MAXN 501
int main() {
  int h, w, a[MAXN][MAXN];
  vector<pair<int, int>> ans;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 1; j < w; ++j) {
      if (a[i][j-1]%2) {
        ans.push_back({i, j-1});
        ans.push_back({i, j});
        a[i][j]++;
      }
    }
  }
  for (int i = 1; i < h; ++i) {
    if (a[i-1][w-1]%2) {
      ans.push_back({i-1, w-1});
      ans.push_back({i, w-1});
      a[i][w-1]++;
    }
  }
  cout << ans.size()/2 << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first+1 << " " << ans[i].second+1;
    if (i%2) cout << endl;
    else cout << " ";
  }
  return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3128
choice1 = int(input())
choice2 = int(input())

if choice1 == 1:
    if choice2 == 2:
        print(3)
    else:
        print(2)
elif choice1 == 2:
    if choice2 == 1:
        print(3)
    else:
        print(1)
elif choice1 == 3:
    if choice2 == 2:
        print(1)
    else:
        print(2)     

Measured memory_bytes: 3060
// AOJ 2739: Delivery to a Luxurious House
// 2017.10.8 bal4u@uu

#include <stdio.h>

int a[102];

int main()
{
	int n, m, m2, t, i, ans;

	scanf("%d%d%d", &n, &m, &t); m2 = m << 1;
	for (i = 0; i < n; i++) scanf("%d", a+i);
	ans = a[0]-m;
	for (i = 1; i < n; i++) {
		if (a[i]-a[i-1] > m2) ans += (a[i]-a[i-1])-m2;
	}
	if (t-a[n-1] > m) ans += t-a[n-1]-m;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n;
    string s;
    while(n>0)
    {
        k=n%26;
        if(k==0) k=26;
        char c=k+96;
        s+=c;
        n=(n-1)/26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<ee;
}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


Measured memory_bytes: 3668
/*
 * atcoder/abc148/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

// n!の因数に含まれる素数pの数
ll g(ll n, ll p) {
  if (n<p) return 0; // nが素数p未満ならpが含まれることはない.
  // 1 * 2 * 3 * ... * nの中でpの倍数はn/pだけある.
  // 今回pの倍数だったものはもう一度pで割れる可能性があるので(n/p)!で再帰的に数える.
  // 今回pの倍数だったものをpで割って出来る数列は(n/p)!になる.
  // 例えば、9! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 で素数が3の場合、
  // 3 6 9 が3の倍数なので3で割ると1 2 3 = 3!となる.
  // 3が3の倍数なので1 = 1!となる.
  return n/p + g(n/p, p);
}

// n!!の因数に含まれる素数pの数
ll h(ll n, ll p) {
  if (n%2==1) {
    return g(n, p) - h(n-1, p); // nは奇数より、n!から偶数部分（(n-1)!!）のみ引いた数.
  }

  ll res = g(n/2, p); // nは偶数より、n!! = 2 * 4 * 6 ... * nなので、全要素を2で割って、n!!/2^(n/2) = n/2!
  if (p==2) res += n/2; // 全要素を2で割っているので、素数pが2の場合のみその割った要素数分を加える.
  return res;
}

/*
 * 整数xの末尾の0の個数はxを10で割り切れる回数に等しい.
 * xを10で割り切れる回数は、min(xを5で割り切れる回数, xを2で割り切れる回数）に等しい.
 * これはxを素因数分解してx = 2^a * 5^b * ... と表した時に、
 * xを1回10で割るたびにx = 2^(a-1) * 5^(b-1)とaとbが両方-1されることから明らか.
 */
void solve() {
  ll n;
  cin >> n;
  cout << min(h(n, 2), h(n, 5)) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < N; i++) {
            sb.append(S.charAt(i)).append(T.charAt(i));
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 21460
n = int(input())
pattern = ["S", "H", "C", "D"]
cards = [[False for i in range(14)] for j in range(4)]

for i in range(n):
    mark,num = input().split()
    num = int(num)
    cards[pattern.index(mark)][num] = True

for i in range(4):
    for k in range(1,14):
        if cards[i][k] == False:
            print("%s %d"%(pattern[i],k))


Measured memory_bytes: 5600
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

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

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl;exit(0);}else return;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

//Dijkstra
template<class T> class Dijkstra {
public:
	vector<T> cost; //startからの距離
	vector<vector<pair<T, int>>> edge;//fromからtoへの<T>costの辺 

	Dijkstra(const int N, T inf) : cost(N, inf), edge(N) {
	}

	void make_edge(int from, int to, T w) {
		edge[from].push_back({ w,to });
	}

	void solve(int start) {
		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		pq.push({ 0,start });
		cost[start] = 0;
		while (!pq.empty()) {
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for (auto u : edge[from]) {
				T w = v + u.first;
				int to = u.second;
				if (w < cost[to]) {
					cost[to] = w;
					pq.push({ w,to });
				}
			}
		}
		return;
	}
};

int main() {
	int K; cin >> K;
	Dijkstra<int> dijk(K, (int)1e9);
	REP(i, K) dijk.make_edge(i, (i + 1)%K, 1);
	REP(i, K) dijk.make_edge(i, (i*10)%K, 0);
	dijk.solve(1);
	cout << dijk.cost[0]+1 << endl;

	
	return 0;
}



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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	ll a;
	vll k(4,0);
	FOR(i,0,5){
		cin >>a;
		k[a-1]++;
	}
	rSORT(k);
	YN(k[0]<3);
}


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

string s,t;
int a[30],c,d;
bool b[30];

int main(){
    cin >> s>> t;
    for(int i = 0;i<s.size();i++){
        c = s[i] - 'a' + 1;
        d = t[i] - 'a' + 1;
        if(!a[c] && !b[d]){
            a[c] = d;
            b[d] = true;
        }else if(a[c]!= d) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}



Measured memory_bytes: 1020
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while 1:
        s=input()
        if "0 0" in s:
            break
        else:
            a,b=map(int,s.split())
            for i in range(a):
                print("#"*b)
        print()

if __name__ == '__main__':
    main()


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> w(n), e(n);
	rep(i, n) {
		if(s[i]=='E') {
			e[i]++;
		} else {
			w[i]++;
		}
	}
	for(int i = 1; i<n; i++) {
		e[i] += e[i-1];
		w[i] += w[i-1];
	}
	int ans = 1001001001;
	rep(i, n) {
		int now;
		if(i > 0) now = w[i-1] + e[n-1] - e[i];
		else now = e[n-1] - e[i];
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3076
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();
    let ans = if convert(&s) == convert(&t) {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);

    use std::collections::HashMap;
    fn convert(v: &Vec<char>) -> Vec<i32> {
        let mut cv = vec![-1; v.len()];
        let mut tb = HashMap::new();

        let mut id = 0;
        for i in 0..v.len() {
            let c = &v[i];
            if let Some(&id) = tb.get(c) {
                cv[i] = id
            } else {
                id += 1;
                tb.insert(c, id);
                cv[i] = id
            }
        }
        cv
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

ll n,k;
int a[300000];
int t=1;
int s[300000];
int flag[300000];

void work()
{
    for (int i=1; i<=k; ++i)
    {
        for (int j=1; j<=n; ++j)
            {
                if(flag[a[j]]==0)
                {
                    flag[a[j]]++;
                    t+=1;
                    s[t]=a[j];
                }else
                {
                    while(s[t]!=a[j]) {flag[s[t]]--,t--;}
                    t--;
                    flag[a[j]]--;
                }
            }
        cout<<i<<endl;
        for (int j=1; j<=t; ++j)
            cout<<s[j]<<' ';
        cout<<endl;
        cout<<endl;
    }
}

int firstifi[300000]; // if begin with i, the number will be firstifi[i]
int nexti[300000]; // nexti[i] = j where min(a[i]==a[j])
int loc[300000]; //loc[a[i]] = j where min(a[i]==a[j])
int firstloc[300000]; //firstloc[num] = loc

void work2()
{
    for (int i=n; i>=1; --i)
    {
        firstloc[a[i]]=i;
        if (loc[a[i]]==0)
            nexti[i] = 0;
        else
            nexti[i] = loc[a[i]];
        loc[a[i]] = i;
    }

    //for (int i=1; i<=n; ++i)
    //    cout<<nexti[i]<<' ';
    //sssssssssssssssssssssssscout<<endl;

    for (int i=n; i>=1; --i)
        if (nexti[i]==0)
            firstifi[i] = a[i];
        else
            firstifi[i] = firstifi[nexti[i]+1];

    //for (int i=1; i<=n; ++i)
    //    cout<<firstifi[i]<<' ';
    //cout<<endl;
    int nownum = 0;
    for (int i=1; i<=k; ++i)
    {
        if (nownum==0)
            nownum = firstifi[1];
        else
            nownum = firstifi[firstloc[nownum]+1];
        s[t] = nownum;
        t++;
        if (nownum==0) break;
    }
    s[0]=0;
    t--;
    //for (int i=1; i<=t; ++i)
    //    cout<<s[i]<<' ';
    //cout<<endl;

    k = k-1;
    k = k%t;

    nownum = s[k];

    if (nownum!=0)
    {
            s[1]=nownum;
            t=1;
            flag[nownum]=1;
    }else
    {
        t=0;
    }


        for (int j=1; j<=n; ++j)
            {
                if(flag[a[j]]==0)
                {
                    flag[a[j]]++;
                    t+=1;
                    s[t]=a[j];
                }else
                {
                    while(s[t]!=a[j]) {flag[s[t]]--,t--;}
                    t--;
                    flag[a[j]]--;
                }
            }
        if (t==0)
        {
            cout<<endl;
            return;
        }

        for (int j=1; j<=t; ++j)
            cout<<s[j]<<' ';
        cout<<endl;


}
int main()
{
    cin>>n>>k;
    for (int i=1; i<=n; ++i)
        scanf("%d",&a[i]);
    work2();
    return 0;
}


Measured memory_bytes: 9216
N=gets.to_i
list=gets.chomp.split(" ").map(&:to_i)
list.sort!
list.reverse!
index=0
val=list[0]
if list.length==2
  print(list.max)
else
  
for i in 1..N-1
  if(val>val.gcd(list[i]))
    index=i
    val=val.gcd(list[i])
  end
end
if index==1
  if list[1].gcd(list[0])<list[1].gcd(list[2])
    index=0
  end
end
class Array
  def gcd
    self.inject{|a,b| a.gcd(b)}
  end
end
list.slice!(index)
print (list.gcd)
  
end

Measured memory_bytes: 10496
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	int N,X,T;
	void work()
	{
		while(scanf("%d%d%d",&N,&X,&T)!=EOF)
			printf("%d\n",(((N-1)/X)+1)*T);
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 3820
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}

//combination(Nが小さい時はこれを使う)
const int MAX = 300000;
int 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;
	}
}
int COMB(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;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = k; i <= n; i++) {
		int p = i * (i - 1) / 2;
		int q = (2 * n - i + 1) * i / 2;
		ans += q - p + 1;
		ans %= mod;
	}
	cout << ans + 1 << endl;
	ggr
}

Measured memory_bytes: 3684
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN=int(1e7)+5;
int n,m;
int fa[MAXN];
struct node {
	int u,v;
	double val;
}e[MAXN];
int cmp(node a,node b) {
	return a.val>b.val;
}
void Init() {
	for(int i=0;i<MAXN;i++)
		fa[i]=i;
}
int Find(int x) {
	if(x==fa[x])
		return x;
	return fa[x]=Find(fa[x]);
}
bool Merge(int x,int y) {
	int fx=Find(x),fy=Find(y);
	if(fx!=fy) {
		fa[fx]=fy;
		return 1;
	}
	return 0;
}
int cor[MAXN][3];
void Build(double &ans) {
	for(int i=1;i<=n;i++)
		scanf("%d%d",&cor[i][1],&cor[i][2]);
	for(int i=1;i<=m;i++) {
        int a,b;
		scanf("%d%d",&a,&b);
		e[i].u=a-1,e[i].v=b-1;
		e[i].val=sqrt((cor[a][1]-cor[b][1])*(cor[a][1]-cor[b][1])+(cor[a][2]-cor[b][2])*(cor[a][2]-cor[b][2]));
		ans+=e[i].val;
	}
}
int main()
{
	while(~scanf("%d%d",&n,&m)) {
		Init();
		double ans=-1;
		Build(ans);
		sort(e+1,e+m+1,cmp);
		for(int i=1;i<=m;i++)
			if(Merge(e[i].u,e[i].v))
				ans-=e[i].val;
		printf("%.3lf\n",ans+1.0);
	}
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << (b-1+a-2)/(a-1);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


typedef array<int, 4> tile;

//タイルを回転させて、色が辞書順最小になるようにする。
void normalize(tile &t) {
	tile rt = t;
	rep(dir, 4) {
		t = min(t, rt);
		rotate(begin(rt), begin(rt) + 1, end(rt));
	}
}

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

	int n; cin >> n;
	vector<tile> c(n);
	map<tile, int> cnt;
	rep(i, n) {
		rep(j, 4) cin >> c[i][j];
		normalize(c[i]);
		cnt[c[i]]++;//同じ色のタイルを区別しない
	}

	int res = 0;
	rep(i, n) {//cをソートする必要はない。
		cnt[c[i]]--;
		REP(j, i + 1, n) {
			cnt[c[j]]--;
			rep(dir, 4) {
				//c[i]が上面のタイルで、c[j]が底面のタイルとする。
				//t[4]は側面のタイル。
				//c[j]を回転させるのは、rep(dir,4)節の最後に行っている。
				tile t[4];
				t[0] = { c[i][0],c[i][3],c[j][0],c[j][3] };
				t[1] = { c[i][3],c[i][2],c[j][1],c[j][0] };
				t[2] = { c[i][2],c[i][1],c[j][2],c[j][1] };
				t[3] = { c[i][1],c[i][0],c[j][3],c[j][2] };
				map<tile, int> ccnt;
				int cur = 1;
				rep(k, 4) {//側面のタイルそれぞれについて
					normalize(t[k]), ccnt[t[k]]++;//正規化してmapに加える
					tile rt = t[k];
					int rot = 0;
					rep(dir2, 4) {//t[k]の色が回転して同じになるかを調べる。
						if (rt == t[k]) rot++;
						rotate(begin(rt), begin(rt) + 1, end(rt));
					}
					cur *= rot;
				}
				for (const auto &p : ccnt) {
					//側面のタイルそれぞれについて、必要枚数を持っているのか調べる。
					//必要枚数より多く持っているなら、curを増やす。
					int have = HAS(cnt, p.first) ? cnt[p.first] : 0, need = p.second;
					rep(k, need) cur *= have - k;
				}
				res += cur;
				rotate(begin(c[j]), begin(c[j]) + 1, end(c[j]));
			}
			cnt[c[j]]++;
		}
	}
	std::cout << res << endl;

	return 0;
}

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

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	vector<double> p,sums;
	sums.resize(n);
	for(int i=0;i<n;++i){
		double a;
		cin >> a;
		p.push_back((a+1.0)/2.0);
	}
	int c = 0;
	double tmp = 0;
	for(int i=0;i<n;++i){
		tmp += p[i];
		if(c == k){
			tmp -= p[i-k];
		}else{
			c++;
		}
		sums[i] = tmp;
	}
	double max = 0;
	for(int i=0;i<n;++i){
		if(max < sums[i])max = sums[i];
	}
	cout << setprecision(7) << max << endl;
}

Measured memory_bytes: 3956
import java.util.*;
 class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int ans,count;
		while(sc.hasNext()){
			ans = sc.nextInt();
			count = 0;
			for(int i = 0;i <= 9;i++){
				for(int j = 0;j <= 9;j++){
					for(int k = 0;k <= 9;k++){
						for(int l = 0;l <= 9;l++){
							if(ans == i + j + k + l){
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 19488
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  vi b(n+1);
  int m = 0;
  for (int i = n; i >= 1; --i) {
    int cnt = 0;
    for (int j = i; j <= n; j += i) {
      cnt += b[j];
    }
    if (a[i-1] != cnt%2) {
      b[i]++;
      m++;
    }
  }

  cout << m << endl;
  FOR(i,1,n+1) {
    if (b[i] != 0) printf("%d ", i);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1e9+7;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i<n; i++){
		cin >> h[i];
	}
	
	vector<int> dp(n, INF);
	
	dp[0] = 0;
	dp[1] = abs(h[0]- h[1]);
	for(int i = 2; i < n; i++){
		if(k == 1){
			dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
		}
		else{
			for(int j = 1; j <= k; j++){
				if(i - j >= 0){
					dp[i] = min(dp[i-j]+abs(h[i] - h[i-j]),dp[i]);
				}
				
			}
		}
	}
	
	cout << dp[n-1];
	return 0;
} 

Measured memory_bytes: 4048
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int peri, n;
        cin >> peri >> n;
        vector<int> a(n);
        for (auto &x : a)
            cin >> x;
        for (size_t i = 0; i < n; i++)
            a.pb(a[i] + peri);
        int res = INT_MAX;
        for (size_t i = 0; i < n; i++)
        {
            res = min(res, a[i + n - 1] - a[i]);
            db(i, res);
        }
        pc(a);
        cout << res << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 1804
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    map<int,int>yanaginagi;
    rep(i,N){
        int t; cin >> t;
        yanaginagi[t] = i;
    }
    for(auto itr : yanaginagi)
        cout << itr.second + 1 << endl;
}


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

int main(){
    int n;
    cin >> n;
    //高速な要素検索のみが必要でソートされることに関心がない場合はふつうunordered_mapを使い, mapを使わない.
    unordered_map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans = 0;
    //範囲for文:https://cpprefjp.github.io/lang/cpp11/range_based_for.html
    //keyを指定するときは.first value は.second
    for(auto& p : mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10660
#include <iostream>
#include <cstring>
typedef long long LL;
using namespace std;

char ary[20];
LL bai[20];
int main(){
	cin>>ary;
	int N=strlen(ary);
	LL hog=1,piy=9;
	for(int i=N-1;i>=0;i--){
		bai[i]=hog*(1<<i);
		hog=hog*2+piy;
		piy*=10;
	}
	LL res=0;
	for(int i=0;i<N;i++){
		res+=bai[i]*(LL)(ary[i]-'0');
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

cnt, ans, num = 0, 0, 10 ** 10
for ai in a:
    cnt += (ai < 0)
    ans += abs(ai)
    num = min(num, abs(ai))
print(ans if cnt % 2 == 0 else ans - 2 * num)


Measured memory_bytes: 85360