akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
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(){

    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;

    return 0;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int s;
	cin >> s;

	vi a(s+1, 0);
	a[0] = 1;

	FOR(i,3,s+1){
		a[i] = a[i-1] + a[i-3];
		a[i] = a[i] % (1000000007);
	}

	cout << a[s] << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vii = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';
const int mod = 1e9 + 7;


int calc(char arr[][1010], int h, int w) {

	int row[1010] = {0};
	int col[1010] = {0};

	for (int i = 1; i < h; i++) {
		if (arr[i][0] == '.') {
			row[i] = 1;
		} else {
			break;
		}
	}

	for (int j = 1; j < w; j++) {
		if (arr[0][j] == '.') {
			col[j] = 1;
		} else {
			break;
		}
	}
	for (int i = 1; i < h; i++) {
		col[0] = row[i];
		for (int j = 1; j < w; j++) {
			if (arr[i][j] == '.') {
				col[j] = (col[j] % mod + col[j - 1] % mod) % mod;
			} else {
				col[j] = 0;
			}
		}
	}
	return col[w - 1];
}





int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	char arr[1010][1010];
	int h, w;
	cin >> h >> w;

	for0(i, h) {
		for0(j, w) {
			cin >> arr[i][j];
		}
	}


	cout << calc(arr, h, w);
	return 0;
}



Measured memory_bytes: 1280
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int main(){
    int n, w;
    cin >> n >> w;
    vector<int> ws(n, 0);
    vector<int> vs(n, 0);
    for(int i = 0; i< n; i++){
        cin >> ws[i] >> vs[i];
    }
    long long dp[100010];
    for(int i = 0; i < 100010; i++){
        dp[i] = -1;
    }

    dp[0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 100000; j >= 0; j--){
            if(dp[j] != -1 && dp[j] + ws[i] <= w ){
                if(dp[j + vs[i]] == -1){
                    dp[j + vs[i]] = dp[j] + ws[i];
                }else{
                    dp[j + vs[i]] = min(dp[j + vs[i]] , dp[j] + ws[i]);
                }
            }
        }
    }
    

    int result;
    for(int i = 0; i < 100001; i++){
        if(dp[i] > 0) result = i;
    }

    cout << result << endl;
    return 0;
}

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

