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

bool change(string *s, int x, int y){
  //  std::cout << x << " " << y << std::endl;
  if(s[y][x] != s[y][x + 1]){
    char tmp = s[y][x];
    s[y][x] = s[y][x + 1];
    s[y][x + 1] = tmp;
    return true;
  }
  return false;
}

void drop(string *s, int w, int h){
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = h - 1; k > i ; k--) {
        if(s[k][j] == '.'){
          char tmp = s[k][j];
          s[k][j] = s[k - 1][j];
          s[k - 1][j] = tmp;
        }
      }
    }
  }
}
bool erace(string *s, int w, int h, int n){
  int count;
  int mark[h][w];
  memset(mark, 0,sizeof(mark));
  char prev;
  bool res = false;
  for (int i = 0; i < h; i++) {
    count = 1;
    prev = s[i][0];
    for (int j = 1; j <= w; j++) {
      if(j < w && prev == s[i][j] && prev != '.'){
        count++;
      }else{
        if(count >= n){
          for (int k = 1; k <= count; k++)
            mark[i][j - k] = 1;
        }
        count = 1;
        if(j < w)prev = s[i][j];
      }
    }
  }
  for (int i = 0; i < w; i++){
    count = 1;
    prev = s[0][i];
    for (int j = 1; j <= h; j++){
      if(j < h && prev == s[j][i] && prev != '.'){
        count++;
      }else{
        if(count >= n){
          for (int k = 1; k <= count; k++) 
            mark[j - k][i] = 1;
        }
        count = 1;
        if(j < h)prev = s[j][i];
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if(mark[i][j] == 1){
        res = true;
        s[i][j] = '.';
      }
    }
  }
  return res;
}

int main(){
  int n, h, w;
  cin >> h >> w >> n;
  string s[40];
  for (int i = 0; i < h; i++){
    cin >> s[i];
  }
  string tmp[40];
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w - 1; j++){
      for (int k = 0; k < h; k++) {
        tmp[k] = s[k];
      }
      if(change(tmp, j, i)){
        drop(tmp, w, h);
        while(erace(tmp, w, h, n)){
          drop(tmp, w, h);
        }
        // std::cout << "after drop" << std::endl;
        // for (int i = 0; i < h; i++) {
        //   std::cout << tmp[i] << std::endl;
        // }
        // std::cout << std::endl;
        int flag = 1;
        for (int y = 0; y < h; y++) {
          for (int x = 0; x < w; x++) {
            if(tmp[y][x] != '.'){
              flag = 0;
            }
          }
        }
        if(flag){
          std::cout << "YES" << std::endl;
          return 0;
        }
      }
    }
  }
  std::cout << "NO" << std::endl;
  return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  for(int i = 0;;i++){
	if(N >= pow(K, i-1) && N < pow(K, i)){
      ans = i;
      break;
    }
  }
  
  cout << ans;
  return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int H = 4, W = 4;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

int run(VVI xs, const vector<int>& ps){
  int res = 1;
  for(;res<6;++res){
	PII p(ps[res-1]%W, ps[res-1]/W);
	xs[p.SS][p.FF]++;
	if(xs[p.SS][p.FF] < 5) continue;
	xs[p.SS][p.FF] = 0;
	
	int crt = 0, nxt = 1;
	queue<pair<PII,int>> q[2];
	REP(d,4)
	  q[crt].push(MP(p, d));
	while(!q[crt].empty()){
	  while(!q[crt].empty()){
		auto p = q[crt].front();
		q[crt].pop();
		PII np(p.FF.FF + dx[p.SS], p.FF.SS + dy[p.SS]);
		if(np.FF < 0 || W <= np.FF || np.SS < 0 || H <= np.SS)
		  continue;
		if(xs[np.SS][np.FF] == 0){
		  q[nxt].push(MP(np, p.SS));
		}
		else{
		  xs[np.SS][np.FF]++;
		}
	  }
	  REP(y,H) REP(x,W)
		if(xs[y][x] >= 5){
		  xs[y][x] = 0;
		  REP(d,4)
			q[nxt].push(MP(MP(x,y), d));
		}

	  swap(crt, nxt);
	}

	bool done = true;
	REP(y,H) REP(x,W)
	  if(xs[y][x])
		done = false;
	if(done) break;
  }

  return res;
}

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

  bool done = true;
  VVI xs(H, VI(W));
  REP(y,H) REP(x,W){
	cin >> xs[y][x];
	done = done && !xs[y][x];
  }
  if(done){
	cout << 0 << endl;
	return 0;
  }

  int ans = 6;
  REP(a,16) REP(b,16) REP(c,16) REP(d,16) REP(e,16){
	mini(ans, run(xs, {a,b,c,d,e}));
  }
  cout << (ans>5?-1:ans) << endl;

  return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<string>
