akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
class UnionFind{
    private:
        vector<ll> par;
        vector<ll> siz;
    public:
        UnionFind(ll sz){
            par.resize(sz);
            siz.assign(sz,1LL);
            rep(i,sz) par[i] = i;
        }

        ll find(ll x){
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }

        void unite(ll x,ll y){
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (siz[x] < siz[y]) swap(x,y);
            siz[x] += siz[y];
            par[y] = x;
        }

        bool same(ll x,ll y){
            return find(x) == find(y);
        }

        ll size(ll x){
            return siz[find(x)];
        }

        ll get(){
            ll res = 0;
            bool done[par.size()] = {0};
            rep(i,par.size()){
                if (done[find(i)] == 0){
                    res++;
                    done[find(i)] = 1;
                }
            }
            return res;
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x,y,z;
    cin >> n >> m;
    UnionFind card(n);
    rep(i,m){
        cin >> x >> y >> z;
        card.unite(x-1,y-1);
    }
    PRINT(card.get());
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int gcd(int a,int b){
    if(a==b){
        return a;
    }

    if(a<b){
        swap(a,b);
    }

    return gcd(a-b,b);
}

int main() {
    int K;
    cin >> K;
    int answer = 0;
    
    REPS(i,K){
        REPS(j,K){
            REPS(l,K){
                answer += gcd(gcd(i,j),l);
            }
        }
    }

    cout << answer << endl;
}


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

int main(){
    string s;
    cin >> s;
    vector<char> vec;
    for(int i=0; i<(int)s.length(); i++){
        if(s[i] != 'B'){
            vec.push_back(s[i]);
        }
        else if(vec.size() > 0){
            vec.pop_back();
        }
    }
    for(auto& c:vec){
        cout << c;
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define N 200010
using namespace std;
int n, a[N], b[N], l, s1[N], s2[N], f[N], x1, y1, ans, flag[N];
map<int, int>mp;
inline int gether(int x){return f[x]?f[x]=gether(f[x]):x;}
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d", &a[i]);
	a[n+1]=0; for(int i=1; i<=n; i++)a[n+1]^=a[i];
	for(int i=1; i<=n; i++)scanf("%d", &b[i]);
	b[n+1]=0; for(int i=1; i<=n; i++)b[n+1]^=b[i];
	n++; l=0; mp.clear();
	for(int i=1; i<=n; i++)if(!mp[a[i]])mp[a[i]]=++l;
	for(int i=1; i<=n; i++)if(!mp[b[i]])mp[b[i]]=++l;
	memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2));
	for(int i=1; i<=n; i++){s1[mp[a[i]]]++; s2[mp[b[i]]]++;}
	for(int i=1; i<=l; i++)if(s1[i]!=s2[i]){printf("-1"); return 0;}
	ans=0; if(a[n]!=b[n])ans--;
	memset(f, 0, sizeof(f)); memset(flag, 0, sizeof(flag));
	for(int i=1; i<=n; i++)if(a[i]!=b[i]){
		flag[mp[a[i]]]=flag[mp[b[i]]]=1;
		ans++; x1=gether(mp[a[i]]); y1=gether(mp[b[i]]);
		if(x1!=y1)f[y1]=x1;
	}
	for(int i=1; i<=l; i++)if(flag[i]&&!f[i])ans++;
	if(flag[mp[a[n]]])ans--;
	printf("%d", ans);
	return 0;
}

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

int main(void)
{
  int N;
  cin >> N;
  if (N / 100 == 7)
  {
    cout << "Yes" << endl;
  }
  else if ((N / 10) % 10 == 7)
  {
    cout << "Yes" << endl;
  }
  else if (N % 10 == 7)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

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

void solve() 
{
    string s;cin>>s;
    string ss="hi";
    string sss="hi";
    REP(i,10){
        if(s==ss){
            cout<<"Yes"<<endl;
            return;
        }else{
            ss+=sss;
        }
    }cout<<"No"<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,s,t;
int d[100005];
vector<int> G[100005];
int dist[100005];
priority_queue<P,vector<P>,greater<P> > que;
bool used[100005];

void dfs(int v,int c,int vv){
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]<vv && dist[G[v][i]]>c){
			dist[G[v][i]]=c;
			que.push(P(c,G[v][i]));
			dfs(G[v][i],c,vv);
		}
	}
}