int main(){
    // あとで消す
    //std::ifstream in("ain2.txt");
    //std::cin.rdbuf(in.rdbuf());

    string S;
    cin >> S;

    // 長さを測る
    int len = S.length();
    //cout << len << endl; //debug
    // 長さ1なら抜ける
    if(len==1){
        cout << 1 << endl;
        return 0;
    }

    int K=1;

    // 最初は1文字で良い
    string prev = S.substr(0,1);
    int cursor = 1;
    int tmplen = 1;

    //
    while(true){
        if(cursor+tmplen>len){
            cout << K << endl;
            return 0;
        }
        // 今のやつ
        string tmp = S.substr(cursor,tmplen);

        // 同じなら
        if(tmp==prev){
            tmplen++;
            continue;
        // 違うなら
        }else{
            K++;
            cursor = cursor + tmplen;
            tmplen = 1;
            prev = tmp;
        }
    }

    cout << K << endl;


    return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main(){
  FastIO;
  ll n;
  cin>>n;
  char a[n];
  for(char &x : a){
     cin>>x;
  }
  ll ans =1;
  for(ll i=1;i<n;i++){
     if(a[i]!=a[i-1]){
        ans++;
     }
  }
  cout<<ans;
  return 0;
} 


Measured memory_bytes: 3708
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    if N-i > exchange:
        if c[-(i+1)] =="R":
            # c = list(c)
            # c[exchange] = "R"
            # c[-(i+1)] = "W"
            # c = "".join(c)
            # c = c[:exchange]+"R"+c[exchange+1:]
            # print("newc=",c)
            # c = c[:-(i+1)]+"W"+c[N-i:]
            # print("newc=",c)
            ans += 1
            for k in range(exchange+1,N-(i+1)):
                if c[k] == "W":
                    exchange = k
                    break
            else:
                break
    else:
        break
print(ans)

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

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

int main(int argc, const char * argv[]) {
    int N;
    int result = 0;
    
    cin >> N;
    
    vector<int> A(N, 0), L(N, 0), R(N, 0);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    L[0] = A[0];
    R[N - 1] = A[N - 1];
    
    for (int i = 1; i < N; i++) {
        L[i] = gcd(L[i - 1], A[i]);
    }
    for (int i = N - 2; i >= 0; i--) {
        R[i] = gcd(R[i + 1], A[i]);
    }
    result = max(L[N - 2], R[1]);
    for (int i = 1; i < N - 1; i++) {
        result = max(result, gcd(L[i - 1], R[i + 1]));
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 1408
use std::io::Read;
fn main() {
    let (_,v) = {
        let inputstr = {
            let mut inputstr = String::new();
            std::io::stdin().read_to_string(&mut inputstr).unwrap();
            inputstr
        };
        let mut inputiter = inputstr.split_whitespace();
        let n =  inputiter.next().unwrap().parse::<usize>().unwrap();
        let v:Vec<usize> = (1 .. n+1)
            .map(|_|{
                inputiter.next().unwrap().parse::<usize>().unwrap()
            })
            .collect::<Vec<_>>();
        (n,v)
    };
    let sorted_v:Vec<f64>={
        let mut v = v.clone();
        v.sort();
        v.into_iter().map(|x|x as f64).collect()
    };
    let ans = sorted_v.iter().fold(sorted_v[0],|a,b|(a+b)/2 as f64);
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include<iostream>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_N = 100, MAX_W = 10000;

int N, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N+1][MAX_W+1];

int main()
{
	std::cin >> N >> W;
	rep( i, N )
		std::cin >> v[i] >> w[i];

	dp[0][0] = 0;
	rep( i, N ) rep( j, W+1 )
	{
		if( j-w[i] >= 0 )
			dp[i+1][j] = std::max( dp[i][j], dp[i][j-w[i]]+v[i] );
		else
			dp[i+1][j] = dp[i][j];
	}

	std::cout << dp[N][W] << std::endl;

	return 0;
}

Measured memory_bytes: 7004
//file_name:ABC42_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(b<a)swap(a,b);
    if(c<b)swap(b,c);
    if(a==5&&b==5&&c==7)yn;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
const long long INF = 1LL<<60;
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

struct edge{LL from, to, cost;};

void bellman_ford(long long N, vector<edge> edges){
    vector<LL> shortest(N, INF);
    shortest[0]=0;
    LL saved=0;

    for(LL i=0; i<3*N; i++){
        for(auto e:edges){
            if(shortest[e.from] >= INF/2)continue;
            auto tmp = shortest[e.from]+e.cost;
            if(tmp < shortest[e.to]){
                shortest[e.to] = tmp;
            }
        }

        if(i==2*N-1)
            saved = shortest[N-1];
    }

    if(saved != shortest[N-1])cout << -1 << endl;
    else cout << max(-shortest[N-1],0LL) << endl;
}

void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vector<edge> edges(M);
    rep(i, M){
        edges[i]=(edge{A[i]-1,B[i]-1,-C[i]+P});
    }
    bellman_ford(N,edges);
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long P;
    scanf("%lld",&P);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, P, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 640
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;

vi init(string& P)
{
    vi b(P.size() + 1);
    int i = 0, j = -1; b[0] = -1;
    while (i < P.size())
    {
        while (j >= 0 && P[i] != P[j]) j = b[j];
        b[++i] = ++j;
    }
    return b;
}

vi kmp(string& T, string& P, vi& b)
{
    vi ret;
    int i = 0, j = 0;
    while (i < T.size())
    {
        while (j >= 0 && T[i] != P[j]) j = b[j];
        ++i; ++j;
        if (j == P.size())
        {
            ret.push_back(i - j);
            j = b[j];
        }
    }
    return ret;
}

std::string operator*(const std::string& s, size_t n) {
    std::string result;
    result.reserve(s.size()*n);
    for(size_t i = 0; i < n; ++i) {
        result += s;
    }
    return result;
}

void solve() {
    string s, t;
    cin >> s >> t;

    if (s.length() < t.length())
        s = s * ((t.length() + s.length() - 1) / s.length());
    int n = s.length();
    s = s * 3;

    int lo = 0;
    int hi = (s.length() + t.length() - 1) / t.length();
    while (lo < hi) {
        int mi = (lo + hi) / 2;
        string u = t * mi;
        vi b = init(u);
        vi m = kmp(s, u, b);
        if (m.empty())
            hi = mi;
        else
            lo = mi + 1;
    }

    string u = t * (lo - 1);
    if (u.length() >= 2 * n) {
        cout << -1 << '\n';
        return;
    }

    cout << lo - 1 << '\n';
    return;
}

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

    std::cout << std::boolalpha;
    std::cout << std::fixed << std::setprecision(6);

    solve();
}


Measured memory_bytes: 30012
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Vector.Unboxed as Vec
import Debug.Trace as De

--getIntList = map read . words <$> getLine


listToTriple abc =(a,b,c)
    where [a,b,c]=abc
main :: IO ()

fir (a,_,_)=a
sec (_,b,_)=b
trd (_,_,c)=c

solve:: Int->Int->Int ->Int
solve k x ans
    |(x `mod` k) == 0  = ans
    |ans>(k+10) = -1
    |otherwise = (solve k ((x*10+7) `mod` k) (ans+1))

main = do
    input <- getLine
    let k=(read input)
    putStrLn(show(solve k 7 1))



    



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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    vector<int> v(n + 1);
    rep(i, n) {
        cin >> v[i];
    }

    v[n] = x;
    sort(all(v));
    vector<int> dist(n);
    rep(i, n)
        dist[i] = abs(v[i + 1] - v[i]);

    int ans = dist[0];
    rep(i, n) {
        ans = gcd(ans, dist[i]);
    }
    out(ans);
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    long long a,b;cin>>a>>b;
    if(a*b<=0){
        cout<<"Zero"<<endl;
        return 0;
    }
    if(a>0){
        cout<<"Positive"<<endl;
        return 0;
    }
    if((b-a)%2==0){
        cout<<"Negative"<<endl;
    }
    else{
        cout<<"Positive"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, P = gets.split.map(&:to_i)
gain = []
score = 0
N.times do |i|
    w, b = gets.split.map(&:to_i)
    score -= b*P
    gain[i] = w*(100-P) + b*P
end
gain.sort!

ans = 0
while score < 0
    score += gain.pop
    ans += 1
end
puts ans

Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
 
#define fr first
#define sc second
#define pii pair<int, int>
#define int long long
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()	
#define prev myyyyrza1
#define y1 myyyyrza2
#define id id1234
#define pb push_back
#define OK() puts("OK")
 
using namespace std;
 
const int N = (1e6 + 12);
const int MOD = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int pw(int a, int b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2) {
		return pw(a, b - 1) * a;
	}
	else {
		int x = pw(a, b / 2);
		return x * x;
	}
}

main()
{
	int a, b;
	cin >> a >> b;
	int gcd = __gcd(a, b);
	int ans = 0;
	for (int i = 2; i * i <= gcd; i++) {
		if (gcd % i == 0) {
			ans++;
			while (gcd % i == 0) {
				gcd /= i;
			}
		}
	}
	
	if (gcd > 1) {
		ans++;
	}
	
	cout << ans + 1 << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  ll l, t;
  cin >> n >> l >> t;
  ll x[n];
  int w[n];
  REP(i, n) {
    cin >> x[i] >> w[i];
    w[i]--;
  }
  vector<ll> vec;
  REP(i, n) {
    if (w[0] != w[i]) {
      vec.push_back(x[i]);
    }
  }
  ll cnt = 0;
  REP(i, vec.size()) {
    if (w[0] == 0) {
      cnt += (2 * t) / l;
      cnt += ((2 * t) % l >= (vec[i] - x[0]));
    } else {
      cnt -= (2 * t) / l;
      cnt -= ((2 * t) % l >= (l - vec[i] + x[0]));
    }
  }
  cnt %= n;
  if (cnt < 0) cnt += n;
  vector<P> ans;
  REP(i, n) {
    if (w[i] == 0) {
      ans.push_back(P(-1, (x[i] + t) % l));
    } else {
      ans.push_back(P(-1, (x[i] + (-t % l) + l) % l));
    }
  }
  sort(ALL(ans));
  int pos = (w[0] == 0 ? -1 : n);
  REP(i, n) {
    if (w[0] == 0 && ans[i].second == (x[0] + t) % l) {
      pos = max(pos, i);
    } else if (w[0] == 1 && ans[i].second == (x[0] + (-t % l) + l) % l) {
      pos = min(pos, i);
      break;
    }
  }
  for (int i = pos, j = 0; i >= 0; --i, ++j) {
    ans[i].first = (cnt - j + n) % n;
  }
  for (int i = pos, j = 0; i < n; ++i, ++j) {
    ans[i].first = (cnt + j) % n;
  }
  sort(ALL(ans));
  REP(i, n) cout << ans[i].second << endl;
  return 0;
};


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        int a;
        cin >> a;
        m[a]++;
    }
    vector<int> v={0,0};
    for(auto [a,c]:m)
    {
        if(c>=2) v.push_back(a);
        if(c>=4) v.push_back(a);
    }
    sort(v.begin(),v.end(),greater<int>());
    cout << (ll)v[0]*v[1] << "\n";
    return 0;
}


