akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

int main() {

  int N;
  cin >> N;

  int l = to_string(N).length();
  int d = pow(10, l-1);
  int q = N/d;
  int r = N%d;

  int ans = 0;
  for (int i=0; i<l-1; ++i) {
	if (i%2 == 0) {
	  ans += 9*pow(10, i);
	}
  }


  if (l == 1) {
	ans = N;
  } else if (l%2 == 1) {
	ans += r;
	ans += pow(10, l-1)*(q-1);
	if (l >= 3) ans += 1;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4160
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int friends[500];
	int n,m;
	pair<int, int> student[10000];
	int result[100];
	int I = 0;
	for (int i = 0;; i++)
	{
		cin >> n;
		cin >> m;
		if (m == 0 && n == 0)
		{
			break;
		}

		for (int a = 0; a < 500; a++)
		{
			friends[a] = 0;
			student[a].first = 0;
			student[a].second = 0;
		}

		for (int a = 0; a < m; a++)
		{
			cin >> student[a].first >> student[a].second;
			student[a].first--;
			student[a].second--;
		}

		sort(student, student + m);

		friends[0] = 1;

		for (int a = 0; a < m; a++)
		{
			if (student[a].first == 0)
			{
				for (int b = 0; b < m; b++)
				{
					if (student[b].first == student[a].second)
					{
						friends[student[b].second] = 1;
					}
					if (student[b].second == student[a].second)
					{
						friends[student[b].first] = 1;
					}
				}
				friends[student[a].second] = 1;
			}
		}

		result[i] = -1;
		for (int a = 0; a < n; a++)
		{
			if (friends[a] == 1)
			{
				result[i]++;
			}
		}
		I++;
	}

	for (int a = 0; a < I;a++)
	{
		cout << result[a] << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll> W(N);
    vector<ll>sum(N+1);
    rep(i,N){
        cin>>W[i];
        sum[i+1]=sum[i]+W[i];
    }
    ll ans = INF;
    rep(i,N){
        chmin(ans,abs(sum[N]-sum[i]*2));
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3600
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 2005 * 2005, mod = (int) 0;
bitset<N> dp;
int main() {
	dp[0] = 1;
	int n, sum = 0;;
	cin >> n;
	for (int j = 0; j < n; ++j) {
		int x;
		cin >> x;
		sum += x;
		dp |= dp << x;
	}
	for (int j = 0; j < N; ++j)
		if (dp[j] && j + j >= sum) {
			cout << j << endl;
			return 0;
		}
}






Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  deque<int> d;
  rep(i, n){
    ll p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (p == 0){
      d.push_front(a[i]);
    }
    else d[p-1] = a[i];
  }
  ll ans = d.size();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int in = sc.nextInt();
        sc.close();
        int[] each_dig = new int[4];
        for(int i = 0; i < 4; i++){
            each_dig[i] = in % 10;
            in /= 10;
        }
        char[] oprs = new char[3];
        for(int i = 0; i < 8; i++){
            int sum = each_dig[3];
            for(int j = 0; j < 3; j++){
                if((i >> j & 1) == 1){
                    sum += each_dig[2 - j];
                }else{
                    sum -= each_dig[2 - j];
                }
            }
            if(sum == 7){
                for(int j = 0; j < 3; j++){
                    if((i >> j & 1) == 1){
                        oprs[j] = '+';
                    }else{
                        oprs[j] = '-';
                    }
                }
                break;
            }
        }
        System.out.println("" + each_dig[3] + oprs[0] + each_dig[2] + oprs[1] + each_dig[1] + oprs[2] + each_dig[0] + "=7");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, in[11000], w[11000], ans, now;
vector<ll> g[11000], s;
vector<P> c, list;
bool used[11000];
void dfs(ll a) {
	w[a] = s[now];
	now++;
	used[a] = true;
	REP(i, g[a].size()) {
		if (!used[g[a][i]]) {
			dfs(g[a][i]);
		}
	}
}
int main() {
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		in[a]++;
		in[b]++;
		g[a].push_back(b);
		g[b].push_back(a);
		list.push_back(P(a, b));
	}
	REP(i, n) {
		ll a;
		cin >> a;
		s.push_back(a);
	}
	sort(ALL(s),greater<ll>());
	REP(i, n) {
		c.push_back(P(in[i], i));
	}
	sort(ALL(c));
	dfs(c[0].second);
	REP(i, n - 1) {
		ans += min(w[list[i].first], w[list[i].second]);
	}
	cout << ans << endl;
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << w[i];
	}
	cout << endl;
}

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

typedef long long LL;
inline LL read(){
	register LL x=0,f=1;register char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f*x;
}

const int MAXN=200005;

struct Node{
	int x,y;LL z;
	friend bool operator <(Node x,Node y){
		return x.z>y.z;
	}
};
priority_queue <Node> q;

int fa[MAXN];
inline int getfa(int x){
	if(x==fa[x]) return x;
	return fa[x]=getfa(fa[x]);
}

int n,m,c;
LL sum;

int main(){
#ifdef file
	freopen("gkk.in","r",stdin);
	freopen("gkk.out","w",stdout);
#endif
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++){
		int x=read(),y=read();LL z=read();
		q.push((Node){x,y,z});
		q.push((Node){x,(x+1)%n,z+1});
		q.push((Node){y,(y+1)%n,z+2});
	}
	while(c<n-1){
		int x=q.top().x,y=q.top().y;LL z=q.top().z;q.pop();
		int u=getfa(x),v=getfa(y);
		if(u==v) continue;
		fa[u]=v;
		sum+=z,c++;
		if(getfa((u+1)%n)^getfa((v+1)%n))
			q.push((Node){(u+1)%n,(v+1)%n,z+2});
	}
	printf("%lld\n",sum);
}

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

vector<vector<int>> adj, radj;
vector<int> order, comp;
vector<bool> vis;

void dfs1(int u){
  vis[u]=1;
  for (int v: adj[u]){
    if (!vis[v])
      dfs1(v);
  }
  order.push_back(u);
}

void dfs2(int u){
  vis[u]=1;
  comp.push_back(u);
  for (int v:radj[u]){
    if (!vis[v])
      dfs2(v);
  }
}

void scc(){
  //INITIALISE n and m - n is number of vertices, m is number of edges
  int n, m;
  cin >> n >> m;
  adj.assign(n, {});
  radj.assign(n, {});
  order.clear();
  comp.clear();
  int ans = -1;
  for (int i=0; i<m; ++i){
    int u,v; //decrement u and v if necessary
    cin >> u >> v;
    u--;
    v--;
    
    //INITIALISE u and v
    adj[u].push_back(v);
    adj[v].push_back(u);
    radj[v].push_back(u);
    radj[u].push_back(v);
  }
  vis.assign(n, 0);
  for (int i=0; i<n; ++i){
    if (!vis[i])
      dfs1(i);
  }
  vis.assign(n, 0);
  for (int i=0; i<n; ++i){
    int u=order[n-1-i];
    if (!vis[u])
      dfs2(u);
    //comp now contains vertices of a SCC
    // for (auto el: comp){
    //   cout << el << " ";
    // }
    // cout << '\n';
    ans = max(ans, (int) comp.size());
    comp.clear();
  }
  cout << ans << '\n';
}

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

    scc();
    return 0;
}