using namespace std;
int main () {
  int N;
  cin >> N;
  string A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  for (int i = 0; i < N; i ++) {
    int p = 2;
    if (A[i] == B[i]) p --;
    if (B[i] == C[i]) p --;
    if (p && A[i] == C[i]) p --;
    ans += p;
  }
  cout << ans << endl;
}

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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N;
set<int>st;

int main() {
	cin >> N;
	while (N--) {
		int a;
		cin >> a;
		if (!st.insert(a).second) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}

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

typedef long long ll;
typedef long double ld;

map <string, bool> ima;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    string s1;
    cin >> s1;
    int x = s1.size();
    char c = s1[x-1];
    ima[s1] = 1;
    n--;
    while(n--){
        string s;
        cin >> s;
        if(ima[s]){cout << "No"; return 0;}
        if(s[0] != c){cout << "No"; return 0;}
        int x = s.size();
        c = s[x-1];
        ima[s] = 1;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin >> q;
  vector<pair<int,int> >p(q);
  int l,r;
  int i,j;
  for(i=0;i<q;i++){
    cin >> l >> r;
    p[i] = make_pair(l,r);
  }
  vector<int>sosu;
  sosu.push_back(2);
  int chk = 0;
  for(i=3;i<100000;i++){
    chk = 1;
    for(j=0;j<sosu.size()&&sosu[j]<=sqrt(i);j++){
      if(i%sosu[j]==0){
        chk=0;
        break;
      }
    }
    if(chk==1)sosu.push_back(i);
  }
  vector<int>sosuu(100001,0);
  for(i=0;i<sosu.size();i++){
    sosuu[sosu[i]]=1;
  }
  vector<int>alike(100001,0);
  for(i=3;i<=100000;i+=2){
    if(sosuu[i]==1 && sosuu[(i+1)/2]==1)alike[i]=1;
  }
  vector<int>wa(100001,0);
  for(i=2;i<100000;i++){
    wa[i] = wa[i-1] + alike[i];
  }
  for(i=0;i<q;i++){
    cout << wa[p[i].second]-wa[p[i].first-1] << endl;
  }


}


Measured memory_bytes: 2688
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b, x;
	
	cin >> x >> a >> b;
	
	if (abs(x - a) > abs(x - b)) {
		cout << "B" << endl;
	}
	else {
		cout << "A" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,ans;
int main()
{
	scanf("%d",&n);
	if(n == 1) printf("1");
	else {
		for(int i=1;i<=n;i++)
		{
			if(pow(2,i)>n) break;
			else ans = pow(2,i);
		}
		printf("%d",ans);
	}
	printf("\n");
	return 0;
}

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

void solve() {
  cout << setprecision(10);
  long long H,W;
  cin >> H >> W;
  if(H%3 == 0 || W%3==0){
    cout << 0 << endl;
    return;
  }
 
  // H方向
  long long min_val = H*W;
  long long S_max, S_min;
  long long S1,S2,S3;
  for(long long i = 1; i < W; i++){
    S1 = H * i;
    S2 = (H/2) * (W - i); 
    S3 = H * W - S1 - S2;
 
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
 
    min_val = min(min_val, S_max - S_min);
 
    S1 = H * i;
    S2 = H * ( (W - i) / 2 );
    S3 = H * W - S1 - S2;
 
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
 
    min_val = min(min_val, S_max - S_min);
 
  }
 
  for(long long i = 1; i < H; i++){
    S1 = W * i;
    S2 = (W/2) * (H - i); 
    S3 = H * W - S1 - S2;
 
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
 
    min_val = min(min_val, S_max - S_min);
 
    S1 = W * i;
    S2 = W * ( (H - i) / 2 ); 
    S3 = H * W - S1 - S2;
 
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
 
    min_val = min(min_val, S_max - S_min);
  }
 
  cout << min_val << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
 }


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

long long extgcd(long long a, long long b, long long &x, long long &y) {
    for (long long u = y = 1, v = x = 0; a; ) {
        long long q = b / a;
        swap(x -= q * u, u);
        swap(y -= q * v, v);
        swap(b -= q * a, a);
    }
    return b;
}

pair<long long, long long> chinese_rem(vector<long long> b, vector<long long> m) {
    long long r = 0, M = 1;
    for (int i = 0; i < (int)b.size(); i++) {
        long long p, q, d = extgcd(M, m[i], p, q);
        if ((b[i] - r) % d != 0) return {0, -1};
        r += (b[i] - r) / d * p % (m[i] / d) * M;
        M *= m[i] / d;
    }
    return {(r % M + M) % M, M};
}

int main() {
    int N, M, D; cin >> N >> M >> D;
    vector<long long> a(M);
    for (auto &ai: a) cin >> ai;
    bool ng = false;
    while (D--) {
        vector<long long> b, m;
        for (int i = 0; i < M; i++) {
            int r; cin >> r;
            if (r != -1) b.emplace_back(r), m.emplace_back(a[i]);
        }
        if (ng || b.empty()) continue;
        auto crt = chinese_rem(b, m);
        if (crt.second == -1 || N < crt.first) {
            ng = true;
        } else {
            N = N - (N - crt.first) % crt.second;
        }
    }
    cout << (ng ? -1 : N) << endl;
    return 0;
}



Measured memory_bytes: 3168
from itertools import permutations
n,m = map(int,input().split())
path = [[False] * n for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    path[a-1][b-1] = True
    path[b-1][a-1] = True
ans = 0
for ss in permutations(range(n)):
    s = list(ss)
    key = 1
    if s[0] != 0:
        key = 0
    for i in range(n-1):
        if path[s[i]][s[i+1]] == False:
            key = 0
    if key:
        ans += 1
print(ans)

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

int main(){
  long long x;
  cin >> x;
  
  long long gohyaku = x / 500;
  long long go = (x - gohyaku * 500) / 5;
  
  //cout << "500 * " << gohyaku << endl;
  //cout << "5 * " << go << endl;
  
  cout << gohyaku * 1000 + go * 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
typedef long double ld;
ll a[30];
ld p[30];
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(x%y,y);
}
int main(){
	cout.precision(20);
	ll i,j,n,m;
	ld ans = 0;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		ll x; cin >> x;
		p[i] = (ld)x/(ld)100;
	}
	for(i=1;i<(1<<n);i++){
		ll s = -1,lcm = 1;
		ld pp = 1;
		for(j=0;j<n;j++){
			if(1<<j & i){
				pp *= p[j]; s *= -1;
				ll b = (a[j]/gcd(lcm,a[j]));
				if((ld)lcm*(ld)b>(ld)m){
					lcm = m + 1;
					break;
				}
				lcm *= b;
			}
		}
		ll val = s*(m/lcm);
		ans += pp*(ld)val;
	}
	cout << ans << endl;
}


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

const int maxn = int(4e4) + 7, mod = int(1e9) + 7;
typedef long long ll;
ll fac[maxn], inv[maxn];

ll power_mod(ll p, ll q) {
    ll ret = 1;
    while (q) {
        if (q & 1) ret = ret * p % mod;
        p = p * p % mod;
        q >>= 1;
    }
    return ret;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxn - 10; ++i) fac[i] = fac[i - 1] * i % mod;
    inv[maxn - 10] = power_mod(fac[maxn - 10], mod - 2);
    for (int i = maxn - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(int x, int y) {
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int n, a[2000007], b[2000007], dp[4007][4007];

int main() {
//    freopen("in.txt", "r", stdin);
    init();
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", a + i, b + i);
        dp[2001 - a[i]][2001 - b[i]]++;
    }
    for (int i = 1; i <= 4001; i++)
        for (int j = 1; j <= 4001; j++) {
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
    ll ans = 0;
    for (int i = 1; i <= n; i++) ans = (ans + dp[2001 + a[i]][2001 + b[i]]) % mod;
    for (int i = 1; i <= n; i++) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod;
    printf("%lld\n", ans * power_mod(2, mod - 2) % mod);
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            Console.WriteLine((A + B) % 24);


        }
    }
}


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

class DisjointSet {
public:
    std::vector<int> rank, p; //p: parent
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

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

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }

    //find parent (represtator) of x set
    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

class Edge {
public:
    int source, target, cost;
    Edge (int source = 0, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};

int kruskal(int N, std::vector<Edge> edges) {
    int totalCost = 0;
    std::sort(edges.begin(), edges.end());

    DisjointSet dset = DisjointSet(N+1);

    for (int i = 0; i < N; i++) dset.makeSet(i);

    for (int i = 0; i < edges.size(); i++) {
        Edge e = edges[i];
        if (!dset.same (e.source, e.target)) {
            totalCost += e.cost;
            dset.unite(e.source, e.target);
        }
    }

    return totalCost;

}



int main()
{

    int N, M;
    int source, target, cost;
    std::vector<Edge> edges;

    std::scanf("%d %d", &N, &M);

    for (int i = 0; i < M; i++) {
        std::scanf("%d %d %d", &source, &target, &cost);
        edges.push_back(Edge(source, target, cost));
    }

    std::cout << kruskal(N, edges) << std::endl;

    return 0;
}



Measured memory_bytes: 5488
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ld = long double;
const ld pi = acos(-1);

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    vector<int> dist(n, INF);
    dist[0] = 0;
    vector<int> pre(n, -1);
    queue<P> que;
    que.push(P(0, 0));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int d = p.first, from = p.second;
        if(d > dist[from])  continue;
        for(int to : graph[from]){
            if(dist[to] > dist[from] + 1){
                dist[to] = dist[from] + 1;
                pre[to] = from;
                que.push(P(dist[to], to));
            }
        }
    }
    
    cout << "Yes\n";
    for(int i = 1; i < n; ++i)  cout << pre[i] + 1 << '\n';
}

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

using namespace std;

long long INF = 1000000000000000000;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << '\n';
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] > (INF / ans)) {
            cout << -1 << '\n';
            return 0;
        } else {
            ans *= a[i];
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3940
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

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

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

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

void solve(long long N, long long X, std::vector<long long> L) {
  int pos=0;
  int ans=1;
  REP(i, N){
    pos += L[i];
    if(pos<=X)ans++;
  }
  cout<<ans<<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  std::vector<long long> L(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &L[i]);
  }
  solve(N, X, std::move(L));
  return 0;
}


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