Measured memory_bytes: 8272
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class Counter
{
	readonly Dictionary<int, int> c = new Dictionary<int, int>();
	public int this[int x] { get { return c.ContainsKey(x) ? c[x] : 0; } }
	public void Add(int x)
	{
		if (c.ContainsKey(x)) c[x]++;
		else c[x] = 1;
	}
}
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = ReadLine();
		for (var i = 0; i < S.Length; i += 2) Write(S[i]);
		WriteLine();
	}
}


Measured memory_bytes: 11232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);                  // 倍数の元
            int iB = int.Parse(sS[1]);                  // 除数
            int iC = int.Parse(sS[2]);                  // 余り

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstRst = new List<int>();         // 余りのあり得る一覧
            int iMul = 0;
            while (true)
            {
                iMul += 1;
                int iRst = (iA * iMul) % iB;
                if (lstRst.Contains(iRst)) { break; }
                else { lstRst.Add(iRst); }
            }
            string sOut = "NO";                        // 存在
            for (int i = 0; i < lstRst.Count; i++)
            {
                if (lstRst[i] == iC) { sOut = "YES"; break; }
            }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}


int32_t  main(){
	IOS;
  int a,b;cin>>a>>b;
  if(b%a==0)cout<<a+b<<endl;
  else cout<<b-a<<endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  int tmp;
  map<int, int> amap;
  vector<int> arr;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    if(amap[tmp]==0) arr.push_back(tmp);
    amap[tmp]++;
  }
  vector<int> arr1;
  for(int i=0;i<arr.size();++i) arr1.push_back(amap[arr[i]]);
  sort(arr1.begin(), arr1.end(), greater<int>());
  int ans = 0;
  for(int i=K;i<arr1.size();++i) ans += arr1[i];
  cout<<ans<<endl;
}



