akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


const int MAX_N = 202020;
vector<int>e[MAX_N + 5];
vector<int>ap;
vector<pair<int, int>>br;
int ord[MAX_N + 5], low[MAX_N + 5], state[MAX_N + 5];
int cnt = 0;
void orddfs(int now,int parent) {
	state[now] = 1;
	ord[now] = cnt;
	cnt++;
	int ccnt = 0;
	int appended = 0;
	int clow = 1e9 + 5;
	int ordlow = 1e9 + 5;
	fore(x, e[now]) { 
		if (state[x] == 1) {
			//後退辺はx→uを含まない
			if(x != parent)ordlow = min(ordlow, ord[x]);
		}
		else {
			orddfs(x,now);
			clow = min(clow,low[x]);
			//関節点(根以外)
			if (parent != -1 && low[x] >= ord[now] && appended == 0) {
				ap.pb(now);
				appended = 1;
			}
			//橋
			if (low[x] > ord[now])br.pb({min(now,x),max(now,x)});
			ccnt++;
		}
	} 
	if (parent == -1 && ccnt >= 2)ap.pb(now);
	low[now] = min(min(clow,ordlow),ord[now]);
}

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

	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; i++){
		int s, t;
		cin >> s >> t;
		e[s].pb(t);
		e[t].pb(s);
	}
	orddfs(0,-1);
	sort(all(ap));
	fore(x,ap)cout << x << endl;

	return 0;
}


Measured memory_bytes: 9656
use proconio::input;
use petgraph::unionfind::UnionFind;
use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        m: usize,
        pairs: [(usize, usize); m],
    }
    
    let mut uf: UnionFind<usize>  = UnionFind::new(n);

    for (a, b) in pairs {
        uf.union(a-1, b-1);
    }

    let mut mm =  BTreeMap::<usize, usize>::new();
    for i in 0..n {
        *mm.entry(uf.find(i)).or_default() += 1;
    }

    println!("{}", *mm.values().max().unwrap());

}

Measured memory_bytes: 10616
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
 
const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);
 
using namespace std;
 
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    sort(ALL(A));
    int ok = 0;
    int ng = 2e5+1;
    
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        ll cnt = 0;
        //mid以上の幸福度を得ることができる握手の回数
        for(int i=0;i<N;i++){
            //左手をA[i]とすると、右手は, mid-A[i] となる地点から配列の最後までできる
            int a = lower_bound(ALL(A),mid - A[i]) - A.begin();
            cnt += N - a;
        }
        if(cnt>=M)ok=mid;
        else ng = mid;
    }
    //一回の握手で最低でもok以上の幸福度が得られる握手の総数は
    //M通り以上ということがわかっている
    vector<ll> b(N);
    b[0] = A[0];
    rep(i,N)if(i>0)b[i] = b[i-1] + A[i];
    //b[i] := A[0]からA[i]までの合計
    ll cnt2 = 0;
    ll ans = 0;
    for(int i=0;i<N;i++){
        //各ゲストについて
        int a = lower_bound(ALL(A),ok - A[i]) - A.begin();
        //aは、握手する人の中で一番幸福度が小さい人の添字
        cnt2 += N - a;
        //A[i]番目の人は(N-a)回握手する
        if(a==0)ans += N*A[i] + b[N-1];//もしも一番左から右端まで握手するなら
        else ans += ( N - a )*A[i]  + b[N-1] - b[a-1];
    }
    cout << ans - (cnt2 - M) *  ok << endl;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
 
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, c;
	cin >> n >>c;
	vector<vector<pii>> dt(c);
	
	rep(i, n){
		int s,t,z;
		cin >>s >>t >>z;
		dt[z-1].emplace_back(2*s-1, 2*t);
	}
	rep(i, c) sort(all(dt[i]));
	
	rep(i, c) if(sz(dt[i])>0){
		vector<pii> vp ={ dt[i][0] };
		rep2(j, 1, sz(dt[i])){
			if(vp.back().second >= dt[i][j].first){
				vp.back().second = dt[i][j].second;
			}else vp.push_back(dt[i][j]);
		}
		dt[i] = vp;
	}
	
	const int MXS=200100;
	vector<int> tm(MXS+100);
	rep(i, c) for(auto z: dt[i]){
		tm[z.first]++; tm[z.second + 1]--;
	}
	rep(i, MXS) tm[i+1] += tm[i];
	int ans =0;
	rep(i, MXS) ans = max(ans, tm[i]);
	cout << ans <<"\n";
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll mod_pow(ll x,ll n,ll mod){
  if(!n)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}

