akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  cout << (N == M ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i=0;i<n;i++)

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


static const ll MOD = 2019;

ll ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int main() {
    // input
    string S;
    cin >> S;

    // process
    ll ans = 0;

    vector<ll> T(2019);
    for (char c:S) {
        vector<ll> dp(2019);
        rep(i, 2019) {
            dp[(i * 10 + ctoi(c)) % 2019] += T[i];
        }
        dp[ctoi(c)]++;
        ans += dp[0];
        T = dp;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//



//
int main(){
	int L,R;cin>>L>>R;

	int r = R-L+1;
	int ans = INF;

	if(r >= 2019){
		ans = 0;
	}
	else{
		vector<int> a(r);
		REP(i,r)a[i] = (i+L)%2019;
		//sort(ALL(a));
		REP(i,r-1)REPS(j,i+1,r)ans = min(ans,(a[i]*a[j])%2019);
	}

	cout << ans << endl;

	return 0;
}




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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, ti;
  cin >> n >> ti;
  vi c(n), t(n);
  re(i, n) cin >> c[i] >> t[i];

  int m = INF;
  bool can = false;
  re(i, n) {
    if(ti >= t[i]) {
      can = true;
      m = min(m, c[i]);
    }
  }
  if(can) cout << m << endl;
  else cout << "TLE" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

li n, m, s;
li a[101], b[101], c[101], d[101];
li dp[51][2501];
vector<li> g[51];
vector<lii> edges;
li adj(li i, li u)
{
	if(edges[i].fi==u) return edges[i].se;
	return edges[i].fi;
}
int main()
{
	stuff;

	cin >> n >> m >> s;
	edges.pb(mp(0,0));
	for(int i=1, x, y; i<=m; i++)
	{
		cin >> x >> y;
		g[x].pb(i); g[y].pb(i); edges.pb(mp(x, y));
		cin >> a[i] >> b[i];
	}
	for(int i=1; i<=n; i++)
	{
		cin >> c[i] >> d[i];
	}
	s = (s>=2500 ? 2500 : s);
	set<pair<li, lii> > st;
	for(int i=1; i<=n; i++)
	{
		for(int j=0; j<=2500; j++)
		{
			dp[i][j] = LLONG_MAX;
		}
	}
	// dp[1][s] = 0;
	st.insert(mp(0, mp(1, s)));
	while(!st.empty())
	{
		auto pr = *st.begin();
		st.erase(st.begin());
		li u=pr.se.fi, mon=pr.se.se, tm=pr.fi;
		// cout << "u: " << u << endl << "m: " << mon << endl << "tm: " << tm << endl << endl;
		if(dp[u][mon] <= tm) continue;
		dp[u][mon] = tm;
		for(auto i : g[u])
		{
			li v = adj(i, u);
			// cout<< i<< v << endl;
			if(a[i]<=mon && dp[v][mon-a[i]]>tm+b[i])
			{
				st.insert(mp(tm+b[i], mp(v, mon-a[i])));
			}
		}
		if(mon<2500) 
		{
			mon = min((li)2500, mon+c[u]);
			st.insert(mp(tm+d[u], mp(u, mon)));
		}

	}
	for(int i=2; i<=n; i++)
	{
		li mn = LLONG_MAX;
		for(int j=0; j<=2500; j++)
		{
			mn = min(mn, dp[i][j]);
		}
		cout << mn << "\n";
	}
	return 0;
}


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

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

using namespace std;

int main()
{
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  int total = a1 + a2 + a3;
  if((a1 + a2 + a3) >= 22)
    cout << "bust";
  else
    cout << "win";
  cout << endl;
  return 0;
}


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

using namespace std;
 
constexpr int INF       = 1000000000;
constexpr int MODULO    = 1000000007;
 
typedef int64_t ll;
 
constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };
 
#define SPRE(x) setprecision(x) 
 
int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll N, W;
	vector<vector<ll>> v(4,vector<ll>());
	cin >> N >> W;
	ll w1, tmp;
	cin >> w1 >> tmp;
	v[0].push_back(tmp);
	for(int i = 1; i < N; ++i) {
		int w;
		cin >> w >> tmp;
		v[w-w1].push_back(tmp);
	}
	for(int i = 0; i < 4; ++i)
		sort(v[i].rbegin(), v[i].rend());
 
	ll maxim = 0;
	for(int a = 0; a <= v[0].size(); ++a) {
		for(int b = 0; b <= v[1].size(); ++b) {
			for(int c = 0; c <= v[2].size(); ++c) {
				for(int d = 0; d <= v[3].size(); ++d) {
					if((a+b+c+d)*w1+b+c*2+d*3 > W)
						break;
					ll sum = 0;
					for(int i = 0; i < a; ++i)
						sum += v[0][i];
					for(int i = 0; i < b; ++i)
						sum += v[1][i];
					for(int i = 0; i < c; ++i)
						sum += v[2][i];
					for(int i = 0; i < d; ++i)
						sum += v[3][i];
					maxim = max(sum, maxim);
				}
			}
		}
	}
	cout << maxim << '\n';
}

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