int main(void){
	scanf("%d%d%d%d",&n,&m,&s,&t);
	s--;
	t--;
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		G[u].push_back(v);
	}
	if(s>=t){
		printf("0\n");
	}else{
		for(int i=0;i<n;i++){
			dist[i]=1e9;
		}
		dist[s]=0;
		que.push(P(0,s));
		int prev=0;
		while(que.size()){
			P p=que.top();
			que.pop();
			if(dist[p.second]<p.first)continue;
			while(prev<=p.second){
				if(dist[prev]>dist[p.second]){
					dist[prev]=dist[p.second];
					que.push(P(dist[p.second],prev));
				}
				prev++;
			}
			for(int i=0;i<G[p.second].size();i++){
				if(G[p.second][i]>p.second){
					int nec=G[p.second][i];
					if(dist[nec]>dist[p.second]+d[nec]){
						dist[nec]=dist[p.second]+d[nec];
						que.push(P(dist[nec],nec));
					}
				}
			}
		}
		printf("%d\n",dist[t]);
	}
	return 0;
}

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

int main(){
    long long a;
    double b;
    cin >> a >> b;
    cout << (a * (long long)(b * 100 + 0.5)) / 100 << endl;
}


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

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

using namespace std;

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

  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int t = 0;
  rep(i, n){
    if(t+1 == a[i]) t++;
  }
  if(!t){
    cout << -1 << endl;
  }else{
    cout << n - t << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int a;
      cin>>a;
      mp[a]++;
    }
  }
  int ans=0;
  for(auto x:mp){
    if(x.second==n)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int x,y;
vector<vector<int> > e;
vector<int> b;

int dfs(int v){
  if(v==x){
    return count(b.begin(),b.end(),1);
  }else{
    vector<int> nv=e[v];
    nv.push_back(v);
    bool nb=false;
    for(int i=0;i<nv.size();i++){
      nb|=b[nv[i]];
    }
    if(nb){
      return dfs(v+1);
    }else{
      int m=x;
      for(int i=0;i<nv.size();i++){
	b[nv[i]]=1;
	m=min(m,dfs(v+1));
	b[nv[i]]=0;
      }
      return m;
    }
  }
}


int main(){
  while(cin>>x>>y,x|y){
    e.clear();
    e.resize(x);
    b.clear();
    b.resize(x);
    while(y--){
      int s,t;
      cin>>s>>t;
      e[s].push_back(t);
      e[t].push_back(s);
    }
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line = br.readLine().split(" ");
      int i=0;
      int[] arrayS = new int[n];
      for (String val : line) {
        arrayS[i++] = Integer.parseInt(val);
      }

      int cnt = mergeSort(arrayS, 0, n);

      dispIntArray(arrayS);
      System.out.println(cnt);
    }
  }

  private static int mergeSort(int[] a, int left, int right) {
    int cnt =0;

    if(left+1 < right){
      int mid = (left + right) / 2;
      cnt += mergeSort(a, left, mid);
      cnt += mergeSort(a, mid, right);
      cnt += merge(a, left, mid, right);
    }

    return cnt;
  }

  private static int merge(int a[], int left, int mid, int right) {
    int cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    int[] arrayL = new int[n1+1];
    int[] arrayR = new int[n2+1];
    
    for(int i=0; i<n1; i++)
      arrayL[i] = a[left+i];
    arrayL[n1] = Integer.MAX_VALUE;

    for(int i=0; i<n2; i++)
      arrayR[i] = a[mid+i];
    arrayR[n2] = Integer.MAX_VALUE;

    for(int i=0,j=0,k=left; k<right; k++) {
      if(arrayL[i] <= arrayR[j])
        a[k] = arrayL[i++];
      else
        a[k] = arrayR[j++];
      cnt++;
    }

    return cnt;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 156552
#include <stdio.h>
int main(){
  int i,j=0,c=0,n1,n2,retu1[100000],retu2[50000],left,right,mid;
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&retu1[i]);
  }
  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&retu2[i]);
  }

  for(i=0;i<n2;i++){
    left=0;
    right=n1;
    while(left<right){
      mid=(left+right)/2;
      if(retu1[mid]==retu2[i]){
	c++;
	break;
      }
      else if(retu1[mid]>retu2[i]){
	right=mid;
    }
      else
	left=mid+1;
  }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int r,g;
           cin>>r>>g;
           //x+r>=2*g x>=2*g-r
           cout<<2*g-r<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	bool a,b,c;
	cin>>a>>b>>c;
	if((a&&b&&!c)||(!a&&!b&&c))cout<<"Open"<<endl;
	else cout<<"Close"<<endl;
}

Measured memory_bytes: 1156
#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 pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
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;}

//head
int total = 0;
ll adj[101][101];
ll sp[101][101];
bool vis[101][101];
int p[101][101];

