akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;


namespace ABC162
{
    class D
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            long sum = 0;

            var Sr = new int[N + 1];
            var Sg = new int[N + 1];
            var Sb = new int[N + 1];

            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'R') Sr[i + 1] = Sr[i] + 1;
                else Sr[i + 1] = Sr[i];

                if (S[i] == 'G') Sg[i + 1] = Sg[i] + 1;
                else Sg[i + 1] = Sg[i];

                if (S[i] == 'B') Sb[i + 1] = Sb[i] + 1;
                else Sb[i + 1] = Sb[i];
            }

            //Console.WriteLine(string.Join(",", Sr));
            //Console.WriteLine(string.Join(",", Sg));
            //Console.WriteLine(string.Join(",", Sb));

            for (int i = 0; i < N - 2; i++)
            {
                for (int j = i + 1; j < N - 1; j++)
                {
                    if (S[i] == S[j]) continue;
                    if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R'))
                    {
                        //Console.WriteLine("B");
                        sum += Sb[N] - Sb[j + 1];
                        if (j + (j - i) < N && S[j + (j - i)] == 'B') sum--;
                    } // k = B
                    if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R'))
                    {
                        //Console.WriteLine("G");
                        sum += Sg[N] - Sg[j + 1];
                        if (j + (j - i) < N && S[j + (j - i)] == 'G') sum--;
                    } // k = G
                    if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G'))
                    {
                        //Console.WriteLine("R");
                        sum += Sr[N] - Sr[j + 1];
                        if (j + (j - i) < N && S[j + (j - i)] == 'R') sum--;
                    } // k = R
                }
            }
            Console.WriteLine(sum);
        }
    }
}



Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
#define M 1000010
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x); i <= (y); i ++)
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	} while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
int f[M];
int sum = 0;
int main() {
	int n = read(); sum = f[1] = n;
	f[2] = 1ll * n * n % MOD; (sum += f[2]) %= MOD;
	rep(i, 3, n) {
		f[i] = 1ll * (n - 1) * (n - 1) % MOD;
		(f[i] += sum) %= MOD;
		(f[i] += MOD - f[i - 2]) %= MOD;
		(f[i] += n - i + 2) %= MOD;
		(sum += f[i]) %= MOD;
	} cout << f[n];
	return 0;
}

Measured memory_bytes: 4096
N = int(input())
A = list(map(int,input().split()))

Ans = 0
j,xorA = 0,0
for i in range(N):
    while j < N and xorA&A[j] == 0:
        xorA |= A[j]
        j += 1
    Ans += j-i
    xorA ^= A[i]

print(Ans)

Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int A, B; cin >> A >> B;
    if (A >= 13) {
        cout << B << '\n';
    } else if (6 <= A) {
        cout << B / 2 << '\n';
    } else {
        cout << 0 << '\n';
    }
    return 0;
}


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

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

using namespace std;

typedef long long ll;

const ll INF=1LL<<61;

struct vertex{
	int p,d;
	bool operator<(const vertex &v)const{ return p!=v.p?p<v.p:d<v.d; }
};