Measured memory_bytes: 14964
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int n, m; cin >> n >> m;
    vector<vector<char> > a(n, vector<char> (n));
    vector<vector<char> > b(m, vector<char> (m));
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
    for(int i = 0; i < m; i++) for(int j = 0; j < m; j++) cin >> b[i][j];
    
    bool ok = false;
    int num = m * m;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
        int cnt = 0;
        for(int ii = 0; ii < m && ii + i < n; ii++) for(int jj = 0; jj < m && jj + j < n; jj++){
            if(b[ii][jj] == a[ii + i][jj + j]) cnt++;
        }
        if(cnt == num) ok = true;
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> dp(n+1,1000000000);
  dp[0]=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=i;j*=6)
      dp[i]=min(dp[i],dp[i-j]+1);
    for(int j=1;j<=i;j*=9)
      dp[i]=min(dp[i],dp[i-j]+1);
  }
  cout<<dp[n]<<endl;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

vvll matmul(vvll& a, vvll& b) {
  ll xx = a.size();
  ll zz = a[0].size();
  assert(zz == (ll)b.size());
  ll yy = b[0].size();
  vvll ret(xx, vll(yy));

  rep(i, xx) rep(j, yy) {
    ll val = 0;
    rep(k, zz) {
      val += (a[i][k] * b[k][j])%mod;
      ret[i][j] = val % mod;
    }
  }

  return ret;
}