void path(int i, int j){
  if(i != j){
    path(i, p[i][j]);
  }
  if(!vis[p[i][j]][j] && !vis[j][p[i][j]]){
    total++;
    vis[p[i][j]][j] = true;
    vis[j][p[i][j]] = true;
  }
}

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

  int n, m;
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      adj[i][j] = INT_MAX;
    }
  }
  memset(vis, false, sizeof(vis));
  for(int i = 0; i < m; i++){
    int u, v, c;
    cin >> u >> v >> c;
    adj[u][v] = c;
    adj[v][u] = c;
  }
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++){
      p[i][j] = i;
    }
  }
  for(int k = 1; k <= n; k++){
    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
        if(adj[i][k] + adj[k][j] < adj[i][j]){
          adj[i][j] = adj[i][k] + adj[k][j];
          p[i][j] = p[k][j];
        }
      }
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if(adj[i][j] != INT_MAX && i != j){
        path(i, j);
      }
    }
  }
  cout << m - total << endl;

}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
//#include<iostream>
using namespace std;

int n;
#define maxn 100011
int a[maxn],cnt[maxn];
int main()
{
	scanf("%d",&n);
	memset(cnt,0,sizeof(cnt));
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	int ans=0;
	for (int i=1;i<=100000;i++)
		ans=max(ans,cnt[i]+cnt[i-1]+cnt[i+1]);
	ans=max(ans,cnt[0]+cnt[1]);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  str s ;
  cin >> s ;
  int n = SZ(s) ;
  str t = "" ;
  REP(i,n){
    if(s[i]!='x'){
      t += s[i] ;
    }
  }
  str u = t ;
  reverse(ALL(u)) ;
  
  if(u!=t){
    cout << -1 <<endl ;
    return 0 ;
  }
  else{
    int ans = 0 ;
    int m = SZ(u) ;
    vector<int> sp(m+1) ;
    int i=0;
    int j=0;
    while(i<n){
      if(s[i]=='x'){
        sp[j]++ ;
      }
      else{
        j++ ;
      }
      i++ ;
    }
    vector<int> sp2 ;
    sp2 = sp ;
    reverse(ALL(sp2)) ;
    REP(i,m+1){
      ans += abs(sp2[i]-sp[i]) ;
    }
    cout << ans/2 <<endl; 
  }
  
  
  
  
  return 0 ;
}



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

int main(){
	int N;
	cin >> N;
	int A[N], p[N], q[N];
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A, A+N);
	long long int ans1 = 0, ans2 = 0;
	if(N % 2 == 0){
		for(int i=0; i<N; i++){
			if(i == N/2) ans1 += A[i];
			if(i == (N/2) - 1) ans1 -= A[i];
			if(i < (N/2) - 1) ans1 -= 2*A[i];
			if(i > N/2) ans1 += 2*A[i];
		}
		cout << ans1 << endl;
	}else{
		for(int i=0; i<N; i++){
			if(i == (N/2) - 1 || i == (N/2)) ans1 -= A[i];
			if(i < (N/2) - 1) ans1 -= 2*A[i];
			if(i > N/2) ans1 += 2*A[i];
		}
		for(int i=0; i<N; i++){
			if(i == (N/2) + 1 || i == (N/2)) ans2 += A[i];
			if(i < N/2) ans2 -= 2*A[i];
			if(i > (N/2) + 1) ans2 += 2*A[i];
		}
		cout << (ans1>ans2?ans1:ans2) << endl;
	}
	return 0;
}

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

int a,b,c;