int main(){
	for(int n;scanf("%d",&n),n;){
		vertex V[4000];
		int d_sum=0;
		rep(i,n){
			scanf("%d%d",&V[i].p,&V[i].d);
			d_sum+=V[i].d;
		}
		sort(V,V+n);

		// corner case
		if(n==2){ printf("%d\n",abs(V[1].p-V[0].p)); continue; }

		// impossible
		if(d_sum<2*n-2){ puts("-1"); continue; }

		int n1=0,n2=0;
		vertex V1[4000],V2[4000];
		rep(i,n){
			if(V[i].d==1) V1[n1++]=V[i];
			else          V2[n2++]=V[i];
		}

		vector<int> p1,p2;
		rep(i,n1) p1.push_back(V1[i].p);
		rep(i,n2){
			int d=V2[i].d;
			if(i>  0 ) d--;
			if(i<n2-1) d--;
			rep(_,d) p2.push_back(V2[i].p);
		}

		// O(n^3) time, O(n^3) space solution
		/*
		// dp[i+1][j+1] := ( p1[0..i] からいくつかを使って p2[0..j] をすべてマッチさせるときの最小コスト )
		vector< vector<ll> > dp(p2.size()+1,vector<ll>(p1.size()+1,INF));
		rep(i,p2.size()+1) dp[i][0]=0;
		rep(i,p2.size()) rep(j,p1.size()) {
			dp[i+1][j+1]=min(dp[i][j+1],dp[i][j]+abs(p2[i]-p1[j]));
		}
		*/

		// O(n^3) time, O(n) space solution
		/*
		// j についてのループを逆向きに回すことで, dp 配列の i 方向を使いまわす
		ll dp[4001];
		rep(j,p1.size()+1) dp[j]=(j==0?0:INF);
		rep(i,p2.size()){
			for(int j=(int)p1.size()-1;j>=0;j--) dp[j+1]=min(dp[j+1],dp[j]+abs(p2[i]-p1[j]));
		}
		*/

		// O(n^2) time, O(n) space solution
		int Left[4000],Right[4000]; // V1[i] とマッチさせる V2 の候補は V2[Left[i]..Right[i]-1]
		rep(i,n1){
			int cost_min=abs(V1[i].p-V2[0].p),j0=0;
			rep(j,n2) if(cost_min>abs(V1[i].p-V2[j].p)) {
				cost_min=abs(V1[i].p-V2[j].p);
				j0=j;
			}
			int cen=lower_bound(p2.begin(),p2.end(),V2[j0].p)-p2.begin();
			Left [i]=max(cen-n1,0);
			Right[i]=min(cen+n1,(int)p2.size());
		}

		ll dp[4001];
		int jl=0,jr=0; // p2[i] とマッチさせる p1 の候補は p1[jl..jr-1]
		rep(j,p1.size()+1) dp[j]=(j==0?0:INF);
		rep(i,p2.size()){
			// update jl, jr
			for(;jl<p1.size();jl++) if(i<Right[jl]) break;
			for(;jr<p1.size();jr++) if(i< Left[jr]) break;
			// update dp[]
			for(int j=jr-1;j>=jl;j--) dp[j+1]=min(dp[j+1],dp[j]+abs(p2[i]-p1[j]));
		}

		printf("%lld\n",dp[p1.size()]+p2.back()-p2.front());
	}

	return 0;
}

Measured memory_bytes: 66908
using System;
using System.Linq;

class C{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int sum = 100000000, sab, Temp = 0, TS = 0;
    for (int M = 100; M > 0; M--){
      TS = 0;
      for (int i = 0; i < Ar.Length; i++){
        sab = Math.Abs(Ar[i] - M);
        Temp = sab * sab;
        TS += Temp;
      }
      sum = Math.Min(sum, TS);
    }
    Console.WriteLine(sum);
  }
}
      

Measured memory_bytes: 17780
#include <cstdio>
#include <cmath>
#include <utility>

typedef std::pair<float, float> point;
typedef std::pair<float, float> vec;

inline float cross_product(const vec& v1, const vec& v2) {
    return v1.first * v2.second - v1.second * v2.first;
}

inline vec vec_sub(const vec& v1, const vec& v2) {
    return std::make_pair(v1.first - v2.first, v1.second - v2.second);
}

int main() {    
    point p1, p2, p3, p4;
    while (scanf("%f %f %f %f %f %f %f %f",
                 &p1.first, &p1.second,
                 &p2.first, &p2.second,
                 &p3.first, &p3.second,
                 &p4.first, &p4.second) != EOF) {
        vec v12 = vec_sub(p1, p2);
        vec v24 = vec_sub(p2, p4);
        float cp1 = cross_product(v12, v24);
        
        vec v23 = vec_sub(p2, p3);
        vec v34 = vec_sub(p3, p4);
        float cp2 = cross_product(v23, v34);
        
        vec v31 = vec_sub(p3, p1);
        vec v14 = vec_sub(p1, p4);
        float cp3 = cross_product(v31, v14);
        
        int r = std::signbit(cp1);
        r += std::signbit(cp2);
        r += std::signbit(cp3);
        
        printf(r == 0 || r == 3 ? "YES\n" : "NO\n");
    }
}

Measured memory_bytes: 1032
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