ll calc(ll n,ll m) {
  ll ans=1;
  rep(i,min(m,n-m)) {
    ans*=n-i;
    ans%=MAX;
    ans*=get_inv(i+1,MAX);
    ans%=MAX;
  }
  return ans;
}

void Main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans=(mod_pow(2,n,MAX)-1+MAX)%MAX;
  ans=(ans-calc(n,a)+MAX)%MAX;
  ans=(ans-calc(n,b)+MAX)%MAX;
  pr(ans);
}

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


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

int main() {
    int n; cin >> n;
    int count = 0;
    for (int i=1; i<=n; i++) {
        int ndivisor = 0;
        if (i%2 == 1) {
            for (int j=1; j<=i; j++) {
                if (i%j == 0) ndivisor++;
            }
            if (ndivisor == 8) count++;
        }
        //if (n%i == 0) count++;
    }
    cout << count << endl;
    return 0;
}


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

int main() {
	// your code goes here
	int h, m, s;
	cin>>s;
	h = s / 3600;
	s=s%3600;
	m = s /60;
	s=s%60;
	cout << h << ":" << m << ":" << s <<endl;
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main()
{
    int a;
    cin >> a;
    for (int i = 0; i < 3; ++i)
    {
        if (((a - 7) % 10) == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        a /= 10;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return !f?x:-x;
}
#define MAXN 500
#define INF 0x3f3f3f3f
int n,a[MAXN+5];
int main(){
	n=read();
	double sum=0;
	for(int i=1;i<=n;i++)
		sum+=1.0/read();
	printf("%.9f\n",1.0/sum);
	return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int H, W;
vector<string> s;

int f(int i, int j) {
    int c = 0;
    int i_1 = i - 1;
    int j_1 = j - 1;
    int it1 = i + 1;
    int jt1 = j + 1;

    if (i_1 >= 0) {
        if ( (j-1) >= 0 && s[i-1][j-1] == '#') {
            c++;
        }
        if (s[i-1][j] == '#') {
            c++;
        }
        if ( (j+1) < W && s[i-1][j+1] == '#') {
            c++;
        }

    }

    if (j-1 >= 0 && s[i][j-1] == '#') {
        c++;
    }
    if (j+1 < W && s[i][j+1] == '#') {
        c++;
    }

    if (i+1 < H) {
        if (j - 1 >= 0 && s[i+1][j-1] == '#') {
            c++;
        }
        if (s[i+1][j] == '#') {
            c++;
        }
        if (j + 1 < W && s[i+1][j+1] == '#') {
            c++;
        }
    }
    return c;
}

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        string t;
        cin >> t;
        s.push_back(t);
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                cout << "#";
            } else {
                cout << f(i, j);
            }

        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int n, m, u, v, s, x[9]={0,1};
vector<int> g[9];

void f(int p, int q) {
	if(q==n) {s++; return;}
	for(int i=0; i<g[p].size(); i++) {
		if(!x[g[p][i]]) {
			x[g[p][i]] = 1;
			f(g[p][i], q+1);
			x[g[p][i]] = 0;
		}
	}
}

int main() {
	cin>>n>>m;
	while(m--) {
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	f(1, 1);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <cmath>

using namespace std;



int  main(){
    int N;
    cin >> N;
    int h[N];
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    char a[16];
    cin>>a;
    int cnt=0;
    if(a[0]!='C')
    	cnt++;
    if(a[1]!='O')
    	cnt++;
    if(a[2]!='D')
    	cnt++;
    if(a[3]!='E')
    	cnt++;
    if(a[4]!='F')
    	cnt++;
    if(a[5]!='E')
    	cnt++;
    if(a[6]!='S')
    	cnt++;
    if(a[7]!='T')
    	cnt++;
    if(a[8]!='I')
    	cnt++;
    if(a[9]!='V')
    	cnt++;
    if(a[10]!='A')
    	cnt++;
    if(a[11]!='L')
    	cnt++;
    if(a[12]!='2')
    	cnt++;
    if(a[13]!='0')
    	cnt++;
    if(a[14]!='1')
    	cnt++;
    if(a[15]!='6')
    	cnt++;
    cout<<cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int MIN=9999;
string S;
void solve(int n,int m,int now){
 	if(m == 3){
      MIN = min(MIN,abs(753-now));
      return;
    }
  	if(n == S.size())
      return;
  	solve(n+1,m+1,10*now+(S[n]-'0'));
}
int main(){
    int s,t,a,res;
    map<int,int> mp;
  cin >> s;
  a = s;
  for(int i=1;;i++){
      if(mp[a] != 0){
          res = i;
          break;
      }else
        mp[a]++;
      if(a % 2){
          a = 3*a+1;
      }
      else{
          a = a/2;
      }
  }
  cout << (res) << endl;
  return 0;
}

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

using namespace std;

int main(void){
    int N, K;
    cin >> N >> K;
    
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    
    vector<bool> stones(K+3, false);
    
    // 1,2, ... Kまでの値で
    // それぞれ先手必勝or後手必勝７日を調べる
    // 答えはstones[K]により判定される
    // stones[K] == trueならば　先手必勝である
    // stones[K] == falseならば　後手必勝である
    
    for (int i = 1; i <= K; i++){
        
        for (int j = 0; j < N; j++){
            
            if (i - a[j] >= 0 && stones[i - a[j]] == false ) stones[i] = true;
        }
    }
    
    if (stones[K]) cout << "First" << endl;
    else cout << "Second" << endl;
    
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

ans = [[0] * W for h in range(H)]
h = 0
w = 0
t = 0

for index, a in enumerate(A):
  for i in range(a):
    ans[h][w] = index+1

    if t == 0 and w+1 < W:
      w += 1
      continue

    if t == 0 and w+1 >= W:
      h += 1
      t = 1
      continue

    if t == 1 and w-1 >= 0:
      w -= 1
      continue

    if t == 1 and w-1 < 0:
      h += 1
      t = 0
      continue

for i in ans:
  for k in i:
    print(k, end=" ")

  print("")

Measured memory_bytes: 3956
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int N;
  cin >> N;
  
  long long int total;
  
  vector<long long int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    total += A[i];
  }
  long long int snuke = 0LL;
  long long int arai = total;
  long long int minDiff = 9000000000;
  for(int i = 0; i < N-1; i++){
    snuke += A[i];
    arai -= A[i];
    minDiff = min(abs(snuke - arai),minDiff);
  }
  cout << minDiff;
  


}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
			
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		while (true) {
			C -= B;
			if (C <= 0) {
				System.out.println("Yes");
				break;
			}
			A -= D;
			if (A <= 0) {
				System.out.println("No");
				break;
			}
		}
	}
}

Measured memory_bytes: 35792
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,a[100010];

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(ll i=0; i<n; i++) cin >> a[i];

    for(ll i=n-2; i>=0; i--){
        if( a[i]>a[i+1] ) a[i]--;
        if( a[i]>a[i+1] ){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	long long sum;
	int i,n,q,s[100001],a,b,c;
	for(i=1;i<=100000;i++)	s[i]=0;
	scanf("%d",&n);
	sum=0;
	for(i=0;i<n;i++)	{
		scanf("%d",&a);
		s[a]++;
		sum+=a;
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%d %d",&b,&c);
		sum+=(long long)s[b]*(c-b);
		printf("%lld\n",sum);
		s[c]+=s[b];
		s[b]=0;
	}
	return 0;
}

Measured memory_bytes: 2120
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H-h)*(W-w) << endl;

}








Measured memory_bytes: 256
while True :
    n = int(input())
    if n == 0:
        break
    
    b = 1
    for i in range(n):
        b *= (i+1)
    
    a = 0
    while True :
        if b % 10 != 0:
            break
        else :
            b = b // 10
            a += 1
    print(a)


Measured memory_bytes: 5628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long L = sc.nextLong();
    long[] a = new long[n];
    String ans = "Impossible";
    int p = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    for(int i = 0; i < n - 1; i++) {
      if((a[i] + a[i + 1]) >= L) {
        p = i + 1;
        ans = "Possible";
        break;
      }
    }
    System.out.println(ans);
    if(ans.equals("Possible")) {
      for(int i = 1; i < p; i++) {
        System.out.println(i);
      }
      for(int i = n - 1; i > p; i--) {
        System.out.println(i);
      }
      System.out.println(p);
    }
  }
}


