akhauriyash/Code-Regression huggingface dataset:
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Set<String> set = new HashSet<String>();
		while (n-- > 0) {
			String a = scanner.next();
			String b = scanner.next();
			if (a.equals("insert")) {
				set.add(b);
			} else {
				System.out.println(set.contains(b) ? "yes" : "no");
			}
		}
	}
}

Measured memory_bytes: 268352
// single-source shortest path (BFS)

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

const int N = 1010;
const int M = 2010;
const int inf = 0x3fffffff;

struct Edge {
	int to, len, next;
} es[M];

int SIZE = 0; // number of edges
int h[N]; // pointer to edge list
int dist[N], queue[N]; // for calculating shortest path
int inq[N], cnt[N];

inline void add(int u, int v, int w) {
	int i = ++SIZE;
	es[i].to = v;
	es[i].len = w;
	es[i].next = h[u];
	h[u] = i; 
}

inline int inc(int x) {
	return (x == N - 1 ? 0 : x + 1);
}

bool sssp(int r, int n) {
	int front = 0, back = 0;
	queue[back++] = r;
	cnt[r] = n - 1;
	while (front != back) {
		int x = queue[front];
		inq[x] = 0;
		front = inc(front);
		for (int i = h[x]; i; i = es[i].next) {
			int y = es[i].to;
			int new_d = dist[x] + es[i].len;
			if (new_d < dist[y]) {
				dist[y] = new_d;
				if (!inq[y]) {
					queue[back] = y;
					inq[y] = 1;
					cnt[y] += 1;
					if (cnt[y] == n)
						return false;
					back = inc(back);
				}
			}
		}
	}
	return true;
}

void run() {
	int n, m, r, x, y, w;
	scanf("%d%d%d", &n, &m, &r);
	memset(h, 0, sizeof(h));
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &x, &y, &w);
		add(x, y, w);
	}
	for (int i = 0; i < n; i++) {
		dist[i] = (i == r ? 0 : inf);
		inq[i] = 0;
	}
	if (sssp(r, n)) {
		for (int i = 0; i < n; i++) {
			if (dist[i] == inf)
				printf("INF\n");
			else
				printf("%d\n", dist[i]);
		} 
	} else {
		printf("NEGATIVE CYCLE\n");
	}
}

int main() {
	run();
}

Measured memory_bytes: 2788
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n,m;
    cin>>n>>m;
    int cnt[n+3];clr(cnt);
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        cnt[u]++;
        cnt[v]++;
    }
    f(i,1,n)
    {
        if(cnt[i]%2==1)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> C(n);
    vector<vector<int>> A(n, vector<int>(m));
    rep(i,n){
        cin >> C[i];
        rep(j,m){
            cin >> A[i][j];
        }
    }
    int ans = INT_MAX;
    for(int bit = 0; bit<(1<<n); bit++){
        vector<int> S;
        rep(i,n){
            if(bit & (1<<i)) S.push_back(i);
        }

        vector<int> sum(m);
        bool j = true;
        int res = 0;
        rep(i,S.size()){
            res += C[S[i]];
            rep(j,m){
                sum[j] += A[S[i]][j];
            }
        }
        rep(i,m) if(sum[i] < x) j = 0;
        if(j) ans = min(ans, res);
    }
    if(ans == INT_MAX) ans = -1;
    cout << ans << endl;
}

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

int main(void)
{
  string s,t,u;
  int a,b;
  
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  
  if(u == s)
  {
    a -= 1;
  }
  else if (u == t)
  {
    b -= 1;
  }
  
  cout << a << " " << b;
}

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

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n;
ll a[200005];
ll base[35];
set<ll>set1;
//<<-----Implement Functions Here---->>//



//<<-----Start of Main--------------->>//
void MAIN(){
		string s,q;ll ans = 0;
		cin>>s>>q;ll n = s.size();
		for(ll i=0;i<n;i++)
		{
			if(s[i]!=q[i])ans++;
		}
		cout<<ans<<endl;
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

  
}

Measured memory_bytes: 6180
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;