void solve() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
        int l = 0, r = n - 1;
        while(l <= r) {
            int mid = l + (r - l)/2;
            if(b[mid] == a[i]) {
                if(mid >= n/2) {
                    cout << b[- 1 + n/2] << "\n";
                }
                else {
                    cout << b[n/2] << "\n";
                }
                break;
            }
            else if (b[mid] > a[i]) {
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
    }
}

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


Measured memory_bytes: 4732
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int l,r;
	cin>>l>>r;
	if(r-l+1 >= 2019)
	{
		cout<<"0"<<endl;
	}
	else
	{
		int mi = 2019;
		for(int i=l;i<=r;i++)
		{
			for(int j =i+1;j<=r;j++)
			{
				mi = min(mi,(i*j)%2019);
			}
		}
		cout<<mi<<endl;
	}
}

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

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

ll fac[MAXn],inv[MAXn];
ll fpow(ll x,ll y){
    ll ret = 1;
    while (y) {
        if (y&1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return ret;
}
void build(){
    fac[0] = inv[0] = 1;
    REP1 (i,MAXn-1) {
        fac[i] = (fac[i-1] * i) % MOD;
        inv[i] = fpow(fac[i],MOD-2);
    }
}
int main(){
    IOS();
    build();
    ll q;
    cin >> q;
    while (q--) {
        ll x,d,n;
        cin >> x >> d >> n;
        if (d == 0) {
            cout << fpow(x,n) << endl;
            continue;
        }
        ll tmp = fpow(d,n);
        ll a = x * fpow(d,MOD-2) % MOD;
        ll t = (a+n-1)/MOD;
        if (MOD*t >= a-1 && MOD*t <= a+n-1) cout << 0 << endl;
        else cout << tmp * fac[(a+n-1)%MOD] % MOD * inv[a-1] % MOD << endl;
    }
}


Measured memory_bytes: 16512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 1e5+10;
const int MAXM = (int) 1e5+10;

///--------------------START-------------------------
int n;
int a[MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int x=0,y=0;
    for(int i=n;i>=1;i--){
        if(a[i]==a[i-1]){
            if(x>0){
                y=a[i];
                i--;
                break;
            }
            else{
                i--;
                x=a[i];
            }
        }
    }
    printf("%lld\n",(LL)x*y);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}







Measured memory_bytes: 640
program cm
   implicit none
   integer::N,M,X
   integer,allocatable,dimension(:)::C
   integer,allocatable,dimension(:,:)::A
   integer,allocatable,dimension(:)::R
   integer::ans=10**9

   integer::i
   read*,N,M,X
   allocate(C(N),A(N,M))
   do i=1,N
      read*,C(i),A(i,:)
   end do

   allocate(R(M))
   do i=0,2**N-1
      call Rcheck(i)
      if(minval(R)>=X)then
         ans=min(ans,calc(i))
      endif
   end do
   print"(i0)",merge(-1,ans,ans==10**9)

contains
subroutine Rcheck(k)
   integer::k
   integer::i,j
   R=0
   do i=1,N
      if(btest(k,i-1))then
         do j=1,M
            R(j)=R(j)+A(i,j)
         end do
      endif
   end do
end subroutine
integer function calc(k)
   integer::k
   integer::i
   calc=0
   do i=1,N
      if(btest(k,i-1))then
         calc=calc+C(i)
      endif
   end do
end function
end program cm

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

int main() {
  long X; cin >> X;
  long C = 100;
  int i = 0;
  while (C < X) {
    long double c2 = 1.01L * C;
    C = floor(c2);
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int G[3][103];
int ans;
int vis[3][103];
int dir[2][2] = {{1,0},{0,1}};
void dfs(int x,int y,int cnt){
    int i;
    if(x == 2 && y == n){
        ans = max(ans,cnt);
        return ;
    }
    for(i = 0; i < 2; i++){
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if(xx <= 2 && yy <= n && !vis[xx][yy]){
            vis[xx][yy] = 1;
            dfs(xx,yy,cnt+G[xx][yy]);
            vis[xx][yy] = 0;
        }
    }
}
int main(){
    int i,j;
    scanf("%d",&n);
    for(i = 1; i <= 2; i++){
        for(j = 1; j <= n; j++){
            scanf("%d",&G[i][j]);
        }

    }
    memset(vis,0,sizeof(vis));
    ans = 0;
    vis[1][1] = 1;
    dfs(1,1,G[1][1]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
bool st(vector<int> v){
  if(
     v[1]+1==v[2]&&
     v[2]+1==v[3]&&
     v[3]+1==v[4]){
    if(v[0]+1==v[1]) return true;
    if(v[0]==1&&v[4]==13) return true;
  }
  return false;
}
int main(){
  string buf;
  int i,j,k;
  while(cin >> buf){
    vector<int> v,p;
    for(i=0;i<buf.size();i++) if(buf[i]==',') buf[i]=' ';
    stringstream ss(buf);
    for(i=0;i<5;i++){
      ss >> k;
      v.push_back(k);
    }
    sort(v.begin(),v.end());
    k=1;
    for(i=1;i<5;i++){
      //cout << v[i] << endl;
      if(v[i-1]==v[i]) k++;
      else {
	p.push_back(k);
	k=1;
      }
    }
    if(k!=1) p.push_back(k);
    sort(p.begin(),p.end(),greater<int>());
    //for(i=0;i<p.size();i++) cout << p[i] << endl;
    if(p[0]==4) cout << "four card" << endl;
    else if(p[0]==3&&p[1]==2) cout << "full house" << endl;
    else if(p[0]==3) cout << "three card" << endl;
    else if(p[0]==2&&p[1]==2) cout << "two pair" << endl;
    else if(p[0]==2) cout << "one pair" << endl;
    else if(st(v)) cout << "straight" << endl;
    else cout << "null" << endl;
  }

}

Measured memory_bytes: 1232
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

bs = []
N.times do |i|
    sum = 0
    (i...N).each do |j|
        sum += as[j]
        bs.push(sum)
    end
end

ans = 0

40.downto(0) do |i|
    cand = ans + (1<<i)
    num = 0
    bs.each do |b|
        num += 1 if cand & b == cand
    end
    ans = cand if num >= K
end
puts ans

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

using namespace std;

int sum[300000];

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

	int n;
	string s;
	cin >> n >> s;
	sum[0] = (s[0] == 'E' ? 1 : 0);
	for(int i = 1; i < n; i++)sum[i] = sum[i - 1] + (s[i] == 'E' ? 1 : 0);
	int ans = n;
	for(int i = 0; i < n; i++)
	{
		int tmp = i - (i != 0 ? sum[i - 1] : 0) + sum[n - 1] - sum[i];
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1812
nabc = input().split()
n = int(nabc[0])
a = int(nabc[1])
b = int(nabc[2])
c = int(nabc[3])
llist = [int(input()) for i in range(n)]


def make_select(idx):
    select = {'a': [], 'b': [], 'c': []}

    for i in range(n):
        bits = (idx>>(i*2)) & 3
        if bits == 1:
            select['a'].append(i)
        if bits == 2:
            select['b'].append(i)
        if bits == 3:
            select['c'].append(i)

    if not select['a'] or not select['b'] or not select['c']:
        return None
    return select


minmp = 10**32


for i in range(4**n):
    select = make_select(i)
    if not select:
        continue

    asum = bsum = csum = 0

    for idx in select['a']:
        asum += llist[idx]
    for idx in select['b']:
        bsum += llist[idx]
    for idx in select['c']:
        csum += llist[idx]

    mp = abs(asum - a) + abs(bsum - b) + abs(csum - c)
    mp += (len(select['a']) - 1) * 10
    mp += (len(select['b']) - 1) * 10
    mp += (len(select['c']) - 1) * 10

    minmp = min(minmp, mp)

print(minmp)


Measured memory_bytes: 3064
#include<stdio.h>
void bubbleSort(int A[], const int N)
{
   int i;
   int flag = 1, cnt = 0;
   int j;
       for(j = 0; flag; ++j){
          flag = 0;
           for(i = N-1; j < i; --i)
           if(A[i] < A[i-1])
              {int tmp = A[i]; A[i] = A[i-1]; A[i-1] = tmp; flag = 1; ++cnt;} }
       for(i = 0; i < N; ++i){
          if(0 < i)
           printf(" ");
           printf("%d", A[i]);}
       printf("\n%d\n", cnt);}
   int main(){
      int i; int N;
       scanf("%d", &N);
       int A[N];
       for(i = 0; i < N; ++i)
       scanf("%d", &A[i]);
       bubbleSort(A, N);
       return 0;
      }
       

Measured memory_bytes: 604
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		for(int i = 0;;i++) {
			int oldLen = set.size();
			set.add(a[i]);
			i = a[i] -2;
			int newLen = set.size();
			if(oldLen == newLen || set.contains(2)) {
				break;
			}
		}
		System.out.println(set.contains(2) ? set.size()-1 : -1);
	}
}

Measured memory_bytes: 50556
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int K, X; cin >> K >> X;
    if (K * 500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)

using ll = long long;
using namespace std;

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

    int n, m; cin >> n >> m;
    int array[n]; REPI(i, n) array[i] = 0;

    REPI(i, m * 2){
        int x; cin >> x;
        array[x - 1]++;
    }
    REPI(i, n) cout << array[i] << '\n';
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> r(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> r.at(i).first >> r.at(i).second;
    }
    for(int i = 0; i < n; ++i){
        cin >> b.at(i).first >> b.at(i).second;
    }

    sort(r.begin(), r.end());
    ll ans = 0;
    vector<bool> used(n, false);
    for(int i = n - 1; i >= 0; --i){
        ll j = -1;
        for(int k = 0; k < n; ++k){
            if(!used.at(k) &&
               r.at(i).first < b.at(k).first && r.at(i).second < b.at(k).second &&
               (j == -1 || b.at(k).second < b.at(j).second)){
                j = k;
            }
        }
        if(j == -1){ continue; }
        ans++;
        used.at(j) = true;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	m := intScanner()
	as := make([][]int, n)
	for i := 0; i < n; i++ {
		as[i] = intSliceScanner(m)
	}
	ng := make(map[int]struct{})
	ans := mod
	for len(ng) != m {
		counter := make([]int, m+1)
		for i := 0; i < n; i++ {
			counter[as[i][0]]++
		}
		mx := 0
		idx := -1
		for i := 1; i < m+1; i++ {
			if counter[i] > mx {
				idx = i
				mx = counter[i]
			}
		}
		ans = smaller(ans, mx)
		ng[idx] = struct{}{}
		for i := 0; i < n; i++ {
			for _, ok := ng[as[i][0]]; ok; {
				if _, ok := ng[as[i][0]]; ok {
					if len(as[i]) == 1 {
						as[i] = as[i][:0]
						break
					} else {
						as[i] = as[i][1:]
					}
				} else {
					break
				}
			}
		}
	}
	fmt.Println(ans)
}


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

int main() {
  
  int N; cin >> N;
  
  string S; cin >> S;
  
  int sumE = 0, sumW = 0, ans = N, leftE = 0, leftW = 0;
  
  for (int i = 0; i < N; i++) {
    
    if (S.at(i) == 'E') sumE++;
    if (S.at(i) == 'W') sumW++;
    
  }
  
  for (int i = 0; i < N; i++) {
    
    int tmp = 0;
    
    if (S.at(i) == 'E') tmp = 1;
    if (S.at(i) == 'W') tmp = 0;
    
    int cost = leftW + sumE - leftE - tmp;
    
    ans = min(ans, cost);
    
    if (S.at(i) == 'E') leftE++;
    if (S.at(i) == 'W') leftW++;
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3928
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans;
signed main(){
	int a,b;
	cin>>a>>b;
	if(b*2<=a)cout<<a-b*2<<endl;
	else cout<<0<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int n = sc.nextInt();
        var a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.nextInt();
        }

        var b = new int[n];
        a.CopyTo(b, 0);
        Array.Sort(b);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < n; i++)
        {
            if (a[i] == b[n - 1]) Console.WriteLine(b[n - 2]);
            else Console.WriteLine(b[n - 1]);
        }
        Console.Out.Flush();
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 17984
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll fact[200000], invFact[200000]; 

long long power(long long x, long long c) {
    if(c==0) return 1;
    if(c==1) return x;
    if (c%2==1) return (power( (x*x)%MOD, c/2)*x)%MOD;
    else return power( (x*x)%MOD, c/2)%MOD;
}

void make_combT(ll n){
    fact[0]=1;
    rep1(i,n) fact[i]= fact[i-1]*i%MOD;
    
    invFact[n] = power(fact[n],MOD-2);
    rrep(i,n-1) invFact[i] = invFact[i+1] * (i+1) %MOD;
}

ll comb(ll n, ll m){
    if(n<m||n<0||m<0) return 0;
    return (fact[n] * invFact[m] %MOD) * invFact[n-m] %MOD;
}

ll dp[1009][1009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make_combT(20009);
    
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    
    rep(i,1009) dp[i][0]=1;
    for(int i=A;i<=B;i++){
        rep(j,N+1)if(dp[i][j]){
            if(j) (dp[i+1][j]+=dp[i][j])%=MOD;
            ll p=1;
            for(int k=1;k<=D&&j+i*k<=N;k++){
                p=(((p*comb(N-j-i*(k-1),i)%MOD)*power(k,MOD-2))%MOD)%MOD;
                if(k>=C) (dp[i+1][j+i*k]+=(dp[i][j]*p)%MOD)%=MOD;
            }
        }
    }
    cout1(dp[B+1][N])
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.6
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,0,3){
    if(s[i]==t[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;
 
const ll mod = 998244353;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,w,k;
	cin >> h >> w >> k;
	vector <vector<ll>> grid(h,vector<ll>(w));
	for (int z=0;z<h;z++){
		for (int x=0;x<w;x++){
			char temp;
			cin >> temp;
			grid[z][x] = temp-'0';
		}
	}
	ll ans = LLONG_MAX;
	for (int i=0;i<(ll(1) << (h-1));i++){
		vector <vector<ll>> c(h,vector<ll>(w));
		set <ll> s;
		for (int z=0;z<h;z++){
			for (int x=0;x<w;x++){
				if (z != 0 && !(i & (ll(1)) << (z-1))) c[z][x] += c[z-1][x];
				c[z][x] += grid[z][x];
			}
		}
		bool ok = true;
		vector <ll> row;
		for (int z=0;z<h;z++){
			if (i & (ll(1)) << (z)){
				row.push_back(z);
			}
		}
		row.push_back(h-1);
		vector <ll> ss(row.size());
		ll temp = row.size()-1;
		for (int z=0;z<w && ok;z++){
			bool col = false;
			for (int x=0;x<row.size() && ok;x++){
				if (c[row[x]][z] > k) ok = false;
				ss[x] += c[row[x]][z];
				if (ss[x] > k) col = true;
			}
			if (col){
				temp++;
				for (int x=0;x<row.size();x++){
					ss[x] = c[row[x]][z];
				}
			}
		}
		if (ok)
		ans = min(ans,temp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFindSymmetries solver = new BFindSymmetries();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFindSymmetries {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            // 愚直な全探索はn^4なので間に合わない
        /*
            i,j -> i+a, j+b への移動を行った結果,
            移動先での
            (x,y) = (y,x)ならよいことになる

            (i, j)  <->  (j + b - a, i + a - b)
            の対応関係が必要
            つまり各a-bについて考えればいい。
            これは a-b = x とおいたときに
            (i, j) <-> (j - x, i + x) ただし、(-(n-1) <= x <= (n-1))
            の対応さえ考えればよく、これらは同じ…？

            つまり
            for x [-(n-1), n)
                for i in [0 , n)
                    for j in [0 , n)
                        対応していないならfalse
                trueならそれを満たす数だけ(※)足せばいい

            満たす数の計算は
            0 -> (0,1,2,3,,,n-1);n
            なのでnから絶対値を引いた数だけ足せばいい
            つまり
            ans += n - math.abs(x)
            これを書いていくことにする
        */

            int n = in.nextInt();
            char[][] a = new char[n][n];
            int ans = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.next().toCharArray();
            }

            for (int x = -(n - 1); x < n; x++) {
                boolean f = true;
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        f = f && (a[i][j] == a[(j - x + n) % n][(i + x + n) % n]);
                    }
                }
                if (f) ans += n - Math.abs(x);
            }

            out.println(ans);
        }

    }
}



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


bool dfs(vector<vector<bool> >& B, int n, int s, vector<bool> & u){
    
    u[s] = 1;
    for(int i = 1; i <= n; i++){
        if(B[s][i] == 1){
            //cout << i << endl;
            B[s][i] = 0;
            B[i][s] = 0;
            dfs(B, n, i, u);
        }
    }

    for(int i = 1; i <= n; i++){
        if(u[i] == 0) return 0;
    }
    return 1;

}

int main(void)
{
    int array[2][50];   
    int n, m; cin >> n >> m;
    vector<vector<bool> > A(n + 1, vector<bool>(n + 1, false));
    vector<vector<bool> > B(n + 1, vector<bool>(n + 1, false));

    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        A[a][b] = true;
        A[b][a] = true;
        array[0][i] = a;
        array[1][i] = b;
    }

    int sum = 0;

    for(int i = 0; i < m; i++){

        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                B[j][k] = A[j][k];
            }
        }
        B[array[0][i]][array[1][i]] = 0;
        B[array[1][i]][array[0][i]] = 0;

        

        vector<bool> u(n + 1, 0);
        int s = 1;
        if(!dfs(B, n, s, u)){
            sum++;
        }

    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import re
s = sys.stdin.readline()
c_i = None
f_i = None
for i, c in enumerate(s):
    if c == 'C':
        c_i = i
        break
for i, c in reversed(list(enumerate(s))):
    if c == 'F':
        f_i = i
        break
if c_i is not None and f_i is not None and c_i < f_i:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <set> 
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
    int p1=0;int lastans=800000000;
    int N,K;cin>>N>>K;
    vector <int> A(0);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        A.push_back(a);
        if(A.back()==1) p1=i;
    }
    int first=max(0,p1-K+1);
    int last=min(N-K+1,p1+K-1); 



    for(int i=first;i<=p1;i++){
        //cout<<"i   "<<i<<"   ";
        int ans=1;
    int leftans=0; int rightans=0;
    int leftnum=i;int rightnum=N-(i+K-1+1);
   // cout<<rightnum<<endl;
    leftans+=leftnum/(K-1);
    if(leftnum%(K-1)!=0) leftans++;
    if(rightnum<=0) goto label;
    rightans+=rightnum/(K-1);
    if(rightnum%(K-1)!=0) rightans++;
    ans += rightans;
    label:
    ans += leftans;  //+rightans;
    //cout<<ans<<endl;
    lastans=min(ans,lastans);




    }
    


    cout<<lastans<<endl;
    return 0;

}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n),q(n),num(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) num[i] = i+1;
    int a = 0,b = 0,cnt = 0;
    do{
        if(num == p) a = cnt;
        if(num == q) b = cnt;
        cnt++;
    }while(next_permutation(num.begin(),num.end()));
    cout << abs(a-b) << endl;
 }

Measured memory_bytes: 3640
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline


def mod_pow(x, n, mod=10**9 + 7) -> int:
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= mod
        x *= x
        x %= mod
        n //= 2

    return (K * x) % mod


MOD = 998244353

n = int(input())
D = [int(i) for i in input().strip().split()]

_max = max(D)

counts = defaultdict(int)

if D[0] != 0:
    print(0)
    sys.exit()

for d in D:
    counts[d] += 1

if counts[0] != 1:
    print(0)
    sys.exit()

ans = 1
for i in range(1, _max + 1):
    if i not in counts.keys():
        print(0)
        sys.exit()
    elif i == 1:
        continue
    else:
        x = counts[i - 1]
        k = counts[i]
        ans = (ans * mod_pow(x, k, MOD)) % MOD

print(ans)


Measured memory_bytes: 98492
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;
	cin>>n;
//	n--;
	string ans="";
    ll b=26;
    char a[27];
    char c='a';
    for(int i=0;i<26;i++)
    {
    	a[i]=c++;
	}
///	a[0]='';
    while(n)
    {
    	n--;
    //	cout<<a[0]<<endl;
    	ans+=a[n%(b)];
    	n/=b;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main() {
	int n;
	int i = 1;
	int x;
	scanf("%d", &n);
	do {
		if (i % 3 == 0 || i % 10 == 3) {
			printf(" %d", i);
		}
		else
		{
			x = i;
			do
			{
				x /= 10;
				if (x%10==3)
				{
					printf(" %d",i);
					break;
				}
			} while (x>=10);
			
		}
		i += 1;
	} while (i <= n);
	printf("\n");
	return 0;
}

Measured memory_bytes: 2732
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop

n,a,b=n1()
X=n1()

ans=0
for i in range(1,n):
    move=a*(X[i]-X[i-1])
    if move > b:
        ans+=b
    else:
        ans+=move
print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int n,ans[maxn],vis[maxn];
vector<int>g[maxn],v[2];


void dfs(int u = 1, int fa = 0, int t = 0)
{
	v[t].pb(u);
	for(int i = 0; i < (int) g[u].size(); ++i) {
		int v = g[u][i];
		if(v == fa) continue;
		dfs(v,u,t ^ 1);
	}
}

int main()
{
	fastIO;
	cin >> n;
	rep(i,0,n - 1) {
		int u,v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs();
	if(v[0].size() > v[1].size()) swap(v[0],v[1]);
	int sum = n / 3;
	if(v[0].size() <= sum) {
		for(int i = 1; i <= n; ++i) {
			if(!v[0].size()) break;
			if(i % 3 == 0) {
				int t = v[0].back();
				ans[t] = i;
				v[0].pop_back();
				vis[i]++;
			}
		}
	}
	else {
		for(int i = 1; i <= n; ++i) {
			if(!v[0].size()) break;
			if(i % 3 == 1) {
				int t = v[0].back();
				ans[t] = i;
				v[0].pop_back();
				vis[i]++;
			}
		}
		for(int i = 1; i <= n; ++i) {
			if(!v[0].size()) break;
			if(i % 3 == 0) {
				int t = v[0].back();
				ans[t] = i;
				v[0].pop_back();
				vis[i]++;
			}
		}
	}
	for(int i = 1; i <= n; ++i) {
		if(!v[1].size()) break;
		if(!vis[i]) {
			int t = v[1].back();
			ans[t] = i;
			v[1].pop_back();
			vis[i]++;
		}
	}
	for(int i = 1; i <= n; ++i) cout << ans[i] << " ";
	return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n, m, x, y;
    cin >> n >> m >> x >> y;

    int a_max = -1;
    rep(i, n){
        int a;
        cin >> a;
        a_max = max(a_max, a);
    }

    int b_min = INF;
    rep(i, m){
        int b;
        cin >> b;
        b_min = min(b_min, b);
    }

    if(x < a_max && b_min <= y && a_max < b_min){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    string s,t;cin>>s>>t;
    int n=s.size(),m=t.size();
    int q;cin>>q;
    int ss[n+1],st[m+1];
    ss[0]=0;st[0]=0;
    rep(i,0,n)ss[i+1]=(ss[i]+(s[i]-'A'+1))%3;
    rep(i,0,m)st[i+1]=(st[i]+(t[i]-'A'+1))%3;
    rep(i,0,q){
        int a,b,c,d;cin>>a>>b>>c>>d;
        int u=(ss[b]-ss[a-1]+3)%3;
        int v=(st[d]-st[c-1]+3)%3;
        if(u==v)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << '\n';
}

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

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b)) , (c))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)


int main(){
    LL A,B,C; cin >> A >> B >> C;
    if(C > A+B) cout << A+B+B+1 << endl;
    else cout << B+C << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Mmax = 200000;
int N, M;
int A[Mmax], B[Mmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<bool> vec(N);
	for(int i=0; i<M; i++){
		if(A[i] == 0) vec[B[i]] = true;
		if(B[i] == 0) vec[A[i]] = true;
	}
	for(int i=0; i<M; i++){
		if((vec[A[i]] && B[i] == N-1) || (vec[B[i]] && A[i] == N-1)){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;


	return 0;
}


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

int main()
{
	int H, W, D;
	cin >> H >> W >> D;
	vector<vector<int>> A(H, vector<int>(W));
	vector<int> x(H * W), y(H * W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j]; A[i][j]--;
			x[A[i][j]] = i;
			y[A[i][j]] = j;
		}
	}
	vector<ll> sum(H * W);
	for (int i = D; i < H * W; i++) {
		sum[i] = sum[i - D] + (abs(x[i] - x[i - D]) + abs(y[i] - y[i - D]));
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int L, R;
		cin >> L >> R; L--, R--;
		cout << (sum[R] - sum[L]) << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, k; cin >> n >> k;
	if (k <= (n - 1)*(n - 2) / 2) {
		cout << n - 1 + (n - 1)*(n - 2) / 2 - k << endl;
		for (int i = 2; i <= n; i++) cout << 1 << ' ' << i << endl;
		int p = (n - 1)*(n - 2) / 2 - k;
		for (int i = 2; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (p <= 0)goto heaven;
				cout << i << ' ' << j << endl; p--;
			}
		}
	heaven:;
	}
	else cout << "-1\n";
	cin >> n;
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::HashSet;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  w: f64,
  h: f64,
  x: i64,
  y: i64,
  }

  let cnt = if x + x == w as i64 && y + y == h as i64 {
    1
  } else {
    0
  };

  println!("{} {}", w * h / 2_f64, cnt);
}


Measured memory_bytes: 2188
N = gets.to_i
AB = N.times.map{|i|
	a, b = gets.split.map(&:to_i)
	next [a, -b]
}
p AB.sort_by{|a,b| b-a }.each_with_index.inject(0){|sum,(ab,i)| sum+ab[i%2] }


Measured memory_bytes: 12688
import sys

x,k,d=map(int,input().split())
x=abs(x)
if(abs(x%d)<abs(x%d-d)):
  min_num=x%d
  min_num2=x%d-d
else:
  min_num=x%d-d
  min_num2=x%d

kaisuu=(x-min_num)/d

if(kaisuu>k):
  print(abs(x-d*k))
  sys.exit()
if((k%2==0 and kaisuu%2==0)or(k%2==1 and kaisuu%2==1)):
  print(abs(min_num))
else:
  print(abs(min_num2))

Measured memory_bytes: 9208
#!/usr/bin/env python3
n = int(input())
ans = 0
# gcd_grid = [[0] * 201 for _ in range(201)]


def gcd(n, m):
    """if n <= 200 and m <= 200:
        if gcd_grid[n][m] != 0:
            return gcd_grid[n][m]"""
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    # gcd_grid[n][m] = b
    # gcd_grid[m][n] = b
    return b


for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        for k in range(j + 1, n + 1):
            ans += 6 * gcd(k, gcd(i, j))
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans += 6 * gcd(i, j)
for i in range(n + 1):
    ans += i
print(ans)


Measured memory_bytes: 9216