int main()
{
    cin>>a>>b>>c;
    for(int i=1;i<=b;i++)
    {
    if((i*a)%b==c){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    auto ok = [](string s) {
        int n = s.size();
        if (n&1) return false;
        bool res = true;
        rep(i, n/2) {
            if (s[i] != s[i+n/2]) res = false;
        }
        return res;
    };

    int n = s.size();
    rep(i, n) {
        s.pop_back();
        if (ok(s)) {
            cout << n-i-1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, ans = INF;
	string S;
	vector<int> w, b;
	
	cin>>N;
	
	cin>>S;
	
	w.resize(N+1);
	b.resize(N+1);
	
	for(int i = 0; i < N; i++){
		if(S[i] == '.') w[i+1]++;
		else b[i+1]++;
		
		w[i+1] += w[i];
		b[i+1] += b[i];
	}
	
	for(int i = 0; i < N; i++){
		int cost = 0;
		cost += b[i] - b[0];
		cost += w[N] - w[i+1];
		ans = min(ans, cost);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

vector<int> num(4);
bool cont = true;
vector<char> ans(3);
int sum;

void test_op(int i,vector<char> &op){
  if(i == 3){
    sum = num.at(0);
    
    for(int j=0;j<3;j++){
      if(op.at(j) == '+') sum += num.at(j+1);
      else sum -= num.at(j+1);
    }
    
    if(sum == 7){
      cont = false;
      for(int j=0;j<3;j++) ans.at(j) = op.at(j);
    }
  }
  
  else if(cont){
    op.at(i) = '+';
    test_op(i+1,op);
    
    op.at(i) = '-';
    test_op(i+1,op);
  }
}
      
int main(){
  string s;
  cin >> s;
  
  vector<char> op(3);
  
  for(int i=0;i<4;i++){
    num.at(i) = s.at(i) - '0';
  }
  
  test_op(0,op);
  
  for(int i=0;i<3;i++) {      
    cout << num.at(i) << ans.at(i); 
  }
  cout << num.at(3) << "=7" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int text1(int a, int b)
{int t = a;
if (a<b)
{t = b;
b = a;
a = t;}
while (a%b)
a += t;
return a;
}
int text2(int a, int b)
{int t;
if (a<b)
{t = b;
b = a;
a = t;}
while (a%b)
{t = a%b;
a = b;
b = t;}
return b;
}
int main()
{int a[100],i=0,n=0;
while(scanf("%lld%llu",&a[i],&a[i+1])!=EOF)
{i+=2;
n+=2;}
for(i=0;i<n;i+=2)
printf("%lld %llu\n",text2(a[i],a[i+1]),text1(a[i],a[i+1]));
return 0;
}

Measured memory_bytes: 604
import sys
#import bisect
input = sys.stdin.buffer.readline
#lb = bisect.bisect_left

def main():
	#N,K=map(int,input().split())
	#vA=list(map(int, input().split()))
	#INF = 1001001001
	H=int(input())
	
	res = 0
	en = 1
	while H:
		res += en
		H //= 2
		en *= 2

	print(res)

main()


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

int main() {
    int n; cin >> n;
    vector<int> S(n);
    rep(i,n){
        cin >> S[i];
    }

    int q; cin >> q;
    vector<int> T(q);
    rep(i,q){
        cin >> T[i];
    }

    int ans = 0;
    rep(i,q){
        int left = 0;
        int right = n;
        while(left < right){
            int mid = (left + right) / 2;
            if(S[mid] == T[i]){
                ans++;
                break;
            } else if (S[mid] > T[i]){
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <sstream>

using namespace std;

string substitute(string const& s, string const& from, string const& to) {
	stringstream result;
	size_t i = 0;
	while (true) {
		auto found = s.find(from, i);
		if (found == string::npos) {
			for (; i < s.size(); i++) {
				result << s[i];
			}
			break;
		}
		else {
			for (; i < found; i++) {
				result << s[i];
			}
			result << to;
			i += from.size();
		}
	}

	return result.str();
}

void solve(int n) {
	vector<string> from(n, "");
	vector<string> to(n, "");

	for (int i = 0; i < n; i++) {
		cin >> from[i] >> to[i];
	}
	string start;
	string end;
	cin >> start;
	cin >> end;

	queue<pair<size_t, string>> replaced;
	replaced.push(make_pair(0, start));

	while (!replaced.empty()) {
		auto top = replaced.front();
		replaced.pop();

		if (top.second == end) {
			cout << top.first << endl;
			return;
		}

		for (int i = 0; i < n; i++) {
			auto next = substitute(top.second, from[i], to[i]);
			if (next.size() <= end.size() && top.second != next) {
				replaced.push(make_pair(top.first + 1, next));
			}
		}
	}
	cout << -1 << endl;
}

int main() {
	int n;
	while (cin >> n && n) {
		solve(n);
	}
}

Measured memory_bytes: 3448
#include <iostream>
 
int main(){
  std::ios_base::sync_with_stdio(false);
  int K;
  std::cin >> K;
  
  auto gcd = [](int a, int b){
  	while(b > 0){
      int tmp = b;
      b = a%b;
      a = tmp;
    }
    return a;
  };
  int sum = 0;
  for(int i=1; i<=K; i++){
    for(int j=1; j<=K; j++){
      for(int k=1; k<=K; k++){
        sum += gcd(gcd(i, j), k);
      }
    }
  }
  std::cout << sum << "\n";
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
//bit全探索による解放
int main(){
    string s;cin>>s;
    bool flag=true;
    for(int bit=0;bit<(1<<3);bit++){
        //bitが立っていれば+
        int tmp=s[0]-'0';
        V k(3);
        char ope[4];
        for(int i=0;i<3;i++){
            if(bit&(1<<i)){
                k[i]=1;
                tmp+=(s[i+1]-'0');
                ope[i]='+';
            }
            else{
                tmp-=(s[i+1]-'0');
                ope[i]='-';
            }
        }
        //rep(j,3)cout<<k[j];
        //printf("tmp=%d\n",tmp);
        if(tmp==7&&flag){
            cout<<s[0];
            rep(i,3){
                cout<<ope[i]<<s[i+1];
            }
            cout<<"=7"<<endl;
            flag=false;
        }
    }
}


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

t = [0] * (n + 1)
a = [0] * (n + 1)
g = [0] * (n + 1)
ac = [0] * (n + 1)

t[0] = 1
t[1] = 4
t[2] = 16
a[1] = 1
a[2] = 4
g[1] = 1
g[2] = 4
ac[2] = 1

for i in range(3, n + 1):
    t[i] = t[i - 1] * 4 - a[i - 2] - ac[i - 1] - g[i - 2] - a[i - 3] * 3
    a[i] = t[i - 1]
    g[i] = t[i - 1] - ac[i - 1]
    ac[i] = t[i - 2] - g[i - 2]

print(t[n] % (10**9 + 7))

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.insert(n+1,0)
total=0
for i in range(1,n+2):
    total+=abs(a[i-1]-a[i])
for i in range(1,n+1):
    print(total-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

Measured memory_bytes: 14048
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    while (sc.hasNext()) {
      int combination = 0;
      int n = sc.nextInt();

      for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
          for (int k = 0; k < 10; k++) {
            for (int l = 0; l < 10; l++) {
              if (i + j + k + l == n) {
                combination++;
              }
            }
          }
        }
      }

      System.out.println(combination);
    }
  }
}

Measured memory_bytes: 17024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{   
    string s;
    cin >> s;
    long long int ans = 0;
    for(int bit = 0;bit < (1 << s.size() - 1);bit++)
    {
        long long int temp = s[0] - '0';
        for(int i = 0;i < s.size() - 1;i++)
        {
            if(bit & (1 << i))
            {
                ans += temp;
                temp = s[i + 1] - '0';
            }
            else
            {
                temp *= 10;
                temp += s[i + 1] - '0';
            }
        }
        ans += temp;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//ll z[1000001]={0};

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    forin(i,0,n-1)
    cout<<a[i]<<b[i];
    cout<<endl;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
typedef long long ll;
int main(){
    int n, s;
    cin >> n >> s;
    int weight[n+1], price[n+1];
    for(int i = 1; i <= n ; ++i) cin >> weight[i] >> price[i];
 
    vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0LL));
 
    for(int i = 1; i <= n ; ++i){
        for(int j = 0; j <= s ; ++j){
            if(j < weight[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], price[i]+dp[i-1][j-weight[i]]);
        }
    }
    printf("%lld\n", dp[n][s]);
 
    return 0;
}

Measured memory_bytes: 80256
def make_set_list(array,valid):
    new_array = []
    for i in range(len(array)//2):
        new_array.append(array[2*i]*array[2*i+1])
    if len(array)%2 == 1 and valid == 1:
        new_array.append(array[len(array)-1])
    return new_array

N, K = list(map(int,input().split()))
As = list(map(int,input().split()))
p_nums = []
n_nums = []
for i in range(N):
    n = As[i]
    if n < 0:
        n_nums.append(n)
    else:
        p_nums.append(n)
As.sort(key = abs)
n_nums.sort()
p_nums.sort(reverse = True)
if len(p_nums) > 0:
    if N > K:
        ok = True
    elif len(n_nums) % 2 == 0:
        ok = True
    else:
        ok = False
elif K % 2 == 0:
    ok = True
else:
    ok = False

ans = 1

if ok:
    if K % 2 == 0:
        set_p_num = make_set_list(p_nums,1)
        set_n_num = make_set_list(n_nums,0)
        set_num = set_p_num + set_n_num
        set_num.sort(reverse = True)
        for i in range(K//2):
            ans = (ans*(set_num[i]%(10**9+7)))%(10**9+7)
    else:
        ans = p_nums.pop(0)
        set_p_num = make_set_list(p_nums,1)
        set_n_num = make_set_list(n_nums,0)
        set_num = set_p_num + set_n_num
        set_num.sort(reverse = True)
        for i in range(K//2):
            ans = (ans*(set_num[i]%(10**9+7)))%(10**9+7)
else:
    for i in range(K):
        ans = (ans*(As[i]%(10**9+7)))%(10**9+7)

print(ans)


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


int main() {
	int n, m;
	cin >> n >> m;
	int g = INT_MAX, l = 1;
	int L, R;


	for (int i = 0; i < m; i++) {
		cin >> L >> R;
		l = max(L, l);
		g = min(R, g);
	}

	cout << max(g - l + 1, 0) << endl;


	return 0;
}


Measured memory_bytes: 384
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("allcodefs.in", "r", stdin)
#define fout freopen("allcodefs.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
LL H, i = 1, cnt;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> H;
    while (H >= 1) {
        cnt += i;
        H /= 2;
        i *= 2;
    }
    cout << cnt;
    ///time;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N = 5010;
int n;
int a[N] , b[N * 3];
char s[N] , t[N];
inline int Abs(int x) { return x < 0 ? -x : x; }
int calc()
{
	int tota = 0 , totb = 0;
	for(int i = 1 ; i < n ; ++i) if(s[i] == '0' && s[i + 1] == '1') a[++tota] = i;
	for(int i = 1 ; i <= n ; ++i) b[++totb] = 0;
	for(int i = 1 ; i < n ; ++i) if(t[i] == '0' && t[i + 1] == '1') b[++totb] = i;
	for(int i = 1 ; i <= n ; ++i) b[++totb] = n;
	int ans = 1e8;
	for(int i = 1 ; i <= totb - tota + 1 ; ++i)
	{
		int res = 0;
		for(int j = 1 ; j < i ; ++j) res += b[j];
		for(int j = 1 ; j <= tota ; ++j) res += Abs(a[j] - b[j + i - 1]);
		for(int j = tota + i ; j <= totb ; ++j) res += n - b[j];
		ans = min(ans , res); 
	}
	return ans;
}

int main()
{
	cin >> n >> (s + 1) >> (t + 1);
	if(n == 1) { cout << (s[1] != t[1]) << '\n'; return 0; }
	if(n == 2) { cout << ((s[1] != t[1]) + (s[2] != t[2])) << '\n'; return 0; }
	int ans = calc();
	for(int i = 1 ; i <= n ; ++i) // 算完红的算蓝的
		s[i] = '1' + '0' - s[i] , t[i] = '1' + '0' - t[i];
	cout << ans + calc() << '\n';
	return 0;
}
/*
2
00
11
*/

Measured memory_bytes: 384
N = int(input())
table = [[0] * 10 for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    if s[-1] == '0': continue
    table[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += table[i][j] * table[j][i]
print(ans)

Measured memory_bytes: 3060
n = int(input())
A = [int(x) for x in input().split()]


def partition(A, p, r):
    x = A[r]
    i = p
    for j in range(p, r):
        if A[j] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1

    A[i], A[r] = A[r], A[i]

    return i


r = partition(A, 0, n - 1)

ans = [str(x) for x in A]
ans[r] = '[{}]'.format(ans[r])
print(' '.join(ans))



Measured memory_bytes: 16592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

const int N = 1000005;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<int> a[15][10];

    int total = 9;
    for(int i=0;i<=9;i++){
        a[1][i].push_back(i);
    }

    int ten = 10;
    for(int i=2;i<=12;i++){
        for(int j = 0;j<=9;j++){
            for(int k = max(0LL,j-1);k<=min(9LL,j+1);k++){
                for(int x : a[i-1][k]){
                    a[i][j].push_back(j*ten + x);
                    total++;
                    if(total > N) break;
                }
                if(total > N) break;
            }
            if(total > N) break;
        }
        if(total > N) break;
        ten*=10;
    }

    vector<int> ans;
    for(int i=1;i<=12;i++){
        for(int j=1;j<=9;j++){
            //cout << "digits " << i << " starting with " << j << "\n";
            for(int x: a[i][j]){
                //cout << x << " ";
                ans.push_back(x);
            }
            //cout << endl << endl;
        }
    }

    int k; cin >> k;
    sort(ans.begin(), ans.end());
    //for(int x : ans) cout << x << " ";
    //cout << "\n";
    cout << ans[k-1] << "\n";




}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i,n) cin >> s[i];
  sort(s.begin(), s.end());

  map <string, int> m;
  REP(i,n) {
    m[s[i]] += 1;
  }
  int mx = 0;
  REP(i,n) {
    mx = max(mx, m[s[i]]);
  }

  for(auto x : m) {
    if (x.second == mx) { cout << x.first << endl; }
  }
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
   ll x; cin >> x;
   ll aa,bb;
   rep(a,-1001,1001){
       rep(b,-1001,1001){
           if((ll)a*a*a*a*a - (ll)b*b*b*b*b == x){
                aa = a; bb = b;
           }
       }
   }
   
   cout << aa << " " <<  bb << "\n";
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

ll MAXN = 100100;
vl fact(MAXN);
vl C(MAXN);

ll mod_pow(ll x, ll p, ll M) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%M;
		x = x*x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll m) {
	return mod_pow(a, m - 2, m);
}

ll nCr(ll n, ll r) {
	ll ret = fact[n];
	ret = (ret*mod_inverse(fact[r], MOD)) % MOD;
	ret = (ret*mod_inverse(fact[n - r], MOD)) % MOD;
	return ret;
}


int main() {
	int n, i, j;
	cin >> n;

	fact[0] = 1;
	for (i = 1; i <= n + 1; i++) {
		fact[i] = (i*fact[i - 1]) % MOD;
	}

	vi a(n + 1);
	vi ichi(n + 1, -1);
	int x1, x2;
	for (i = 0; i < n + 1; i++) {
		cin >> a[i];
		if (ichi[a[i]] == -1) {
			ichi[a[i]] = i;
		}
		else {
			x1 = ichi[a[i]];
			x2 = i;
		}
	}
	//cout << x1 << " " << x2 << endl;
	for (int k = 1; k <= n + 1; k++) {
		ll cnt = 0;
		//cout << nCr(n + 1, k) << endl;
		cnt += nCr(n + 1, k);
		if (k <= n + x1 - x2 + 1) {
			cnt -= nCr(n + x1 - x2, k - 1);
		}
		while (cnt < 0) {
			cnt += MOD;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int x;
	cin >> x;
	cout << 1 - x << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int maxint = (int)1e10;
using ll = long long;

struct ufind{
  vector<int> uf;
  stack<int> preferbox;
  ufind(int q){
    uf=vector<int>(q);
    for(int i=0;i<q;i++)uf.at(i)=i;
  }
  
  void stick(int a,int b){
    if(uf.at(a)==uf.at(b))return;
    //int ma=fpe(a);
    //int mb=fpe(b);
    a=fpe(a);
    b=fpe(b);
    int minx=(a<b)?a:b;
    //uf.at(ma)=minx;
    //uf.at(mb)=minx;
    uf.at(a)=minx;
    uf.at(b)=minx;
  }
  
  int fpe(int a){
   return (uf.at(a)==a)?a:uf.at(a)=fpe(uf.at(a));
  }
  
  
  
  bool find(int a,int b){
    return fpe(a)==fpe(b);
  }
  
  bool find2(int a,int b){
    if(uf.at(a)==uf.at(b))return true;
   return fpe(a)==fpe(b); 
  }
  
};



int findp(vector<int> v,int x){
  auto it = lower_bound(v.begin(), v.end(), x);
  
  int pos = distance(v.begin(),it);
  return pos;
  
}

int main() {
  
  
  
  vector<int> gdx={-maxint,maxint},gdy={-maxint,maxint};
  int N,M;
  cin >> N >> M;
  vector<int> Xv(N),Y1(N),Y2(N),X1(M),X2(M),Ys(M);
  for(int i=0;i<N;i++){
    cin >> Y1[i] >> Y2[i] >> Xv[i]; 
    gdx.push_back(Xv[i]);
    gdy.push_back(Y1[i]);
    gdy.push_back(Y2[i]);
  }
  
  for(int i=0;i<M;i++){
    cin >> Ys[i] >> X1[i] >> X2[i]; 
    gdy.push_back(Ys[i]);
    gdx.push_back(X1[i]);
    gdx.push_back(X2[i]);
  }
  sort(gdx.begin(),gdx.end());
  sort(gdy.begin(),gdy.end());
  
  gdx.erase(unique(gdx.begin(),gdx.end()),gdx.end());
  gdy.erase(unique(gdy.begin(),gdy.end()),gdy.end());
  
  vector<vector<int>> vline( gdy.size(),vector<int>(gdx.size(),0 ) );
  vector<vector<int>> sline( gdy.size(),vector<int>(gdx.size(),0 ) );
  
  for(int i=0;i<N;i++){
    int x0 = findp(gdx, Xv[i]);
    int y1 = findp(gdy, Y1[i]);
    int y2 = findp(gdy, Y2[i]);
    vline[y1][x0]++;
    vline[y2][x0]--;
  }
   
               
  for(int i=0;i<M;i++){
    int x1 = findp(gdx, X1[i]);
    int x2 = findp(gdx, X2[i]);
    int y0 = findp(gdy, Ys[i]);
    sline[y0][x1]++;
    sline[y0][x2]--;
  }
  
  int vy=gdy.size();
  int sx=gdx.size();
  ufind uf(gdx.size()*gdy.size());
 
  for(int y=0;y<gdy.size();y++){
    for(int x=0;x<gdx.size();x++){
      if(x)sline[y][x]+=sline[y][x-1];
      if(y)vline[y][x]+=vline[y-1][x];
      if(x&&!vline[y][x])uf.stick(y*sx+x,y*sx+x-1);
      if(y&&!sline[y][x])uf.stick(y*sx+x,(y-1)*sx+x);
    }
  }
  
  int rex,rey;
  for(int i=0;i<sx;i++){
   if(gdx.at(i)<=0){
     rex=i;
   }else{
     break;
   }
  }
  
  for(int i=0;i<vy;i++){
   if(gdy.at(i)<=0){
     rey=i;
   }else{
     break;
   }
  }
  
  int current = rey*sx+rex;
  if(uf.find2(current,0)){
   cout << "INF" << endl; 
    return 0;
  }
  
  long long area=0;
  
  
  for(int i=1;i<vy-1;i++){
    for(int j=1;j<sx-1;j++){
     
     if(uf.find2(current,i*sx+j)){
       long long ax = gdx[j+1]-gdx[j];
       long long ay = gdy[i+1]-gdy[i];
        area+=ax*ay;
     }
    }
  }
  cout << (long long)area << endl;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    double ans = 0;

    rep(i,N)
    {
        double x;
        string tmp;
        cin >> x >> tmp;

        if( tmp == "JPY" ) ans += x;
        else ans += x * 380000.0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String p = scan.next();
        s = s + s;
        if (s.indexOf(p) != -1)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 17288
n = int(input())
li = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        li[i][x-1] = y

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

print(ans)

Measured memory_bytes: 9240
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll a,b,c; cin >> a >> b >> c;
  cout << min(a+b,min(a+c,b+c)) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main(R,C,K,rcv):
  inf=float('inf')
  dp0=[[-inf,-inf,-inf,0] for _ in range(C)]
  # dp0[i][j]:i列目の時点で残りちょうどj個取れる時の最大値
  rcv.sort(key=lambda x:C*R*x[0]+x[1])
  i=0
  nowc=0
  for j in range(R):
    # j+1行目に対する操作
    # 初期化
    for c in range(C):
      dp0[c][3]=max(dp0[c])
      dp0[c][2]=-inf
      dp0[c][1]=-inf
      dp0[c][0]=-inf
    nowc=0
    while i<K and rcv[i][0]==j+1:
      nextc=rcv[i][1]-1
      for k in range(nowc+1,nextc+1):
        dp0[k][0]=max(dp0[k][0],dp0[nowc][0])
        dp0[k][1]=max(dp0[k][1],dp0[nowc][1])
        dp0[k][2]=max(dp0[k][2],dp0[nowc][2])
      v=rcv[i][2]
      dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
      dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
      dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
      i+=1
      nowc=nextc
    for k in range(nowc+1,C):
      dp0[k][0]=max(dp0[k][0],dp0[nowc][0])
      dp0[k][1]=max(dp0[k][1],dp0[nowc][1])
      dp0[k][2]=max(dp0[k][2],dp0[nowc][2])
    #print(dp0)
  print(max(dp0[-1]))
if __name__=='__main__':
  R,C,K=map(int,input().split())
  rcv=[list(map(int,input().split())) for _ in range(K)]
  main(R,C,K,rcv)


Measured memory_bytes: 140172
#include <iostream>
#include <queue>

using namespace std;

int main(void)
{
    unsigned int x, K;
    queue<unsigned int> queue;

    cin >> K;

    for(int i = 1; i <= 9; i++)
        queue.push(i);

    for(int i = 0; i < K - 1; i++)
    {
        x = queue.front();
        queue.pop();
        
        if ((x % 10) != 0)
            queue.push((10 * x) + (x % 10) - 1);

        queue.push((10 * x) + (x % 10));

        if ((x % 10) != 9)
            queue.push((10 * x) + (x % 10) + 1);
    }

    cout << queue.front();

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n;
		Scanner sc = new Scanner(System.in);
		for(n = sc.nextInt();n != 0;n = sc.nextInt()){
			int num = 0;
			for(int i = 5;i <= n;i = i*5){
				num = num + n / i;
			}
			System.out.println(num);
		}
	}

}

Measured memory_bytes: 12000
N = int(input())
def dfs(s): 
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    # s 自体が七五三数なら +1 
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Measured memory_bytes: 55004
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,dp[404][404],a[404],sum[404];
signed main(){
	cin>>n;
	memset(dp,45,sizeof(dp));
	for(int i=1;i<=n;i++)	cin>>a[i],sum[i]=sum[i-1]+a[i],dp[i][i]=0;
	for(int i=1;i<n;i++)	dp[i][i+1]=a[i]+a[i+1];
	for(int len=3;len<=n;len++){
		for(int l=1,r=len;r<=n;l++,r++){
			for(int k=l;k<r;k++){
				dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+sum[r]-sum[l-1]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
    int n,i,ans;
    int d[100000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    qsort(d, n, sizeof(int), compare_int);
    ans = d[n/2] - d[(n/2)-1];
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main()
{
	int a;
	string s,ans;
	getline(cin,s);
	a=s.size();
	cout<<s[0];
	for(int i=2;i<=a;i++)
	{
		if(s[i]>=65&&s[i]<=90&&s[i-1]==' ')
			ans+=s[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256