int main() {
	ll s[20000], t[1000], n, q, c;
	c = 0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> s[i];
	cin >> q;
	for (int i = 0; i < q; i++)cin >> t[i];
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (t[i] == s[j]){
              c++;
              break;
            }
		}
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3136
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
 
import java.util.*;
class Main {
 
    static char[] xx = new char[] {'S','H','C','D'};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[][] l = new boolean[4][13];
        for(int i = 0; i < n; i++) {
            char k = sc.next().charAt(0);
            int r = sc.nextInt();
            if(k == 'S') {
                l[0][r-1] = true;
            }
            if(k == 'H') {
                l[1][r-1] = true;
            }
            if(k == 'C') {
                l[2][r-1] = true;
            }
            if(k == 'D') {
                l[3][r-1] = true;
            }
        }
        for(int i = 0 ; i< 4; i++) {
            for(int j = 0; j < 13; j++) {
                if(!l[i][j]) {
                    System.out.println(xx[i] + " " + (j+1));
                }
            }
        }
    }
}


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

int main() {
    int x, y;
    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x <= y) {
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

int main(){
    int n; cin>>n;
    vector<double> x(n), y(n);
    for(int i=0; i<n; i++) cin>>x[i]>>y[i];

    vector<double> length;
    for(int i=0; i<n; i++){
        double dist = sqrt(abs(x[i] - x[(i+1)%n]) * abs(x[i] - x[(i+1)%n]) + abs(y[i] - y[(i+1)%n]) * abs(y[i] - y[(i+1)%n]));
        length.emplace_back(dist);
    }

    if(n % 2 == 1){
        cout << "NA" << endl;
        return 0;
    }

    bool valid = true;
    for(int i=0; i<n/2; i++){
        if(!equals(length[i], length[i+n/2])) valid = false;
    }

    if(valid){
        double ansx = (x[0] + x[n/2]) / 2;
        double ansy = (y[0] + y[n/2]) / 2;
        printf("%.10f %.10f\n", ansx, ansy);
    }
    else{
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#include<time.h>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, K; cin >> N >> K;
	vector<int> a(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	if (K <= N) {
		int now = 1;
		while (K) {
			now = a[now];
			K--;
		}
		cout << now << endl;
	}

	else {
		vector<int> vi(N + 1);
		vi[1] = 1;
		int now = 1;
		for (ll i = 2; i <= N + 2; i++) {
			now = a[now];
			if (!vi[now]) vi[now] = i;
			else {
				ll T = i - vi[now];
				ll rem = (K - i) % T;
				//cout << "T=" << T << " rem=" << rem << endl;
				for (int j = 0; j <= rem; j++) {
					now = a[now];
				}
				break;
			}
		}

		cout << now << endl;
	}
}


Measured memory_bytes: 4836
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] h = new int[10];
		for(int i=0; i<h.length; i++){
			h[i] = sc.nextInt();
		}
		
		for(int i=0; i<3; i++){
			for(int j=i; j<h.length; j++){
				if(h[j] > h[i]){
					int max = h[j];
					h[j] = h[i];
					h[i] = max;
				}
			}
			System.out.println(h[i]);
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    ld a, b, c;
    cin>>a>>b>>c;
    cout<<(2*sqrt(a*b)<c-a-b?"Yes\n":"No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  ll N, M;
  cin >> N >> M;
  vvll dist(N, vll(N, INF));
  if(M==0){cout << -1 << endl; return 0;}
  for(int i = 0; i < M; i++){
    ll s, t, d;
    cin >> s >> t >> d;
    dist.at(s).at(t) = d;
  }
  vvll dp((1<<15), vll(N, INF));
  function<ll(ll, ll)> dfs = [&](ll bit, ll v){
    if(bit == (1<<v)) return dp.at(bit).at(v) = dist.at(0).at(v);
    if(dp.at(bit).at(v) != INF) return dp.at(bit).at(v);
    ll prebit = bit & ~(1<<v);
    ll res = INF;
    for(int i = 0; i < N; i++){
      if(prebit & (1<<i)){
        if(dist.at(i).at(v) == INF) continue;
        chmin(res, dfs(prebit, i) + dist.at(i).at(v));
      }
    }
    return dp.at(bit).at(v) = res;
  };
  ll ans =  dfs((1<<N)-1, 0);
  if(ans >= INF) ans = -1;
  cout << ans << endl;
}


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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,ans=0;
    cin>>x>>y;
    while(x<=y){
        x*=2;
        ans++;
    }
    cout <<ans<<endl;
    return 0;
}


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

int  main()
{

	int n; cin >> n;
	int cnt = 0;
	string s[n];
	queue<string> aq;
	queue<string> bq;
	string bxa;
	string ab;
	string str;

	rep(i, n)
	{
		cin >> s[i];
		if (s[i].front() == 'B' && s[i].back() == 'A')
		{
			bxa += s[i];
		}
		else if (s[i].front() == 'B')
		{
			bq.push(s[i]);
		}
		else if (s[i].back() == 'A')
		{
			aq.push(s[i]);
		}
		else
			str += s[i];
	}
	if (bq.size() == aq.size())
	{
		if (!bq.empty() && !aq.empty())
		{
			bxa = aq.front() += bxa;
			bxa += bq.front();
			aq.pop(); bq.pop();
		}
	}
	while (!aq.empty() && !bq.empty())
	{
		ab += (aq.front()+bq.front());
		aq.pop(); bq.pop();
	}
	if (!aq.empty())
	{
		while (!aq.empty())
		{
			bxa = aq.front() += bxa;
			aq.pop();
		}
	}
	if (!bq.empty())
	{
		while (!bq.empty())
		{
			bxa += bq.front();
			bq.pop();
		}
	}

	string ans = bxa + ab + str;
	rep(i, ans.size())
	{
		if (ans.substr(i, 2) == "AB")
			cnt++;
	}
	cout << cnt << endl;
	return (0);
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
  int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s[0]=='S'){
        if(s[1]=='U'){
            cout<<7<<'\n';
        }
        if(s[1]=='A'){
            cout<<1<<'\n';
        }
    }
    else if(s[0]=='M'){
        cout<<6<<'\n';
    }
    else if(s[0]=='T' && s[1]=='U'){
        cout<<5<<'\n';
    }
    else if(s[0]=='W'){
        cout<<4<<'\n';
    }
    else if(s[0]=='T' && s[1]=='H'){
        cout<<3<<'\n';
    }
    else if(s[0]=='F'){
        cout<<2<<'\n';
    }
    return(0);
}

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

int main(){
    int n,q;
    cin>>n;
    int* S=new int[n];
    int number;
    for(int i;i<n;++i){
        cin>>number;
        S[i]=number;
    }
    cin>>q;
    int* T=new int[q];
    for(int i=0;i<q;++i){
        cin>>number;
        T[i]=number;
    }
    int cnt=0;
    for(int i=0;i<q;++i){
        for(int j=0;j<n;++j){
            if(S[j]==T[i]){
                ++cnt;
                break;
            }
        }
    }
    cout<<cnt<<"\n";
    delete[] T;
    delete[] S;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	int k,x; cin>>k>>x;
	if(500*k>=x) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	int N;
	cin >> N;
	vector<int> ans(N, 0);
	rep(i, N)
	{
		int A;
		cin >> A;
		ans[A - 1] = i + 1;
	}

	rep(i, N)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;

int n,m;
int gx,gy;
int INF=1000000;
char fie[121][121];
int jp[121][121];
int ans;
int dx[5]={1,0,-1,0,0};
int dy[5]={0,1,0,-1,0};
typedef pair<int,int> P;
typedef pair<P,int> PP;

void bfs(){
	queue<PP> que;
	for(int i=0;i<=120;i++){
		for(int j=0;j<=120;j++){
			jp[j][i]=INF;
		}
	}
	que.push(PP(P(gx,gy),0));
	jp[gx][gy]=0;
	while(que.size()){
		PP p=que.front();que.pop();
		int nx=p.first.first,ny=p.first.second;
		for(int i=0;i<4;i++){
			int kx=nx+dx[i],ky=ny+dy[i],k=p.second;
			if(ky>=0 && ky<n && kx>=0 && kx<m){
				if(fie[kx][ky]=='.' && k<jp[kx][ky]){
					que.push(PP(P(kx,ky),k));
					jp[kx][ky]=k;
				}
				if(fie[kx][ky]=='#' && fie[nx][ny]=='#' && k<jp[kx][ky]){
					que.push(PP(P(kx,ky),k));
					jp[kx][ky]=k;
				}
				if(fie[kx][ky]=='#' && (fie[nx][ny]=='.' || fie[nx][ny]=='&') && k+1<jp[kx][ky]){
					que.push(PP(P(kx,ky),k+1));
					jp[kx][ky]=k+1;
				}
			}else ans=min(ans,k);
		}
	}
}

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		ans=INF;
		for(int i=0;i<m;i++){
			cin >> fie[i];
			for(int j=0;j<n;j++){
				if(fie[i][j]=='&')gx=i,gy=j;
			}
		}
		bfs();
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>

int main()
{
	int num,sum;
	while(scanf("%d", &num) != EOF){
		sum = 0;
		for(int i = num; i <= 600 - num; i += num){
			sum += i * i * num;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n;
	cin>>n;
	vi v(n);
	rep(i,0,n)cin>>v[i];
	sort(v.begin(),v.end());
	vector<double> d(n);
	d[0]=1.0*v[0];
	rep(i,0,n-1){
		d[i+1]=(v[i+1]+d[i])/2;
	}
	cout<<d[n-1];
	return 0;
}

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

//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())

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

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

//main code

LL gcd(LL bigger,LL smaller) {
    if (bigger % smaller != 0) {
        return gcd(smaller,(bigger % smaller));
    }
    return smaller;
}

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    vector<LL> t(n);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        ans = max(ans,t[i]);
    }
    for (auto&& var : t) {
        ans *= (var / gcd(var,ans));
    }
    cout << ans << endl;
    return 0;
}


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

#define LL long long

LL arr[200009];

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

	for(int i=0;i<n;i++){cin>>arr[i];}
	LL ans = 0;
	
	int l=0,r=0;
	LL sum=arr[l],sumxor=arr[l];

	while(r<n){
		if(sum == sumxor){ans = ans + 1 + (r-l);r++;sum+=arr[r];sumxor^=arr[r];}
		else{
			sum-=arr[l];sumxor^=arr[l];
			l++;
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }
    else{
        if(a == c){
            cout << b << endl;
        }
        else{
            cout << a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
int main(){
    double n=in(),m=in(),d=in();
    double ans=d>0?2:1;
    ans*=(n-d)*(m-1)/n/n;
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
using namespace std;

const int MAX = 2010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long 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(){
    int N, K;
    cin >> N >> K;

    COMinit();

    for(int i = 1; i <= K; i++){
        long long ans = COM(N-K+1, i)%MOD*COM(K-1, i-1)%MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
re1 = 0
re2 = 0

for i in range(0,n,2):
    if s[i] == "1":
        re1 += 1

for i in range(1,n,2):
    if s[i] == "0":
        re1 += 1
        
for i in range(0,n,2):
    if s[i] == "0":
        re2 += 1
        
for i in range(1,n,2):
    if s[i] == "1":
        re2 += 1
        
print(min(re1,re2))

Measured memory_bytes: 49392
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

__attribute__((constructor)) static void init()
{
    ios::sync_with_stdio(false);
    std::cin.tie(0);
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (auto&& i : h) {
        cin >> i;
    }

    vector<bool> good(n, true);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        good[a] = (good[a] && h[a] > h[b]);
        good[b] = (good[b] && h[a] < h[b]);
    }

    int sum = count(all(good), true);

    cout << sum << "\n";
}


Measured memory_bytes: 3788
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
v = LI()

v.sort()
pre = v[0]
for i in range(1,N):
    pre = (pre + v[i])/2


print(pre)


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int n;
int k;
int a[105];

// i番目までの子供にj個のアメを配る方法の数
mint dp[105][100005];

int main() 
{
    cin >> n >> k;
    rep(i,n) cin >> a[i];

    rep(i,n+1)rep(j,k+1) {
        dp[i][j] = 0;
    }
    dp[0][0] = 1;

    
    for (int i = 1; i<=n; i++) {
        for (int j=0; j<=k; j++) {
            if (j-1-a[i-1] >=0) dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1-a[i-1]];
            else dp[i][j] = dp[i][j-1] + dp[i-1][j]; 
        }
    }

    cout << dp[n][k] << endl;


    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x]<0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x==y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};

int main(){
    ll n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    UnionFind u(n);
    vector<ll> ans(m);
    ans[m-1] = n*(n-1)/2;

    for (ll i=m-1; i>=0; i--) {
        if (i==0) continue;
        if (u.same(a[i], b[i])) {
            ans[i-1] = ans[i];
            continue;
        }
        ll res = u.size(a[i])*u.size(b[i]);
        u.unite(a[i], b[i]); 
        ans[i-1] = ans[i] - res;
    }

    rep(i, m) {
        cout << ans[i] << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3328
import heapq
f=lambda:map(int,input().split());n=int(input());g=[[]for _ in range(n+1)];z=[-1]*n;d=[1e9]*n+[0];q=[-1]*(n+1);r='';Q=[];heapq.heappush(Q,(0,-2,n))
for _ in range(n-1):a,b=f();a-=1;b-=1;g[a]+=[(1,a,b)];g[b]+=[(1,b,a)]
for _ in range(int(input())):a,b=f();a-=1;g[n]+=[(b,n,a)];z[a]=b
while Q:
	e=heapq.heappop(Q)
	if q[e[2]]!=-1:continue
	q[e[2]]=e[1]
	for f in g[e[2]]:
		if d[f[2]]>e[0]+f[0]:d[f[2]]=e[0]+f[0];heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))
for _ in g:
	if any(e[1]!=n and abs(d[e[1]]-d[e[2]])!=1 for e in _):r='No'
else:
	if any(z[i]>=0 and z[i]!=d[i] for i in range(n)):r='No'
print(r or "Yes\n"+"\n".join(map(str,d[:n])))

Measured memory_bytes: 70856
// 問題: N枚のコインからK枚を選んで金額が[L,R]の範囲になる選び方の数を求める
// 解法: 

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

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

#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 ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair

map<ll, ll> make_map(vector<ll>& As) {
    map<ll, ll> ret;
    for(auto a: As) ++ret[a];
    return ret;
}

map<ll, ll> make_combination(map<ll, ll>& As, map<ll, ll>& Bs) {
    map<ll, ll> ret;
    for(auto a: As) {
        for(auto b: Bs) {
            auto val = a.first + b.first;
            auto cnt = a.second * b.second;
            ret[val] += cnt;
        }
    }
    return ret;
}

ll coin_combination_2(ll N, ll K, ll L, ll R,
                      vector<ll>& As) {
    // 前半部の全列挙
    const auto N2 = N / 2;
    vector<vector<ll>> former(N2 + 1);
    REP(i, (1 << N2)) {
        ll sum = 0;
        int cnt = 0;
        REP(j, N2) {
            if (i & (1 << j)) {
                sum += As[j];
                cnt++;
            }
        }
        former[cnt].pb(sum);
    }

    // 後半部の全列挙
    vector<vector<ll>> latter(N - N2 + 1);
    REP(i, (1 << (N - N2))) {
        ll sum = 0;
        int cnt = 0;
        REP(j, (N - N2)) {
            if (i & (1 << j)) {
                sum += As[N2 + j];
                cnt++;
            }
        }
        latter[cnt].pb(sum);
    }

    REP(n, N2 + 1) sort(ALL(former[n]));
    REP(n, N - N2 + 1) sort(ALL(latter[n]));

    ll ans = 0;
    // 前半部でn個使う場合
    REP(n, N2 + 1) {
        if (n + N - N2 < K) continue;
        if (n > K) break;

        ll tmp = 0;
        for (auto e: former[n]) {
            if (e > R) break;
            auto mn = max(0LL, L - e);
            auto mx = R - e;

            auto it1 = lower_bound(ALL(latter[K - n]), mn);
            auto it2 = lower_bound(ALL(latter[K - n]), mx + 1);
            ans += (it2 - it1);
            tmp += (it2 - it1);
        }
        // cout << "former " << n << ", latter " << (K - n) << ", " << tmp << "added" << endl;
    }
    return ans;
}

int main() {
    ll N, K, L, R;
    cin >> N >> K >> L >> R;
    vector<ll> As(N);
    REP(n, N) cin >> As[n];
    cout << coin_combination_2(N, K, L, R, As) << endl;

    return 0;
}



Measured memory_bytes: 23436
import decimal,math
decimal.getcontext().prec = 100
def sum1(pre,l,r):
    l=max(l,0)
    if(l==0):
        return pre[r]
    return pre[r] - pre[l - 1]
abc=[]
def printDivisors(n) : 
    i = 1
    while i <= math.sqrt(n): 
          
        if (n % i == 0) : 
              
            if (n / i == i) : 
                abc.append(i) 
            else : 
                abc.append(i)
                abc.append(n/i)
        i = i + 1
n,k=map(int,raw_input().split())

arr=map(int,raw_input().split())
s=sum(arr)
printDivisors(s)
abc.sort()
abc=abc[::-1]
ans=1
for i in abc:
    l=0
    flag=0
    c=[]
    for j in arr:
        c.append(j%i)
    c.sort()
    if(sum(c[:-sum(c)/i])<=k):
        print i
        exit()

Measured memory_bytes: 4268
from collections import Counter 
def check(s): 
    c=Counter(s)
    if max(c.values())>len(s)/2:
        return 1 
    return 0 
s=input()
n=len(s)
for i in range(n):
    for j in range(i+1,min(n,i+15)):
        if check(s[i:j+1]):
            print(i+1,j+1)
            exit()
print(-1,-1)

Measured memory_bytes: 44632
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
N = int(input())
S = input()
a = ''
for item in S:
  a_index = alphabet.index(item) + N
  if a_index > 25:
    a_index = a_index - 26
  a += alphabet[a_index]
print(a)


Measured memory_bytes: 3060
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j - wv[i][0] >= 0:
      dp[i+1][j] = max(dp[i][j], dp[i][j-wv[i][0]]+wv[i][1])
    else:
      dp[i+1][j] = dp[i][j]

print(max(dp[N]))

Measured memory_bytes: 171656
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    char s[3];
    scanf("%s", s);

    int isCheck = 0;
    if (s[0] == 'a') {
        if (s[1] == 'b' && s[2] == 'c') {
            isCheck = 1;
        }
        if (s[1] == 'c' && s[2] == 'b') {
            isCheck = 1;
        }

    }
    if (s[0] == 'b') {
        if (s[1] == 'a' && s[2] == 'c') {
            isCheck = 1;
        }
        if (s[1] == 'c' && s[2] == 'a') {
            isCheck = 1;
        }
    }
    if (s[0] == 'c') {
        if (s[1] == 'a' && s[2] == 'b') {
            isCheck = 1;
        }
        if (s[1] == 'b' && s[2] == 'a') {
            isCheck = 1;
        }
    }
    printf("%s", (isCheck == 1 ? "Yes" : "No"));




    return 0;

}


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

int main(void){
	string s, s1, s2;
	cin >> s;
	for (int i = 2; i < 200; i += 2){
		s1 = s.substr(0, (s.size()-i)/2);
		s2 = s.substr((s.size()-i)/2, (s.size()-i)/2);
		if (s1 == s2){
			cout << (s1.size())*2 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	string S;
	cin >> S;

	if (S.length() == 1) {
		cout << S;
		return 0;
	}

	for (int i = 1; i < S.length(); i++) {
		if (S[i] != '9') {
			cout << (S.length() - 1) * 9 + int(S[0]) - 48 - 1;
			return 0;
		}
	}

	cout << 9 * (S.length()-1) + int(S[0]) - 48;




}


Measured memory_bytes: 256
string_a = input()
string_b = input()
isCorrespond = False
for n in range(len(string_b)):
    tmp = string_a[0]
    string_a = string_a[1:].strip() + tmp
    if(string_a == string_b):
        isCorrespond = True
        break

print("Yes" if isCorrespond else "No")

Measured memory_bytes: 2940
// C++のテンプレート
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b+c || b == a+c || c == a+b )
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}

Measured memory_bytes: 384
N = int(input())
N_digit = len(str(N))
K = int(input())
ans = 0
factorial = [1, 1]
for i in range(2, 101):
    factorial.append(factorial[-1] * i)


def nCr(n, r):
    if n - r < 0:
        return 0
    return factorial[n] // (factorial[r] * factorial[n - r])


if K == 1:
    ans += 9 * (nCr(N_digit - 1, 1))  # 1桁目を0に固定、2桁目以降は自由
    ans += int(str(N)[0])  # 1桁目を考える。2桁目以降は0

elif K == 2:
    ans += (9 ** 2) * (nCr(N_digit - 1, 2))  # 1桁目を0に固定、2桁目以降から自由に2つ
    ans += (int(str(N)[0]) - 1) * 9 * (nCr(N_digit - 1, 1))  # 1桁目を0でなく、かつN以下が確定するように固定
    for d2_position in range(1, N_digit):  # 2つめの0でない数をどこに置くか
        for d2_value in range(1, 10):  # 2つめの0でない数を何にするか
            # 数をつくる
            S = ['0'] * N_digit
            S[0] = str(N)[0]
            S[d2_position] = d2_value
            S = int(''.join(map(str, S)))

            ans += (S <= N)

elif K == 3:
    ans += (9 ** 3) * (nCr(N_digit - 1, 3))  # 1桁目を0に固定、2桁目以降から自由に3つ
    ans += (int(str(N)[0]) - 1) * (9 ** 2) * (nCr(N_digit - 1, 2))  # 1桁目を0でなく、かつN以下が確定するように固定
    for d2_position in range(1, N_digit):  # 2つめの0でない数をどこに置くか
        for d3_position in range(d2_position + 1, N_digit):  # 3つめの0でない数をどこに置くか
            for d2_value in range(1, 10):  # 2つめの0でない数を何にするか
                for d3_value in range(1, 10):  # 3つめの0でない数を何にするか
                    # 数を作る
                    S = ['0'] * N_digit
                    S[0] = str(N)[0]
                    S[d2_position] = str(d2_value)
                    S[d3_position] = str(d3_value)
                    S = int(''.join(S))

                    ans += (S <= N)

print(ans)


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

int main()
{
	while (true)
	{
		int H, W;
		cin >> H >> W;

		if (H == 0 && W == 0)
		{
			break;
		}
		
		for (int i = 0;i < W;i++)
		{
			cout << '#';
		}
		cout << '\n';

		for (int i = 0;i < H - 2;i++)
		{
			cout << '#';
			for (int j = 0;j < W - 2;j++)
			{
				cout << '.';
			}
			cout << "#\n";
		}

		for (int i = 0;i < W;i++)
		{
			cout << '#';
		}
		cout << "\n\n";

	}

	return 0;
}


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

class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        HashSet<long> hashSet = new HashSet<long>();
        int count = 0;
        for (int i = 0; i < n; i++)
        {
            var x = long.Parse(Console.ReadLine());
            if (hashSet.Contains(x))
            {
                hashSet.Remove(x);
                count--;
            }
            else
            {
                hashSet.Add(x);
                count++;
            }
        }
        Console.WriteLine(count);

    }

}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a;
  b=a/100;
  c=a%100;
  if(0<b&&b<13&&0<c&&c<13){
    s="AMBIGUOUS";
  }else if(0<b&&b<13){
    s="MMYY";
  }else if(0<c&&c<13){
    s="YYMM";
  }else{
    s="NA";
  }
  cout <<s;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
    int a,b,c,d,cnt=0;
    scanf("%d%d%d",&a,&b,&c);

    for(a;a<=b;a++){
        d=c%a;
        if(d==0){
            cnt++;
        }
    }

    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 596
n,m=map(int,input().split())
ans=[]

for i in range(m):
    ans.append(list(map(int,input().split())))
for j in range(10**n):
    if len(str(j))==n and all(str(j)[s-1]==str(c) for s,c in ans):
        print(j)
        break
else:
    print(-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    string s;
    cin >> s;
    auto run = runlength(s);
    // rep(i, sz(run)) cout << run[i].F << " " << run[i].S << endl;
    if (run[0].F == '>') run.insert(run.begin(), make_pair('<', 0));
    if (run[sz(run) - 1].F == '<') run.eb(make_pair('>', 0));
    // rep(i, sz(run)) cout << run[i].F << " " << run[i].S << endl;
    ll ans = 0;
    for (int i = 0; i < sz(run); i += 2) {
        ans += (ll)run[i].S * (run[i].S + 1) / 2;
        ans += (ll)run[i + 1].S * (run[i + 1].S + 1) / 2;
        ans -= min(run[i].S, run[i + 1].S);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3864
#pragma  warning (disable:4996) 
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
#include<iomanip>
#include<set>
#include <numeric>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int sum = 0;
	while (n)
	{
		n /= k;
		sum++;
	}
	printf("%d", sum);
}



Measured memory_bytes: 256
import java.util.Scanner;



class Main {
	public static void main(String args[]) {
		
		//????????£????????§??´??°?????????????????????
	    Scanner sc = new Scanner(System.in);
	    String s1 = sc.next();
	    int a = Integer.parseInt(s1);
	    String s2 = sc.next();
	    int b = Integer.parseInt(s2);
	    String s3 = sc.next();
	    int c = Integer.parseInt(s3);
	    int sum = 0;
	    
	    //??´??°a???b???c????????¶??????????????????????????????????????????a<=b??§??????????¢????
	    if(1 <= a && a <= 10000){
	    	if(1 <= b && b <= 10000){
	    		if(1 <= c && c <= 10000){
	    			if(a <= b){
	    					
	    			    //c?´???°???a??????b?????§?????????????????????????¨????
	    				for(int i = a; i <= b; i++){
	    					if(c % i == 0){
	    					    sum++;
	    					}
	    				}
	    				
	    				//?´???°?????°?????¨???
	    				System.out.println( sum );
	    			}
	    		}
	    	}
	    }
	}
}

Measured memory_bytes: 17316
#まとめ
import datetime
H1,M1,H2,M2,K=map(int,input().split())

dt1=datetime.datetime(year=1,month=1,day=1,hour=H1,minute=M1)
dt2=datetime.datetime(year=1,month=1,day=1,hour=H2,minute=M2)

dt_diff=dt2-dt1

def timedelta_to_HM(td):
    sec = td.total_seconds()
    return (sec//60)

time=timedelta_to_HM(dt_diff)

A=time-K
A=int(A)

print(A)

Measured memory_bytes: 9500
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        char[] c = s.toCharArray();
        for(int i = 0; i < c.length; i++){
            if(i%2 == 0){
                if(c[i] == 'L'){
                    System.out.println("No");
                    return;
                }
            }else{
                if(c[i] == 'R'){
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    int h,w,m;
    cin>>h>>w>>m;
    map<int,set<int>> mpx;
    map<int,set<int>> mpy;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        mpx[x].insert(y);
        mpy[y].insert(x);
    }
    int mxx=-1,mxy=-1;
    for(auto P:mpx){
        mxx=max(mxx,int(P.second.size()));
    }
    for(auto P:mpy){
        mxy=max(mxy,int(P.second.size()));
    }
    // deb(mxx);deb(mxy);
    vector<int> a,b;
    for(auto P:mpx){
        if(P.second.size()==mxx){
            a.emplace_back(P.first);
        }
    }
    for(auto P:mpy){
        if(P.second.size()==mxy)b.emplace_back(P.first);
    }
    if(sz(a)*sz(b)>300000){
        int x=a[0],y=b[0];
        cout<<int(mpx[x].size()+mpy[y].size())<<"\n";
        return;
    }
    int ans=0;
    int cnt=0;
    for(auto x:a){
        for(auto y:b){
            // cout<<x<<":"<<y<<"\n";
            ++cnt;
            ans=max(ans,int(mpx[x].size()+mpy[y].size()-(mpx[x].count(y)||mpy[y].count(x))));
        }
        if(cnt==1000000)break;
    }
    cout<<ans<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 91784
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    int cnt = 0;
        for(int i=0; i<N; i++){
            if(p[i]!=i+1){
                cnt++;
            }
        }
    if(cnt == 0 || cnt == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256