LL mod=1000000007LL;
//         
int main(){
    int X;

    cin>>X;
    if(X==1){cout<<1<<endl;return 0;}
    for(int x=X;x>=2;x--){
        //dump(x);
        for(int i=2;i<=sqrt(x);i++){
          //  dump(i);
            if(x%i==0){
                int x2=x;
                while(x2%i==0){
                    x2/=i;
                }
                if(x2==1){
                    cout<<x<<endl;
                    return 0;
                }
            }
        }

    }




}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    set<char> st;
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        char c;
        cin >> c;
        st.insert(c);
    }
    if(st.size() == 4) cout << "Four";
    else cout << "Three";
    cout << endl;

    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <map>
#include <iterator>

using namespace std;

int N = 0;
long long result = 0;
string word;
map <string,int> test;

int main() {
  cin >> N;
  for(int n = 0; n < N; n++)
  {
    cin >> word;
    map <char,int> letter;
    for(char a: word) {letter[a]++;}
    word = "";
    for(map<char,int>::iterator iter = letter.begin();iter != letter.end(); iter++)
    {word += string((*iter).second,(*iter).first);}
    test[word]++;
  }
  for(map<string,int>::iterator iter = test.begin(); iter != test.end(); iter++)
  {
    if((*iter).second > 1)
    {
      long long sum = (*iter).second;
      sum *= (sum-1);
      result += sum/2;
    }
  }
  cout << result;
}

Measured memory_bytes: 12800
#define RUN
#ifdef RUN
#include <bits/stdc++.h>
using namespace std;

#define int long long

int N;
int M;

signed main() {
    cin >> N >> M;
    int ans = (N * (N - 1)) / 2 + (M * (M - 1)) / 2;
    cout << ans << endl;
    return 0;
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld                long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
//Bitwise 
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          (1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=1e6+5;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}

int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	int n,m;
	cin>>n>>m;
	int tot=0;
	rep(i,0,m){
		int temp;
		cin>>temp;
		tot+=temp;
	}
	if(tot>n) cout<<-1<<endl;
	else cout<<n-tot<<endl;
	return 0;
}

Measured memory_bytes: 3584
N = int(input())
A = [0] + list(map(int,input().split()))

count = 0
B = [0]*(N+1)