int main(){
    // input
    int N;
    cin >> N;
    vector<long> H(N);
    for( int i=0; i<N; i++ ){
        cin >> H[i];
    }

    // calc position
    int best_posi   = 0;
    int lower_count = 0;
    int lower_max   = 0;
    for( int i=1; i<N; i++ ){
        if( H[i] <= H[i-1] ){
            lower_count++;
        }else{
            if( lower_max < lower_count ){
                lower_max = lower_count;
            }
            lower_count = 0;
        }
    }
    if( lower_max < lower_count ){
        lower_max = lower_count;
    }
    
    // out
    cout << lower_max << endl;
} 

Measured memory_bytes: 1024
mod = 10**9+7
def fur(n,r,mod):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod

n,a,b = map(int,input().split())

Sum = pow(2,n,mod) - 1

Sum %= mod

Sum -= fur(n,a,mod) % mod
Sum -= fur(n,b,mod) % mod
Sum %= mod
print(Sum)

Measured memory_bytes: 3064
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

#nCrをmodで割った余りを求める。Nに最大値を入れて使用。
N = 3*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
def cmb(n,r,mod=998244353):
    if r<0 or r>n :
        return 0
    r = min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod
for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod % i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

def main():
    ans = 0
    n,a,b,k = map(int,ipt().split())
    for xa in range(n+1):
        if (k-a*xa)%b == 0:
            xb = (k-a*xa)//b
            if 0 <= xb <= n:
                ans += cmb(n,xa)*cmb(n,xb)

    print(ans%mod)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 136568
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    ll N;
    string S;
    cin >> N >> S;

    vector<ll> w(N+1), b(N+1);
    w[0] = 0; b[0] = 0;

    int numw = 0, numb = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') {
            numw++;
        }else {
            numb++;
        }
        w[i+1] = numw;
        b[i+1] = numb;
    }

    // for (int i = 0; i < N+1; i++) {
    //     cout << w[i] << " " << b[i] << endl;
    // }

    ll ans = N;
    for (int i = 0; i < N+1; i++) {
        ans = min(ans, w[N]-w[i]+b[i]);
    }

    cout << ans << endl;


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    rep(i,N) a[i]--;
    vector<int> idx(N);
    rep(i,N) idx[a[i]] = i;
    set<int> s;
    ll ans = 0;
    for(int x=N-1;x>=0;x--){
        //数字の位置を大きい順にsetに詰めていく
        int i=idx[x];
        ll c=0;
        s.insert(i);
        //自分よりでかい数の位置２つを双方向で求める
        vector<int> l(2,-1);
        vector<int> r(2,N);
        // calc l
        auto it=s.find(i);
        rep(j,2){
            if(it==s.begin()) break; 
            //--itを先にやると最初の要素でブレイクしてしまう
            --it; 
            l[j]=*it;
        }
        // calc r
        it=s.find(i);
        rep(j,2){
            ++it;
            if(it==s.end()) break;
            r[j]=*it;
        }
        vector<int> ls(2);
        ls[0] = i-l[0]; ls[1] = l[0]-l[1];
        vector<int> rs(2);
        rs[0] = r[0]-i; rs[1] = r[1]-r[0];
        c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];
        ans+=c*(x+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
from heapq import heappush, heappop


def solve_d(n, l_list):
    res = 0
    l_list_s = sorted(l_list)
    h = []
    for i in range(1, n - 1):
        for j in range(0, i):
            heappush(h, l_list_s[i] + l_list_s[j])
        while len(h) > 0:
            a = heappop(h)
            if a > l_list_s[i + 1]:
                heappush(h, a)
                break
        res += len(h)

    return res


def main():
    n = int(input())
    l_list = list(map(int, input().split()))
    res = solve_d(n, l_list)
    print(res)


def test():
    assert solve_d(4, [3, 4, 2, 1]) == 1
    assert solve_d(3, [1, 1000, 1]) == 0
    assert solve_d(7, [218, 786, 704, 233, 645, 728, 389]) == 23


if __name__ == "__main__":
    test()
    main()


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

int main()
{
    ll n,w;
    cin>>n>>w;

    ll arr[n+1][2];
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
    }

    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++)    dp[i][0] = 0;
    for(ll i=0;i<=w;i++)    dp[0][i] = 0;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=w;j++)
        {
            dp[i][j] = dp[i-1][j];
            if((j-arr[i][0])>=0)
                dp[i][j] = max(dp[i][j],dp[i-1][j-arr[i][0]] + arr[i][1]);
        }
    }

    cout<<dp[n][w];
    return 0;
}