vvll matpow(vvll& m, ll n) {  // m^n
  ll xx = m.size();
  assert(xx == (ll)m[0].size());
  vvll ret(xx, vll(xx, 0));
  vvll cum = m;
  rep(i, xx) ret[i][i] = 1;
  while (n > 0) {
    if ((n & 1) == 1) ret = matmul(cum, ret);
    if (n == 1) break;
    cum = matmul(cum, cum);
    n >>= 1;
  }
  return ret;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  vvll as(n, vll(n));
  rep(i, n) rep(j, n) cin >> as[i][j];

  vvll res = matpow(as, k);
  ll ans = 0;
  rep(i, n) rep(j, n) ans = (ans +res[i][j])%mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long n,ans;
string s;
map<string,long long> mp;
int main(){
	cin>>n;
	for (long long i=0;i<n;i++){
		cin>>s;
		string t="";long long a[30]={0};
		for (long long j=0;j<s.size();j++) a[s[j]-'a']++;
		for (long long j=0;j<26;j++) t+=char(a[j]+'a');
		mp[t]++;
	}
	map<string,long long>::iterator it=mp.begin();
	for (;it!=mp.end();it++) if (it->second>1) ans+=(it->second-1)*it->second/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14464
import java.io.*;
import java.util.*;

public class Main {
    public static int MAX = 1000001;
    public static PrintWriter out;
    static class Query
    {
        public int l, r, idx;
        public Query(int l, int r, int idx){
            this.l=l;
            this.r=r;
            this.idx=idx;
        }
    }

    static void update(int idx, int val,
                       int bit[], int n)
    {
        for (; idx <= n; idx += idx & -idx)
            bit[idx] += val;
    }

    // querying the bit array
    static int query(int idx, int bit[], int n)
    {
        int sum = 0;
        for (; idx > 0; idx -= idx & -idx)
            sum += bit[idx];
        return sum;
    }

    static void answer(int[] arr, int n,
                                 Query[] queries, int q)
    {

        int[] bit = new int[n + 1];
        Arrays.fill(bit, 0);

        int[] last_visit = new int[MAX];
        Arrays.fill(last_visit, -1);
        
        int[] ans = new int[q];
        int qcount = 0;
        for (int i = 0; i < n; i++)
        {
            
            if (last_visit[arr[i]] != -1)
                update(last_visit[arr[i]] + 1, -1, bit, n);


            last_visit[arr[i]] = i;
            update(i + 1, 1, bit, n);

            while (qcount < q && queries[qcount].r == i)
            {
                ans[queries[qcount].idx] =
                        query(queries[qcount].r + 1, bit, n)
                                - query(queries[qcount].l, bit, n);
                qcount++;
            }
        }

        for (int i = 0; i < q; i++)
            out.println(ans[i]);
    }

    public static void main(String[] args) throws IOException
    {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int q = Integer.parseInt(st.nextToken());
        int[] arr = new int[n];
        st = new StringTokenizer(f.readLine());
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        Query[] queries = new Query[q];
        for(int i = 0; i < q; i++){
            st = new StringTokenizer(f.readLine());
            int a = Integer.parseInt(st.nextToken())-1;
            int b = Integer.parseInt(st.nextToken())-1;
            queries[i] = new Query(a, b, i);
        }

        Arrays.sort(queries, new Comparator<Query>()
        {
            public int compare(Query x, Query y)
            {
                if (x.r < y.r)
                    return -1;
                else if (x.r == y.r)
                    return 0;
                else
                    return 1;
            }
        });
        answer(arr, n, queries, q);
        out.close();
    }
}

Measured memory_bytes: 82816
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int selectionSort(int *num, int n) {
    int minj = 0;
    int count = 0;
    int i, j;
    for(i=0; i<n; i++) {
        minj = i;
        for(j=i; j<n; j++) {
            if(num[j]<num[minj]) {
                minj = j;
            }
        }
        swap(num[i], num[minj]);
        if(minj!=i) {
            count++;
        }    
    }
    return count;
}

int main() {
    int n;
    int count = 0;
    cin >> n;
    
    int num[n];
    for(int i=0; i<n; i++) {
        cin >> num[i];
    }
    
    count = selectionSort(num, n);
    for(int i=0; i<n; i++) {
        printf("%d", num[i]);
        if(i!=n-1) {
            printf(" ");
        }
    }
    printf("\n");
    printf("%d\n", count);
    
   return 0;
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);
            var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var count = 0;
            var vote = a.Sum();
            var limit = vote % (4 * m) == 0 ? vote / (4 * m) : vote / (4 * m) + 1;
            for(var i = 0; i < n; i++){
                if(a[i] >= limit){
                    count++;
                }
            }

            Console.WriteLine(count >= m ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int min = 1000;
    for (int j = 0; j < s.size(); j++) {
      string x = s.substr(j,3);
      int xx = stoi(x);
      int f = (xx-753)>0 ? xx-753:753-xx;
      if(f < min) {
        min = f;
      }
    }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<iomanip>
#include<cassert>
#include<functional>
typedef long long ll;

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

	std::string cur_char;
	int stack_count = 0;
	std::vector<int> stack;
	
	while (std::cin >> cur_char){
		switch (cur_char[0]){
		case '+':
			stack[stack_count - 2] += stack[stack_count - 1];
			stack.pop_back();
			stack_count--;
			break;
		case '-':
			stack[stack_count - 2] -= stack[stack_count - 1];
			stack.pop_back();
			stack_count--;
			break;
		case '*':
			stack[stack_count - 2] *= stack[stack_count - 1];
			stack.pop_back();
			stack_count--;
			break;
		default:
			stack.push_back(std::atoi(cur_char.c_str()));
			stack_count++;
			break;
		}
	}

	std::cout << stack[0] << '\n';

	return 0;
}


Measured memory_bytes: 3224
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.List
import Data.Ord
import Numeric

main = C.interact $ put . sol . get

get = fmap (unfoldr (C.readInteger . C.dropWhile (==' '))) . C.lines

put = C.pack . unlines

sol [[n,a,b],vs] = [showFFloat (Just 6) ave "",show cnt]
  where
  as = genericTake a $ sortBy (flip compare) vs
  v = last as
  x = genericLength $ filter (==v) as
  y = genericLength $ filter (==v) vs
  ave = fromIntegral (sum as)/fromIntegral a
  cnt = if x==a
    then sum $ binom y <$> [x..min y b]
    else binom y x

binom :: Integer -> Integer -> Integer
binom = loop 1 1
  where
  loop fn fk _ 0 = fn `div` fk
  loop _  _  0 _ = 0
  loop fn fk n k = loop (fn*n) (fk*k) (n-1) (k-1)

Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> niz(n);

    for (int i = 0; i < n; i++)
        cin >> niz[i];

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            sum += niz[i]*niz[j];
        }
    }

    cout << sum;
}

