akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;

void solve2(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll k = n-1;
    ll ans = 0;
    rep(i,n){
        if(a[i]>k){
            ans += a[i]-k;
        }
    }
    
    cout << ans << endl;
}
void solve1(){
    ll k;
    cin >> k;
    int n = 50;
    vector<ll>a(n);
    int c = 0;
    while(k%50)k+=51,c++;
    //show(k);
    ll m = k/50LL+49;
    rep(i,n){
        if(i < c)a[i] = m-i-50-1;
        else a[i] = m;
    }
    cout << n << endl;
    rep(i,n-1){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

bool f[200005],g[200005];
void solve3(){
    int n,m;
    cin >> n >> m;
    int a,b;
    rep(i,m){
        cin >> a >> b;
        if(a==1)f[b] = true;
        if(b==n)g[a] = true;
    }
    rep(i,n){
        if(f[i+1] ==true&& g[i+1] == true){
            cout << "POSSIBLE" << endl;
            exit(0);
        }
    }
    cout << "IMPOSSIBLE" << endl;
}
int main(){
    solve3();
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - (a - b), 0) << ln;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int cntoper(int n, int m)
{
	if(n <= 0) return 0;
	return (n - 1) / m + 1;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	printf("%d\n", cntoper(n - 1, k - 1));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define lli long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// int const mod = 7340033;
int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}
 
int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 1e5+5;
int const inf = 1e18;
vector<pair<int,pii> > v;

void solve(){
    int i,j,l;
    int n,k,s;
    cin>>n>>k>>s;
    for(i=0;i<k;i++) cout<<s<<" ";
    if(s == 1e9) j = 1;
    else j = 1e9;
    for(i=k;i<n;i++) cout<<j<<" "; cout<<endl;
}   

int32_t main(){
    IOS;
    int t;
    t = 1;
    // pre();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

/*

*/

Measured memory_bytes: 1280
#include <stdio.h>
 
int main()
{
    int floor[4][3][10]={0};
    int i, j, k, n, b, f, r, v;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        floor[b-1][f-1][r-1]+=v;
    }
 
    for(i=0; i<4; i++) {
        if(i) puts("####################");
        for(j=0; j<3; j++) {
            for(k=0; k<10; k++) {
                printf(" %d", floor[i][j][k]);
            }
            putchar('\n');
        }
    }
 
    return 0;
}
 

Measured memory_bytes: 612
#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 argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0){
        x=-x;
    }
    if(x/d>k){
        cout<<x-k*d<<endl;
    }
    else{
        k=k-x/d;
        if(k%2==0)cout<<x%d<<endl;
        else cout<<d-x%d<<endl;
    }



    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll  long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define f(i,n)   for(int i=0;i<n;i++)

using namespace std;
/************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/


int main()
{
	int n;

	cin>>n;


	int dp[n][3],a[n],b[n],c[n];
	f(i,n)
	{
         cin>>a[i]>>b[i]>>c[i];
    

	}
 dp[0][0]=a[0];
 dp[0][1]=b[0];
 dp[0][2]=c[0];
 for(int i=1;i<n;i++)
 {
       dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
         dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];




 }

  cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);

}

Measured memory_bytes: 2688
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
int main(){

    int s;
    cin >> s;
    vector<int> alist;
    int count = 1;
    int ax;
    ax = s;
    while(binary_search(alist.begin(),alist.end(),ax)!=true){
        alist.push_back(ax);
        sort(alist.begin(),alist.end());
        count++;
        if(ax%2==0){
            ax = ax / 2;
        }else{
            ax = 3 * ax + 1;
        }
    }
    cout << count;
        

}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int a, b;
    cin >> a >> b;
    (((a + b) % 2 == 0) ? cout << (a + b) / 2 << endl : cout << ((a + b) / 2) + 1 << endl);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    ll n; cin >> n;
    vector<i64> v(n);
    map<int, int> odd, even;
    rep(i, n) {
        if (i % 2 == 0) {
            cin >> v[i];
            even[v[i]]++;
        }
        else {
            cin >> v[i];
            odd[v[i]]++;
        }
    }

    ll ev = 0, ev1 = 0, od = 0, od1 = 0;
    ll e1 = 0, e2 = 0, o1 = 0, o2 = 0;
    ll cnt = 0;
    for (auto itr = odd.begin(); itr != odd.end(); itr++) {
        if (itr->second > cnt) {
            cnt = itr->second;
            od = itr->first;
        }
    }
    o1 = cnt; cnt = 0;
    for (auto itr = odd.begin(); itr != odd.end(); itr++) {
        if (itr->second > cnt && itr->first != od) {
            cnt = itr->second;
            od1 = itr->first;
        }
    }
    o2 = cnt; cnt = 0;

    for (auto itr = even.begin(); itr != even.end(); itr++) {
        if (itr->second > cnt) {
            cnt = itr->second;
            ev = itr->first;
        }
    }
    e1 = cnt; cnt = 0;
    for (auto itr = even.begin(); itr != even.end(); itr++) {
        if (itr->second > cnt && itr->first != ev) {
            cnt = itr->second;
            ev1 = itr->first;
        }
    }
    e2 = cnt;

    if (ev == od) {
        cout << min(n - e1 - o2, n - e2 - o1) << endl;
    }
    else {
        cout << n - e1 - o1 << endl;
    }
}

Measured memory_bytes: 8652
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        p=K-A-B
        for i in range(len(I)):
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            if len(I)>0:
                I.pop(0)
            else:break
        L.append(sum(I))
print(max(L))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

// range-add, range-min query
 
struct LazySegTree{
	int size;
	vector<llint> seg, delay;
	
	LazySegTree(){}
	LazySegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i] = inf;
			delay[i] = inf;
		}
	}
	
	void eval(int l, int r, int k)
	{
		if(delay[k] < inf/2){
			chmin(seg[k], delay[k]);  //総和クエリのときは区間幅を乗じる必要がある
			if(l < r){
				chmin(delay[k*2], delay[k]);
				chmin(delay[k*2+1], delay[k]);
			}
			delay[k] = inf;
		}
	}
	
	void update(int i, llint val)
	{
		int l = 0, r = (1<<size)-1, k = 1;
		eval(l, r, k);
		for(int j = size-1; j >= 0; j--){
			k <<= 1;
			if(i & (1<<j)){
				k++;
				r = (l+r)/2;
			}
			else l = (l+r)/2+1;
			eval(l, r, k);
		}
		
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}
	
	void add(int a, int b, int k, int l, int r, llint val)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			chmin(delay[k], val);
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		seg[k] = min(seg[k*2], seg[k*2+1]);
	}
	void add(int a, int b, llint val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}
 
	llint query(int a, int b, int k, int l, int r)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
LazySegTree wseg(18), hseg(18);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	
	wseg.init(), hseg.init();
	wseg.add(1, n, n), hseg.add(1, n, n);
	
	//for(int i = 1; i <= n; i++) cout << wseg.query(i, i) << " "; cout << endl;
	
	llint ans = (n-2)*(n-2);
	llint t, x;
	for(int i = 1; i <= Q; i++){
		cin >> t >> x;
		if(t == 1){
			llint res = wseg.query(x, x);
			ans -= res-2;
			hseg.add(1, res-1, x);
		}
		else{
			llint res = hseg.query(x, x);
			ans -= res-2;
			wseg.add(1, res-1, x);
		}
		//for(int i = 1; i <= n; i++) cout << wseg.query(i, i) << " "; cout << endl;
		//for(int i = 1; i <= n; i++) cout << hseg.query(i, i) << " "; cout << endl;
	}
	cout << ans << endl;
	
	return 0;
}

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

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 302;

int used[maxn][maxn][maxn];
double dp[maxn][maxn][maxn];
int n;

void solve(int a, int b, int c) {
    if (a < 0 || b < 0 || c < 0 || a + b + c == 0) return;
    if (used[a][b][c]) return;
    used[a][b][c] = 1;
    solve(a - 1, b, c);
    solve(a + 1 , b - 1, c);
    solve(a, b + 1, c - 1);
    dp[a][b][c] = n * 1.0 / (double) (a + b + c) * 1.0;
    dp[a][b][c] += (a - 1 >= 0 ? dp[a - 1][b][c] * (double) a * 1.0 / (a + b + c)  : 0);
    dp[a][b][c] += (b - 1 >= 0 ? dp[a + 1][b - 1][c] * (double) b * 1.0 / (a + b + c)  : 0);
    dp[a][b][c] += (c - 1 >= 0 ? dp[a][b + 1][c - 1] * (double) c * 1.0 / (a + b + c)  : 0);
}

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

    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x]++;
    }
    solve(mp[1], mp[2], mp[3]);
    cout << fixed << setprecision(10) << dp[mp[1]][mp[2]][mp[3]] << "\n";
    return 0;
}

Measured memory_bytes: 430464
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;

int main()
{
	string a,b;	cin >> a; cin >> b;	a += a;
	if (a.find(b)!=string::npos) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007

int main(){
    double l;
    cin>>l;
    l/=3;
    l=pow(l,3);
    cout<<fixed<<setprecision(10)<<l<<endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

void bubble_myself(int x[],int y);

int main()
{
  int a,i;
  int in[100];

  scanf("%d",&a);
  if(1<=a&&a<=100){
    for(i=0;i<a;i++){
      scanf("%d",&in[i]);
    }
    bubble_myself(in,a);
  }

  return 0;
}

void bubble_myself(int x[],int y){
  int i,j,z;
  int count=0;
  
  for(i=0;i<y-1;i++){
    for(j=y-1;j>i;j--){
      if(x[j-1]>x[j]){
	z=x[j];
	x[j]=x[j-1];
	x[j-1]=z;
	count++;
      }
    }
  }
  for(j=0;j<y;j++){
    if(j>0) printf(" ");
    printf("%d",x[j]);
  }
   printf("\n%d\n",count);
}



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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);i++)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  map<int, bool> b;
  int count = 0;
  
  FOR(i, 1, n) {
    if(a[i] == a[i-1] && b[i-1] == false) {
      count++;
      b[i] = true;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
// file creato da gio il 2020-06-24 19:30:16.615571

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define MOD 1000000007
#define S second
#define F first
#define PB push_back
using namespace std;

#define MAXN 200000

int ci[MAXN];

int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

	int n;
	cin >> n;
    int cxor=0;
    for(int i=0;i<n;i++){
        cin >>ci[i];
        cxor^=ci[i];
    } 
    for(int i=0;i<n;i++)cout <<(cxor^ci[i])<<" ";


}


Measured memory_bytes: 4396
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
struct NODE{
        int cost,x,y,l,r,o;
        NODE(int C,int a,int b,int c,int d,int e){cost = C,x=a,y=b,l=c,r=d,o=e;}
};
bool operator<(const NODE& a,const NODE& b){
        return a.cost > b.cost;
}
 
// «ÝpÏO,CÆA_fîñ,}XÌf[^,_f§À(=m)ðwè·éÆAY¦Ég¤_fÆÁZ·éRXgð»ê¼êãüµÄ­êéB
int get(int &O,int &C,int s,int d,int lim){
        if(d<0){
                O = s;
                C = -d;
        }else{
                O = min(lim,s + d);
                C = 0;
        }
}
 
int solve(int W,int H,int m,int o,vector<vector<int> >data){
		if(o < 2)return INF;
        int O,C;
        bool done[10][10][10][10][51] = {0}; // [x][y][l][r][o]
        priority_queue<NODE> Q;
        rep(i,W){
                get(O,C,o-1,data[0][i],m);
                Q.push(NODE(C,i,0,i,i,O));
        }
        while(Q.size()){
                NODE q = Q.top(); Q.pop();
                if(q.o == 0) continue;
                
                if(q.y == H-1) return q.cost;
                
                if(done[q.x][q.y][q.l][q.r][q.o])continue;
                else done[q.x][q.y][q.l][q.r][q.o] = true;
                
                // cè_fª1ÈçÎÚ®Å«È¢ÌÅcontinue
                if(q.o == 1) continue;
                
                //¡Ú®
                static const int dx[] = {-1,1};
                rep(i,2){
                        int tx = q.x+dx[i];
                        int l = min(q.l,tx) , r = max(q.r,tx);
                        if(tx < 0 || tx >= W) continue;
                        
                        if(l == q.l && r == q.r) C = 0 , O = q.o-1 ;
                        else get(O,C,q.o-1,data[q.y][tx],m);
                        
                        Q.push(NODE(q.cost+C,tx,q.y,l,r,O));
                }
                
                //cÚ®
                if(q.y < H-1){
                        get(O,C,q.o-1,data[q.y+1][q.x],m);
                        Q.push(NODE(q.cost+C,q.x,q.y+1,q.x,q.x,O));
                }
        }
        return INF;
}
int main(){
        int W,H,f,m,o;
        while(cin >> W >> H , W){
                cin >> f >> m >> o;
                vector< vector<int> > data(H,vector<int>(W));
                rep(i,H)rep(j,W)cin >> data[i][j];
                int ans = solve(W,H,m,o,data);
                if(ans <= f) cout << ans << endl;
                else cout << "NA" << endl;
        }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define N 50
int graph[N+1][N+1];//隣接行列
int visited[N+1];
void dfs(int);
int n,m;
int main(){
    cin>>n>>m;
    int a[m],b[m];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
    }
    /*for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cout<<graph[i][j];
        }cout<<endl;
    }*/
    int cnt=0;
    
    for(int i=0;i<m;i++){//辺iを取り除いてdfsして連結でないならbridge
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=0;
        for(int j=1;j<=n;j++){
            visited[j]=0;//初期化
        }
        dfs(1);
        int bridge=0;//初期化
        //１こでもvisitしてない葉があれば橋
        for(int j=1;j<=n;j++){
            if(!visited[j])bridge=1;
        }
        if(bridge)cnt++;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
    }
    cout<<cnt<<endl;
}

