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

using namespace std;

using i64 = long;

const i64 INF = 1e18 + 7;

vector<i64> scc(vector<vector<i64>>& edges){
    i64 n = edges.size();
    vector<vector<i64>> rev(n);

    for(i64 i = 0; i < n; ++i)
        for(auto& x : edges[i])
            rev[x].emplace_back(i);

    vector<i64> dfs_num(n, -1);
    vector<i64> flag(n, 0);
    i64 num = 0;
    function<void(i64)> dfs = [&](i64 pos){
        flag[pos] = 1;
        for(auto& xx : edges[pos])
            if(!flag[xx]){
                dfs(xx);
        }
        dfs_num[pos] = num++;
    };

    for(i64 i = 0; i < n; ++i)
        if(!flag[i])
            dfs(i);

    vector<i64> dfs_inv(n);
    for(i64 i = 0; i < n; ++i)
        dfs_inv[n - 1 - dfs_num[i]] = i;

    num = 0;

    vector<i64> scc_vec(n, -1);

    function<void(i64)> rdfs = [&](i64 pos){
        scc_vec[pos] = num;
        for(auto t : rev[pos])
            if(scc_vec[t] == -1)
                rdfs(t);
    };

    for(i64 i = 0; i < n; ++i)
        if(scc_vec[dfs_inv[i]] == -1){
            rdfs(dfs_inv[i]);
            ++num;
        }

    return scc_vec;
}

signed main(){

    i64 n, m;
    cin >> n >> m;
    vector<vector<i64>> pos_(n, vector<i64>(8, 0));
    for(i64 i = 0; i < n; ++i){
        vector<i64> pos(3);
        for(auto& x : pos)
            cin >> x;
        for(i64 j = 0; j < 8; ++j){
            for(i64 k = 0; k < 3; ++k){
                i64 mul = (j & (1 << k)) ? 1 : -1;
                pos_[i][j] += mul * pos[k];
            }
        }
    }

    vector<vector<i64>> edges(n);
    for(i64 i = 0; i < m; ++i){
        i64 a, b;
        cin >> a >> b;
        edges[--a].emplace_back(--b);
    }
    auto ret = scc(edges);
    i64 n_ = *max_element(ret.begin(), ret.end()) + 1;
    vector<vector<i64>> edg(n_);
    for(i64 i = 0; i < n; ++i){
        for(auto& j : edges[i])
            edg[ret[i]].emplace_back(ret[j]);
    }
    vector<i64> cnt(n_, 0);
    for(i64 i = 0; i < n_; ++i){
        sort(edg[i].begin(), edg[i].end());
        edg[i].erase(unique(edg[i].begin(), edg[i].end()), edg[i].end());
    }
    vector<i64> tps;
    queue<i64> que;
    for(i64 i = 0; i < n_; ++i)
        if(!cnt[i])
            que.emplace(i);
    while(!que.empty()){
        i64 i = que.front();
        tps.emplace_back(i);
        que.pop();
        for(auto& e : edg[i]){
            if(--cnt[e] == 0)
                que.emplace(e);
        }
    }
    vector<vector<i64>> elm(n_, vector<i64>(8, -INF));
    for(i64 i = 0; i < n; ++i)
        for(i64 j = 0; j < 8; ++j)
            elm[ret[i]][j] = max(elm[ret[i]][j], pos_[i][j]);

    reverse(tps.begin(), tps.end());
    for(auto& pos : tps){
        for(auto& e : edg[pos]){
            for(i64 i = 0; i < 8; ++i)
                elm[pos][i] = max(elm[pos][i], elm[e][i]);
        }
    }

    for(i64 i = 0; i < n; ++i){
        i64 r = 0;
        for(i64 j = 0; j < 8; ++j)
            r = max(r, elm[ret[i]][j] - pos_[i][j]);
        cout << r << endl;
    }
}



Measured memory_bytes: 80204
N,X = map(int,input().split())
W = list(map(int,input().split())) + [X]
W = sorted(W)
dist = 10**18
if len(W) == 2:
  print(W[1]-W[0])
  exit()
for i in range(1,N+1):
  dist = min(dist, W[i]-W[i-1])
  while (W[i]-W[i-1])%dist != 0:
    dist -= 1
  if dist == 1:
    break
print(dist)

Measured memory_bytes: 14224
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using usize = std::size_t;

template<typename T, bool sort = false>
auto divisors(T n) -> std::vector<T> {
	std::vector<T> r;
	T i = 1;
	for (; i * i < n; ++i) {
		if (n % i == 0) {
			r.emplace_back(i);
			r.emplace_back(n / i);
		}
	}
	if (i * i == n) {
		r.emplace_back(i);
	}
	if (sort) {
		std::sort(r.begin(), r.end());
	}
	return r;
}