Measured memory_bytes: 3560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    int ans=0;
    REP(i,1,n){
        ans+=to_string(i).length()%2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;


int main() {
    int h,w;
    cin >> h >> w;
    string edge;
    for(int i = 0;i < w+2;i++){
        edge += '#';
    }
    for(int i = 0;i < h+2;i++){
        
        if(i == 0 || i == h+1){
            cout << edge << endl;
        }else{
            string z;
            cin >> z;
            string x;
            for(int i = 0;i < 3;i++){
                if(i == 0 || i == 2){
                    x += '#';
                }else{
                    x += z;
                }
            }
            cout << x << endl;
        }
    }
}




Measured memory_bytes: 256
var
	i,j,h,w,n,a,c,t:Longint;
	u:array[1..100]of Longint;
begin
	t:=1;
	read(h,w,n,a);
	for i:=1 to h do begin
		if i mod 2=1 then begin
			for j:=1 to w do begin
				u[j]:=t;
				inc(c);
				if a=c then begin
					read(a);
					c:=0;
					inc(t);
				end;
			end;
		end else begin
			for j:=w downto 1 do begin
				u[j]:=t;
				inc(c);
				if a=c then begin
					read(a);
					c:=0;
					inc(t);
				end;
			end;
		end;
		for j:=1 to w do writeln(u[j]);
	end;
end.


Measured memory_bytes: 128
def abc051_c():
  sx, sy, tx, ty = map(int, input().split())
  # ひとまずsの右上にtがある前提で経路作る
  path = ''
  # 1周目：左上方向に1ずつふくらむ
  path += 'R' * abs(tx - sx)
  path += 'U' * (abs(ty - sy) + 1)
  path += 'L' * (abs(tx - sx) + 1)
  path += 'D' * (abs(ty - sy) + 1)
  path += 'R'
  # 2周目：右下方向に1ずつふくらむ
  path += 'D'
  path += 'R' * (abs(tx - sx) + 1)
  path += 'U' * (abs(ty - sy) + 1)
  path += 'L' * (abs(tx - sx) + 1)
  path += 'D' * abs(ty - sy)
  # sとtの位置関係により座標反転
  if tx < sx:
    path.replace('R','X').replace('L','R').replace('X','L')
  if ty < sx:
    path.replace('U','Y').replace('D','U').replace('Y','D')
  print(path)

abc051_c()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
typedef long long int ll;
#define N 100005
int par[N],lev[N],tot[N];
void makeset(int n)
{
    fill(par,par+n,-1);
    fill(tot,tot+n,1);
    return;
}
int findset(int x)
{
    int y=x;
    while(par[y]>=0)
        y=par[y];
    if(x!=y)
        par[x]=y;
    return y;
}
void combine(int a,int b)
{
    a=findset(a);
    b=findset(b);
    if(a!=b)
    {
        if(lev[a]<lev[b])
            par[a]=b,tot[b]+=tot[a];
        else if(lev[a]>lev[b])
            par[b]=a,tot[a]+=tot[b];
        else
            lev[b]++,par[a]=b,tot[b]+=tot[a];
    }
    return ;
}
int color[N],vis[N];
vvi ad(N);
void dfs(int s)
{
    int i,x,a;
    x=ad[s].size();
    vis[s]=1;
    rep(i,x)
    {
        a=ad[s][i];
        if(!vis[a])
            color[a]=3-color[s],dfs(a);
    }
    return ;
}
int main()
{
    int n,i,a,b,c,x;
    in(n);
    vii vp;
    makeset(n);
    rep(i,n-1)
    {
        in3(a,b,c);
        if(c&1)
            vp.pb({a-1,b-1});
        else
            combine(a-1,b-1);
    }
    x=vp.size();
    rep(i,x)
    {
        a=findset(vp[i].F);
        b=findset(vp[i].S);
        ad[a].pb(b);
        ad[b].pb(a);
    }
    rep(i,n)
    {
        if(vis[i]==0 & par[i]<0)
            color[i]=1,dfs(i);
    }
    rep(i,n)
    {
        a=findset(i);
        color[i]=color[a];
    }
    rep(i,n)
        pr(color[i]-1);



}


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

int main(){
    int N,K;
    cin >> K >> N;
    vector<char> v;
    for(int i=0;i<N;i++){
        char s;
        cin >> s;
        v.push_back(s);
    }
    for(int i=K;i<100000;i++){
        stringstream ss;
        ss << i;
        string s=ss.str();
        for(int j=0;j<N;j++){
            if(s.find(v[j])!=string::npos) break;
            if(j==N-1){
                cout << s << endl;
                return 0;
            }
        }
    }
    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 ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n;cin>>n;
    vi v(n+1), w(n+1);
    rep(i,n)cin>>v[i+1]>>w[i+1];
    
    int q;cin>>q;
    vi s(q),tot(q);
    int mtot=0;
    rep(i,q){
        cin>>s[i]>>tot[i];
        mtot = max(mtot, tot[i]);
    }
    
    int size = min(n+1, 512);
    vv dp(size, vi(mtot+2, 0));
    
    for(int i=1; i<size; i++){
        for(int j=1; j<=mtot; j++){
            dp[i][j] = max(dp[i][j-1], dp[i/2][j]);
            if(j-w[i]>=0)
                dp[i][j] = max(dp[i][j], dp[i/2][j-w[i]]+v[i]);
        }
    }//dp[1~511][0~100000]のvが求まった
    
    rep(i,q){
        if(s[i]<size){
            cout << dp[s[i]][tot[i]] << endl;
            continue;
        }
        
        int len=0, b=s[i];
        while(b>511){
            b /= 2;
            len ++;
        }
        
        
        //int len = (int)log2(s[i])-8+1;
        
        int ans = 0;
        
        rep(k,1<<len){
            int vsum = 0, wsum = 0;
            b = s[i];
            rep(j,len){
                //if(wsum>tot[i])continue;
                if(k & 1<<j){
                    vsum += v[b];
                    wsum += w[b];
                }
                b /= 2;
            }
            
            if(wsum>tot[i])continue;
            ans = max(ans, vsum + dp[b][tot[i]-wsum]);
        }
        
        cout << ans << endl;
    }
    
    return 0;
}

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

int main() {
  long long N;
  cin >> N;
  for (int i = 0; ; i++) {
    if (N < i * i) {
      cout << (i - 1) * (i - 1) << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,N,ans,i,j,s,a[100005],flag=1;
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);

    }
    for(i=1; i<n; i++)
    {
        if(a[i+1]>a[i])
        {
            a[i+1]--;
        }
        if(a[i+1]<a[i])
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(void)
{
    long long int sum=0,range=0,a1,b1,a2,b2;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,money;
    //vector <int> v;
    //float f,g,h;
    int c,d,big=0;
    cin>>a1>>a2;
    cin>>b1>>b2;
    if(a1!=b1) cout<<1;
    else cout<<0;
    return 0;
}





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

int n, a[3010];
std::vector<int> adj[3010];

bool dfs(int x, int pre) {
	int adjx_size = adj[x].size();
	bool sgx = 0;
	for (int i = 0; i < adjx_size; ++i) {
		int y = adj[x][i];
		if (y != pre && a[x] > a[y] && !dfs(y, x)) sgx = 1;
	}
	return sgx;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y), adj[y].push_back(x);
	}
	for (int i = 1; i <= n; ++i) if (dfs(i, 0)) printf("%d ", i);
}		

Measured memory_bytes: 384
N,D = map(int,input().split())
grid = []
for i in range(N):
  array = list(map(int, input().strip().split()))
  grid.append(array)

var = 0
for i in range(N):
  x = grid[i][0]
  y = grid[i][1]
  if (x**2 + y**2) <= D**2:
    var += 1
print(var)

Measured memory_bytes: 45456
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<(ll)(n); i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int X1, Y1, X2, Y2;
	cin >> X1 >> Y1 >> X2 >> Y2;
	int dx = X2 - X1;
	int dy = Y2 - Y1;
	cout << X2 - dy << " " << Y2 + dx << " " << X1 - dy << " " << Y1 + dx << endl;
	return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll P[10], arr[10];
ll Q[10];

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &P[i]);
		arr[i] = P[i];
	}
	ll cnt = 0;
	ll X, Y;
	sort(arr, arr + N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &Q[i]);
	}
	do {
		cnt++;
		int flag = 0;
		int flag1 = 0;
		for(int i = 0; i < N; i++) {
			if(arr[i] != P[i]) {
				flag = 1;
				break;
			}
		}
		for(int i = 0; i < N; i++) {
			if(arr[i] != Q[i]) {
				flag1 = 1;
				break;
			}
		}
		if(!flag) {
			X = cnt;
		}
		if(!flag1) {
			Y = cnt;
		}
	}while(next_permutation(arr, arr + N));
	cout << abs(X - Y);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256