Measured memory_bytes: 39188
/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is quite cool.It becomes cooler when you enjoy learning new things
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)
    cin>>a[i];

  vll dp(n);
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }

  cout<<dp[n-1]<<endl;
} 

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

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

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 4456
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int main() {
	string S;
	cin >> S;
	int cnt=0;
	
	for(int i=0; i<3; i++){
		if(S[i] == '1') cnt++;
	}
	
	cout << cnt;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

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

int main(){
  ll a,b;
  while(cin>>a>>b) cout<<gcd(a,b)<<" "<<a*b/gcd(a,b)<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int k,ans=-1,a;
int main()
{
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		a=a*10+7;
		if(a%k==0)
		{
			ans=i;
			break;
		}
		a%=k;
	}
	cout<<ans;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    int c4=0,c2=0;
    REP(i,N){
        int a; cin>>a;
        if(a%4==0) c4++;
        else if(a%2==0) c2++;
    }
    
    if(c4>=N/2 or c4*2+c2>=N) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n,x,i;
    cin>>n>>x;
    int l[n];
    rep(i,n)cin>>l[i];
    int ans=1,place=0;
    rep(i,n){
        place+=l[i];
        if(x>=place)ans++;
    }
    fin(ans);
//////////////////////////////////////////////////////
return 0;}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

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<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  string s;
  cin >> s;

  ll cnt = 0;
  REP(i, 4) if(s[i]=='2') cnt++;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <utility>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fore(i, init, n) for(int i = init; i <= n; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAXN = 1e5+5;
int n, a[MAXN][3], dp[MAXN][3];

int main() {
    FIN;
    cin >> n;
    
    fore(i,1,n) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    
    dp[1][0] = a[1][0];
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];

    fore(i,2,n) {
        fore(k,0,2) {
            dp[i][k] = max(dp[i-1][(k+1)%3] + a[i][k], dp[i-1][(k+2)%3] + a[i][k]);
        }
    }

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


Measured memory_bytes: 2560
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
a,A,B,C=0,0,0,0
for i in range(N):
    s=input()
    for j in range(len(s)-1):
        if s[j]=="A" and s[j+1]=="B":
            a+=1
    if s[0]=="B":
        A+=1
    if s[-1]=="A":
        B+=1
        if s[0]=="B":
            C+=1
if A==B==C:
    a+=max(0,C-1)
else:
    a+=min(A,B)
print(a)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
	int h, w;
	int i, j;
	while(1){
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0)break;
		for(i = 0;i < w;i++)printf("#");
		printf("\n");
		for(i = 1;i < h - 1;i++){
			printf("#");
			for(j = 1;j < w - 1;j++){
				printf(".");
			}
			printf("#\n");
		}
		for(i = 0;i < w;i++)printf("#");
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int a[3][3];
bool flag[3][3]; // true: 穴 false: ヒットなし
int main() {
  for(int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
          cin >> a[i][j];

      }
      cin.ignore();
  }

  int n;
  cin >> n;
  vector <int> b;
  int tmp;
  for (int i = 0; i < n; i++){
      cin >> tmp;
      cin.ignore();
      b.push_back(tmp);
  }

  // 初期化
  for (int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
          flag[i][j] = false;
      }
  }

  // Check
  for(int k = 0; k < n; k++){
      tmp = b[k];
      for(int i = 0; i < 3; i++){
          for(int j = 0; j < 3; j++){
              if(a[i][j] == tmp){
                  flag[i][j] = true;
              }
          }
      }
  }

  // bingo?
  // hexa
  bool bingo = true;
  for (int i = 0; i < 3; i++){
      bingo = true;
      for(int j = 0; j < 3; j++){
          bingo = bingo && flag[i][j];
      }
      if(bingo == true){
          cout << "Yes" << endl;
          return 0;
      }
  }

  // vert
  bingo = true;
  for (int i = 0; i < 3; i++){
      bingo = true;
      for(int j = 0; j < 3; j++){
          bingo = bingo && flag[j][i];
      }
      if(bingo == true){
          cout << "Yes" << endl;
          return 0;
      }
  }

  // naname
  bingo = flag[0][0] && flag[1][1] && flag[2][2];
  if(bingo == true){
      cout << "Yes" << endl;
      return 0;
  }

  bingo = flag[2][0] && flag[1][1] && flag[0][2];
  if(bingo == true){
      cout << "Yes" << endl;
      return 0;
  }

  cout << "No" << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  bool flag = true;
  int i = 1;
  for (int j = 0; j < N; j++) {
    if (i == 2) {
      cout << j << endl;
      flag = false;
      break;
    }
    else {
      i = a.at(i - 1);
    }
  }
  if (flag) {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
from collections import deque


def solve(S, s):
    if S[s[0]][s[1]] != ".":
        return -1
    queue = deque([s])
    visited = [[-1 for _ in range(W)] for _ in range(H)]
    visited[s[0]][s[1]] = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1,0], [-1,0], [0,1], [0,-1]):
            new_y, new_x = y+j, x+k
            if new_x in range(W) and new_y in range(H) and S[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    res = -1
    for v in visited:
        for u in v:
            res = max(res, u)
    return res


H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = -1
for i in range(H):
    for l in range(W):
        ans = max(ans, solve(S, [i, l]))
print(ans)



Measured memory_bytes: 3316
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
   int n,m;cin>>n>>m;
   pair<int,char> a[m];
   for(int i=0;i<m;i++){
       cin>>a[i].F>>a[i].S;
   }
   for(int i=0;i<=999;i++){
       string s=to_string(i);
       if(s.length()==n){
           bool b=true;
           for(int j=0;j<m;j++){
               if(s[a[j].F-1]!=a[j].S)b=false;
           }
           if(b){
               cout<<i<<endl;
               return;
           }
       }
   }
   cout<<-1<<endl;
}