Measured memory_bytes: 61864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

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

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

	// ???????????°
	int vertical = Integer.parseInt(br.readLine());
	// ?¨?????????°
	int horizontal = Integer.parseInt(br.readLine());

	// ?????????????????°??????????????????
	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	// ?????\???????????????????´???????????????????????????????
	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	// ???????????????????????????????????¨?????\???????????????????????????????????????1??????????????????
	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    private static int[] getDrawedArray(List<int[]> changeRequests, int amidaLength, int loopCount) {
	// ?????\?????????????????????????????????????????????
	// outputArray[0]????????¨?????????
	int[] outputArray = new int[amidaLength + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	// ?????????????????????????£????????????\????????????
	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24236
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;vvi E2;
  const ll Inf = llINF;const int MAX_V=2555;vector<ll>d;
  Graph(int n):E(n),E2(n){d.resize(MAX_V);E.resize(MAX_V);V=n;E2.resize(MAX_V);}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});E2[to].pb(from);}
  //bellman_ford
  bool bellman_ford(int s) { // nは頂点数、sは開始頂点
    init();
    bool li[2555]={};
    li[V-1]=true;
    queue<ll>que;
    que.push(V-1);
    while(!que.empty()){
      ll now=que.front();
      que.pop();
     
      for(int i=0;i<E2[now].size();i++)
	if(li[E2[now][i]]==false){
	  li[E2[now][i]]=true;
	  que.push(E2[now][i]);
	}
    }
    d[s]=0;
    /*   for(int i=0;i<V;i++)
      cout<<li[i]<<" ";
      cout<<endl;*/
    for (int i=0;i<MAX_V;i++) {
      for (int v=0;v<MAX_V;v++) {
	for (int k=0;k<E[v].size();k++) {
	  Edge e=E[v][k];
	  if (d[v]!=Inf&&d[e.to]>d[v]+e.cost) {
	    d[e.to]=d[v]+e.cost;
	    if(i==MAX_V-1){
	      //cout<<v<<" "<<e.to<<endl;
	      if(li[e.to])
		return true; // n回目にも更新があるなら負の閉路が存在
	    }
	  }
	}
      }
    }
    return false;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,p;cin>>n>>m>>p;
  Graph g(n);
  for(int i=0;i<m;i++){
    ll a,b,c;cin>>a>>b>>c;
    --a;--b;
    g.add_edge(a,b,-(c-p));
  }
  if(g.bellman_ford(0)==false){
    cout<<max(0LL,-g.d[n-1])<<endl;
  }else{cout<<-1<<endl;}
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll A[57][57];

int main() {
    ll H,W;cin >>  H >> W;
    char C[57][57];
    rep(i,H){
        rep(j,W){
            cin  >> C[i+1][j+1];
            if(C[i+1][j+1]=='#'){
                A[i][j]++;
                A[i][j+1]++;
                A[i][j+2]++;
                A[i+1][j]++;
                A[i+1][j+2]++;
                A[i+2][j]++;
                A[i+2][j+1]++;
                A[i+2][j+2]++;
            }
        }
    }
    rep(i,H){
        rep(j,W){
            if(C[i+1][j+1]=='#'){
                cout <<"#";
            }
            else{
                cout << A[i+1][j+1];
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
const int M=2e5 +10;
long long a[M],b[M],n;
int main(){
	cin >> n;
	for(long long i=1;i<=n;i++){
		int x,y;
		cin >> x >> y;
		a[i]=x-y;b[i]=x+y;
	}
	sort(1+a,a+1+n); sort(b+1,b+n+1);
	long long ans = max(a[n]-a[1],b[n]-b[1]);
	cout<<ans<<'\n';
	return 0;
}

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

using namespace std;

typedef long long ll;

bool isPalin(int x){
	string s = to_string(x);
	int n = s.size();

	rep(i, n / 2){
		if(s[i] != s[n-1-i]) return false;
	}

	return true;
}

int palinNum(int x){
	int ret = 0;
	for(int i = 1; i <= x; i++){
		if(isPalin(i)) ret++;
	}

	return ret;
}

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

	int a, b;
	cin >> a >> b;

	cout << palinNum(b) - palinNum(a-1) << endl;
}


Measured memory_bytes: 256
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <set>
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
#define fi first
#define se second
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;
int main()
{
    LL a;
    float b;
    cin >> a >> b;
    LL d = (LL)(b*100 + 0.5);
    LL c =  a * d;
    cout << c / 100 << endl;
    return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", &s);
    long long int R=0, G=0, B=0;

    for(int i=0;i<n;i++){
        if(s[i]=='R') R++;
        if(s[i]=='G') G++;
        if(s[i]=='B') B++;
    }

    long long int X=0;
    for(int d=1;d<n;d++){
        for(int i=0;i+d+d<n+1;i++){
            if(i+d+d >= n) continue;
            if(s[i] != s[i+d] && s[i+d] != s[i+d+d] && s[i] != s[i+d+d]){
                //printf("%c %c %c\n", s[i], s[i+d], s[i+d+d]);
                X++;
            }
        }
    }
    //printf("%d\n", R*G*B);
    //printf("%d\n", X);
    printf("%lld\n", R*G*B-X);
    return 0;
}


Measured memory_bytes: 1736
n, m = map(int, input().split())
if n == 1 and m == 1:
    result = 1
elif n == 1:
    result = m - 2
elif m == 1:
    result = n - 2
elif n == 2 or m == 2:
    result = 0
else:
    result = (n-2)*(m-2)
print(result)


Measured memory_bytes: 2940
import sys

input = sys.stdin.buffer.readline

def query(i):
    '''
    a[0] + a[1] + … + a[i-1] を求める
    O(logN)
    '''
    res = 0
    while i > 0:
        res += BIT[i]
        i -= i & -i
    
    return res


def update(i, x):
    '''
    a[i-1]にxを加算
    O(logN)
    '''
    while i <= n:
        BIT[i] += x
        i += i & -i


n, q = map(int, input().split())
c = list(map(int, input().split()))
query_ = [list(map(int, input().split())) + [i] for i in range(q)]

query_.sort(key=lambda x: x[1])

res = [0] * q
pos = [-1] * n
BIT = [0] * (n+1)
p = 0
for l, r, idx in query_:
    for i in range(p, r):
        if pos[c[i]-1] != -1:
            update(pos[c[i]-1]+1, -1)
        update(i+1, 1)
        pos[c[i]-1] = i
    
    res[idx] = query(r) - query(l-1)
    p = r

for v in res:
    print(v)

Measured memory_bytes: 232476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
int n;
ll d[110][4][4][4];
string s="ACGT";
ll md=1e9+7;
ll res;
int main()
{
	cin >>n;
	d[0][3][3][3]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<4;j++)
		{
			for (int k=0;k<4;k++)
			{
				for (int l=0;l<4;l++)
				{
					for (int m=0;m<4;m++)
					{
						if (j==0 && k==2 && j==1) continue;
						if (j==0 && k==1 && j==2) continue;
						if (j==2 && k==0 && j==1) continue;
						if (k==0 && l==2 && m==1) continue;
						if (k==0 && l==1 && m==2) continue;
						if (k==2 && l==0 && m==1) continue;
						if (j==0 && k==2 && m==1) continue;
						if (j==0 && l==2 && m==1) continue;
						d[i][k][l][m]=(d[i][k][l][m]+d[i-1][j][k][l])%md;
						//cout <<i<<" "<<s[k]<<" "<<s[l]<<" "<<s[m]<<" "<<d[i][k][l][m]<<" ##\n";
					}
				}
			}
		}
	}
	for (int i=0;i<4;i++)
	{
		for (int j=0;j<4;j++)
		{
			for (int k=0;k<4;k++)
			    res=(res+d[n][i][j][k])%md;
		}
	}
	cout <<res;
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=100005;
int a[MAXN],n,b[MAXN];
vector<int> C;
bool check(int mod)
{
	for(int i=0;i<=n;i++)b[i]=(a[i]%mod+mod)%mod;
	for(int i=n;i>=mod;i--)if(b[i])
	{
		int h=b[i];b[i]=0;
		b[i-(mod-1)]+=h;if(b[i-(mod-1)]>=mod)b[i-(mod-1)]-=mod;
	}
	for(int i=min(n,mod-1);i>=0;i--)if(b[i])return false;
	return true;
}
int gcd(int a,int b){return a==0?b:gcd(b%a,a);}
bool is[MAXN];
int main()
{
//	freopen("a.in","r",stdin);
	int t=0;
	n=read();for(int i=n;i>=0;i--)a[i]=read(),t=gcd(t,a[i]);t=abs(t);
	for(int i=2;1LL*i*i<=t;i++)if(!(t%i))
	{
		C.emplace_back(i);
		while(!(t%i))t/=i;
	}if(t>1)C.emplace_back(t);
	for(int i=2;i<=n;i++)if(!is[i])
	{
		C.emplace_back(i);
		for(int j=2;i*j<=n;j++)is[i*j]=1;
	}
	sort(C.begin(),C.end());
	C.erase(unique(C.begin(),C.end()),C.end());
	for(auto p:C)if(check(p))
		pr2(p);
	return 0;
}



Measured memory_bytes: 384
#include <cstring>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <cmath>
#include <queue>
using namespace std;
const int maxn=500000;
vector<string> s;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        string x;
        cin>>x;
        s.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j]=='#')
                cout<<'#';
            else
            {
                int cnt=0;
                if(i-1>=0&&j-1>=0)
                    if(s[i-1][j-1]=='#')
                    cnt++;
                if(i-1>=0)
                    if(s[i-1][j]=='#')
                    cnt++;
                if(i-1>=0&&j+1<m)
                    if(s[i-1][j+1]=='#')
                    cnt++;
                if(j-1>=0)
                    if(s[i][j-1]=='#')
                    cnt++;
                if(j+1<m)
                    if(s[i][j+1]=='#')
                    cnt++;
                if(i+1<n)
                {
                    if(j-1>=0)
                        if(s[i+1][j-1]=='#')
                        cnt++;
                    if(s[i+1][j]=='#')
                        cnt++;
                    if(j+1<m)
                        if(s[i+1][j+1]=='#')
                        cnt++;
                }
                cout<<cnt;
            }
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import bisect

N,Q = (int(x) for x in input().split())

stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]

