akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
s = ['.' * (W + 2)]
s = s + ['.' + input() + '.' for _ in range(H)] + s
flg = True
for i in range(1, H + 1, 1):
    for j in range(1, W + 1, 1):
        if s[i][j] == '#' and s[i][j + 1] == '.' and s[i][j - 1] == '.' and s[i + 1][j] == '.' and s[i - 1][j] == '.':
            flg = False
            break
    if not flg:
        break
print("Yes" if flg else "No")

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int x1=0,x2=0,X=0;
    
    scanf("%d %d\n",&x1,&x2);
    
    if(((0<=x1)&&(x1<=100))&&((0<=x2)&&(x2<=100))){
        
        if(x1>x2)
        {
            X=x1-x2;
        }else{
            X=x2-x1;
        }
        printf("%d\n",X);
    }
    
    return 0;
}


Measured memory_bytes: 2080
#include<bits/stdc++.h>
using  namespace std;
#define pb push_back
#define M 1000000007
#define f first
#define s second
typedef long long int ll;

ll dp[3][3003][3003] = {0}, grid[3003][3003];
void solve(){
	ll r, c, k, x, y ,v;
	cin >> r >> c >> k;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			grid[r][c] = 0;
		}
	}
	for(int i = 0; i < k; i++){
		cin >> x >> y >> v;
		grid[x][y] = v;
	}
	for(int i = 0; i <= r; i++){
		for(int j = 0; j <= c; j++){
			for(int k = 0; k < 3; k++){
				if(i == 0 || j == 0){
					dp[k][i][j] = 0;
					continue;
				}
				dp[k][i][j] = dp[k][i][j-1];
				if(k == 0){
					dp[k][i][j] = max(dp[k][i][j], dp[2][i-1][j] + grid[i][j]);
				}
				else{
					dp[k][i][j] = max(max(dp[k-1][i][j-1], dp[2][i-1][j]) + grid[i][j], dp[k][i][j]);
				}
			}
		}
	}

	cout << dp[2][r][c] << endl;
}		

int main(){

	int t;
	// cin >> t;
	t = 1;
	for(int q = 0; q < t; q++){
		solve();
	}

	return 0;
}

Measured memory_bytes: 285068
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;

#define pb push_back
#define mp make_pair

ll dp[3001][3001];


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

    ll t,n,s;
    cin>>n>>s;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    memset(dp,0,sizeof(dp));
    ll ans=0;
    for(ll i=0;i<n;i++){
        memcpy(dp[i+1],dp[i],sizeof(dp[0]));
        dp[i+1][a[i]]=dp[i+1][a[i]]+i+1;
        for(ll j=0;j+a[i]<=s;j++){
                dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%mod;
        }
        ans=(ans+dp[i+1][s])%mod;
    }
    cout<<ans;

    return 0;
}




Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N; cin >> N;
int D = N/100;
int r = N%100;
if(r <= D*5) cout << 1 << endl;
else cout << 0 << endl;

return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x>=r&&x<=W-r)&&(y>=r&&y<=H-r))
		printf("Yes\n");
	else {
		printf("No\n");
		
	}
}