void dfs(int u){//visitするだけ
    visited[u]=1;
    //printf("u=%d\n",u);
    for(int v=1;v<=n;v++){
        if(graph[u][v]==0)continue;
        if(visited[v])continue;
        dfs(v);
    }
}

Measured memory_bytes: 256
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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


signed main() {
int n;cin >>n;
set<string> s;
rep(i,n){
    string str;cin >>str;
    s.insert(str);
}
cout <<s.size()<<endl;
}

















Measured memory_bytes: 19224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int count = 0, p = 0;
		String s;
		char s1[], tmp;
		boolean e = true;
		
		s = sc.nextLine();
		sc.close();
		tmp = s.charAt(0);
		s1 = new char[s.length()];
		
		for(int i = 0; i < s.length(); ++i) {
			s1[i] = s.charAt(i);
			if(tmp != s1[i])e = false;
		}
		
		if(e)System.out.println(count);
		else {
			while(!e) {
				e = true;
				if(tmp == 'W')tmp = 'B';
				else tmp = 'W';
				
				for(int i = p; i < s.length(); ++i) {
					if(s1[i]!= tmp)s1[i] = tmp;
					else { 
						p = i;
						break;
					}
				}
				for(int i = p; i < s.length(); ++i) {
					if(s1[i] != tmp) {
						e = false;
						break;
					}
				}
				++count;
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 26904
#include <bits/stdc++.h>
using namespace std;
int vis[200000];
string s;
int main()
{

	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
		vis[i]=0;
	for(int i=0;i<n-1;i++)
	{
		if(s[i]=='R' && s[i+1]=='L')
		{
			
			vis[i]++;
			vis[i+1]++;
			int j=i,isodd=1;
			while(1)
			{
				j--;
				if(s[j]=='R')
					vis[i+isodd]++;
				else
					break;
				isodd=1-isodd;
			}
			j=i+1; isodd=0;
			while(1)
			{
				j++;
				if(s[j]=='L')
					vis[i+isodd]++;
				else
					break;
				isodd=1-isodd;
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<vis[i]<<" ";
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter


n = int(input())
v = list(map(int, input().split()))

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""一番多く出現する2つの数字を探す"""
max_hit = 0
for odd_val, odd_hit in Counter(v[1::2]).most_common(2):
    for even_val, even_hit in Counter(v[::2]).most_common(2):
        if odd_val == even_val:
            continue  # 奇数と偶数は同じ数字じゃだめ
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)
exit()


Measured memory_bytes: 16228
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/
//グローバル変数宣言
 ll p=0,q=0,r=0;

int main(){
   ll n;
   cin>>n;
   vl P(n),Q(n),a(n);
   rep(i,n)cin>>P[i];
   rep(i,n)cin>>Q[i];
   rep(i,n)a[i]=i+1;

      do {
   r++;
   if (a==P)
   {
      p=r;
   }
   if (a==Q)
   {
      q=r;
   }
   
   
} while (next_permutation(a.begin(), a.end()));

   
   
   if(p>q){print(p-q)}else print(q-p);
}

Measured memory_bytes: 3608
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ans = 0
n.times do |i|
  if b[i] <= a[i]
    ans += b[i]
    a[i] -= b[i]
  else
    c = [a[i] + a[i+1], b[i]].min
    ans += c
    a[i+1] -= c - a[i]
    a[i] = 0
  end
end
puts ans


Measured memory_bytes: 24772
import sys
from copy import deepcopy

def canMake(k, Nums):#Numsにある数でkを作れるか
    L = len(Nums)
    index = 0
    bit = []
    for i in reversed(range(60)):
        flag = 0
        for j in range(index, L):
            if Nums[j] & (1 << i) == (1 << i):
                flag = 1
                Nums[index], Nums[j] = Nums[j], Nums[index]
                bit.append(i)
                break
        if flag == 1:
            for j in range(L):
                if Nums[j] & (1 << i) == (1 << i) and index != j: Nums[j] ^= Nums[index]
        if flag == 1: index += 1
    ans = 0
    for i in range(60):
        if k & (1 << i) == (1 << i):
            if i in bit: ans ^= Nums[bit.index(i)]
    if ans == k: return True
    else: return False


def solve():
    input = sys.stdin.readline
    T = int(input())
    Ans = [0] * T
    for t in range(T):
        N = int(input())
        A = [int(a) for a in input().split()]
        S = input().strip("\n")
        used = []
        for i in reversed(range(N)):
            if S[i] == "0":
                used.append(A[i])
            else:
                compare = deepcopy(used)
                if not canMake(A[i], compare):
                    Ans[t] = 1
                    break
    
    print(*Ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 71976
# spent 4 hrs for this question why i am noob:(
# group all the consecutive elements and keep a count of each group and type of group whether it's one or zero
# After grouping all the same elements the string would alternate for 0 and 1
# suppose if u are current group of 1 then u need to chose next 2*k group as 0101,010101,01010101 as k is 2, 3, 4 respectively 
# u can flip every consecutive zero's in the above
# suppose if the current group start's with 0 then u need to choose next 2*k-1 groups as 101 , 10101 as k is 2 , 3 respectively
# u can flip every consecutive zero's 
def main():
	n , k = map(int , input().split())
	hd = input()
	grp=[]
	if hd[0]=='1':
		grp = [[0,0]]
	else:
		grp=[[0,0]]
	cnt =1
	for i in range(1, len(hd)):
		if hd[i]==hd[i-1]:
			cnt = cnt+1
		else:
			grp.append([cnt,i])
			cnt = 1
	grp .append([cnt , len(hd)-1])
	pre = [0 for i in range(0 , len(grp)+9)]
	pre[0]=grp[0][0]
	for i in range(1, len(grp)):
		pre[i]=pre[i-1]+grp[i][0]
	ans = 0
	for i in range(0 , len(grp)):
		if hd[grp[i][1]]=='0':
			rgt = min(i+2*k, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		else:
			rgt = min(i+2*k+1, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		if rgt==len(grp)-1:
			break
	print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 88648
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  int a[100000];
  map<int,int> mp;
  
  cin>>n;
  int cnt=0;
  rep(i,n){
    cin>>a[i];
    mp[a[i]]++;
    if(mp[a[i]]!=1) cnt++;
  }
  cout<<n-((cnt+1)/2)*2<<endl;
  

  return 0;
}





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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = a + b + c;
  if (x >= 22)
    cout << "bust";
  else
    cout << "win";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<string>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define mem(a,b) memset(a,b,sizeof(a))
#define random(a,b) (rand()%(b-a+1)+a)
#define ll long long
#define ull unsigned long long
#define e 2.71828182
#define Pi acos(-1.0)
#define ls(rt) (rt<<1)
#define rs(rt) (rt<<1|1)
#define lowbit(x) (x&(-x))
using namespace std;
const int MAXN=1e3+5;
const int MAXM=20;
const int MAX=2e4+5;
const int INF=0x7fffffff;
int a[MAXN],b[MAXN];
int c[MAXM];
struct DLX
{
    int n,m,cnt,g,tmp;
    int U[MAX],D[MAX],R[MAX],L[MAX],row[MAX],col[MAX];
    int H[MAXN],S[MAXM];
    bool v[MAX];
    void init(int _n,int _m)
    {
        n=_n,m=_m,g=INF,tmp=0;
        for(int i=0;i<=m;++i)
        S[i]=0,U[i]=D[i]=i,L[i]=i-1,R[i]=i+1;
        R[m]=0,L[0]=m,cnt=m;
        mem(H,-1);
    }
    void add(int r,int c)
    {
        ++S[col[++cnt]=c];
        row[cnt]=r;
        D[cnt]=D[c],U[D[c]]=cnt;
        U[cnt]=c,D[c]=cnt;
        if(H[r]<0) H[r]=L[cnt]=R[cnt]=cnt;
        else R[cnt]=R[H[r]],L[R[H[r]]]=cnt,L[cnt]=H[r],R[H[r]]=cnt;
    }
    void remove(int c)
    {
        for(int i=D[c];i!=c;i=D[i])
        L[R[i]]=L[i],R[L[i]]=R[i];
    }
    void resume(int c)
    {
        for(int i=U[c];i!=c;i=U[i])
        L[R[i]]=R[L[i]]=i;
    }
    int h()
    {
        int ret=0;
        for(int i=R[0];i!=0;i=R[i]) v[i]=true;
        for(int i=R[0];i!=0;i=R[i])
        {
            if(!v[i]) continue;
            //ret++,v[i]=false;
            v[i]=false;
            int tt=INF;
            for(int j=D[i];j!=i;j=D[j])
            {
            	tt=min(tt,a[row[j]]);
            	for(int k=R[j];k!=j;k=R[k])
            	v[col[k]]=false;
			}
			ret+=tt;
        }    
        return ret;
    } 
    void dance(int d)
    {
        if(tmp+h()>=g) return;
        //if(tmp>=g) return;
        if(R[0]==0)
        {
            if(tmp<g) g=tmp;
            return;
        }
        int c=R[0];
        for(int i=R[0];i!=0;i=R[i])
        if(S[i]<S[c]) c=i;
        for(int i=D[c];i!=c;i=D[i])
        {
            remove(i);
            for(int j=R[i];j!=i;j=R[j]) remove(j);
            tmp+=a[row[i]];//cout<<"a:"<<a[row[i]]<<endl;
			dance(d+1);
            tmp-=a[row[i]];
            for(int j=L[i];j!=i;j=L[j]) resume(j);
            resume(i);
        }
        return ;
    }
}dlx;
int read()
{
	int s=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') s=-1;ch=getchar();}
	while(isdigit(ch)) {x=10*x+ch-'0';ch=getchar();}
	return x*s;
}
int main()
{
	int N=read(),M=read();
	dlx.init(M,N);
	for(int i=1;i<=M;++i)
	{
		a[i]=read(),b[i]=read();
		for(int j=1;j<=b[i];++j)
		{
			c[j]=read();
			dlx.add(i,c[j]);
		}
	}
	dlx.dance(0);
	if(dlx.g==INF) cout<<-1;
	else cout<<dlx.g;
}


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

const int MAX = 200001;
const int MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX], po[MAX];
ll N,M,K,ans;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    po[0] = 1;
    po[1] = M-1;
    REP(int,i,2,MAX){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
        po[i] = po[i-1] * (M-1) % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin >> N >> M >> K;
    COMinit();

    ans=0;
    REP(int,i,0,K+1){
        ans=(ans+COM(N-1,i)*(M*po[N-i-1]%MOD)%MOD)%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9868
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    vector<bool> isprime(100010,true);
    isprime[0]=false;
    isprime[1]=false;
    for(int i=2;i*i<=100000;i++){
        if(isprime[i]){
            for(int j=2;i*j<=100000;j++) isprime[i*j]=false;
        }
    }
    
    int n;
    cin>>n;
    
    int cnt=0;
    rep(i,0,55556){
        if(isprime[i] && i%10==1){
            cout<<i<<endl;
            cnt++;
        }
        if(cnt==n) break;
    }

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
class Main{
    public static void main(String[] str) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		while (line != null) {
			String numArray[] = line.split(" ");
			double a = Double.valueOf(numArray[0]);
			double b = Double.valueOf(numArray[1]);
			double c = Double.valueOf(numArray[2]);
			double d = Double.valueOf(numArray[3]);
			double e = Double.valueOf(numArray[4]);
			double f = Double.valueOf(numArray[5]);
			double x = (b * f - c * e) / (d * b - a * e);
			double y = (c - a * x) / b;
			BigDecimal xBD = new BigDecimal(x);
			BigDecimal yBD = new BigDecimal(y);
			BigDecimal xROUND = xBD.setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal yROUND = yBD.setScale(3, BigDecimal.ROUND_HALF_UP);
			System.out.print(xROUND);
			System.out.print(" ");
			System.out.println(yROUND);
			line = br.readLine();
		}
    }
}

Measured memory_bytes: 24716
#include <iostream>
#include <memory.h>
#include <string>
#include <limits.h>
#include <algorithm>
using namespace std;
const int MAXN = 200000 + 10;
int net[26][MAXN];
int dp[MAXN];

int main() {
//    freopen("test.txt", "r", stdin);
    string s;
    cin >> s;
    int n = s.size();
    memset(net, -1, sizeof(net));
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            net[j][i] = net[j][i+1];
        }
        net[s[i]-'a'][i] = i;
    }
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        dp[i] = INT_MAX;
        for (int j = 0; j < 26; j++) {
            if (net[j][i] == -1) {
                dp[i] = 1;
                break;
            }
            dp[i] = min(dp[i], 1+dp[net[j][i]+1]);
        }
    }
    string ret;
    int cur = 0;
    for (int i = 0; i < dp[0]; i++) {
        for (int j = 0; j < 26; j++) {
            if (net[j][cur] == -1) {
                ret.push_back('a'+j);
                break;
            }
            if (dp[net[j][cur]+1] == dp[0]-i-1) {
                ret.push_back('a'+j);
                cur = net[j][cur]+1;
                break;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    int ans=0;
    for (int i=0 ; i<N ; i++)
        cin >> V.at(i);
    for (int i=1 ; i<N-1 ; i++){
        vector<int> Z={
        {V.at(i-1),V.at(i),V.at(i+1)}
    	};
        sort(Z.begin(),Z.end());
        if(Z.at(1)==V.at(i))
        ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
plist = list(map(int, input().split()))

a = [0 for _ in range(N)]
ans = 0
p = 0

# pを2進数で表示(電球のラベルの番号が大きい方が2進数で左にくるので注意(以下もそうなっている))
for i in range(M):
    x = plist[i]
    p |= x << i


# aにスイッチと電球の繋がりの情報を入れる(1なら繋がっている,0なら繋がっていない)
for i in range(M): # iは電球のラベル
    k = ks[i][0]
    for j in range(1, k+1): # jは繋がりのラベル
        s = ks[i][j] - 1 # sは電球iと繋がっているスイッチ(0からに直しておく)
        a[s] |= 1 << i # 元のa[s]と1<<iのORをとったものを新たにa[s]に代入


for s in range(1 << N): # sはスイッチの全ての状態をとる(0以上1<<N未満。N=3のとき1<<Nは1000=8であり、sは000=0,001,010,...,111=7までとれる。つまり1<<Nを2**Nとかいても同じこと。)
    t = 0
    for i in range(N): # 0以上N未満
        if s >> i & 1: # s >> iの最下位bitが立っているか(s>>1を右から見てi番目が1かどうか),0のときFalseそれ以外でTrue
            t ^= a[i]
    if t == p:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    long memo[n + 1];
    for(int i = 0; i < n + 1; i++){
        memo[i] = -1;
    }
    int destroied[m];
    for(int i = 0; i < m; i++){
        scanf("%d", &destroied[i]);
    }
    memo[0] = 1;
    memo[1] = 1;
    for(int i = 0; i < m; i++){
        memo[destroied[i]] = 0;
    }
    for(int i = 2; i < n + 1; i++){
        if(memo[i] != 0){
            memo[i] = memo[i - 2] + memo[i - 1];
            if(memo[i] >= 1000000007){
                memo[i] = memo[i] % 1000000007;
            }
        }
    }
    printf("%ld", memo[n]);
}

Measured memory_bytes: 1280
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
        dp[i][j]%=(10**9+7)
print(dp[0][0])


Measured memory_bytes: 27588
def selectionSort(A, N):
    c = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            c += 1
    return c

N = int(input())
A = list(map(int, input().split()))
c = selectionSort(A, N)
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=' ')
print(c)


Measured memory_bytes: 5612
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s, t;
    cin >> s >> t;

    int ans = LLINF;
    function<void(int,int,string)> dfs = [&](int idx, int cost, string str) {
      if(idx == n || str == t) {
        chmin(ans, cost);
        return;
      }
      // idx番目をstr[idx]->t[idx]にもっていく
      int diff = (t[idx]-str[idx]+10)%10;
      string tmp = str;
      // [idx, i] を回転させる
      FOR(i, idx, str.size()) {
        tmp[i] = ((tmp[i]-'0') + diff)%10 + '0';
        dfs(idx+1, cost+(diff==0?0:1), tmp);
      }
    };

    dfs(0, 0, s);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
 
using namespace std;
 
struct Point { double x,y; };
typedef pair<double,double> Segment;
const int MAX_N = 2010;
const int IINF = INT_MAX;
int N;
double sx[MAX_N],sy[MAX_N],ex[MAX_N],ey[MAX_N],L,R;
 
inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }
inline bool inside(double a,double b,double c) { return LTE(a,c) && LTE(c,b); }
inline double getDist(double x,double y) { return sqrt(x*x+y*y); }
 
int main(){
  scanf("%d",&N);
  vector<Segment> segs(N);
  rep(i,N) {
    scanf("%lf %lf %lf %lf",sx+i,sy+i,ex+i,ey+i);
    vector<Point> vec(4);
    vec[0] = (Point){sx[i],sy[i]};
    vec[1] = (Point){sx[i],ey[i]};
    vec[2] = (Point){ex[i],sy[i]};
    vec[3] = (Point){ex[i],ey[i]};
    segs[i] = Segment(IINF,-IINF);
    rep(j,4){
      double arg = atan2(vec[j].y,vec[j].x) * 180 / M_PI;
      if( LT(arg,0.0) ) arg += 360;
      if( sx[i] > 0 && sy[i] < 0 && ey[i] >= 0 ) {
        if( LTE(0.0,arg) && LTE(arg,91.0) ) arg += 360;
      } 
      segs[i].first  = min(segs[i].first ,arg);
      segs[i].second = max(segs[i].second,arg);
    }
  }
 
  sort(segs.begin(),segs.end());
  rep(i,N) segs.push_back(Segment(segs[i].first+360,segs[i].second+360));
  int ans = N;
  rep(i,N){
    int cost = 0;
    REP(j,i,i+N){
      ++cost;
      L = segs[j].first, R = segs[j].second;
      while( j+1 < i+N && ( inside(L,R,segs[j+1].first) || inside(L,R,segs[j+1].second) ) ){
        L = max(L,segs[++j].first);
        R = min(R,segs[j].second);
      }
    }
    ans = min(ans,cost);
    }
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;

typedef long long ll;

bool match(vector<int> a, vector<int> b){
	int n = a.size();
	int m = b.size();
	
	if(n != m) return false;
	rep(i, n) if(a[i] != b[i]) return false;
	return true;
}

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

	int n;
	cin >> n;

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

	int a = 0, b = 0;
	vector<int> v(n);
	rep(i, n) v[i] = i + 1;

	int cnt = 1;
	do{
		if(match(p, v)) a = cnt;
		if(match(q, v)) b = cnt;
		cnt++;
	}while(next_permutation(v.begin(), v.end()));

	cout << abs(a - b) << endl;

}


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

int main(void) {
    int N,X;
    int sum = 0;
    int minm=INT_MAX,m;
    cin >> N >> X;
    for(int i=0;i<N;i++) {
        cin >> m;
        sum += m;
        if(minm > m) {
            minm = m;
        }
    }

    cout << N + (X-sum)/minm << endl;
    return 0;
}


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

int main() {
	vector<int> v; int n; cin >> n; int ans = 0;
	for (int i = 1; i <= INT_MAX - (i == 1 ? 0 : v.back()); i *= 2) {
		if (i == 1) v.push_back(i); else v.push_back(v.back() + i);
	}
	auto itr = v.begin(); while (n >= *itr) { ans++; itr++; }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3148
(defun f(lst)
  (labels ((rec (i str acc)
                (if (= i (- (length str) 1))
                  (- (length str) acc)
                  (if (char= (char str i) (char str (1+ i)))
                    (rec (1+ i) str (1+ acc))
                    (rec (1+ i) str acc)))))
    (rec 0 lst 0)))
(let* ((line0 (read-line nil nil))
       (line (read-line nil nil)))
  (format t "~A" (f line)))


Measured memory_bytes: 15332
from itertools import product

N = int(input())


memo = []
for i in range(N):
    a = int(input())
    l = []
    for _ in range(a):
        x,y = map(int,input().split())
        l.append((x-1,y==1))
    memo.append(l)
    
def check(p):
    return all(p[x]==y for i,l in enumerate(memo) for x,y in l if p[i])

m = max(sum(p) for p in product((True,False), repeat=N) if check(p))
print(m)


Measured memory_bytes: 50652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    string s;
    cin >> n >> s;
    for(auto c: s) {
        ll x = c - 'A';
        x = (x + n) % 26;
        cout << (char)('A' + x);
    }
    cout << endl;
}


Measured memory_bytes: 256
n = int(input())
data = [-1 for i in range(n)]
for i in range(n):
    p = int(input())
    data[p-1] = i

#print(data)
res = 1
now = 1
for i in range(1,n):
    if data[i-1] < data[i]:
        now += 1
    else:
        now = 1
    res = max(res,now)

print(n-res)

Measured memory_bytes: 52464
# B - AcCepted
S = str(input())
count = 0
if S[0] == 'A':
    for i in range(2,len(S)-1):
        if S[i] == 'C':
            count += 1
        else:
            pass

    if count == 1:
        S_1 = set(S)
        S_1.remove('A')
        S_1.remove('C')
        if str(S_1).islower() :
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3064
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    String a = sc.next();

    
    if(a.equals("Sunny")){
      System.out.println("Cloudy");
    }else if(a.equals("Cloudy")){
      System.out.println("Rainy");
    }else{
      System.out.println("Sunny");
    }
 
  }
}

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

int main(){
  int n,m,x; cin >>n>>m>>x;
  int cnt0=0, cntn=0;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin >>a[i];
    if(a[i]>x) cntn++;
    else cnt0++;
  }
  cout <<min(cnt0,cntn)<<endl;
}

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

class MainClass
{
    public static void Main()
    {
        int input = int.Parse(Console.ReadLine());
        for (int i = 1; i <= input; i++)
        {
            int x = i;
            bool isInThree = false;

            while (x > 10)
            {
                x /= 10;
                if (x % 10 == 3)
                    isInThree = true;
            }

            if (i % 10 == 3 || i % 3 == 0 || isInThree)
                Console.Write(" " + i);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 9288