for i in range(N,0,-1):
    a = A[i]
    for j in range(2,N//i+1):
        a += B[i*j]
    if a % 2 == 1:
        count += 1
        B[i] = 1
print(count)

for i in range(N+1):
    if B[i] == 1:
        print(i)

Measured memory_bytes: 67164
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#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 clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
const int maxn = 1005;
const int maxm = 2005;
const int inf = 0x3f3f3f3f;
bool visit[maxn];
LL dis[maxn];
int a[maxm], b[maxm], c[maxm];
int n, m;

void solve() {
	rep(i, 0, m) c[i] = -c[i];
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	rep(i, 0, n-1) {
		rep(j, 0, m) {
			if (dis[b[j]] > dis[a[j]]+c[j]) {
				dis[b[j]] = dis[a[j]] + c[j];
			}
		}
	}
	
	LL ans = dis[n];
	memset(visit, false, sizeof(visit));
	
	rep(i, 0, n) {
		rep(j, 0, m) {
			if (dis[b[j]] > dis[a[j]]+c[j]) {
				dis[b[j]] = dis[a[j]] + c[j];
				visit[b[j]] = true;
			}
			if (visit[a[j]])
				visit[b[j]] = true;
		}
	}
	
	if (visit[n])
		cout << "inf" << endl;
	else
		cout << -ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	scanf("%d %d", &n, &m);
	rep(i, 0, m)
		scanf("%d %d %d", a+i, b+i, c+i);
	solve();
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


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

int main(){
  int N,count=0;
  cin>>N;
  vector<int> p(N);
  vector<int> fuga(N);
  for(int i=0; i<N; i++){
    cin>>p[i];
    fuga[i]=p[i];
  }
  sort(p.begin(),p.end());
  for(int i=0; i<N; i++){
    if(p[i]!=fuga[i]){
      count++;
    }
  }
  cout<<(count<=2?"YES":"NO");
}
      

Measured memory_bytes: 3644
N = list(input())
N.reverse()

# print(N)

p = [0,1,6,8]
h = [2,4,5,7,9]
b = [3]

if int(N[0]) in p:
    print("pon")
    
elif int(N[0]) in b:
    print("bon")
    
elif int(N[0]) in h:
    print("hon")

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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 (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

class UnionFindTree{
  public:
    vector<int> rank,p,count;

    UnionFindTree() {}

    UnionFindTree(int size){
      rank.assign(size, 0);
      p.assign(size, 0);
      count.assign(size,1);
      REP(i,size)makeSet(i);
    }

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    void unite(int x, int y){
      if(findSet(x) == findSet(y))return;

      x = findSet(x);
      y = findSet(y);
      
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]){
          rank[y]++;
        }
      }

      int tmp = count[x] + count[y];
      count[x] = tmp;
      count[y] = tmp;
    }

    int findSet(int x){
      if(x != p[x]){
        p[x] = findSet(p[x]);
      }
      return p[x];
    }

    int getCount(int x){
      return count[findSet(x)];
    }

    void print(){
      REP(i,p.size()){
        cout << p[i] << " ";
      }
      cout << endl;
      REP(i,p.size()){
        cout << rank[i] << " ";
      }
      cout << endl;
    }

};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFindTree tree(n);
  REP(i,m){
    int x,y,z;
    cin >> x >> y >> z;
    x--;y--;

    tree.unite(x,y);
  }

  set<int> st;
  REP(i,n){
    st.insert(tree.findSet(i));
  }
  cout << st.size() << endl;
}



Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin>>N;
  VEC<pair<string, int>>S(N);
  map<pair<string, int>, int>M;
  REP(i,0,N){
    cin>>S[i].first>>S[i].second;
    M[S[i]]=i;
  }
  auto f = [](pair<string,int>a, pair<string,int>b){
    if(a.first==b.first){
      return a.second>b.second;
    }else{
      return a.first<b.first;
    }
  };
  sort(ALL(S), f);
  REP(i,0,N){
    cout<<M[S[i]]+1<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int x, max = 1;
    cin >> x;
    for (int i = 2; i < sqrt(x); i++) {
        int tmp = 0, y = 1;
        while (y <= x) {
            tmp = y;
            y *= i;
        }
        if (max <= tmp) max = tmp;
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000
/*int initialze(void);
int isEmpty(void);
int isFull(void);*/
void push(int);
int pop(void);

int top=0,STACK[MAX];

int main(){

  char stack[MAX];
  int a,b;

  while(scanf("%s",stack)!=EOF){
    switch(stack[0]){

    case '+':
      a=pop();
      b=pop();
      push(a+b);
      break;
      
    case '-':
      a=pop();
      b=pop();
      push(b-a);
      break;
      
    
    case '*':
      a=pop();
      b=pop();
      push(a*b);
      break;
      
      /*case '/':
      a=pop();
      b=pop();
      push(a/b);
      break;
      */
    default:
      push(atoi(stack));
      
    }
  }
  printf("%d\n",pop());
  return 0;

}

void push(int x){
  STACK[++top]=x;
}
int pop(){
  top--;
  return STACK[top+1];


}

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

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

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)

// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < n; ++i){
// 		res += max(0ll, a[i]-x/f[i]);
//     }
//     return res <= k;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }



int main(){
 int A, B;
 cin >> A >> B;
 if(A > 9 | B > 9) print(-1);
 else print(A * B);
}

Measured memory_bytes: 256
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

function Tree() {
  this.root = null;
}
Tree.prototype.insert = function (val) {
  var z, y, x;
  z = {'left': null, 'right': null, 'key': val, 'parent': null};
  y = null;
  x = this.root;
  while (x !== null) {
    y = x;
    if (z.key < x.key) x = x.left;
    else x = x.right;
  }
  z.parent = y;

  if (y === null) this.root = z;
  else if (z.key < y.key) y.left = z;
  else y.right = z;
}
Tree.prototype.printTree = function() {
  function p(node, depth) {
    var indent = '', i;
    for (i = 0; i < depth; i++) indent = indent + '  ';
    if (node === null) {
      console.log(indent + 'NIL');
      return;
    }
    console.log(indent + node.key);
    p(node.left, depth+1);
    p(node.right, depth+1);
  }
  p(this.root, 0);
}
Tree.prototype.print = function() {
  function inorder(node) {
    var res = [];
    if (node === null) return res;
    res = res.concat(inorder(node.left));
    res.push(node.key);
    res = res.concat(inorder(node.right))
    return res;
  }
  function preorder(node) {
    var res = [];
    if (node === null) return res;
    res.push(node.key);
    res = res.concat(preorder(node.left));
    res = res.concat(preorder(node.right));
    return res;
  }
  console.log(' ' + inorder(this.root).join(' '));
  console.log(' ' + preorder(this.root).join(' '));
}

si = require('fs').createReadStream(config.input, 'r');
rl = require('readline').createInterface({
  input: si, output: process.stdout});

t = new Tree();

rl.on('line', function (line) {
  var inst;
  inst = line.split(' ');
  if (inst[0] === 'insert') t.insert(parseInt(inst[1], 10));
  else if (inst[0] === 'print') {
    //t.printTree();
    t.print();
  }
});

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

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

}