int32_t main() {
    IOS;
    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

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

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

    int d = abs(a - b);
    if (d % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        int m = min(a, b);
        cout << m + d / 2 << endl;
    }
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int par[300001];
int treesize[300001];
int group = 300000;
bool flag[110000];

int find(int x) {           //親探し
	if (par[x] == x) {
		return x;
	}
	else {
		int z = find(par[x]);
		par[x] = z;
		return z;
	}
}

bool  unit(int x, int y) {

	int xpar = find(x);
	int ypar = find(y);

	if (xpar == ypar) { return false; }   //すでに結合済み
	group--;
	par[ypar] = xpar;
	treesize[xpar] += treesize[ypar];
	return true;
}
int main()
{
	int N, M;

	cin >> N >> M;
	fx(N) {
		par[x + 1] = x + 1;
		treesize[x + 1] = 1;
	}
	fx(M) {
		par[x + 100001] = x + 100001;
		treesize[x + 100001] = 1;
	}
	pairs(K);
	fx(N) {
		int k;
		cin >> k;
		fy(k) {
			int l;
			cin >> l;
			pb(K, make_pair(x + 1, l + 100000));
			flag[l] = true;
		}
	}
	int notUse = 0;
	fx(M) {
		if (!flag[x+1]) {
			notUse++;
		}
	}
	fx(K.size()) {
		unit(K[x].first,K[x].second);
	}
	//doublece(treesize[find(1)],notUse)
	if (treesize[find(1)] == N + M - notUse) {
		ce("YES")
	}
	else {
		ce("NO")
	}
    return 0;
}



Measured memory_bytes: 4340
package main

import "fmt"

func main() {
	var a string

	fmt.Scanf("%s",&a)

	if(a == "a" || a == "i" || a == "u" || a == "e" || a == "o") {
		fmt.Println("vowel")
	} else {
		fmt.Println("consonant")
	}
}


Measured memory_bytes: 512
def gcd(a,b):
    r = a%b
    #print(a,b,r)
    if(r==0): return b
    return gcd(b,r)
n = int(input()) 
#n=4
hps = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
    ##2 4 5 -> 1
    ## minと全ての要素のgcd
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])
#print(hps)
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define MOD 1000000007