Measured memory_bytes: 2704
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  int i, j;
  int ans, judge;
  judge = -1;

  cin >> ans;

  for (i = 1; i < 10; i++){
    for (j = 1; j < 10; j++){
      if (i * j == ans){
        judge = 1;
        break;
      }
    }
  }

  if (judge == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    readln.chomp.map!(a => a - '0').map!(a => a == 1 ? 9 : a == 9 ? 1 : a).each!write;
    writeln;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;


int main(void) {
  int A, B; cin >> A >> B;
  if (A <= 5) {
    cout << 0 << endl;
  } else if (A <= 12) {
    cout << (B / 2) << endl;
  } else {
    cout << B << endl;
  }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#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>

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);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 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;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b;
	while(!cin.eof() && cin >> a >> b){
		if(b > a){
			int temp = b;
			b = a;
			a = temp;
		}
		while(b > 0){
			int z  = a % b;
			a = b;
			b = z;
		}
		cout << a << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll modfact[100001];

ll modpow(ll a, ll n){
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

ll nCr(ll n, ll r){
	return ((modfact[n]*modinv(modfact[n-r]))%MOD*modinv(modfact[r]))%MOD;
}

int main(){
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	ll modmax = 0, modmin = 0;

	modfact[0] = 1;
	for (int i = 1; i <= 100000; i++){
		modfact[i] = i*modfact[i-1];
		modfact[i] %= MOD;
	}

	for (int i = k-1; i < n; i++){
		modmax += (nCr(i, k-1)*a[i])%MOD;
	}

	for (int i = 0; i < n-k+1; i++){
		modmin += (nCr(n-i-1, k-1)*a[i])%MOD;
	}

	ll ans = (modmax - modmin)%MOD;
	if (ans < 0) cout << ans + MOD << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
     
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		if (N/100==N%10) {
    			System.out.println("Yes");
    		} else {
    			System.out.println("No");
    		}
     
    	}
    }

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

struct card{
    char suit;
    int value;
};

void selection(struct card a[], int n){
    for (int i=0; i<n; i++){
        int minj=i;
        for (int j=i; j<n; j++){
            if (a[j].value <a[minj].value){
                minj=j;
            }
        }
        swap(a[i],a[minj]);
    }
}

void bubble(struct card a[],int n){
    for (int i=1;i<n; i++){
        for (int j=n-1; j>=i; j--){
            if (a[j].value <a[j-1].value){
                swap(a[j],a[j-1]);
            }
        }
    }
}

void print (struct card a[], int n){
    for (int i=0; i<n-1; i++){
        cout <<a[i].suit <<a[i].value <<" " ;
    }
    cout << a[n-1].suit <<a[n-1].value<<endl;
}

bool isStable(struct card c1[], struct card c2[], int n){
    for (int i=0; i<n; i++){
        if (c1[i].suit != c2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >>n;
    struct card c1[n],c2[n];
    for (int i=0; i<n; i++){
        cin >> c1[i].suit >> c1[i].value ;
    }
    for (int i=0; i<n; i++){
        c2[i]=c1[i];
        
    }
    bubble(c1,n);
    print(c1,n);
    cout << "Stable" <<endl;

    selection(c2,n);
    print(c2,n);
    if (isStable(c1,c2,n)){
        cout <<"Stable" <<endl;
    }
    else {
        cout << "Not stable" <<endl;
    }
}


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

int main(void){
    char S[101];
    scanf("%s",S);
    int i;
    
    for(i=0;i<strlen(S);i++){
        if(i%2==0){
            if(S[i]=='L') break;
        }else{
            if(S[i]=='R') break;
        }
    }
    
    if(i!=strlen(S))printf("No\n");
    else printf("Yes\n");
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;  cin>>n;  double ans;
  double a[n];
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  ans=a[0];
  rep1(i,n){
    ans+=a[i];
    ans/=2;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int n;
    double v, y1, y2, t;

    while(scanf("%lf", &v) != EOF){
        t = v / 9.8;
        y1 = 4.9 * t * t;
        y2 = 0;
        n = 0;

        while(y2 < y1){
            n++;
            y2 = 5 * n - 5;
        }
        printf("%d\n", n);
    }
    return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
bool st[N];
int a[N][N];

int main()
{
    int n,k; cin >> n >> k;
    for(int i = 1; i <= n; i ++) st[i] = true;
    int cnt = 0,res = 0;
    while(k --)
    {
        int x;
        cin >> x;
        ++ cnt;
        for(int i = 1; i <= x; i ++)
        {
            cin >> a[cnt][i];
            if(st[a[cnt][i]])
            {
                st[a[cnt][i]] = false;
                res ++;
            }
        }
    }
    cout << n - res << endl;
}

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >    

using namespace std;   


        
int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	double t,d,s;
	cin>>d>>t>>s;
  	
  	
  	if(s*t >= d)
      cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
	
	return 0;
}

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

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int INF = 1000000000;
const int N_MAX = 40;
const int S_MAX = 1 << (N_MAX / 2);

typedef pair<int, int> P;

int N, Ma, Mb;
int a[N_MAX];
int b[N_MAX];
int c[N_MAX];

P ps[S_MAX];

void solve() {
  int n1 = N / 2;
  int S = 1 << n1;
  REP(i, S) {
    int at = 0, bt = 0, ct = 0;
    REP(j, n1) if (i >> j & 1) {
      at += a[j];
      bt += b[j];
      ct += c[j];
    }
    ps[i] = P(bt * Ma - at * Mb, ct);
  }
  sort(ps, ps + S);

  int ans = INF;
  int m = 1;
  // printf("ps[%d]: %d, %d\n", 0, ps[0].first, ps[0].second);
  FOR(i, 1, S - 1) {
    if (ps[i].first > ps[m - 1].first) {
      // printf("ps[%d]: %d, %d\n", m, ps[i].first, ps[i].second);
      ps[m++] = ps[i];
    } else if (ps[i].first == 0) {
      ans = min(ans, ps[i].second);
    }
  }

  int n2 = N - n1;
  REP(i, 1 << n2) {
    int at = 0, bt = 0, ct = 0;
    REP(j, n2) if (i >> j & 1) {
      at += a[n1 + j];
      bt += b[n1 + j];
      ct += c[n1 + j];
    }
    P p2 = P(at * Mb - bt * Ma, 0);
    P *p1 = lower_bound(ps, ps + m, p2);
    // printf("p2[%d]: %d, %d\n", i, p2.first, ct);
    // printf("p1[%d]: %d, %d\n", (int) (p1 - ps), p1->first, p1->second);
    if (p1 == ps + m || p1->first != p2.first) continue;
    if (p1->second + ct == 0) continue;
    ans = min(ans, p1->second + ct);
  }
  if (ans == INF) {
    puts("-1");
    return;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d%d", &N, &Ma, &Mb);
  REP(i, N) scanf("%d%d%d", a + i, b + i, c + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 8448
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

vector <int> adj[200005];
bool vis[200005];
int cnt;
void dfs(int node) 
{
    vis[node] = true;
    cnt++;
    for(int i = 0;i < adj[node].size();++i)    
    {
         if(!vis[adj[node][i]])
        dfs(adj[node][i]);
    }
}


void solve()
  {
	int n,m;
	cin>>n>>m;
	memset(vis,false,sizeof vis);
	rep(i,m)
	{
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int maxm=0;
	repA(i,1,n)
	{
		cnt=0;
		if(!vis[i])
		dfs(i);
		maxm=max(maxm,cnt);
	}
	cout<<maxm;

  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}
	


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

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		Set<Character> set = new HashSet<>();
		for (int i = 0;i < k;i++) {
			set.add(sc.next().charAt(0));
		}
		for (int i = n;i < 100000;i++) {
			String s = String.valueOf(i);
			boolean b = true;
			for (int j = 0;j < s.length();j++) {
				if (set.contains(s.charAt(j))) b = false;
			}
			if (b) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c;
    cin>>n;
    vector<ll>vc;
    vector<ll>vc1;
    for(i=0;i<n;i++)
    {
        cin>>k;
        vc.push_back(k);
    }
    k=1;
    c=0;
    for(i=0;i<n;i++)
    {
        if(vc[i]==k)
        {
            vc1.push_back(vc[i]);
            k++;
        }
        else
        {
            c++;
        }
    }
    if(!vc1.empty())
    {
        cout<<c<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
return 0;
}


Measured memory_bytes: 4848
#include<stdio.h>
#include<string.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a != 1 &&b != 1){
        printf("1");
    }else if(a != 2 && b!= 2){
        printf("2");
    }else{
        printf("3");
    }
    return 0;
}

Measured memory_bytes: 128
function Main (input) {
  let x = input.split(" ");
  
  let number = 1;
  for (let i = 0; i < 5; i++) {
    if (x[i] == 0) {
      number += i;
      console.log(number);
      break;
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> prices(N);
    for (int i = 0; i < N; ++i) {
        cin >> prices[i];
    }
    sort(begin(prices), end(prices));
    int ans = accumulate(prices.begin(), prices.begin() + K, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

#define endl '\n'
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

void solve()
{
    int x;

    cin >> x;

    if(x == 1)
        cout << 0;
    else
        cout << 1;


}

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

//    int t; cin >> t; while(t--){
        solve();
//    }
    return 0;
}


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

int main() {
  long count =0;
  int N;
  cin>>N;
  string S,T;
  cin>>S>>T;
  rep(i,N){
    cout<<S[i];
    cout<<T[i];
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int K, S;
	int X;
	int answer = 0;
	if (scanf("%d%d", &K, &S) != 2) return 1;
	for (X = 0; X <= K && X <= S; X++) {
		int left = S - X;
		int Ymin = left - K;
		int Ymax = left;
		if (Ymin < 0) Ymin = 0;
		if (Ymax > K) Ymax = K;
		if (Ymin <= Ymax) answer += Ymax - Ymin + 1;
	}
	printf("%d\n", answer);
	return 0;
}


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

int main() {
    string s; cin >> s;

    int count = 0;
    int _max = 0;

    for (char i : s) {
        if(i == 'A' || i == 'T' || i == 'C' || i == 'G') {
            count++;
        }
        else{
            if(count > _max) {
                _max = count;
            }
            count = 0;
        }
    }
    print(max(_max,count));
}

Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int n, a[200005], x;

int main(){
	cin >>n;
	rep(i, n) {cin >> a[i]; x^=a[i];}
	rep(i, n) cout << (x^a[i]) << ' ';
	cout<<endl;
}

Measured memory_bytes: 4232
using System;
using System.Collections.Generic;

namespace AtCoder_CSharp
{
    class AtCoder
    {
        static void Main(string[] args)
        {
            int X, A;

            string[] input = Console.ReadLine().Split(' ');

            X = int.Parse(input[0]);
            A = int.Parse(input[1]);

            if (X < A)
            {
                Console.WriteLine(0);
                return;
            }
            Console.WriteLine(10);
        }
    }
}


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

using namespace std;

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)

const int INF = 0x3f3f3f3f;

long long read();
string s;

int main() {
	cin >> s;
	for (int i = 1; i < s.size(); ++i) {
		if (s.at(i) == s.at(i - 1)) {
			puts("Bad");
			return 0;
		}
	}
	puts("Good");
  return 0;
}

long long read() {
  long long a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveStringArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0].Select(x=>int.Parse(x.ToString())).ToArray();
			var K = retreiveLongArray()[0];


			long ans = 0;
			//N桁目が0の場合の数
			ans += combination(N.Length - 1, K) * (long)Math.Pow(9, K);


			//N桁目が1以上nより小さいとき
			ans += combination(N.Length - 1, K-1) * (long)Math.Pow(9, K-1)*(N[0]-1);

			//N桁目がnのとき
			if (K==1) {//K=1ならn000000を足しておしまい
				ans += 1;
				Console.WriteLine(ans);
				return;
			}

			var k = K - 1;
			var i = 1;
			while (i < N.Length) {
				if (N[i]==0) {
					i++;
		
					continue;
				}
				var n = N[i];
				//N-i桁目が0の場合
				ans += combination(N.Length - (i+1), k) * (long)Math.Pow(9, k);
				//N-i桁目が1以上(n-i)(その桁の数値)より小さいとき
				ans += combination(N.Length - (i + 1), k - 1) * (long)Math.Pow(9, k - 1) * (n - 1);
				if (k==1) {
					ans += 1;
					Console.WriteLine(ans);
					return;
				}
				k--;
				i++;
	
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// nこからrこを選ぶ組み合わせの数
		/// </summary>
		/// <param name="n"></param>
		/// <param name="r"></param>
		/// <returns></returns>
		private static long combination(long n, long r) {

			long bunshi = 1;
			for (int i = 1; i <= r; i++) {
				bunshi = bunshi * (n - r + i);
			}

			long bunbo = 1;
			for (int i = 1; i <= r; i++) {
				bunbo = bunbo * (i);
			}
			//逆元を使って、組み合わせの数を求める	
			return bunshi / bunbo;

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 28452
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static int tc=1;
    static String[] s;
    
    public static long[] ila(String[] s){
        long[] array=new long[s.length];
        for(int i=0;i<array.length;i++){
            array[i]=Long.parseLong(s[i]);
        }
        return array;
    }
    public static void main(String[] args)throws IOException {
        //tc=Integer.parseInt(br.readLine());
        while(tc-->0){
            s=br.readLine().split(" ");
            int x=Integer.parseInt(s[0]);
            int y=Integer.parseInt(s[1]);
            int money=0;
            if(x==1){
                money+=300000;
            }else if(x==2){
                money+=200000;
            }else if(x==3){
                money+=100000;
            }
            if(y==1){
                money+=300000;
            }else if(y==2){
                money+=200000;
            }else if(y==3){
                money+=100000;
            }
            if(x==1 && y==1)
                money+=400000;
            System.out.println(money);
            
        }
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
#include<math.h>
#include<pthread.h>
#include<omp.h>
#define mall (node*)malloc(sizeof(node))
using namespace std;
typedef long long ll;
ll n,a[400005],k;
ll tree[1600005]={0};
void chan(ll k,ll l,ll r,ll p,ll x)
{
	if(l==p&&p==r)
	{
		tree[k]=x;
		return;
	}
	if(l<=p&&p<=r) 
	{
		ll m=(l+r)/2;
		chan(k*2+1,l,m,p,x);
		chan(k*2+2,m+1,r,p,x);
		tree[k]=max(tree[k*2+1],tree[k*2+2]);
	}
}
ll cal(ll k,ll l,ll r,ll l1,ll r1)
{
	if(l1<=l&&r<=r1) return tree[k];
	else if(l1<=r&&l<=r1)
	{
		ll m=(l+r)/2;
		return max(cal(k*2+1,l,m,l1,r1),cal(k*2+2,m+1,r,l1,r1));
	}
	else return 0;
}
int main(void)
{
	scanf("%lld%lld",&n,&k);
	ll N=300000;
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	chan(0,0,N,a[1],1);
	for(ll i=2;i<=n;i++)
	{
		ll mag=cal(0,0,N,max(a[i]-k,0ll),min(a[i]+k,N));
		chan(0,0,N,a[i],mag+1);
	}
	printf("%lld\n",cal(0,0,N,0,N));
}

Measured memory_bytes: 14364
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
    }
    if (a * b) % 2 == 1 {
        println!("Yes")
    } else {
        println!("No")
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <utility>

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstdint>

using namespace std;

typedef long long ll;

inline int sm(unsigned int a) {
	int ret = 0;
	for(int i = 0;i < 10;i++)
		if((a>>i)&1) ret += i;
	return ret;
}

inline int cnt(unsigned int a) {
	int ret = 0;
	for(int i = 0;i < 10;i++)
		if((a>>i)&1) ret += 1;
	return ret;
}

int main(int argc,char** argv) {
	int n,s;
	cin >> n >> s;
	while(n | s) {
		unsigned int r = 1<<10;
		int c = 0;
		for(unsigned int i = 0;i < r;i++)
			if(sm(i) == s && cnt(i) == n) c++;
		cout << c << endl;
		cin >> n >> s;
	}
}



Measured memory_bytes: 3004
import Control.Monad
import Data.List
main :: IO ()
main = do
	n <- readLn
	xs <- replicateM n getLine
	let flag = (shiritori xs) && (null . filter (/= 1) . map length . group . sort $ xs)
	putStrLn $ if flag then "Yes" else "No"

shiritori :: [String] -> Bool
shiritori [x] = True
shiritori (x:xs) = (last x == (head $ head xs)) && (shiritori xs)


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

typedef long long int lli;

#define F(i,n) for(int i=0;i<n;i++)
#define FR(i,n) for(int i=n-1;i>=0;i--)
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vpii vector<pii>
#define vpll vector<pll>
#define vi vector<int>
#define pb push_back
#define all(c) c.begin(),c.end()
#define FL(i,a,b,p) for(int i=a;i<=b;i+=p)
#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

void solve(){
	map<int,int>mp;
	FL(i,1,100,1){
		FL(j,1,100,1){
			FL(k,1,100,1){
				int num=i*j+j*k+k*i+i*i+j*j+k*k;
				mp[num]++;
			}
		}
	}
	int n;
	cin>>n;
	FL(i,1,n,1){
		cout<<mp[i]<<endl;
	}
	return ;
}
int main()
{
	FastIO;
	solve();
	return 0;
}

Measured memory_bytes: 5448
def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    Q4 = 4*Q
    H2 = 2*H
    D12 = D/2
    M = min(Q4, H2, S)
    if D12 < M:
        ans = (N//2)*D + (N%2)*M
    else:
        ans = N*M
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par, rank;

    UnionFind(int n) {
        par.resize(n), rank.resize(n, 0);
        for(int i = 0; i < n; i++) par[i] = i; 
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vint p(n);
    rep(i, n) {
        cin >> p[i];
        --p[i];
    }
    UnionFind uf(n);
    int x, y;
    rep(i, m) {
       cin >> x >> y;
       uf.unite(--x, --y);
    }
    int ans = 0;
    rep(i, n) {
        if (i == p[i] || uf.same(i, p[i])) ans++;
    }

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

Measured memory_bytes: 1408
#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 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);

    int N;
    cin >> N;
    vector<int> v(N);
    LL a = 0, b = 0;
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        b += v[i];
    }

    LL res = LINF;
    for(int i = 0; i < N - 1; ++i) {
        b -= v[i];
        a += v[i];
        res = min(res, llabs(b - a));
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define LL long long
using namespace std;
int a[500010];
int main()
{
    int n;
    cin >> n;
    int b[5]= {0};
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        a[i]=a[i]%4;
        b[a[i]]++;
    }
    if(b[2]>=1)b[2]=1;
    if(b[0]+1>=b[1]+b[2]+b[3])
        cout << "Yes" << endl;
    else
        cout << "No"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	char c;
	cin >> c;
	if(isupper(c)) cout << 'A';
	else cout << 'a';	
	
}





Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
	long N, M;
	cin >> N >> M;
	long long counter=0;
	vector<pair<long, long>> penis(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> penis.at(i).first >> penis.at(i).second;
	}
	sort(penis.begin(), penis.end());
	for (size_t i = 0; i < N; i++)
	{
		if (M>penis.at(i).second)
		{
			counter += penis.at(i).first*penis.at(i).second;
			M -= penis.at(i).second;
		}
		else
		{
			counter += penis.at(i).first * M;
			break;
		}
	}
	cout << counter;
}

Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <fstream>
#include <complex>
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 pair<long, long> PLL;
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(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

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

const double EPS = 1e-12;
const double INF = 1e12;

LL sum[100001];
int main(){
	
	long n,m;
	cin>>n>>m;
	sum[0]=0;
	REP(i,n-1){
		long d;
		cin>>d;
		sum[i+1]=sum[i]+d;
	}
	int pos=0;
	long res=0;
	REP(i,m){
		int a;
		cin>>a;
		res+=abs(sum[pos+a]-sum[pos]);
		pos+=a;
		res%=100000;
	}
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 1940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int INF = 1e9 + 7;

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

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

	if (a <= b) {
		cout << a << endl;
	}
	else {
		cout << a - 1 << endl;
	}

}

Measured memory_bytes: 256
process.stdin.resume();
var x = '';
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (input) {
    x += input;
});

process.stdin.on('end', function () {
    var xArray = x.split('\n');
    var output = [];
    for(var i = 0; i < xArray.length; i++) {
        if(0 != xArray[i]) {
            output.push('Case ' + (i + 1) + ': ' + xArray[i]);
        }
    }
    console.log(output.join('\n'));
});

Measured memory_bytes: 19492
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int i, n, x[100], y[100];
int distance(int k);int distance_infinit(void);

int main(void){
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d", &y[i]);
    }
    distance(1);
    distance(2);
    distance(3);
    distance_infinit();
    return 0;
}

int distance(int k){
    double sum = 0;
    for (i = 0; i < n; i++){
        sum += pow(fabs(x[i] - y[i]), k);
    }
    printf("%f\n", pow(sum, 1.0/k));
    return 0;
}

int distance_infinit(void){
    double max = 0;
    for (i = 0; i < n; i++){
        if (fabs(x[i] - y[i]) > max) max = fabs(x[i] - y[i]);
    }
    printf("%f\n", max);
    return 0;
}

Measured memory_bytes: 3380
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;

int n;

int quick_power(int x,int y)
{
	int res=1;
	for (;y;y=y>>1,x=(x*x)%mod)
	{
		if (y&1)  res=(res*x)%mod;
	}
	return res;
}

signed main()
{
	cin>>n;
	int ans=quick_power(10,n);
	ans=((ans-2*quick_power(9,n))%mod+mod)%mod;
	ans=(ans+quick_power(8,n))%mod;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

string cov2num(int _num) {
	string s = "+++";
	REP(i, 3) {
		if (_num % 2 == 0) {
			s[i] = '-';
		}
		_num /= 2;
	}
	return s;
}

int main() {
	string sn;
	cin >> sn;
	int num[4];
	REP(i, 4) {
		num[i] = sn[i] - '0';
	}
	string op;
	REP(i, 8) {
		op = cov2num(i);
		int ans = num[0];
		REP(i, 3) {
			if (op[i] == '+') {
				ans += num[i + 1];
			}
			else ans -= num[i + 1];
		}
		if (ans == 7) {
			cout << num[0];
			REP(i, 3) cout << op[i] << num[i + 1];
			cout << "=7";
			break;
		}
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
def dfs(N, M, Bulb, P, switches, cur):
  if cur == N:
    for i, b in enumerate(Bulb):
      s = 0
      for x in b[1:]:
        s += switches[x-1]
      if s % 2 != P[i]:
        return 0
    return 1
  else:
    a = 0
    switches[cur] = 0
    a += dfs(N, M, Bulb, P, switches, cur+1)
    switches[cur] = 1
    a += dfs(N, M, Bulb, P, switches, cur+1)
    return a

N, M = map(int, input().split())
Bulb = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
print(dfs(N, M, Bulb, P, [0] * N, 0))



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

int main() {
    int K;
    string S;
    cin>>K>>S;
    if(S.length()<=K){
        cout<<S<<endl;
    }else{
        rep(i,K){
            cout<<S.at(i);
        }
        

            cout<<"..."<<endl;
        

    }

    
}

Measured memory_bytes: 3632
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let h: usize = sc.next();
    let w: usize = sc.next();
    let mut map: Vec<Vec<usize>> = sc.next_mat(w, h);
    let mut ans: Vec<[usize;4]> = Vec::new();
    for i in 0..h {
        for j in 0..w-1 {
            if map[i][j] % 2 == 0 {
                continue;
            }
            ans.push([i+1,j+1,i+1,j+2]);
            map[i][j+1] += 1;
        }
    }
    for i in 0..h-1 {
        if map[i][w-1] % 2 == 0 {
            continue;
        }
        ans.push([i+1,w,i+2,w]);
        map[i+1][w-1] += 1;
    }
    println!("{}",ans.len());
    for x in ans {
        println!("{} {} {} {}", x[0], x[1], x[2], x[3]);
    }
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 13304
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s;
    int ans = INF;
    rep(i,0,26){
        char c = (char)('a' + i);
        t = s;
        int tmp = 0;
        while(1){
            bool f = true;
            rep(i,0,t.length()){
                if(t[i]!=c){f = false;break;}
            }
            if(f){break;}
            rep(i,0,t.length()-1){
                if(t[i]==c||t[i+1]==c){t[i]=c;}
            }
            t.resize(t.length()-1);
            tmp++;
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long 

int main () {
  ll n, h;
  cin >> n >> h;
  pair<ll, ll> ab[n];
  for (ll i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);  
  }  
  sort(ab, ab + n);
  ll max = ab[n - 1].first;
  vector<pair<ll, ll> > ans;
  ans.push_back(make_pair(ab[n - 1].second, ab[n - 1].first));
  for (ll i = 0; i < n - 1; i++) {
    if (ab[i].second > max) {
      ans.push_back(make_pair(ab[i].second, ab[i].first));  
    } 
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  ll ANS = 0;
  ll sum = 0;
  for (ll i = 0; i < ans.size(); i++) {
    sum += ans[i].first;
    if (sum >= h) {
      cout << i + 1 << endl;
      return 0;
    }  
  }
  // 魔力を使うしかない
  h = h - sum;
  ANS = ans.size();
  if (h % max == 0) {
    ANS += h / max;  
  }
  else {
    ANS += h / max + 1;  
  }
  cout << ANS << endl;
}

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

static const int INF = 0x3f3f3f3f;

template<typename Type>
struct SegmentTree {
        vector<Type> data;
        int n;
        SegmentTree(int x) {
                n = pow(2, ceil(log2(x)));
                data.resize(2 * n - 1, INF);
        }
        Type merge(Type x, Type y) { //更新関数
                return min(x, y);
        }
        void update(int k, Type p) { //k番目をpに更新する
                k += n - 1;
                data[k] = p;
                while (k > 0) {
                        k = (k - 1) / 2;
                        data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
                }
        }
        // [l, r)
        Type query(int a, int b) { return query(a, b, 0, 0, n); }
        Type query(int a, int b, int k, int l, int r) {
                if (r <= a || b <= l) return INF; //初期値
                if (a <= l && r <= b) return data[k];
                int m = (l + r) / 2;
                return merge(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
        }
};

int n, k, p[505050];
bool used[505050];
int ans[505050], ord;

void decide(int idx, SegmentTree<int> &st) {
        while (true) {
                int least = st.query(0, p[idx]);
                if (least >= idx + k) break;
                decide(least, st);
        }
        ans[idx] = ord ++;
        used[idx] = true;
        st.update(p[idx], INF);
}

void solve() {
        cin >> n >> k;
        SegmentTree<int> st(n);
        for (int i = 0; i < n; i ++) {
                cin >> p[i];
                p[i] --;
                st.update(p[i], i);
        }
        ord = 0;
        for (int i = 0; i < n; i ++) if (!used[i]) decide(i, st);
        for (int i = 0; i < n; i ++) cout << ans[i] + 1 << endl;
        return;
}

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



Measured memory_bytes: 59008