Measured memory_bytes: 3652
//Kinniku kaihou
#include <iostream>
#include <algorithm>
using namespace std;

int h[6], w[6];

int main() {
	int i, j, k, l;
	int len[12];
	
	for (i = 0; i < 6; i++) {
		cin >> h[i] >> w[i];
		len[2 * i] = h[i];
		len[2 * i + 1] = w[i];
	}
	sort(len, len + 12);
	
	for (i = 0; i < 12; i++) {
		for (j = i + 1; j < 12; j++) {
			for (k = j + 1; k < 12; k++) {
				int a[6];
				a[0] = len[i] * 2000 + len[j];
				a[1] = len[i] * 2000 + len[j];
				a[2] = len[j] * 2000 + len[k];
				a[3] = len[j] * 2000 + len[k];
				a[4] = len[i] * 2000 + len[k];
				a[5] = len[i] * 2000 + len[k];
				
				int b[6];
				for (l = 0; l < 6; l++) {
					if (h[l] < w[l]) { b[l] = h[l] * 2000 + w[l]; }
					else { b[l] = w[l] * 2000 + h[l]; }
				}
				sort(a, a + 6);
				sort(b, b + 6);
				
				for (l = 0; l < 6; l++) {
					if (a[l] != b[l]) {
						break;
					}
				}
				if (l == 6) {
					cout << "yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "no" << endl;
	return 0;
}

Measured memory_bytes: 3152
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
// #define sd(t) scanf("%d",&t)
// #define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define pdd pair<double , double>
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N    200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
#define s3   1.73205080757          // square root 3
const  int inf = (int)1e18+10 ;
const int MAX= 100;

 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set S;

int powmod(int x , int y){
	int res = 1;
	while(y > 0){
		if(y%2==1)
			res = (res*x)%mod;
		x = (x*x)%mod;
		y/=2;
	}
	return res;
}
int mul(int x , int y){
	return (x*y)%mod;
}

signed main(){
  fast;
 
  int x ,y;
  cin >> x >> y;
  if(x == 1){
  	   if(y==2) cout << 3 << endl;
  	   else  cout << 2 << endl;
  }
  else if(x == 2){
  	   if(y==1) cout << 3 << endl;
  	   else  cout << 1 << endl;
  }
  else{
  	if(y==2) cout << 1 << endl;
  	  else  cout << 2 << endl;
  }
 }

Measured memory_bytes: 256
import sys


def solve():
    s = input()
    if len(s) == 1:
        print(0)
        sys.exit(0)
    zero = 0
    one = 0
    for i in range(len(s)):
        if s[i] == '0':
            zero += 1
        else:
            one += 1
    if zero > one:
        print(one*2)
    else:
        print(zero*2)


solve()


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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> L(N);
  REP(i, 0, N) cin >> L[i];

  sort(L.begin(), L.end());

  ll x = 0;
  REP(i, 0, N - 1) {
    x += L[i];
  }

  cout << (L.back() < x ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, X := sc.nextInt(), sc.nextInt()
	var mp, mb [51]int
	ans := 0
	var f func(n, cur int) (int, int, int)
	f = func(n, cur int) (int, int, int) {
		if n == 0 {
			if cur > 0 {
				cur--
				ans++
			}
			return cur, 1, 0
		}
		if mp[n] > 0 {
			if cur >= mp[n]+mb[n] {
				cur -= mp[n] + mb[n]
				ans += mp[n]
				return cur, mp[n], mb[n]
			}
		}
		var p1, p2, b1, b2 int
		if cur > 0 {
			cur--
		}
		if cur > 0 {
			cur, p1, b1 = f(n-1, cur)
		}
		if cur > 0 {
			cur--
			ans++
		}
		if cur > 0 {
			cur, p2, b2 = f(n-1, cur)
		}
		if cur > 0 {
			cur--
		}
		p, b := 1+p1+p2, 2+b1+b2
		mp[n], mb[n] = p, b
		return cur, p, b
	}
	f(N, X)

	fmt.Fprintln(wtr, ans)
}


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

int main()
{
	int a,b,c,x,s=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					s++;
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define swap(a,b) (a^=b^=a^=b)
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
int n,val[MN],num[16],ans;
int f[1<<16],inf;
int dfs(int S)
{
	register int i,j;
	if(!S) return f[S]=0; 
	if(f[S]<inf)return f[S];
    for(i=0;i<16;i++)if(S&(1<<i))for(j=0;j<16;j++)if(i!=j&&(S&(1<<j)))
    {
    	int p=i^j,x=S^(1<<i)^(1<<j)^(1<<p);
    	if(S&(1<<p)) f[S]=min(f[S],dfs(x)+2);
    	else f[S]=min(f[S],dfs(x)+1);
    }
    return f[S];
}
int main()
{
	n=read();
	register int i,j,k,x,y,z,S=0;
	for(i=1;i<n;++i)
		x=read(),y=read(),z=read(),val[x]^=z,val[y]^=z;
	for(i=0;i<n;++i) num[val[i]]++;
	for(i=1;i<16;++i) ans+=(num[i]>>1),S+=(1<<i)*(num[i]&1);
	memset(f,127,sizeof(f));inf=f[0];f[0]=0;
	printf("%d\n",ans+dfs(S));
}

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


int main(){long N;
cin >> N;
vector<long> s(N);
rep(i, N) cin >> s.at(i);
long sum = 0;
rep(i, N) sum += s.at(i);
long ans;
sort(s.begin(), s.end());
long smin = sum;
for(long i = 0; i < N; i++){
    if(s.at(i) % 10 != 0){
        smin = s.at(i);
        break;
    }
}

if(sum % 10 != 0) ans = sum;
else ans = sum - smin;


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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
long ans=0;
void dfs(long n,long node,const vector<vector<long>> &G,vector<bool> &seen){
    seen[node]=true;
    if(count(seen.begin(),seen.end(),true)==n){
        ans++;
    }
    for(auto next:G[node]){
        if(seen[next])continue;
        dfs(n,next,G,seen);
        seen[next]=false;
    }
}

int main(){
    long n,m;
    cin >> n >> m;
    vector<vector<long>> G(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    vector<bool> seen(n,false);
    dfs(n,0,G,seen);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

//struct Point {
//	int x,y;
//};
//long long ccw(const Point& A, const Point& B, const Point& C) { // 시계방향이면 음수 
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int d[5001][5001];

int main() { // 골드 1, 플레 1
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	string s; cin >> s;
	s = "9" + s;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (s[i] == s[j] && j - i > d[i - 1][j - 1]) {
				d[i][j] = d[i - 1][j - 1] + 1; 
				ans = max(ans, d[i][j]);
			}
		}
	}
	cout << ans << '\n';



}

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

using namespace std;
typedef long long ll;

int main() {
    ll n;   cin >> n;
    vector<int> s;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    int k = 0, tmp = 1;  
    while (n != 0) {
        if (n % 2)
            s.push_back(1);
        else 
            s.push_back(0);

        n -= s[k++];
        n /= -2;
    }
    for (int i = s.size()-1; i >= 0; i--)
        cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#define N 20
using namespace std;

int main(){
    int n,a[N],b[N],c[N],x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    x=0;
    for(int i=0;i<n;i++){
        x+=b[a[i]-1];
        
        if(a[i]==a[i-1]+1){
            x+=c[a[i-1]-1];
        }
        
    }
    cout<<x<<endl;
}


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

using namespace std;

#if 1
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif

long func(long a, long b){
	long long q =  ((long long)a*a - (long long)b*b); 
	long long p =  ((long long)2*((long long)a-b));

	if( q % p != 0 ){
		return -1;
	}
	else{
		return q / p;
	}

}

int main(){
	int a,b;
	cin >> a >> b;

	int k = -1;
#if 0
	for( int i=0; i < 1e9; ++i ){
		if( abs(a - i) == abs(b - i) ){
			k = i;
		}
	}
#endif
	// a^2 - 2ak + k^2 = b^2 - 2bk + k^2
	// a^2 - 2ak = b^2 - 2bk
	// a^2 - b^2 = 2(a - b)k
	// k = (a^2 - b^2) / 2(a-b)
	// k = 

	k = func(a,b);

	if( k == -1 ){
		cout << "IMPOSSIBLE" << endl;
	}
	else{
		cout << k << endl;
	}

	return 0;
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int main(){
    int i,j,k,l;
    string s;
    cin>>s;
    
    int n,r;
    n = 0;
    r = 0;
    for (i=0;i<s.size();i++){
        if (s[i]=='T'){
            if (--n<0){
                n = 0;
                r++;
            }
        }else if (s[i]=='S'){
            n++;
        }
    }
    cout << (r+n) << endl;

    return 0;
}

Measured memory_bytes: 640
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,m,d;
    cin>>m>>d;
    if(d>=m)
    cout<<m<<'\n';
    else cout<<m-1<<'\n';

   return 0;
}





Measured memory_bytes: 3656
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] val_str = Console.ReadLine().Split(' ');
            int piece_count = (int.Parse(val_str[0]) * 3) + int.Parse(val_str[1]);

            int result = piece_count / 2;

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
#[macro_use] extern crate text_io;
use proconio::marker::*;
use std::mem;

struct Tree{
    n:usize,
    g:Vec<Vec<usize>>,
}
impl Tree{
    fn new(n:usize)->Self{
        Self{
            n:n,
            g:vec![Vec::new();n],
        }
    }
    fn add_edge(&mut self,s:usize,t:usize){
        self.g[s].push(t);
        self.g[t].push(s);
    }
    fn dfs<F:FnMut(usize,usize)>(&mut self,n:usize,p:usize,f:&mut F){
        for e in mem::take(&mut self.g[n]){
            if e==p{
                continue;
            }
            f(e,n);
            self.dfs(e,n,f);
        }
    }
}

//#[fastout]
fn main() {
    input!{
        n:usize,q:usize,
        v:[(usize,usize);n-1],
        que:[(usize,usize);q],
    }
    let mut cnt=vec![0;n];
    let mut g=Tree::new(n);
    for (s,t) in v{
        g.add_edge(s-1,t-1);
    }
    for (p,x) in que{
        cnt[p-1]+=x;
    }
    g.dfs(0,n,&mut|e,n|{cnt[e]+=cnt[n];});
    println!("{}",&mut cnt.into_iter().map(|v|v.to_string()).collect::<Vec<String>>().join(" "));
}

Measured memory_bytes: 46564
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll x,a,b;cin>>x>>a>>b;
    if(b<=a) cout<<"delicious"<<endl;
    else if(b-a<=x) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}


Measured memory_bytes: 256
s=input()
n=int(input())
flag=1
left=""
right=""
for i in range(n):
    l=list(input().split())
    if len(l)==1:
        flag*=(-1)
    elif l[1]=="1" and flag==1 or l[1]=="2" and flag==-1:
        left+=l[2]
    else:right+=l[2]
s=left[::-1]+s+right
if flag==-1:print(s[::-1])
else:print(s)

Measured memory_bytes: 4596
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  sides <- replicateM n getLine
  let lns = map words sides
      ordered_sides = sort . map (read :: String -> Int) <$> lns
  mapM_ putStrLn $ map (\(x:y:z:[]) -> if x^2 + y^2 == z^2 then "YES" else "NO") ordered_sides



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

template<typename integer>
integer __lcm(integer a, integer b) {
    return (a * b) / __gcd(a, b);
}


template <typename T>
int argmin(vector<T> arr) {
    int min_index = -1;
    double min_val = 1001001001;

    rep (i, arr.size()) {
        if (arr[i] < min_val) {
            min_index = i;
            min_val = arr[i];
        }
    }

    // 1-origin
    return ++min_index;
}


double calc_temperature(int x, int t) {
    return t - x*0.006;
}


int main() {
    int n, t, a;
    cin >> n >> t >> a;

    vector<int> h(n);
    vector<double> b(n);
    rep (i, n) cin >> h[i];
    rep (i, n) b[i] = abs(a - calc_temperature(h[i], t));
    cout << argmin(b) << endl;

    return 0;
}



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

int n;
int a[2][100001];
int b[2][2];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		int t;
		cin >> t;
		++a[i%2][t];
	}
	for(int i=1; i<=100000; ++i){
		if(a[0][b[0][1]] < a[0][i]){
			b[0][1] = i;
			if(a[0][b[0][0]] < a[0][b[0][1]])
				swap(b[0][0], b[0][1]);
		}
		if(a[1][b[1][1]] < a[1][i]){
			b[1][1] = i;
			if(a[1][b[1][0]] < a[1][b[1][1]])
				swap(b[1][0], b[1][1]);
		}
	}
//	cout << b[0][0] << " " << b[0][1] << " " << b[1][0] << " " << b[1][1] << "\n";
	int ans = n;
	if(b[0][0] != b[1][0]) ans = n - a[0][b[0][0]] - a[1][b[1][0]];
	else ans = min(n - a[0][b[0][0]] - a[1][b[1][1]], n - a[0][b[0][1]] - a[1][b[1][0]]);
	cout << ans << "\n";
}

Measured memory_bytes: 1024
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

import random
best=0

for x in range(4000):
    if x==0:
        tmp=[random.randint(1, 26) for _ in range(D)]
        tbest=tmp
    else:
        tmp=[random.randint(1, 26) for _ in range(D)]
    if score(tmp)>best:
        tbest=tmp
        best=score(tmp)
    else:
        continue
for t in tbest:
    print(t)


Measured memory_bytes: 80856
# -*- coding: utf-8 -*-

def main(N,A):
    zenbu = sum(A)
    part_sum = [A[0]]
    ans = float("INF")
    for i in range(1,N): 
        ans = min(ans, abs(zenbu-2*part_sum[-1]))
        part_sum.append(part_sum[-1]+A[i])

    print(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Measured memory_bytes: 24936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n,sum=0;
  cin>>n;
  vector<int>a(n),b(n),c(n);
  rep(i,n) {
    cin>>a[i];
    a[i]--;
  }
  rep(i,n) cin>>b[i];
  rep(i,n-1) cin>>c[i];
  rep(i,n){
    sum+=b[a[i]];
    if(i>0 && a[i]==a[i-1]+1)
      sum+=c[a[i-1]];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b, sum;
    
    while(true){
        cin >> a >> b;
        if(cin.fail()) break;
        
        sum = a + b;
        
        if(sum / 10 != 0 && sum / 100 == 0)
            cout << 2 << endl;
        else if(sum / 100 != 0 && sum / 1000 == 0)
            cout << 3 << endl;
        else if(sum / 1000 != 0 && sum / 10000 == 0)
            cout << 4 << endl;
        else if(sum / 10000 != 0 && sum / 100000 == 0)
            cout << 5 << endl;
        else if(sum / 100000 != 0 && sum / 1000000 == 0)
            cout << 6 << endl;
        else 
            cout << 7 << endl;
    }
}



Measured memory_bytes: 3008
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int h = sc.nextInt();
		int w = sc.nextInt();
 
		String[][] aka = new String[h][w];
		String[][] ao = new String[h][w];
 
		ArrayList<Integer> tate = new ArrayList<>();
		ArrayList<Integer> yoko = new ArrayList<>();
 
		char[][] c = new char[h][];
 
		for (int i = 0; i < h; i++) {
			c[i] = sc.next().toCharArray();
		}
 
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (c[i][j] == '#') {
					tate.add(i);
					yoko.add(j);
				}
			}
		}
 
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (j == 0) {
					aka[i][j] = "#";
					ao[i][j] = ".";
				} else if (j == w - 1) {
					aka[i][j] = ".";
					ao[i][j] = "#";
				} else {
					if (i % 2 == 0) {
						aka[i][j] = "#";
						ao[i][j] = ".";
					} else {
						aka[i][j] = ".";
						ao[i][j] = "#";
					}
				}
 
			}
		}
 
		for (int i = 0; i < tate.size(); i++) {
			aka[tate.get(i)][yoko.get(i)] = "#";
			ao[tate.get(i)][yoko.get(i)] = "#";
		}
 
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print(aka[i][j]);
			}
			System.out.println();
		}
		System.out.println();
 
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print(ao[i][j]);
			}
			System.out.println();
		}
	}
 
}

Measured memory_bytes: 55964