Measured memory_bytes: 79104
n = int(input())
L = [int(x) for x in input().split()]
n = int(input())
for _ in range(n):
    b, e, t = [int(x) for x in input().split()]
    L[b:e], L[t:t+e-b] = L[t:t+e-b], L[b:e]
print(*L)



Measured memory_bytes: 5836
/* created   : 2019-08-11 23:31:37
 * accepted  : 2019-08-12 23:52:16
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      cnt++;
    }
    else {
      ans[i] += cnt / 2;
      ans[i - 1] += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  assert(cnt == 0);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'L') {
      cnt++;
    }
    else {
      ans[i] += cnt / 2;
      ans[i + 1] += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << (i == n - 1 ? "\n" : " ");
  }
}

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


Measured memory_bytes: 1104
N,K = map(int, input().split())
A_list = list(map(int, input().split()))

for i in range(N-K):
  #print(i,K+i)
  #print(A_list[i],A_list[K+i])
  if(A_list[i]<A_list[K+i]):
    print("Yes")
  else:
    print("No")

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

int main() {
  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;

  int a = 0, b = 0, c = 0;
  char next = 'a';
  while (true) {
    if (next == 'a' && a == Sa.length()) {
      puts("A");
      return 0;
    }
    if (next == 'b' && b == Sb.length()) {
      puts("B");
      return 0;
    }
    if (next == 'c' && c == Sc.length()) {
      puts("C");
      return 0;
    }
    if (next == 'a') {
      next = Sa[a++];
    } else if (next == 'b') {
      next = Sb[b++];
    } else if (next == 'c') {
      next = Sc[c++];
    } else {
      puts("error");
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int main(){
//  ios::sync_with_stdio(false);
//  cin.tie(0);
  int n;
  string a,b,c;
  cin >>n>>a>>b>>c;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i] && b[i] == c[i]) continue;
    else if (a[i] == b[i] || a[i] == c[i] || b[i] == c[i]) ans++;
    else ans += 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<double> cmplx;
const double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = (int)1e+9 + 7;
const double eps = 1e-8;
const int N = 500'000;

int n, m, k;
int a[500][500];

struct xxx{
    int a, b, c, d;
};

void solve()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    vector<xxx> ans;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] & 1) {
                ans.push_back({i, j, i + 1, j});
                ++a[i + 1][j];
            }
        }
    }
    for (int i = 0; i < m - 1; ++i) {
        if (a[n - 1][i] & 1) { 
            ++a[n - 1][i + 1];
            ans.push_back({n - 1, i, n - 1, i + 1});
        }
    }
    cout << ans.size() << '\n';
    for (auto&& p : ans) {
        cout << p.a + 1 << ' ' << p.b + 1 << ' '
            << p.c + 1 << ' ' << p.d + 1 << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int test = 1;
    //cin >> test;
    for (; test; --test)
        solve();
    return 0;
}


Measured memory_bytes: 5232
#include<stdio.h>

void BubbleSort(int* data)
{
	int i, j;

	for(i = 0; i < 9; ++i)
	{
		for(j = 9; j > i; --j)
		{
			if(data[j - 1] < data[j])
			{
				int temp;
				temp = data[j];
				data[j] = data[j - 1];
				data[j - 1] = temp;
			}
		}
	}

	return ;
}

int main(void)
{
	int i, data[10];

	for(i = 0; i < 10; ++i)
	{
		scanf("%d", &data[i]);
	}
	
	BubbleSort(data);

	for(i = 0; i < 3; ++i)
	{
		printf("%d\n", data[i]);
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cmath>
#include <string.h>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	bool fl[1000001];
	memset(fl, true, sizeof(fl));
	for (int i = 2; i <= sqrt(num); i++) {
		if (fl[i]) {
			for (int j = 2; j*i <= num; j++) {
				fl[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= num; i++) {
		if (fl[i]) {
			count++;
		}
	}
	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

Measured memory_bytes: 4052
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(arr[k - 1])

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < 4; i++) {
            if(s[i] == '+') ans++;
            else ans--;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35476
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String strIn = new String(in.readLine());
		String[] strArray = strIn.split(" ", 2);
		int a = Integer.parseInt(strArray[0]), b = Integer.parseInt(strArray[1]);
		if(a < 1 || a > 100) {
			return;
		}
		if(b < 1 || b > 100) {
			return;
		}
		System.out.println((a * b) + " " + ((a + b) * 2));

	}

}



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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll N, ll M, ll K) {
  bool ans = false;

  rep(i, N + 1) {
    rep(j, M + 1) {
      if (M * i + N * j - 2 * i * j == K) ans = true;
    }
  }

  yesOrNo(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  ll K;
  scanf("%lld", &K);
  solve(N, M, K);
  return 0;
}


Measured memory_bytes: 3716
N=gets.to_i
R=N.times.map { gets.to_i }

maxv=-1000000000
minv=R[0]

for j in 1..N-1 do
  maxv = R[j]-minv if R[j]-minv>maxv
  minv = R[j] if R[j] < minv
end

p maxv



Measured memory_bytes: 8904
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

cookies = np.array(lr())
if any(cookies&1):
    print(0)
    exit()
if len(set(cookies)) == 1:
    print(-1)
    exit()

count = 0
half_total = cookies.sum() // 2
while True:
    cookies = half_total - cookies//2
    count += 1
    if any(cookies&1):
        print(count)
        break
    if count == 1000000:
        print(-1)
        exit()


Measured memory_bytes: 14512
N = int(input())
import math

num2alpha = lambda c: chr(c)
tmp_N = N
result = ''
while (tmp_N / 26) > 1.0:
    k = int(tmp_N / 26)
    res = tmp_N % 26
    if res == 0:
        res = 26
        k -= 1
    result += num2alpha(res+64).lower()
    tmp_N = k
res = tmp_N % 26
if res == 0:
    res = 26
    k -= 1
result += num2alpha(res+64).lower()
new_str = ''.join(list(reversed(result)))
print(new_str)

Measured memory_bytes: 9196
n=int(input())
l=list(map(int,input().split()))
dp=[0 for _ in range(n)]
dp[1]=abs(l[1]-l[0])

for i in range(2,n):
    single=abs(l[i]-l[i-1])+dp[i-1]
    double=abs(l[i]-l[i-2])+dp[i-2]
    dp[i]=min(single,double)

print(dp[n-1])

Measured memory_bytes: 52720
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef long double float128;
const ll is_query = -(1LL<<62), inf = 1e18;
struct Line
{
    ll m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const
    {
        if (rhs.b != is_query) return m < rhs.m;
        const Line* s = succ();
        if (!s)  return 0;
        ll x = rhs.m;
        return b - s->b < (s->m - m) * x;
    }
};

struct HullDynamic : public multiset<Line> // // will maintain lower hull for minimum/maximum
{
    bool bad(iterator y)
    {
        auto z = next(y);
        if (y == begin())
        {
            if (z == end())       return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m && y->b <= x->b;
        return (float128)(x->b - y->b)*(z->m - y->m) >= (float128)(y->b - z->b)*(y->m - x->m);
    }
    void add_line(ll m, ll b)
    {
        auto y = insert({ -m, -b });   // For minimum
//        auto y = insert({ m, b });       // For maximum
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if (bad(y))
        {
            erase(y); return;
        }
        while (next(y) != end() && bad(next(y)))    erase(next(y));
        while (y != begin() && bad(prev(y)))        erase(prev(y));
    }

    ll getbest(ll x)
    {
        auto l = *lower_bound((Line)
        {
            x, is_query
        });
        return -(l.m * x + l.b);  // For minimum
//        return (l.m * x + l.b);     // For maximum
    }
} st;

const int MX=200000;
ll h[MX], dp[MX];

int main()
{
    FasterIO;
    ll n, c;
    cin>>n>>c;
    for(int i=0; i<n; i++) cin>>h[i];
    st.add_line(-2*h[0], h[0]*h[0]);
    for(int i=1; i<n; i++)
    {
        dp[i]=st.getbest(h[i])+c+h[i]*h[i];
//        st.add_line(-x[i],dp[i]); // for maximum
       st.add_line(-2*h[i],h[i]*h[i]+dp[i]); // for minimum
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

int main () {

    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A + 3, greater<int>());

    cout << 10 * A[0] + A[1] + A[2] << endl;

    return 0;
}

Measured memory_bytes: 256
str0=input()
q=int(input())
for i in range(q):
  ord=input()
  if "print" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    print(str0[a:b+1])
  if "replace" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    str0=str0[0:a]+buff[3]+str0[b+1:]
  if "reverse" in ord:
    buff=ord.split()
    a=int(buff[1])
    b=int(buff[2])
    tmp=str0[a:b+1]
    str0=str0[0:a]+''.join(list(reversed(tmp)))+str0[b+1:]



Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <set>
#include <unordered_map>
#include <vector>

int black[2 * 100000 + 2];
int white[2 * 100000 + 2];

int main(){
  std::string s;
  black[0] = 0;
  white[0] = 0;
  int dummy;
  std::cin >> dummy;
  std::cin >> s;
  for(int i = 1; i <= s.length(); i++){
    black[i] = black[i - 1];
    white[i] = white[i - 1];
    if(s[i - 1] == '#') black[i]++;
    if(s[i - 1] == '.') white[i]++;
  }
    black[s.length() + 1] = black[s.length()];
    white[s.length() + 1] = white[s.length()];
  int min_sum = 2 * 100000 + 2;
  for(int i = 0; i <= s.length(); i++){
    int tmp = black[i] + (white[s.length()] - white[i]);
    if(min_sum > tmp) min_sum = tmp;
  }
  std::cout << min_sum << std::endl;

}


Measured memory_bytes: 2180
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
char s[8];
int hoge(void){
  return (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
}
int sort(void){
  char temp;
  for(int i = 0;i < 3; i++){
    for(int j = 3;j > i; j--){
      if (s[j] > s[j-1]){
	temp = s[j];
	s[j] = s[j-1];
	s[j-1] = temp;
      }
    }
  }
  return hoge();
}
int reverse(void){
  char temp;
  temp = s[0]; s[0] = s[3]; s[3] = temp;
  temp = s[1]; s[1] = s[2]; s[2] = temp;
  return hoge();
}
int main(void){
  int n,ans;
  for( ; ; ){
    cin >> s;
    if(s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0') break;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
      cout << "NA" << endl;
      continue;
    }
    ans = 0;
    n = atoi(s);
    for( ; ; ){
      if(strlen(s) < 4){
	for(int i = strlen(s);i < 4; i++) s[i] = '0';
	s[4] = '\0';
      }
      if(n == 6174){
	cout << ans << endl;
	break;
      }
      n = sort() - reverse();
      sprintf(s,"%d",n);
      ans++;
    }
  }
}


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

#define _max(_x, _y) ((_x)>(_y)?(_x):(_y))

int main(void)
{
  char S[101], T[101];
  long A, B, K;
  long Ax, Bx;
  scanf("%ld %ld %ld", &A, &B, &K);
  Ax = _max(A - K, 0);
  Bx = _max(B - _max(K - A, 0), 0);
  printf("%ld %ld\n", Ax, Bx);
  
return 0;
}

Measured memory_bytes: 128
import string
s=input()
n=len(s)
l=string.ascii_lowercase
if n<26:
    for c in l:
        if c not in s:
            print(s+c)
            exit()
elif s==l[::-1]:
    print(-1)
    exit()
else:
    for i in range(24,-1,-1):
        for j in range(25,i,-1):
            if s[i]<s[j]:
                print(s[:i]+s[j])
                exit()

Measured memory_bytes: 3892
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = [0,0,0]
    ans = 1
    for i in a:
        ans *= d.count(i)
        ans %= mod
        if ans == 0:
            break
        for j in range(3):
            if d[j] == i:
                d[j] += 1
                break
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 54172
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner i=new Scanner(System.in);
		int n=i.nextInt();
		int[] a=new int[n+1];
		for(int s=0;s<n;s++){
			a[s]=i.nextInt();
		}
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		long gt=0;
		for(int s=0;s<n;s++){
			if(min>a[s]){min=a[s];}
			if(max<a[s]){max=a[s];}
			gt+=a[s];
		}
		System.out.println(min+" "+max+" "+gt);
	}
}

Measured memory_bytes: 31700
#include <iostream>
#include <vector>
#include <map>
// #include <string>
// #include <algorithm>
// #include <set>
// #include <cmath>

using namespace std;
typedef unsigned long long ull;


template<typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m) {
    os << "{";
    for (const auto x : m) {
        os << x.first << ":" << x.second << " ";
    }
    os << "}";
    return os;
}


int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    map<int, int> M;
    for (int i = 0; i < N; i++) {
        auto iter = M.find(A[i]);
        if (iter == M.end()) {
            M[A[i]] = 1;
        } else {
            M[A[i]] += 1;
        }
    }
    // cout << M << endl;

    int count = 0;
    int n_2 = 0;
    for (auto item : M) {
        if (item.second % 2 == 0) {
            count += (item.second - 2) / 2;
            n_2 += 1;
        } else {
            count += (item.second - 1) / 2;
        }
    }
    count += (n_2 + 1) / 2;

    cout << N - count*2 << endl;

    return 0;
}


Measured memory_bytes: 5376
def mod_inv(a, m):
    return pow(a,m-2,m)


X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

if (X + Y) % 3:
    print(0)
    exit()

n = (X + Y) // 3
nx, ny = X - n, Y - n

if nx < 0 or ny < 0:
    print(0)
    exit()

ans = 1
for i in range(1, nx + ny + 1):
    ans = ans * i % MOD
for i in range(1, nx + 1):
    ans = ans * mod_inv(i, MOD) % MOD
for i in range(1, ny + 1):
    ans = ans * mod_inv(i, MOD) % MOD

print(ans)

Measured memory_bytes: 40540
package main

import (
	"fmt"
)

func main() {

	var n string
	fmt.Scan(&n)

	if string(n[0]) == "1" {
		fmt.Print(9)
	} else if string(n[0]) == "9" {
		fmt.Print(1)
	} else {
		fmt.Print(string(n[0]))
	}

	if string(n[1]) == "1" {
		fmt.Print(9)
	} else if string(n[1]) == "9" {
		fmt.Print(1)
	} else {
		fmt.Print(string(n[1]))
	}

	if string(n[2]) == "1" {
		fmt.Print(9)
	} else if string(n[2]) == "9" {
		fmt.Print(1)
	} else {
		fmt.Print(string(n[2]))
	}
}


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


int main(){
    string a,b,c;
    cin >> a >> b >> c;
    locale l = locale::classic();
    cout << toupper(a[0],l) << toupper(b[0],l)<< toupper(c[0],l) << endl;
}

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

int calcDef(int a, int b){
  if(a > b){
    return a-b;
  }else{
    return b-a;
  }
}

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

  if(calcDef(a,x) > calcDef(b,x)){
    cout << "B" << endl;
  }else{
    cout << "A" << endl;
  }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let A: u8 = read();
    let B: u8 = read();
    let C: u8 = read();
    let mut vec = vec![A, B, C];
    vec.sort();
    if (A == B && B == C && A == C) || (A != B && B != C && C != A) {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
x,y=map(int,input().split())

def main():
    if 0<=(y/2 -x)<=x:
        if y==0 or x==0:
            return 'No'
        if (y/2 -x)%1==0:
            return('Yes')
        else:
            return('No')
    else:
        return('No')
print(main())



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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    int a[310][310];
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) cin >> a[i][j];

    int ans = n;
    vector<bool> used(m,false);
    for (int z = 0;z < m;++z) {
        vector<int> cnt(m,0);
        for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (!used[a[i][j]-1]) {
            cnt[a[i][j]-1]++;
            break;
        }
        int k = 0;
        for (int i = 0;i < m;++i) if (cnt[i] > cnt[k]) k = i;
        ans = min(ans,cnt[k]);
        used[k] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640