int llen(ll x)
{
	int res = 0;
	while (x) {
		res++;
		x /= 10;
	}
	return res;
}

signed main()
{
	ll x;
	cin >> x;
	int l = llen(x);
	ll y = x;
	while (y >= 10) {
		y /= 10;
	}
	int res1 = (l-1) * 9 + y - 1;
	int res2 = 0;
	while (x) {
		res2 += x % 10; 
		x /= 10;
	}
	cout << max(res1, res2) << endl;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  string s;
  cin>>s;

  LL idx = 0;
  LL d = 0;
  LL cnt = 0;
  while (true)
  {
    if(idx+2>=s.size()){
      break;
    }


    if(s[idx]=='A'&&s[idx+1]=='B'&&s[idx+2]=='C'){
      d++;
      cnt += d;
      d --;
      s[idx] = 'B';
      s[idx+1] = 'C';
      s[idx+2] = 'A';
      idx += 2;
    }
    else if (s[idx] == 'A')
    {
      d++;
      idx++;
    }
    else
    {
      d = 0;
      idx++;
    }
  }

  cout << cnt << endl;
}


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

int main(){
  int d,t,s;
  cin>>d>>t>>s;
  double dd, tt, ss;
  dd = d*1.0;
  tt=t*1.0;
  ss=s*1.0;
  if(dd/tt>ss) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  if (N < K) {
    cout << min(N, abs(N - K * (N/K+1))) << endl;
  } else if (K == 1) {
    cout << 0 << endl;
  } else if (N == K) {
    cout << 0 << endl;
  } else {
    cout << abs(N - K * (N/K+1)) << endl;
  }
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
typedef long long int ll;
typedef unsigned long long int ull;
typedef float fl;
typedef short int si;
using namespace std;

void solve()
{   string a,b; cin >> a >>b; b.pop_back();
    if (a==b) cout << "Yes";
    else cout << "No";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAX_FACT=1000001;
typedef long long ll;
const ll mod=1000000007;
ll fact[MAX_FACT];

ll pow_mod(ll a,ll n){
  ll cur=1;
  ll mul=a;
  while(n){
    if(n%2)cur=(cur*mul)%mod;
    mul=(mul*mul)%mod;
    n/=2;
  }
  return cur;
}

ll div_mod(int a){
  return pow_mod(a,mod-2);
}
// factを前計算
void calcFact(){
  fact[0]=1;
  for(int i=1;i<MAX_FACT;i++)
    fact[i]=(fact[i-1]*i)%mod;
}
// aCbのmodを計算
// 計算量はO(log(fact[a])+log(fact[a-b]))程度
ll comb(ll a,ll b){
  if(a<0||b<0)return 0;
  else if(b==0)return 1;
  ll res=fact[a];
  res=(res*div_mod(fact[b]))%mod;
  res=(res*div_mod(fact[a-b]))%mod;
  return res;
}

int main(){
  calcFact();
  int N,M,K;
  cin>>N>>M>>K;
  ll res=0;
  for(int p=0;p<=K;p++){
    ll a=1;
    a=(a*comb(N+2*p,p))%mod;
    a=(a*(N+1))%mod;
    a=(a*div_mod(N+p+1))%mod;
    a=(a*comb(M+2*(K-p),K-p))%mod;
    a=(a*(M+1))%mod;
    a=(a*div_mod(M-p+1+K))%mod;
    a=(a*comb(N+M+2*K,N+2*p))%mod;
    res=(res+a)%mod;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 8644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n;
    cin>>n;
    vector<int> a(n);
    cinf(n,a);
    vector<int> b((int)1e5,0);
    rep(i,n) b[a[i]]++;
    int ans=0;
    for(int i=1;i<99999;i++) chmax(ans,b[i-1]+b[i]+b[i+1]);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
use proconio::{input,fastout};

#[fastout]
fn main() {
    input! {
        n: u64,
    }
    let mut i: u64 = 1;
    let mut j1: u64 = 1;
    let mut j2: u64 = n;
    loop {
        i += 1;
        if n % i == 0 {
            j1 = i;
            j2 = n / i;
        }
        if i * i >= n {break;}
    }
    println!("{}", j1 + j2 - 2);
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n;
int pass[20][20];

int main(){
    while(cin>>n){
        if(n==0)break;
        
        int m=-1;
        rep(i,20)rep(j,20)pass[i][j]=999999999;
        rep(i,20)pass[i][i]=0;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            pass[a][b]=c;
            pass[b][a]=c;
            m=max(m,max(a,b));
        }
        m++;
        
        rep(k,m){
            rep(i,m){
                rep(j,m){
                    pass[i][j] = min(pass[i][j],pass[i][k]+pass[k][j]);
                }
            }
        }
        
        
        int num=-1;
        int val = 999999999;
        rep(i,m){
            int sum=0;
            rep(j,m){
                sum+=pass[i][j];
            }
            if(val>sum){
                num=i;
                val=sum;
            }
        }
        cout<<num<<" "<<val<<endl;
        
    }
}

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

using namespace std;

typedef long long ll;

int main(){
    ll K, A, B;
    while(scanf("%lld%lld%lld", &K, &A, &B) != EOF){
        if(A>=B) printf("%lld\n", K+1);
        else if(K<=A) printf("%lld\n", K+1);
        // else if((K-A)%2==0)
        else printf("%lld\n", max(K+1, (K-A+1)/2*B-((K-A+1)/2-1)*A+((K-A)%2==0)));
    }

    return 0;
}

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

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

using namespace std;

bool linerSearch(vector<int> vec, int key) {
    rep(i, vec.size()) if (vec[i] == key) return true;
    return false;
}

int main() {
    int n, q, key;
    scanf("%d", &n);
    vector<int> S(n);
    rep(i, n) scanf("%d", &S[i]);

    int ans = 0;
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &key);
        if (linerSearch(S, key)) ++ans;
    }

    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n,i;
  cin >> n;
  ll h[n+4];
  for(i=0;i<n;i++) cin >> h[i];

  ll answer = 0;
  ll tmp = 0;

  for(i=0;i<n-1;i++){
    if(h[i]>=h[i+1]){
      answer++;
    }else if(tmp<answer){
      tmp = answer;
      answer=0;
    }else{
      answer=0;
    }
  }

  if(tmp<answer) cout << answer;
  else cout << tmp;

  return 0;
}


Measured memory_bytes: 1024
n=int(input())
d={}
for x in range(n):
  s=int(input())
  if s in d:
    if d[s]==0:
      d[s]=1
    else:
      d[s]=0
      
  if s not in d:
    d[s]=1
  
ans=0
for y in d:
  if d[y]==1:
    ans+=1
    
print(ans)

Measured memory_bytes: 19328
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	getline(cin, s);
	while(n--){
		getline(cin, s);
		bool accept = false;
		for(int a = 1; !accept; ++a){
			if(a % 2 == 0 || a % 13 == 0){ continue; }
			for(int b = 0; !accept && b < 26; ++b){
				char map[26];
				for(int i = 0; i < 26; ++i){
					map[(i * a + b) % 26] = i + 'a';
				}
				string t = s;
				for(int i = 0; i < t.size(); ++i){
					if(islower(t[i])){ t[i] = map[t[i] - 'a']; }
				}
				bool found_this = (t.find("this") != string::npos);
				bool found_that = (t.find("that") != string::npos);
				if(found_this || found_that){
					s = t;
					accept = true;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
//
//  Watch.c
//  AOJ
//
//  Created by admin on 2014/07/12.
//
//

#include <stdio.h>

main()
{
    int s;
    
    scanf("%d",&s);
    
    int h,m;
    
    h = s/3600;
    s %= 3600;
    m = s/60;
    s %= 60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
    
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  if(n%1000!=0)
  cout<<1000-n%1000<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);
        int x = a.nextInt();
        int y = a.nextInt();
        int z = a.nextInt();

        int Arr[] = {x, y, z};
        Arrays.sort(Arr);
        for (int i = 0; i < 3; i++) {
            if (i == 2){
                System.out.println(Arr[i]);
                break;
            }else{
                System.out.print(Arr[i]);
                System.out.print(" ");
            }
        }
    }
}

Measured memory_bytes: 17332
mnt = int(input())
list_of_heght = [int(i) for i in input().split()]
# 海を見れる旅館の数
num_of_hotel = 1
idx =1
for i in list_of_heght[1:]:
    tmp = list_of_heght[0:idx]
    if max(tmp) <= i:
        num_of_hotel += 1
    idx += 1
print(num_of_hotel)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

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

    bool flag = false;
    vector<int> reserve(1001, 0);

    rep(i,0,n){
        int s,f;
        cin >> s >> f;
        for(int i = s; i <= f; i++){
            reserve[i] = 1;
        }
    }

    rep(i,a,b){
        if(reserve[i] == 1){
           if((i == a && reserve[i+1] == 0) || (i == b && reserve[i-1] == 0)){
               continue;
           }else{
               cout << 1 << endl;
               return 0;
           }
        }
    }

    cout << 0 << endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int N, Q; 
vector<int> a, b; 
vector<int> p, x;
vector<vector<int>> tree;
vector<ll> cnt;
vector<bool> flag;
void dfs(int _p, int count) {
  if(_p != 1) cnt[_p] += count;
  flag[_p] = true;
  for(int i = 0; i < tree[_p].size(); ++i) {
    if(flag[tree[_p][i]] == true) continue;
    dfs(tree[_p][i], cnt[_p]);
  }
}

int main() {
  cin >> N >> Q;
  tree.resize(N + 1);
  a.resize(N - 1); b.resize(N - 1);
  REP(i, N - 1) {
    int A, B; cin >> A >> B;
    tree[A].push_back(B);
    tree[B].push_back(A);
  }
  p.resize(Q); x.resize(Q); REP(i, Q) cin >> p[i] >> x[i];
  cnt.resize(N + 1);
  for(int i = 0; i < Q; ++i) {
    cnt[p[i]] += x[i];
  }
  flag.assign(N + 1, false);
  dfs(1, cnt[1]);
  for(int i = 1; i <= N; ++i) {
    cout << cnt[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 27392
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner n=new Scanner(System.in);
		int a = n.nextInt();
		int b = 1;
		while (a != 0){
			System.out.println("Case "+b+": "+a);
			b++;
			a = n.nextInt();
		}
	}
}

Measured memory_bytes: 33060
#include<stdio.h>

long n;
long A[200000];

/*void bubbleSort(){
  int i, j;
  int tmp;

  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(A[j] < A[j-1]){
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        count++;
      }
    }
  }
}*/
#define LIMIT 200000
#define INFTY 2000000000

long L[LIMIT/2+2], R[LIMIT/2+2];

long merge(long A[], long left, long mid, long right){
  long n1, n2, i, j, k;
  long count = 0;

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY; R[n2] = INFTY;

  i = 0; j = 0;
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
      count += n1 - i;
    }
  }
  return count;
}

long mergeSort(long A[], long left, long right){
  long mid;
  long cnt1, cnt2, cnt3;

  if(left+1 < right){
    mid = (left + right)/2;
    cnt1 = mergeSort(A, left, mid);
    cnt2 = mergeSort(A, mid, right);
    cnt3 = merge(A, left, mid, right);
    return cnt1+cnt2+cnt3;
  }else return 0;
}

int main(){
  long i, count;

  scanf("%ld", &n);
  for(i = 0; i < n; i++){
    scanf("%ld", &A[i]);
  }

  count = mergeSort(A, 0, n);

  printf("%ld\n", count);

  return 0;
}



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

int main() {
    const int num = 1000000;
    vector<int> pnums(num);
    vector<bool> np(num);
    np[0] = np[1] = true;

    for(int i = 2; i < num; ++i) {
        pnums[i] = pnums[i - 1] + !np[i];

        if(!np[i]) {
            for(int j = i; j < num; j += i) {
                np[j] = true;
            }
        }
    }

    for(int n; cin >> n;)
        cout << pnums[n] << endl;

    return 0;
}

Measured memory_bytes: 6560
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[4];
int main() {
	for(int i=0; i<4; i++) cin >> a[i];
	sort(a, a+4);
	cout << (a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9 ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int solve(int n) {
  if (n < 2) {
    return 0;
  }
  return 1 + solve((n + 2) / 3);
}

int main() {
  int N;
  cin >> N;
  int ans = solve(N);
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string ans;
    for(int i=0;i<2*n;i++){
        if(i%2) ans[i]=t[i/2];
        else ans[i]=s[i/2];
    }
     for(int i=0;i<2*n;i++) cout<<ans[i];
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector <int> v(n);
  ffor(n) cin >> v[i];
  sort(v.begin(), v.end());
  vector <int> dp(k + 1, 0); // dp[i] is 1 if winning, 2 if losing, 0 if unknown
  for(auto e: v) {
    dp[e] = 1;
  }
  for(int i = 1; i < v[0]; i++) dp[i] = 2;
  for(int i = 1; i <= k; i++) {
    if (dp[i] != 0) continue;
    bool can_force_loss = false;
    for (auto x: v) {
      if (i - x < 0) break;
      if (dp[i - x] == 2) can_force_loss = true;
    }
    if (can_force_loss) dp[i] = 1;
    else dp[i] = 2;
  }
  if (dp[k] == 1) cout << "First\n";
  else cout << "Second\n";
}

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

int main() {
    int n, a, b;
    int max_n, min_n;
    string s;
    cin >> n >> a >> b;

    if ( a > b){
        max_n = b;
    } else {
        max_n = a;
    }

    int sum;
    sum = a + b - n;
    if ( sum > 0) {
        min_n = sum;
    } else {
        min_n = 0;
    }

    cout << max_n << " " << min_n << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

m, d = na()

cur_m = 1
cur_d = 1
ans = 0
while cur_m // (m + 1) != 1:
    while cur_d // (d + 1) != 1:
        if cur_d % 10 >= 2 and cur_d // 10 >= 2:
            ans += ((cur_d % 10) * (cur_d // 10)) == cur_m
        cur_d += 1
    cur_d = 1
    cur_m += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define PI 3.14159265358979323846
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin>>s;
    if(s=="SUN") cout<<7;
    else if(s=="MON") cout<<6;
    else if(s=="TUE") cout<<5;
    else if(s=="WED") cout<<4;
    else if(s=="THU") cout<<3;
    else if(s=="FRI") cout<<2;
    else if(s=="SAT") cout<<1;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s1 = in.nextString();
            String s2 = in.nextString();

            int n = s1.length() + s2.length();
            String ans = "";
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    ans += s1.charAt(i / 2);
                } else {
                    ans += s2.charAt(i / 2);
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader in;
        private StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define int long long int
   int n,k;
   vector<int> a,b;
  
   int good(int x)
   {
   	int change=0;
   	for(int i=0;i<n;i++)
   	{
   		if(a[i]*b[i]>x)
   		{
 		   change+=(a[i]-x/b[i]);
   		}
   	}

   	return change;
   }

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
     cin>>n>>k;
     a.resize(n);
     b.resize(n);
    for(int i=0;i<n;i++)
    	cin>>a[i];
    for(int i=0;i<n;i++)
    	cin>>b[i];
    sort(a.begin(),a.end(),greater<int>());
    sort(b.begin(),b.end());
    int lo=0,hi=1000000000010;
    int ans=0;
    while(lo<hi)

    {
    	int mid=(hi+lo)/2;
    	if(good(mid)<=k)
    	{
    		ans=mid;
    		hi=mid;
    	}
    	else
    		lo=mid+1;
    }

    cout<<ans;


   }



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

int main(){
  int x;
  cin >>x;
  int hund=x/100, ten=x%100;
  if(hund*5>=ten) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256