i32 a[200001];
i32 used[1000001];

auto main() -> i32 {
	i32 n;
	scanf("%d", &n);
	for (i32 i = 0; i < n; ++i) {
		scanf("%d", a + i);
	}
	std::sort(a, a + n);
	i32 ans = 0;
	for (i32 i = 0; i < n; ++i) {
		bool ok = true;
		if (a[i] != a[i + 1]) {
			for (auto d : divisors(a[i])) {
				if (used[d]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				ans += 1;
			}
		}
		used[a[i]] = true;
	}
	printf("%d\n", ans);
	return 0;
}


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if(a >= k) drop(k);
  int ans = a;
  k -= a;
  if(b >= k) drop(ans);
  k -= b;
  cout << ans-k << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3588
#!/usr/bin/env php
<?php
fscanf(STDIN, "%d %d", $N, $Q);
fscanf(STDIN, "%s", $S);
$left = [];
for($i = 0; $i < $N; $i++) {
    $t = $S[$i];
    if ($i > 0) {
        $left[$i] = $left[$i - 1];
    } else {
        $left[$i] = 0;
    }
    if ($t != 'A') {
        continue;
    }
    if ($i + 1 >= $N) {
        continue;
    }
    if ($S[$i + 1] != 'C') {
        continue;
    }
    $left[$i]++;
}
while (($item = fgets(STDIN)) !== false) {
    list($i, $j) = explode(' ', $item);
    $l = 0;
    $r = 0;
    if ($i > 1) {
        $l = $left[$i-2];
    }
    if ($j > 1) {
        $r = $left[$j-2];
    }
    $num = $r - $l;

    echo $num.PHP_EOL;
}


Measured memory_bytes: 10744
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <iostream>
#include <string.h>

using namespace std;

int main(int argc, char const* argv[])
{
	char str[81];
	stack<double> data;
	double a,b;

	while(cin.getline( str, 80 )){
		char *t;

		while( data.empty() == false ) data.pop();

		t = strtok( str, " " );
		if( strcmp(t , "+" ) == 0){
			a = data.top();
			data.pop();
			b = data.top();
			data.pop();
			data.push( b + a );
		} else if( strcmp(t , "-" ) == 0){
			a = data.top();
			data.pop();
			b = data.top();
			data.pop();
			data.push( b - a );
		} else if( strcmp(t , "/")  == 0){
			a = data.top();
			data.pop();
			b = data.top();
			data.pop();
			data.push( b / a );
		} else if(( strcmp(t, "*" ) == 0)){
			a = data.top();
			data.pop();
			b = data.top();
			data.pop();
			data.push( b * a );
		} else {
			data.push( atof( t ) );
		}

		while( ( t = strtok( NULL, " " ) ) != NULL ){
			if( strcmp(t , "+" ) == 0){
				a = data.top();
				data.pop();
				b = data.top();
				data.pop();
				data.push( b + a );
			} else if( strcmp(t , "-" ) == 0){
				a = data.top();
				data.pop();
				b = data.top();
				data.pop();
				data.push( b - a );
			} else if( strcmp(t , "/")  == 0){
				a = data.top();
				data.pop();
				b = data.top();
				data.pop();
				data.push( b / a );
			} else if(( strcmp(t, "*" ) == 0)){
				a = data.top();
				data.pop();
				b = data.top();
				data.pop();
				data.push( b * a );
			} else {
				data.push( atof( t ) );
			}
		}
		printf("%.6f\n",data.top());
		data.pop();

	}
	return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    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 <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char S[7][7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
    char test[30];
    gets(test);
    if(strcmp(S[0],test)==0)
        printf("7");
     else if(strcmp(S[1],test)==0)
        printf("6");
     else if(strcmp(S[2],test)==0)
        printf("5");
     else if(strcmp(S[3],test)==0)
        printf("4");
     else if(strcmp(S[4],test)==0)
        printf("3");
     else if(strcmp(S[5],test)==0)
        printf("2");
     else if(strcmp(S[6],test)==0)
        printf("1");



   return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}


int main(){
 ll d ; cin>> d ;
 ll c[26] ; rep(i,26) cin>>c[i] ;
 ll s[d][26] ;
 vector<ll> bns(d)  ;
  rep(i,d){
     rep(j,26){
        cin>> s[i][j] ;
        if(s[i][bns[i]] <s[i][j]) bns[i]= j ;
     }
 }
 
 ll t[d] ; 
 
 rep(i,d){
   t[i]=(bns[0]+i)%26 ;
 }
 
 ll m= 365*100 ;
 ll p[m] ;ll q[m] ;
 rep(i,m){
   p[i]=m%365 ;
   ll a= m/365 ;
   q[i]= 25- ((i+a)%26) ;
 }
 ll ans=0 ;
ll last[26] ; rep(i,26) last[i]=0 ;
rep(i,d){
  ans+= s[i][t[i]] ;
  rep(i,26) last[i] ++ ;
  last[t[i]]=0 ;
  ll sum=0 ;
  rep(i,26) sum+= c[i]*last[i] ;
  ans-= sum ;
  }
  
  
  
  rep(i,m){
   ll rans= ans ;
   ll memo = t[p[i]] ;
   t[p[i]]= q[i] ;
   ll maex=p[i]+1, atox= d-p[i] ;
   ll maey=p[i]+1 ,atoy= d-p[i] ;
    rep(j,d){
     if(t[j]==memo&&j<p[i]) maex=p[i]-j ;
     if(t[j]==memo&&j>p[i]){
       atox= j-p[i] ;
       break ;
     }
    }
    rep(j,d){
     if(t[j]==q[i]&&j<p[i]) maey=p[i]-j ;
     if(t[j]==q[i]&&j>p[i]){
       atoy= j-p[i] ;
       break ;
     }
    }
    ans -= c[memo]*atox*maex ;
    ans += c[q[i]]*atoy*maey ;
    ans = ans- s[p[i]][memo] + s[p[i]][q[i]] ;
    if(ans<rans){
      t[p[i]]= memo ;
    }
  }

   rep(i,d) cout<< t[i]+1<<endl ;
 return 0 ;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  int n;
  cin >> n;

  vl x(n), y(n);
  rep (i, n) {
    cin >> x[i] >> y[i];
  }

  vector<pair<double, pii>> txy(n);
  rep (i, n) {
    txy[i].first = atan2(y[i], x[i]);
    txy[i].second = pii(x[i], y[i]);
  }
  sort(all(txy));

  ll ans = 0;
  rep (i, n) {
    ll now_x = 0, now_y = 0;
    for (int m = 1; m <= n; m++) {
      now_x += txy[(i + m - 1) % n].second.first;
      now_y += txy[(i + m - 1) % n].second.second;
      chmax(ans, now_x * now_x + now_y * now_y);
    }
  }

  double res = sqrt(ans);
  Sp(res);
}


Measured memory_bytes: 256
n=int(input())

cnt=1##文字数
tmp=26

while n>tmp:
    cnt+=1
    tmp+=26**cnt
 
num=n-(tmp//26)
 
alp=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
 
ans=["0"]*cnt
for i in range(cnt):
    j=num%26
    num//=26
    ans[-i-1]=alp[j]

print(*ans, sep='')

Measured memory_bytes: 61796
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long  
using namespace std;
//using ll = unsigned long long;
ll md=MD;
 
 
ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}
//#define int long long
int n,m,k;
ll ans=INT_MAX;
int c[12],a[12][12];

void fun(int x)
{
//	db1(x);
	int i=0,flag=0;
	ll sum=0;
	vector<ll> t(m,0);
	while(x>0)
	{
		if(x&1){
			sum+=c[i];
			for(int j=0;j<m;++j)t[j]+=a[i][j];
		}
		++i;
		x=x>>1;
//		cout<<x<<" ";
	}
//	cout<<"\n";
	for(int i=0;i<m;++i)
	{
		if(t[i]<k){
		flag=1;break;}
	}
//	cout<<x<<" "<<sum<<" "<<flag<<"\n";
	if(!flag)
	ans=min(ans,sum);
	
}


int main()
{
	IOS;
//	int n,m,x;
	cin>>n>>m>>k;
//	int c[n];
	for(int i=0;i<n;++i )
	{
		cin>>c[i];
		for(int j=0;j<m;++j) cin>>a[i][j];
	}
	int mx=1,n1=n;
	while(n1--)
	{
		mx=mx<<1;
	}
//	cout<<mx<<" ";
	for(int i=1;i<mx;++i) fun(i);
	if(ans==INT_MAX)cout<<"-1\n";
	else cout<<ans<<"\n";
	return 0;
}

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

int x[100005],y[100005],n,m,ans;

int ok[100005],eat[405];
bool gun[405];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i)
	scanf("%d%d",&x[i],&y[i]);

    for(int i=1;i<=n;++i)
    {
	for(int j=m;j;--j)
	    if(eat[x[j]]==i)
	    {
		if(eat[y[j]]==i)eat[i]=i;
		eat[y[j]]=i,ok[j]=i;
	    }
	    else if(eat[y[j]]==i)eat[x[j]]=i,ok[j]=i;
	    else if(x[j]==i)eat[y[j]]=i,ok[j]=i;
	    else if(y[j]==i)eat[x[j]]=i,ok[j]=i;
	for(int j=1;j<=m;++j)
	    if(ok[j]!=i)
		if(eat[x[j]]==i)eat[y[j]]=i;
		else if(eat[y[j]]==i)eat[x[j]]=i;
	if(eat[i]==i){gun[i]=1;continue;}
	for(int j=1;j<i;++j)
	    if(eat[j]!=i&&!gun[j])++ans;
    }

    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 1408
N,M=map(int,input().split())
x=[list(map(int,input().split())) for i in range(N)]
ans=[0]*8
#x+y+z
a=[sum(i) for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[0]+=a[i]
#x+y-z
a=[i[0]+i[1]-i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[1]+=a[i]
#x-y+z
a=[i[0]-i[1]+i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[2]+=a[i]
#x-y-z
a=[i[0]-i[1]-i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[3]+=a[i]
#-x+y+z
a=[-i[0]+i[1]+i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[4]+=a[i]
#-x+y-z
a=[-i[0]+i[1]-i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[5]+=a[i]
#-x-y+z
a=[-i[0]-i[1]+i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[6]+=a[i]
#-x-y-z
a=[-i[0]-i[1]-i[2] for i in x]
list.sort(a,reverse=True)
for i in range(M):
    ans[7]+=a[i]
print(max(ans))

Measured memory_bytes: 3316
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[] a = new int[2*n];
			int[] b = new int[2*n];
			for(int i=0;i<n;i++){
				a[sc.nextInt()-1]++;
			}
			for(int i=0;i<2*n;i++){
				if(a[i]==0)b[i]++;
			}
			
			boolean p = true;
			int ca = 0;
			int cb = 0;
			while(true){
				for(int i=0;i<2*n;i++){
					if(p==true && a[i]==1){
						p=false;
						a[i]--;
						ca++;
					}else if(p==false && b[i]==1){
						p=true;
						b[i]--;
						cb++;
					}
					if(ca==n || cb==n)break;
				}
				if(ca==n || cb==n){
					System.out.println(n-cb);
					System.out.println(n-ca);
					break;
				}
				if(p==true){
					p=false;
				}else if(p==false){
					p=true;
				}
			}
					
		}
	}
}

Measured memory_bytes: 20384
#include<stdio.h>

long long x,a,b,c,ans;

int main(void){
	register int i,j,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&x);
	for(i=0;i<=a;i++)
		for(j=0;j<=b;j++)
			for(k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					ans++;
				else if(i*500+j*100+k*50>x)
					break;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
 
using namespace std;
 
int main(void){
  int X, Y, Z, tmp;
  
  cin >> X >> Y >> Z;
  // A swap B
  tmp = X;
  X = Y;
  Y = tmp;
  // A swap C
  tmp = X;
  X = Z;
  Z = tmp;
  cout << X << " " << Y << " " << Z << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, x, a[2005], b[2005];
int ans = inf;
signed main() {
	cin >> n >> x;
	rep(i, n) {
		cin >> a[i];
		b[i] = inf;
	}
	rep(i, n) {
		int memo = 0;
		rep(j, n) {
			b[j] = min(b[j], a[(n + (j - i)) % n]);
			memo += b[j];
		}
		ans = min(ans, memo + i * x);
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll N; cin >> N;
    ll A[N];
    for(ll i=0; i<N; i++) cin >> A[i];
    ll maxi = 0;
    ll ma2 = 0;
    ll ma = 0;
    for(ll i=0; i<N; i++){
        if(ma < A[i]){
            ma = A[i];
            maxi = i;
        }
    }
    for(ll i=0; i<N; i++){
        if(i==maxi) continue;
        if(ma2 < A[i]) ma2 = A[i];
    }
    for(ll i=0; i<N; i++){
        if(i==maxi) cout << ma2 << endl;
        else{
            cout << ma << endl;
        }
    }
}

    


Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<deque>
#include<algorithm>
#define F first
#define S second
#define all(n) n.begin(),n.end()
using namespace std;
typedef pair<int,int> P;
typedef vector<vector<char> > VVC;

class Pox
{
public:
  P p;
  int cost;
  Pox(P p = P(0,0),int cost = 0):p(p),cost(cost){}
};

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int h,w;

void draw(VVC& G,P p)
{

  for(int i=0;i<4;i++)
    {
      int nx = p.F + dx[i];
      int ny = p.S + dy[i];
      if(!(1<=ny&&ny<=h && 1<=nx&&nx<=w))
	continue;
      if(G[ny][nx] == '&' || G[ny][nx] == '#')
	continue;
      G[ny][nx] = '&';
      draw(G,P(nx,ny));
    }
  
}

int main()
{
  
  while(cin >> w >> h,(w||h))
    {
    
      VVC G;
      P ed;
      G.resize(h+2);
      deque<Pox> deq;
      int mincost[h+3][w+3];
      for(int i=0;i<=h+1;i++)
	{
	  G[i].resize(w+2);
	  string line;
	  if(i == 0 || i == h+1)
	    line = string(h+2,'.');
	  else
	   cin >> line;
	   
	  for(int j=0;j<=w+1;j++)
	    {
	      mincost[i][j] = (1<<28);
	      if(i == 0 || j == 0 || i == h+1 || j == w+1)
		{
		  G[i][j] = '.';
		  deq.push_back(Pox(P(j,i),0));
		  mincost[i][j] = 0;
	 	  continue;
		}
	      G[i][j] = line[j-1];
	      if(G[i][j] == '&')
		ed = P(j,i);
	    }
	}
	  
      draw(G,ed);
      
      int men = (1<<28);
      while(!deq.empty())
	{
	  Pox pox = deq.front(); deq.pop_front();
	  P p = pox.p;
	  int cost = pox.cost;

	  for(int i=0;i<4;i++)
	    {
	      int nx = p.F + dx[i];
	      int ny = p.S + dy[i];

	      if(!(1<=nx&&nx<=w && 1<=ny&&ny<=h))
		  continue;
		
	      int d = 0;
	      if(G[ny][nx] == '#')
		{
		  while(1<=nx&&nx<=w && 1<=ny&&ny<=h && G[ny][nx] == '#')
		    nx += dx[i],ny += dy[i];
		  d = 1;
		}
	      
	      if(mincost[ny][nx] > cost + d)
		{
		  mincost[ny][nx] = cost + d;
		  if(G[ny][nx] == '&')
		    {
		      men = min(men,mincost[ny][nx]);
		      continue;
		    }
		  deq.push_back(Pox(P(nx,ny),mincost[ny][nx]));
		}
	    }

	}
      cout << men << endl;

    }
  return 0;
}

Measured memory_bytes: 1524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

//二分累乗法
ll mult(ll n,ll m){//n^m%modを求める
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

//nCkの1e9+7における余り
template <class T>
T comb_mod(T n,T k){
    T ans=1;
    T r=min(k,n-k);
    FOR(i,n-r+1,n+1){
        ans*=(i%mod);
        ans%=mod;
    }
    FOR(i,1,r+1){
        ans*=mult(i,mod-2);
        ans%=mod;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    FOR(l,1,n){
      ans+=(((l*(n-l))%mod)*(m*m%mod))%mod;
      ans%=mod;
    }
    FOR(l,1,m){
      ans+=(((l*(m-l))%mod)*(n*n%mod))%mod;
      ans%=mod;
    }
    ans*=comb_mod(n*m-2,k-2);
    ans%=mod;
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;

bool is_Prime (int n){
    bool flag = true;
    if(n==1){
        return false;
    }
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
	    flag = false;
	    break;
        }
    }
    return flag;
}

int main(){
    int X; cin >> X;
    int flag = false;
    int ans;
    for(int i = X;i < 200000; i++){
        flag = is_Prime(i);
        if (flag == true){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int i,j;
    int count=1;
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    int max=a[0];
    for(i=1;i<n;i++){
    	if(max>=a[i]){
    		count++;
    		max=a[i];
		}
	}
	printf("%d",count);
    return 0;
}

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

a.sort()
m = a[-1]
def near_abs_id(l,n): # リストlの中で絶対値がもっともnに近い要素のindex
    idx = 0
    m = 10**12
    for i in range(len(l)):
        if abs(l[i]-n) < m:
            m = abs(l[i]-n)
            idx= i
    return idx
j = near_abs_id(a,m/2)
if j==n-1:
    j-=1
print(m,a[j])

Measured memory_bytes: 14428
#include<iostream>
using namespace std;
int IsChar(int i,int j,int h,int w)
{
	if (i==0 || i==h-1)
		return 1;
	else if(j==0 || j==w-1)
		return 1;
	else 
		return 0;
}
void Draw(int h,int w)
{
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if (IsChar(i,j,h,w)==1)
				cout<<"#";
			else
				cout<<".";
		}		
		cout<<endl;
	}	
}

int main()
{
	int h ,w;
	while(true){
		cin>>h>>w;
		if(h==0&&w==0)
			break;
		Draw(h,w);
		cout<<endl;	
	}	
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int D;
vll C, T;
vvll S;
ll score[366] = {};
vvll last = makeVector(366, 26, 0ll);

void calcScore(ll pos) {
	for (int i = pos; i <= D; i++) {
		score[i] = score[i-1] + S[i][T[i]];

		for (int j = 0; j < 26; j++) last[i][j] = last[i-1][j];
		last[i][T[i]] = i;
		
		for (int j = 0; j < 26; j++) {
			score[i] -= (i-last[i][j])*C[j];
		}
	}
}

void Main() {
	cin >> D;
	C = makeVector(26, 0ll); cin >> C;
	S = makeVector(D+1, 26, 0ll);
	for (int i = 1; i <= D; i++) cin >> S[i];
	T = makeVector(D+1, 0ll);
	
	calcScore(1);

	ll maxv = -LLINF;
	int M = 100000;
	for (int i = 0; i < M; i++) {
		int d = rand()%D; d++;
		int q = rand()%26; 

		ll tmp = T[d];
		T[d] = q;
		calcScore(d);
		if (score[D] <= maxv) T[d] = tmp;
		else maxv = score[D];
	}

	for (int i = 1; i <= D; i++) {
		cout << T[i]+1 << el;
	}
	//cout << maxv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3840
def inpl(): return list(map(int, input().split()))
N, M = inpl()
L = [0]*M
for i in range(M):
    for s in inpl()[1:]:
        L[i] += pow(2, s-1)
P = inpl()
print(sum([sum([bin(L[j]&i).count("1")%2 == P[j] for j in range(M)]) == M for i in range(pow(2, N))]))

Measured memory_bytes: 40304
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 300010
#define maxs 410
#define lowbit(_x) ((_x) & -(_x))
std::vector<int> v1[maxn], v2[maxn];
int n, m, b[maxn], ans[maxn], cnt[maxn];
inline void add(R int pos, R int val) {for (; pos < maxn; pos += lowbit(pos)) b[pos] += val;}
inline int query(R int pos) {R int ret = 0; for (; pos; pos -= lowbit(pos)) ret += b[pos]; return ret;}
int main()
{
//	setfile();
	n = F(), m = F();
	for (R int i = 1; i <= n; ++i)
	{
		R int l = F(), r = F();
		++cnt[r]; v1[l - 1].push_back(r);
	}
	for (R int i = 1; i <= m; ++i)
		for (R int j = i; j <= m; j += i)
			v2[j].push_back(i);
	for (R int i = m; i; --i)
	{
		add(i, cnt[i]);
		for (R int j = 0; j < v1[i].size(); ++j) add(v1[i][j], -1);
		for (R int j = 0; j < v2[i].size(); ++j)
		{
			R int now = v2[i][j];
			ans[now] += query(i + now - 1);
		}
	}
	for (R int i = 1; i <= m; ++i) printf("%d\n", ans[i] );
	return 0;
}


Measured memory_bytes: 26880
w = int(input())
c = [i for i in range(1, w + 1)]
n = int(input())
for i in range(n):
  a, b = map(int, input().split(","))
  r = c[a - 1]
  c[a - 1] = c[b - 1]
  c[b - 1] = r
for i in range(w):
  print(c[i])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
    T f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

string s;

int main()
{
    //File("");
    cin >> s;
  	if (s[s.size() - 1] == 's') cout << s << "es" << endl;
  	else cout << s << "s" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
  int A[20];
  int x[20][20];
  int y[20][20];
  rep(i,n){
    int a;
    cin >> a;
    A[i] = a;
    rep(j,a){
      int p, q;
      cin >> p >> q;
      x[j][i] = p;
      y[j][i] = q;
    }
  }
  int ans = 0;
  
  for(int bit = 0; bit < (1<<n); bit++){
    bool have = true;
    bitset<15> s(bit);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (s.test(i)) {
        sum++;
        for(int j = 0; j < A[i]; j++){
          if(y[j][i] == 1){
            if(s.test(x[j][i]-1)){
            }
            else{
              have = false;
            }
          }
          if(y[j][i] == 0){
            if(s.test(x[j][i]-1)){
              have = false;
            }
          }
        }   
      }
    }
    
    if(have){
      
      ans = max(ans,sum);
    }
  }
   
  cout << ans;
    
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		sc.close();
		if (S.length() <= K) {
			System.out.println(S);
		} else {
			System.out.println(S.substring(0, K) + "...");
		}
	}
}


Measured memory_bytes: 38588
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int a[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int sum = 0;
	rep(i, n - 1) {
		if (a[i] < 0) {
			a[i] *= -1;
			a[i + 1] *= -1;
		}
	}
	rep(i, n)sum += abs(a[i]);
	if (a[n - 1] >= 0)cout << sum << endl;
	else {
		int mn = inf;
		rep(i, n) {
			if (mn > abs(a[i])) {
				mn = abs(a[i]);
			}
		}
		cout << sum - 2*mn << endl;
	}
}

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


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,w;
	cin>>h>>w;
	if(h!=1&&w!=1){
	if((h*w)%2==0) cout<<(h*w)/2<<"\n";
	 else cout<<(h*w)/2 +1<<"\n";
	}
	else cout<<"1\n";
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
import collections

dx = [-1,0,1,0]
dy = [0,-1,0,1]
def movable(dst):
    if dst[0]<0 or dst[0]>b-1:
        return False
    elif dst[1]<0 or dst[1]>a-1:
        return False
    elif MM[dst[0]][dst[1]] == '#':
        return False
    else:
        return True

while True:
    c = 1
    a,b = map(int,input().split())
    if a==0 and b==0:
        exit()
    else:
        MM = []
        for i in range(b):
            q = list(input())
            MM.append(q)
            if '@' in q:
                st = [i, q.index('@')]

        D = [[-1 for _ in range(a)] for _ in range(b)]
        D[st[0]][st[1]] = 0 # 始点への距離は 0, 他の距離は-1
        Q = collections.deque()
        Q.append(st) # 始点
        while len(Q) > 0:
            #print("bfs", Q) # 各ステップでの Q の動作を確認
            cur = Q.popleft()
            for dir in range(4):
                # curからdstに移動可能かつ、dstが未訪問だったら
                dst = [cur[0]+dx[dir], cur[1]+dy[dir]]
                #print(dst)
                if movable(dst) and D[dst[0]][dst[1]] == -1:
                    D[dst[0]][dst[1]] = D[cur[0]][cur[1]]+1
                    c += 1
                    Q.append(dst) # Qにdstを詰める
        print(c)



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

int main() {
    int n;
    cin >> n;
    for (double i = 0; i <= 50000; i++) {
        if ((int)(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;
const int INF = 0x3f3f3f3f;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	printf("%d\n",max(max(a+b, a-b), a*b));
	return 0;
}


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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef magUNbos
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif // magUNbos
    int N;
    cin>>N;
    int B[N + 20];
    for(int i = 0; i <N; i++)
        cin>>B[i];
    B[N] = 0;
    N++;

    vector<int> A;
    for(int i = 0 ; i < N - 1  ; i++){
        if(B[i] == B[i+1]) continue;
        A.push_back(B[i]);
        //cout<<B[i]<<" ";
    }//cout<<endl;

    //A.push_back(1000000000 + 10);
    //A.push_back(0);
    N = A.size();

    int ans = 0;
    int i = 0;
    while(i < N ){
        ans++;
        if( i < N -1){
            if(A[i] < A[i + 1]){
                while(A[i] < A[i + 1] && i < N -1)
                    i++;
            }
            else{
                while(A[i] > A[i + 1] && i < N-1)
                    i++;
            }
        }
        i++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();

		int result = 0;

		for(int i = 0; i< a.length(); i++) {

			char c = a.charAt(i);

			if(c == '-') {
				result--;
			}else {
				result++;
			}
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 20820
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

#include <bits/stdc++.h>

struct UnionFind {
  private:
	std::vector<int> rank, par, col;
	int n_;

  public:
	UnionFind(int n) : n_(n) {
		rank.resize(n, 1);
		par.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
		}
		col.resize(n, 1);
	}
	int root(int i) {
		while (par[i] != i) {
			i = par[i];
		}
		return i;
	}
	bool isSame(int x, int y) { return root(x) == root(y); }
	void unite(int x, int y) {
		if (isSame(x, y)) return;
		x = root(x), y = root(y);
		if (rank[x] < rank[y]) {
			par[x] = y;
			col[y] += col[x];
		} else {
			if (rank[x] == rank[y]) rank[x]++;
			par[y] = x;
			col[x] += col[y];
		}
	}
	int cnt(int x) {
		x = root(x);
		return col[x];
	}
};

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	UnionFind uf(n + 1);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		uf.unite(a, b);
	}
	set<ll> s;
	for (int i = 1; i <= n; i++) {
		s.insert(uf.root(i));
	}
	dump(s.size());
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int x[100010] = {};
	int y[100010] = {};
	int sum = 0;
	for (int i = 0; i < n - 1; i++) {
		int inp;
		cin >> inp;
		sum += inp;
		x[i + 1] = sum;
	}
	int road = 0;
	int index = 0;
	for (int i = 0; i < m; i++) {
		int inp;
		cin >> inp;
		int gap = x[index] - x[index + inp];
		road += (gap > 0) ? gap : -gap;
		road %= 100000;
		index += inp;
	}
	cout << road << endl;
}

Measured memory_bytes: 3476
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 105

using namespace std;

int main()
{
    char str[sz];

    scanf("%s",str);

    ll len=strlen(str);

    printf("%c%lld%c\n",str[0],len-2,str[len-1]);

    return (0);
}




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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dp[100001][4];

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

    string s;
    cin >> s;

    dp[0][0] = 1;
    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j <= 3; ++j) {
            if(s[i] == '?') dp[i + 1][j] += (dp[i][j] * 3) % MOD;
            else dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
        }
        for(int j = 0; j < 3; ++j) {
            if(s[i] == "ABC"[j] || s[i] == '?') {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
            }
        }
    }
    cout << dp[s.size()][3] << endl;
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

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

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b, x;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> x;

  ll mi = 0, ma = 0;
  ll ans = 0;
  if(a > 0) {
    mi = (a - 1) / x;
  } else {
    ans++;
  }
  ma = b / x;

  ans += (ma - mi);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  vector<long long> F;
  for (long long i = 1; i * i <= N; i++){
    if (N % i == 0){
      F.push_back(i);
      F.push_back(N / i);
    }
  }
  for (long long i = 1; i * i <= N - 1; i++){
    if ((N - 1) % i == 0){
      F.push_back(i);
      F.push_back((N - 1) / i);
    }
  }
  F.erase(unique(F.begin(), F.end()), F.end());
  int C = F.size();
  int count = 0;
  for (int i = 0; i < C; i++){
    long long K = F[i];
    if (K == 1){
      continue;
    }
    long long N2 = N;
    while (N2 % K == 0){
      N2 /= K;
    }
    if (N2 % K == 1){
      count++;
      //cout << K << endl;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<set>
using namespace std;
int main(){
    int n;
    cin>>n;
    set<string> got;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        got.insert(s);
    }
    cout<<got.size()<<"\n";
    return(0);
}

Measured memory_bytes: 19196
#include<stdio.h>
int w[101000];
int n,i,a,r;
int main(){
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
    }
    for(i=1;i<=n;i++){
        if(w[w[i]] == i)r++;
    }
    printf("%d\n",r/2);
}

Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<double> p(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lf", &p[i]);
  }
  vector<double> v(N, 0);
  for (int i = 0; i < N; ++i)
  {
    v[i] = (p[i] + 1.0) / 2.0;
  }
  double sum = 0;
  for (int i = 0; i < K; ++i)
  {
    sum += v[i];
  }
  double ans = sum;
  for (int i = K; i < N; ++i)
  {
    sum = sum - v[i - K] + v[i];
    ans = max(ans, sum);
  }
  printf("%.9lf\n", ans);

  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K; cin >> N >> K;
  int p[N]; for(int i = 0; i < N; i++) cin >> p[i];
  sort(p, p + N);
  int ans = 0;
  for(int j = 0; j < K; j++) ans += p[j];
  cout << ans;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int a[200005];
int p[1000005];
int cnt[1000005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!p[a[i]]) {
      if (cnt[a[i]] == 1)
        ans++;
      p[a[i]] = 1;
      for (int j = a[i] + a[i]; j <= 1000000; j += a[i])
        p[j] = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 12032
# 標準入力
num = int(input())
data = [int(input()) for i in range(num)]
# 降順にソート
data.sort(reverse=True)
# 初期化
res = 1

for i in range(len(data) - 1):
    if data[i] > data[i + 1]:
        res += 1

print(res)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
    int n = 0;
    int h = 0;
    int w = 0;
    int count = 0;
    cin >> n >> h >>w;
    for (int i = 0; i < n; ++i) {
        int t = 0;
        int y = 0;
        cin >> t >> y;
        if(t >= h && y >= w){
            count++;
        }
    }

    cout << count;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for (int i = 1; i <= 9; ++i) {
            for (int j = 1; j <= 9; ++j) {
                if (i * j == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

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

int A, P;

int main() {
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
# abc158_d.py
import sys
import time
import unittest
from io import StringIO


def resolve():
    S = input()
    Q = int(input())
    reverseFlg = False
    preR = ""
    post = ""
    for i in range(Q):
        QQ = input().split()
        if QQ[0] == "1":
            reverseFlg = not reverseFlg
        else:
            if reverseFlg:
                if QQ[1] == "1":
                    post += QQ[2]
                else:
                    preR += QQ[2]
            else:
                if QQ[1] == "1":
                    preR += QQ[2]
                else:
                    post += QQ[2]

    if reverseFlg:
        print(post[::-1] + S[::-1] + preR)
    else:
        print(preR[::-1] + S + post)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def checkTLE(self, input):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin

    def debugIO(self, input):
        stdin = sys.stdin
        sys.stdin = StringIO(input)
        resolve()
        sys.stdin = stdin

    def setUp(self):
        self.startTime = time.time()

    def tearDown(self):
        t = time.time() - self.startTime
        print('%s: %.3f' % (self.id(), t), flush=True)

    def test_入力例_1(self):
        input = """a
4
2 1 p
1
2 2 c
1"""
        output = """cpa"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """a
6
2 2 a
2 1 b
1
2 2 c
1
1"""
        output = """aabc"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """y
1
2 1 x"""
        output = """xy"""
        self.assertIO(input, output)


if __name__ == "__main__":
    if "IS_LOCAL" in locals():
        suite = unittest.TestLoader().loadTestsFromTestCase(TestClass)
        unittest.TextTestRunner(verbosity=0).run(suite)
    else:
        resolve()


Measured memory_bytes: 7160