stop_arr.sort(key=lambda x:x[2])

ans_arr = [-1]*Q
skip_arr = [-1]*(Q+1)

def update_skip(skip_arr, x):
    if skip_arr[x] == -1:
        return x
    x_dest = update_skip(skip_arr, skip_arr[x])
    skip_arr[x] = x_dest
    return x_dest

for s,t,x in stop_arr:
    q_start = bisect.bisect_left(Q_arr, s-x)
    q_stop = bisect.bisect_left(Q_arr, t-x)
    l = q_start
    while l < q_stop:
        if skip_arr[l] == -1:
            skip_arr[l] = q_stop
            ans_arr[l] = x
            l += 1
        else:
            l = update_skip(skip_arr, l)

print(*ans_arr, sep="\n")


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) {
    cin >> p.at(i);
    p.at(i)--;
  }
  rep(i, n) cin >> c.at(i);

  ll ans = -1e18 - 1;
  rep(si, n) {
    // まず周期を求める
    int current = si;
    vector<int> s;
    ll tot = 0;
    while (1) {
      current = p.at(current);
      s.push_back(c.at(current));
      tot += c.at(current);
      if (current == si) break;
    }

    // 最大値を求める
    int l = s.size();
    ll t = 0;
    rep(i, l) {
      t += s.at(i);
      if (i + 1 > k) break;
      ll now = t;
      if (tot > 0) {
        ll loopNum = (k - i - 1) / l;
        now += tot * loopNum;
      }
      ans = max(ans, now);
    }
  }

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

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

int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(a>=b&&c>=d)
        {
            printf("%d\n",b+d);
        }
        else if(b>=a&&c>=d)
        {
            printf("%d\n",a+d);
        }
        else if(b>=a&&d>=c)
        {
            printf("%d\n",a+c);
        }
        else if(a>=b&&d>=c)
        {
            printf("%d\n",b+c);
        }
    }
    return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 600000;

/* ...o(^-^)o... */
lint arr[MAX];
struct segtree{
    int n;
    segtree(int n_){
        n = 2;
        while(n < n_) n *= 2;
        rep(i, n*2) arr[i] = 0;
    }
    void update(int k, lint a){
        k += n - 1;
        arr[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            arr[k] = max(arr[k * 2 + 1], arr[k * 2 + 2]);
        }
    }
    long query_(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return arr[k];
        else{
            int vl = query_(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query_(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    long query(int a, int b){
        return query_(a, b, 0, 0, n);
    }
};

int main(){
    int n; cin >> n;
    vector<P> vp;
    rep(i, n){
        lint x, d; cin >> x >> d;
        vp.push_back(P(x, x + d));
    }
    sort(all(vp));

    rep(i, n){
        P p = P(vp[i].se, -INF);
        auto itr = lower_bound(all(vp), p);
        vp[i].se = itr - vp.begin();
    }

    segtree st(n+1);
    rep(i, n) st.update(i, i);
    vector<lint> r(n);
    repr(i, n){
        lint q = st.query(i, vp[i].se);
        r[i] = q;
        st.update(i, q);
    }

    vector<lint> dp(n+1);
    dp[n] = 1;
    repr(i, n){
        dp[i] = dp[i+1];
        if(r[i] + 1 <= n) dp[i] += dp[r[i]+1];
        dp[i] %= MOD9;
    }

    out(dp[0]);
}

Measured memory_bytes: 11244
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long mod = 1000000007;
		long[] A = new long[N];
		long sum = 0;
		for(int i = 0; i < N; i++){
			A[i] = sc.nextLong();
			sum += A[i];
			sum %= mod;
		}
		
		long ans = 0;
		
		//i について全探索する
		for(int i = 0; i < N; i++){
			//A[i+1] ... A[N] の値を更新する
			sum -= A[i];
			if(sum < 0) sum += mod;
			
			ans += A[i]*sum;
			ans %= mod;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 62708
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	
	unordered_set<int> with_snacks;
	
	while(k--){
		int d;
		cin>>d;
		
		while(d--){
			int p;
			cin>>p;
			with_snacks.insert(p);
		}
	}
	
	cout<<n - with_snacks.size();
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

ll a[3005];
ll dp[3005][3005];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int w = 1; w <= n; w++) {
		for (int i = 0; i + w <= n; i++) {
			if (w % 2 == n % 2) dp[i][i + w] = max(dp[i + 1][i + w] + a[i], dp[i][i + w - 1] + a[i + w - 1]);
			else dp[i][i + w] = min(dp[i + 1][i + w] - a[i], dp[i][i + w - 1] - a[i + w - 1]);
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}

Measured memory_bytes: 70016
A,B = gets.split.map(&:to_i)
S = gets.chomp
C = S.split('').slice(0,A)
D = S.split('').slice(A+1,B)
E = S.split('')
if C.all?{|x| x != '-'} && D.all?{|x| x != '-'} && E[A] == '-'
 puts 'Yes'
else 
    puts 'No'
end


Measured memory_bytes: 1788
'use strict';
(function(stdin) {
  var inputs  = stdin.toString();
  var r = parseFloat(inputs);
  var circlearea = Math.pow(r,2) * Math.PI ;
  var circumference = 2 * Math.PI * r;

//  console.log(circlearea.toFixed(5),circumference.toFixed(5));
  console.log(circlearea,circumference);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int freq[64];
unsigned long long arr[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    unsigned long long k, a; cin >> n >> k;

    for(int i = 0; i < n; ++i){
        cin >> a;
        arr[i] = a;
        for(int p = 0; p < 63; ++p)
            if((a >> p) & 1)
                ++freq[p];
    }

    unsigned long long nc1, nc2, x = 0;

    bool is_less = false;

    for(int pos = 63; pos >= 0; --pos){

        if(is_less == false && ((k >> pos) & 1) == 0)
            continue;

        if(freq[pos] * 2 < n){
            x |= 1ULL << pos;
        } else if((k >> pos) & 1){
            is_less = true;
        }

    }

    unsigned long long tot = 0;
    for(int i = 0; i < n; ++i)
        tot += x ^ arr[i];

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 1024
def solve():
    K = int(input())
    lunluns = []
    for i in range(1,10):
        dfs(1,i,lunluns)
    
    lunluns.sort()
    print(lunluns[K-1])

def dfs(d,now,lunluns):
    lunluns.append(now)

    if d == 10:
        return
    
    for i in [-1,0,1]:
        add = now % 10 + i

        if 0 <= add <= 9:
            dfs(d+1,now*10+add, lunluns)
        
if __name__ == '__main__':
    solve()


Measured memory_bytes: 80736
# abc122_b.py
# https://atcoder.jp/contests/abc122/tasks/abc122_b

# B - ATCoder /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 英大文字からなる文字列 Sが与えられます。Sの部分文字列 (注記を参照) であるような最も長い ACGT 文字列 の長さを求めてください。
# ここで、ACGT 文字列とは A, C, G, T 以外の文字を含まない文字列です。

# 注記
# 文字列 Tの部分文字列とは、T の先頭と末尾から 0文字以上を取り去って得られる文字列です。
# 例えば、ATCODER の部分文字列には TCO, AT, CODER, ATCODER, (空文字列) が含まれ、AC は含まれません。

# 制約
#     Sは長さ 1 以上 10以下の文字列である。
#     Sの各文字は英大文字である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S

# 出力
# Sの部分文字列であるような最も長い ACGT 文字列の長さを出力せよ。

# 入力例 1
# ATCODER

# 出力例 1
# 3

# ATCODER の部分文字列であるような ACGT 文字列のうち、最も長いものは ATC です。

# 入力例 2
# HATAGAYA

# 出力例 2
# 5

# HATAGAYA の部分文字列であるような ACGT 文字列のうち、最も長いものは ATAGA です。

# 入力例 3
# SHINJUKU

# 出力例 3
# 0

# SHINJUKU の部分文字列であるような ACGT 文字列のうち、最も長いものは (空文字列) です。


def calculation(lines):
    line = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0
    tmp = 0

    # print(f'line=[{line}]')

    for char in line:

        # print(f'char=[{char}]')

        if char == 'A':
            flag = True
        elif char == 'C':
            flag = True
        elif char == 'G':
            flag = True
        elif char == 'T':
            flag = True
        else:
            flag = False

        if flag:
            tmp += 1
            # print(f'result=[{result}], tmp=[{tmp}]')
            if result < tmp:
                result = tmp
        else:
            tmp = 0

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['ATCODER']
        lines_export = [3]
    if pattern == 2:
        lines_input = ['HATAGAYA']
        lines_export = [5]
    if pattern == 3:
        lines_input = ['SHINJUKU']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin >> n;
    if(n%2==0){
        cout << 1.0/2;
    }else{
        cout << (n+1)*1.0/(2*n);
    }
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a; string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s << '\n';
    }
    else {
        cout << "red\n";
    }

}



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

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

  ll n, money = 1000, stock = 0;
  cin >> n;

  vector<ll> v(n);
  for (int i = 0; i < n; i++) cin >> v.at(i);
  
  for (int i = 0; i < n; i++)
  {
    if(i == n-1)
    {
      money += v[i] * stock;
      stock = 0;
      break;
    }

    if(v.at(i) < v.at(i+1))
    {
      ll order = money / v[i];
      money -= v[i] * order;
      stock += order;
    }
    else
    {
      money += v[i] * stock;
      stock = 0;
    }
  }
  
  cout << money << endl;

  return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VLL x(n);
    ll sum = 0;
    rep(i,n){
      cin >> x[i];
      sum += x[i];
    }
    ll lsum = 0;
    ll ans = 1e15;
    rep(i,n){
      lsum += x[i];
      sum -= x[i];
      ans = min(abs(lsum-sum),ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  // ここでストリームに obj を書き込みます。
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << "\n";
  }
  return os;
}


int operator<(vector<int> v1,vector<int> v2){
  rep(i,v1.size())
    if(v1[i]>v2[i]) return 0;
  return 1;
}


string yobi[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
  map<string,int> mp;
  rep(i,7) mp[yobi[i]]=i;
  string today; cin >>today;
  print(7-mp[today]);
  
}





Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        
        if(u.equals(s)){
            a+=-1;
        }else{
            b+=-1;
        }
        
        System.out.println(a+" "+b);
    }
}

Measured memory_bytes: 23508
#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, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    ll ans = 0, MOD = 1e9 + 7, xs = 0, ys = 0;
    rep(i, n - 1) {
        xs = (xs + ((i + 1LL) * (n - 1 - i)) % MOD * (x[i + 1] - x[i])) % MOD;
    }
    rep(i, m - 1) {
        ys = (ys + ((i + 1LL) * (m - 1 - i)) % MOD * (y[i + 1] - y[i])) % MOD;
    }
    cout << (xs * ys) % MOD << endl;
}

Measured memory_bytes: 1792
import numpy as np

n = int(input())

sqrt_n = int(round(np.sqrt(n)))

i = 0 

while True:
    if n % (sqrt_n+i) == 0:
        ans = [sqrt_n+i,int(n/(sqrt_n+i))]
        break
    
    if n % (sqrt_n-i) == 0:
        ans = [sqrt_n-i,int(n/(sqrt_n-i))]
        break
    
    i += 1

len_ans = [0,0]

len_ans[0] = len(str(ans[0])) 
len_ans[1] = len(str(ans[1])) 

print(max(len_ans))

Measured memory_bytes: 12508