akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int n;cin>>n;
  vi h(n);
  rep(i,n)cin>>h[i];

  int ans=0;
  int max=0;
  rep(i,n){
    if(max<h[i])max=h[i];
    if(h[i]>=max)ans++;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 125568
A,B = map(int,input().split())
n = min(A//0.08,B//0.1)-1
flag = False
while n*0.1<B+1 and n*0.08<A+1:
    if n*0.08//1 == A and n*0.1//1 == B:
        flag = True
        break
    else:
        n += 1

if flag:
    print(int(n))
else:
    print("-1")

Measured memory_bytes: 3188
a = []
q = int(input())
for i in range(q):
  order = list(input().split())
  if int(order[0]) == 0:
    x = int(order[1])
    a.append(x)
  if int(order[0]) == 1:
    p = int(order[1])
    print(a[p])
  if int(order[0]) == 2:
    del a[len(a)-1]


Measured memory_bytes: 13372
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<queue>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
void pv(int bit,int h,int w){
	rep(i,h)rep(j,w)cerr<<!!(bit&1<<i*w+j)<<(j==w-1?"\n":" ");
}

unsigned char cost[1<<20];
int mask[5][5][6][6];
void gen(){
	memset(cost,-1,sizeof(cost));
	cost[0]=0;
	rep(i,5)rep(j,5)for(int h=1;h<=5-i;h++)for(int w=1;w<=5-j;w++){
		int m=(1<<w)-1;
		rep(k,h)mask[i][j][h][w]^=m<<(i+k)*5+j;
	}
	queue<int> Q; Q.push(0); int cnt=0;
	while(!Q.empty()){
		int c=Q.front(),cc=cost[c]; Q.pop();
		rep(i,4)rep(j,5)for(int h=1;h<=4-i;h++)for(int w=1;w<=5-j;w++){
			int nc=c^mask[i][j][h][w];
			if(cost[nc]>cc+1)cost[nc]=cc+1,Q.push(nc);
		}
	}
}
int lim;
int getcost(int c){
	int ret=cost[c&(1<<20)-1],bit=0;
	for(c>>=20;c;c&=c-1)bit++;
	return ret+min(bit,6-bit);
}
void rec(int c,int x,int cnt){
	if(c>>20==0)lim=min(lim,cost[c]+cnt);
	if(x>=5)return;
	
	rep(i,5)for(int j=x;j<5;j++){
		int nc=c^mask[i][x][5-i][j-x+1];
		if(!(nc&1<<20+x))rec(nc,x+1,cnt+1);
	}
	if(!(c&1<<20+x))rec(c,x+1,cnt);
}
int solve(int c){
	lim=getcost(c);
	rec(c,0,0);
	return lim;
}
int main(){
	gen();
	
	int n,ans;
	while(cin>>n,n){
		int c=0,t;
		rep(i,n)rep(j,n){
			cin>>t;
			if(t)c^=1<<i*5+j;
		}
		ans=n<5?cost[c]:solve(c);
		rep(i,ans)cout<<"myon"; cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4464
from collections import Counter
import sys

N = int(input())
ds = list(map(int,input().split()))
ctr = Counter(ds)
if 0 in ctr:
    print(0)
    sys.exit()

hs = (1 << 24) + 1
undef = []
for d,c in ctr.items():
    if c > 2:
        print(0)
        sys.exit()
    elif c == 2:
        hs |= (1 << d)
        hs |= (1 << (24-d))
    else: #c == 1
        undef.append(d)

ans = 0
for i in range(2**len(undef)):
    _hs = hs
    for j,u in enumerate(undef):
        if (i >> j) & 1:
            _hs |= (1 << u)
        else:
            _hs |= (1 << (24-u))
    min_interval = 24
    prev = 0
    for k in range(1,25):
        if (_hs >> k) & 1 == 0: continue
        min_interval = min(min_interval, k - prev)
        prev = k
    ans = max(ans, min_interval)
print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 18

int dist[1<<N];

int main() {
  int n, t[N][N];
  while(cin >> n && n) {
    rep(i, n) {
      rep(j, n+1) {
        cin >> t[i][j];
      }
    }
    rep(i, (1<<n)) {
      dist[i] = INF;
    }
    pvqueue que;
    rep(i, n) {
      dist[1<<i] = t[i][0];
      que.push(P(dist[1<<i], 1<<i));
    }
    while(!que.empty()) {
      P e = que.top(); que.pop();
      int cost = e.first, v = e.second;
      if(dist[v] < cost) continue;
      rep(i, n) {
        int p = t[i][0];
        if(v & (1 << i)) continue;
        rep(j, n) {
          if(v & (1 << j)) {
            p = mind(p, t[i][j+1]);
          }
        }
        if(dist[v] + p < dist[v | (1 << i)]) {
          dist[v | (1 << i)] = dist[v] + p;
          que.push(P(dist[v] + p, v | (1 << i)));
        }
      }
    }
    cout << dist[(1 << n) - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 2100
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define INF 1e18
    const int mod=1e9+7;
    int cnt=0; 
    signed main() {
 
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   /* #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif
    */
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1;
     //cin>>t;
    while(t--)
    {
      int n,k;
      cin>>n>>k;
      int h[n];
      f(i,0,n)
      {
        cin>>h[i];
      }
      int mi=INF;
      int dp[n];
      f(i,0,n)
      dp[i]=INF;
      dp[0]=0;
      if(k<n)
      {
      f(i,1,k)
      {
        f(j,0,i)
        dp[i]=min(dp[j]+abs(h[j]-h[i]),dp[i]);
      }
      
      f(i,k,n)
      {
        f(j,1,k+1)
        {
          dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]),dp[i]);
        }
      }
    }
    else
    {
      f(i,1,n)
      {
        f(j,0,i)
        dp[i]=min(dp[j]+abs(h[j]-h[i]),dp[i]);
      }
    }
      cout<<dp[n-1]<<endl;
    }
    } 
 

Measured memory_bytes: 1792
class UnionFind
  def initialize
    @parent = Hash.new
    @rank = Hash.new
  end
  def make(x)
    @parent[x] = x
    @rank[x] = 0
  end
  def union(x, y)
    a = find(x)
    b = find(y)
    if @rank[a] > @rank[b]
      @parent[b] = a
    elsif @rank[a] < @rank[b]
      @parent[a] = b
    elsif a != b
      @parent[b] = a
      @rank[a] = @rank[a] + 1
    end
  end
  def find(x)
    @parent[x] == x ? x : @parent[x] = find(@parent[x])
  end
  def size
    @parent.keys.map{|k| find(k)}.sort.uniq.size
  end
end

while gets
  subset = gets.split.map{|d| d.chars.map(&:to_i)}
  disjoint_set = UnionFind.new
  degree = Hash.new{0}

  subset.flatten.sort.uniq.each do |d|
    disjoint_set.make(d)
  end

  subset.each do |d|
    degree[d.first] += 1
    degree[d.last] += 1
    disjoint_set.union(*d)
  end

  puts disjoint_set.size == 1 && degree.select{|k, v| v.odd?}.size <= 2 ? "Yes" : "No"
end

Measured memory_bytes: 6124
L,R = map(int,input().split())
 
x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
print(x)

Measured memory_bytes: 38896
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <utility>
#include <algorithm>

using namespace std;

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

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}
template<typename T> 
void showmatrix(T a){
  for(auto j: a){for(auto i : j){ cout << i; }cout << endl;}
  cout << endl;
}
void check(int i = 0){
  cout << "checkpoint:[" << i << "]" << endl;
}


int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long , long long >> a(n);
  for(auto& i: a){
    cin >> i.first >> i.second;
  }
  auto comp = [](pair<long long, long long>& a, pair<long long, long long>& b){
    return a.first < b.first;
  };
  sort(a.begin(), a.end(), comp);
  long long res = 0l;
  
  for(int i =0;i <n; i++){
    m -= a[i].second;
    res += a[i].first * a[i].second;
    if(m == 0){
      break;
    }
    else if(m < 0){
      m = abs(m);
      res -= a[i].first * m;
      break;
    }
  }
  cout << res << endl;

}


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

Measured memory_bytes: 1028
#include <iostream>
#include <sstream>

using namespace std;


int main()
{
      int a , b , x;
      cin >> a >> b >> x;
      if(a > x)
            cout << "NO";
      else if(a +b >= x)
            cout << "YES";
      else
            cout << "NO";

      return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
    int A , B ;
    cin >> A >> B ;
    int ans ;
    
    ans=A - 2*B;
    if(ans<0){
        cout << 0 <<endl;
    }else{
        cout << ans <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main() {
    string s;
    int i,j,k,n,b=0,r=0,red;
    cin>>n>>s;
for(i=0;i<n;i++){
    if(s[i]=='R')r++;
    else if(s[i]=='B')b++;
}
if(r>b){
    cout << "Yes" << endl;
}else {

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

Measured memory_bytes: 256
import math

N = int(input())

# d桁の-2進法表記で表現できる最大の数を返す関数。偶数桁目のbitが全て1、奇数桁目のbitが全て0
def max_negative2(d):
    if d == 1:
        return 1
    elif d%2 == 1:
        return int((1-4**(math.ceil(d/2)))/(1-4))
    else:
        return (-2)**(d-1) + int((1-4**(math.ceil(d/2)))/(1-4))

def min_negative2(d):
    if d == 1:
        return 0
    elif d%2 == 1:
        return (-2)**(d-1) + int((-2)*(1-4**(d//2))/(1-4))
    else:
        return int((-2)*(1-4**(d//2))/(1-4))

# 10進数の数値nと桁数dを与えると、nを-2進法表記したときにd桁目が1となるかどうかを返す関数
def top_bit_flag(n,d):
    if n == 0 and d == 1:
        return False
    else:
        return True if min_negative2(d) <= n <= max_negative2(d) else False

# Nの-2進数表記を大きい桁から埋めていく
# -10**9<=N<=10**, min_negative2(31)<10**9<max_negative2(31), min_negative2(32)<-10**9<max_negative2(32)なので、Nは-2進法表記時に最大で32桁
S = ""
n = N
for d in reversed(range(1,33)):
    if top_bit_flag(n,d):
        S += "1"
        n -= (-2)**(d-1)
    else:
        S += "0"

print(int(S))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; } 
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/
bool comp(string a,string b)
{
  return a.length()<b.length();
}
void solve()
{
  ll n;
  cin>>n;
  ld odd=0;
  if(n%2)
    odd=n/2+1;
  else
    odd=n/2;
  cout.precision(9);
  cout<<fixed<<odd/n;      
}
int main()
{ 
  ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 256
txt=raw_input()
i=0
j=len(txt)-1
x_count = 0
while i<j:
	if txt[i]==txt[j]:
		i+=1
		j-=1
	elif txt[i]=='x':
		i+=1
		x_count+=1
	elif txt[j]=='x':
		j-=1
		x_count+=1
	else:
		print -1
		exit(0)
print x_count 

Measured memory_bytes: 2692
// --------------
// Tejas Pandey  |
// 12 - 01 - 20  |
// ABC #151      |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		char c;
		cin >> c;
		cout << (char)(c + 1) << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int souwa(vector<vector<int>>& );
int H,W,K;
int lastans;
vector<int> nuru(20);
vector<vector<int>>hyoureal;
void tansaku(int n,int a,vector<int> nuruc){
  if(n==H+W){
    vector<vector<int>>hyouc;
    hyouc=hyoureal;
    rep(i,H){
      if(nuruc[i]==1){
        rep(j,W){
          hyouc[i][j]=0;
        }
      }
    }
    rep(i,W){
      if(nuruc[H+i]==1){
        rep(j,H){
          hyouc[j][i]=0;
        }
      }
    }
    if(souwa(hyouc)==K)lastans++;
  }
  else{
    nuruc[n]=a;
    tansaku(n+1,0,nuruc);
    tansaku(n+1,1,nuruc);
  }
}
int souwa(vector<vector<int>>& hyou){
  int ans=0;
  rep(i,H){
    rep(j,W){
      ans+=hyou[i][j];
    }
  }
  return ans;
}
int main (){
  cin>>H>>W>>K;
  vector<vector<int>>hyou(H,vector<int>(W));
  rep(i,H){
    string C;
    cin>>C;
    rep(j,W){
      if(C[j]=='.')hyou[i][j]=0;
      if(C[j]=='#')hyou[i][j]=1;
    }
  }
  hyoureal=hyou;
  tansaku(0,0,nuru);
  tansaku(0,1,nuru);
  cout<<lastans/2;
}


Measured memory_bytes: 3636
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    string n;
  
 
   cin >> n;
  
  
  
for(int i = 0;i< n.size();i++){
     
   if(n[i]=='9'){
     
    //  cout << "1" << endl;
      n.replace(i, 1, "1");
     
   }else if(n[i]=='1'){
      n.replace(i, 1, "9");
   }

}
   cout << n << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
a = [0]+LIST()
a_acc = list(accumulate(a))
dp = [[None]*(N+1) for _ in range(N+1)]

def rec(l, r):
    if dp[l][r]: return dp[l][r] 
    if l == r:
        return 0
    mi = INF
    for i in range(l, r):
        mi = min(mi, rec(l, i)+rec(i+1, r))
    dp[l][r] = mi + (a_acc[r]-a_acc[l-1])
    return dp[l][r]

print(rec(1, N))


Measured memory_bytes: 82300
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

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



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

string t;
int dp[N][3];
main() {
  file("threesum");
  ios;
  cin >> t;/*
  for (int i = 0; i < t.size(); ++i) {
    if (!i) {
      dp[i][1] = 1;
      continue;
    }
    if (t[i] == 'P') {
      dp[i][0] = dp[i - 1][0];
    } else {
      if (t[i] == 'D') {
        dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1);
      } else {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
      }
    }
  }
  int n = t.size() - 1;
  cout << max(dp[n][0], dp[n][1]);*/
  for (int i = 0; i < t.size(); ++i) {
    if (t[i] != '?') cout << t[i];
    else {
      cout << 'D';
    }
  }
  return 0;
}
/**

*/


Measured memory_bytes: 3792
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    int p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    int n,d,ans;
    cin >> n >> d;
    ans = n / (d*2+1);
    if(n % (d*2+1) != 0)
    {
        ans++;
    }
    cout << ans;
}

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

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double aw = 0.5, bw = 6.0;
    int total_m = h * 60 + m;
    double w = abs(aw * (double)total_m - bw * (double)m);
    printf("%.20lf\n", sqrt(a * a + b * b - 2 * a * b * cos(w * M_PI / 180.0)));
    return 0;
}

Measured memory_bytes: 4164
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {

	string a, b;

	cin >> a >> b;

	a = a + b;

	int num = stoi(a), numsqrt = sqrt(num);

	if (num == numsqrt*numsqrt)cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a=Integer.parseInt(scan.next());
		int b=Integer.parseInt(scan.next());
		int c=Integer.parseInt(scan.next());
		if(a<b&&b<c)System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 17120
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
s = input().strip()

if ('R' not in s) or ('G' not in s) or ('B' not in s):
    print(0)
    sys.exit(0)

from collections import deque

index_cache = {'R': deque(), 'G': deque(), 'B': deque()}
for i, v in enumerate(s):
    index_cache[v].append(i)

ans = 0
for i, v in enumerate(s):
    index_cache[v].popleft()

    v2, v3 = set('RGB') - set(v)
    if len(index_cache[v2]) == 0 or len(index_cache[v3]) == 0:
        break

    i2, i3 = index_cache[v2][0], index_cache[v3][0]
    ans += len(index_cache[v2]) * len(index_cache[v3])

    if i2 < i3:
        for i4 in index_cache[v2]:
            if i4 + (i4 - i) < n and s[i4 + (i4 - i)] == v3:
                ans -= 1
            if (i + i4) % 2 == 0 and s[(i + i4) // 2] == v3:
                ans -= 1
    else:
        for i5 in index_cache[v3]:
            if i5 + (i5 - i) < n and s[i5 + (i5 - i)] == v2:
                ans -= 1
            if (i + i5) % 2 == 0 and s[(i + i5) // 2] == v2:
                ans -= 1

print(ans)


Measured memory_bytes: 75412
M = 10**9 + 7
gets
A = gets.split.map(&:to_i)

s = 0

S = A.reverse.map do |a|
  s += a
  s %= M
end.reverse

# pp S

w = 0

(A.length - 1).times do |i|
  w += (A[i] * S[i + 1]) % M
  w %= M
end

puts w


Measured memory_bytes: 32828
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;


int main() {
	int a, b, c;
	bool f = false;
	cin >> a >> b >> c;
	if (a > b) {
		if (a > c) {
			if (a == b + c) {
				f = true;
			}
		}
		else {
			if (c == a + b) {
				f = true;
			}
		}
	}
	else {
		if (b > c) {
			if (b == a + c) {
				f = true;
			}
		}
		else {
			if (c == a + b) {
				f = true;
			}
		}
	}
	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
const ll mod = 1000000007;

int pp_s[100000]={0};

int pp(int n){
	if(n<3) return 0;
	else if(n==3) return 1;
	else if(pp_s[n]) return pp_s[n];
	else {
		int r=1;
		for(int i=n-3; i>=3; i--) {
			r = (r+pp(i))%mod;
		}
		pp_s[n] = r;
		return r;
	}
}

int main(){
	int s;
	scanf("%d", &s);
	printf("%d\n", pp(s));
}

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

int h,w;
string g[100];
bool use[100][100];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

void rec(int y,int x,char c){
  if(use[y][x])return;
  use[y][x] = true;

  for(int i=0;i<4;i++){
    int ny = y+dy[i], nx = x+dx[i];
    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
    if(g[ny][nx] == c)rec(ny,nx,c);
  }
}

int main(){
  while(cin >> h >> w,h||w){
    for(int i=0;i<h;i++){
      cin >> g[i];
      for(int j=0;j<w;j++)use[i][j] = false;
    }

    int res = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(!use[i][j]){
	  rec(i,j,g[i][j]);
	  res++;
	}
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    while(true){
      int H=sc.nextInt();
      int W=sc.nextInt();
      if(H==0 && W==0) break;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(i==0 || i==H-1 || j==0 || j==W-1){
            System.out.print("#");
          }else{
            System.out.print(".");
          }
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}



Measured memory_bytes: 34396
#include <stdio.h>

main()
{
  int n[100],N,i,j,l=0,s=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&n[i]);
  }

  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--)
      {
	if(n[j]<n[j-1]){
	  s++;
	  l=n[j];
	  n[j]=n[j-1];
	  n[j-1]=l;
	  }
      }
  }
	for(i=0;i<N-1;i++){
	  printf("%d ",n[i]);
	}
	printf("%d\n",n[i]);
	printf("%d\n",s);

	return 0;
}

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

int main(){
	int n, id;
	long long int a, b;

	while( cin >> n , n ){
		map<int,long long int> employees;
		vector<int> vc;
		bool flag = true;
		
		for(int i=0 ; i<n ; ++i ){
			cin >> id >> a >> b;
			if( !employees[id] ) vc.push_back( id );
			employees[id] += a * b;	
		}
		for(int i=0 ; i<vc.size() ; ++i ){
			if( employees[ vc[i] ] >= 1000000 ){
				cout << vc[i] << endl;
				flag = false;
			}
		}
		if( flag ){
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2710&lang=jp
// reference : http://suikaba.hatenablog.com/entry/2017/05/24/231631
typedef pair<int, int> pii;
#define INF 1<<25

pii rec(int l, int r, const string& S,vector<vector<pii>>& dp) {
	pii& ret = dp[l][r];
	/* Updated */
	if (ret != pii{ -INF, INF }) return ret;

	if (l == r) {
		return ret = { S[l] - '0',S[l] - '0' };
	}

	if (S[l] == '(' && r - l >= 3) {
		pii x = rec(l + 1, r, S, dp);
		ret.first = max(ret.first, x.first);
		ret.second = min(ret.second, x.second);
	}
	if (S[r] == ')' && r - l >= 3) {
		pii x = rec(l, r - 1, S, dp);
		ret.first = max(ret.first, x.first);
		ret.second = min(ret.second, x.second);
	}
	for (int m = l + 1; m < r; m++) {
		if (S[m] == '+' || S[m] == '-') {
			pii x1 = rec(l, m - 1, S, dp);
			pii x2 = rec(m + 1, r, S, dp);
			if (S[m] == '+') {
				ret.first = max(ret.first, x1.first + x2.first);
				ret.second = min(ret.second, x1.second + x2.second);
			}
			else {
				ret.first = max(ret.first, x1.first - x2.second);
				ret.second = min(ret.second, x1.second - x2.first);
			}
		}
	}
	return ret;
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	string S; cin >> S;
	/*  dp[l][r] := { maximum value of the interval(l-r) , minimum value of ~ }*/
	vector<vector<pii>> dp(S.length(), vector<pii>(S.length(), { -INF,INF }));
	cout << rec(0, S.length() - 1, S, dp).first << endl;
}

Measured memory_bytes: 3320
#include<stdio.h>
int main(){
 	int i;
  int a,b,c;
  	int ans = 0;
  
  scanf("%d %d %d",&a,&b,&c);
  
  for(i=a;i<=b;i++){
   if(i%c==0){
    ans++; 
   }
  }
  
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1732
use proconio::input;
#[allow(unused_mut)]
fn main() {
    input! {
        s: String,
        _t: String,
        a: usize,
        b: usize,
        u: String
    }
    if s == u {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


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

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

    if(n % 2 != 0) {
        cout << "No" << endl;
    } else {
        bool flag = true;
        for(int i = 0; i < n/2; i++) {
            if(s[i] != s[i + n/2]) {
                flag = false;
                break;
            }
        }
        if(flag) cout << "Yes" << endl;
        else     cout << "No" << endl;
    }

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var K = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var ok = true;
        if (A.Max() < K)
        {
            Console.WriteLine("IMPOSSIBLE");
            return;
        }
        if (A.Contains(K))
        {
            Console.WriteLine("POSSIBLE");
            return;
        }
        long gcd = A[0];
        for (int i = 1; i < N; i++)
        {
            gcd = Gcd(gcd, A[i]);
        }
        ok = gcd == 1 || K % gcd == 0;
        Console.WriteLine(ok ? "POSSIBLE" : "IMPOSSIBLE");
    }
    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 26584
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <limits>
const int mod = 1e9 + 7;
#define INF 1000000000000000
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
long long gcd(long long a, long long b) {
    if (a < b)
        swap(a, b);
    long long r = a % b;
    if (r == 0)
        return b;
    else
        return gcd(b, r);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> v(n+2);
    rep(i, n) cin >> v[i+1];
    v[0]=0;
    v[n+1]=0;
    int sum = 0;
    FOR(i,1,n+2) sum += abs(v[i]-v[i-1]);
    FOR(i,1,n+1){
        int ans = sum;
        ans -= abs(v[i]-v[i-1]);
        ans -= abs(v[i+1]-v[i]);
        ans += abs(v[i+1]-v[i-1]);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2048
n,m = map(int,input().split())
l = [0] * m
r = [0] * m
for i in range(0,m):
	l[i], r[i] = map(int, input().split())

count = 0

max_l = max(l)
min_r = min(r)

for i in range(1,n+1):
	
	if max_l <= i <= min_r:
		count += 1
			
print(count)
		

Measured memory_bytes: 10868
/*s1190073  Rina Sato
  File name: prog10c.c
  This is a program that finds the longest common subsequence of two sequence.
*/

#include <stdio.h>
#include <string.h>

int LCSlength(char X[],char Y[]){
  int i,j,c[1003][1003];
  int m,n;
  
  m = strlen(X);
  n = strlen(Y);
  
  for(i = 0 ; i <= m ; i++){
    c[i][0] = 0;
  }
  for(j = 0 ; j <= n ; j++){
    c[0][j] = 0;
  }
  
  for(i = 1 ; i <= m ; i++){
    
    for(j = 1 ; j <= n ; j++){
      
      if(X[i-1] == Y[j-1]){
	c[i][j] = c[i-1][j-1] + 1;
	
      }
      else {
	if(c[i-1][j] >= c[i][j-1]){
	  c[i][j] = c[i-1][j];
	}
	else {
	  c[i][j] = c[i][j-1];
	}
      }
      
    }
  }
  
  return c[m][n];
}

int main(void){
  int n,Z[1000000],m,l,i,j,lcs[1003];
  char X[1003],Y[1003];
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf("%s",X);
    
    scanf("%s",Y);
    
    lcs[i] = LCSlength(X,Y);
  }
  
  for(i = 0 ; i < n ; i++){
    printf("%d\n",lcs[i]);
  }
  
  return 0;
}

Measured memory_bytes: 4308
#include <stdio.h>

int main(void) {
	int i,j,x,y,s,max,count;
	int board[14][14]={0};
	int sibuki_x[3][13]={{0,1,0,-1,0},{0,1,1,1,0,-1,-1,-1,0},{0,1,1,1,0,-1,-1,-1,0,0,2,0,-2}};
	int sibuki_y[3][13]={{-1,0,1,0,0},{-1,-1,0,1,1,1,0,-1,0},{-1,-1,0,1,1,1,0,-1,0,2,0,-2,0}};
	
	while(scanf("%d,",&x)!=EOF){
		scanf("%d,%d",&y,&s);
		for(i=0;s==1?i<5:s==2?i<9:i<13;i++){
			board[2+x+sibuki_x[s-1][i]][2+y+sibuki_y[s-1][i]]++;
			//printf("%d %d\n",x+sibuki_x[s][i],y+sibuki_y[s][i]);
		}
	}
	for(i=0,count=0,max=0;i<10;i++){
		for(j=0;j<10;j++){
			if(max<board[2+i][2+j])max=board[2+i][2+j];
			if(board[2+i][2+j]==0)count++;
		}
	}
	printf("%d\n%d\n",count,max);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    string s;
    cin >> s;

    int cnt = 0;
    string k = "";
    VI x;
    for (char i : s) {
        if (i == 'x')cnt++;
        else {
            x.push_back(cnt);
            k += i;
            cnt = 0;
        }
    }
    x.push_back(cnt);

    int len = k.length();
    FOR(i, 0, len / 2)if (k[i] != k[len - i - 1]) {
        cout << "-1\n";
        return 0;
    }

    int ans = 0;
    FOR(i, 0, (len + 1) / 2)ans += abs(x[i] - x[len - i]);
    if (len % 2 == 0)ans += abs(k[len / 2] - k[len / 2 - 1]);

    cout << ans << "\n";

}


Measured memory_bytes: 1100
button = [int(i) for i in input().split()]
ans = 0
for i in range(2):
    if button[0] > button[1] or button[0] == button[1]:
        ans += button[0]
        button[0] -= 1
    else:
        ans += button[1]
        button[1]-= 1


print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > Mat;
#define getMat(r, c) Mat(r, vector<int>(c));

const int INF = 1<<28;
const int R = 4;
const int C = 8;

Mat G = getMat(R, C);
map<Mat, int> mem;

void show() {
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      if (j) cout << " ";
      if (G[i][j] == 0) cout << "00";
      else cout << G[i][j];
    }
    cout << endl;
  }
}

int diff() {
  int res = 0;
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C-1; ++j) {
      if (G[i][j] != (i+1) * 10 + (j+1)) {
        ++res;
      }
    }
  }
  return res;
}

int rec() {
  if (mem.count(G)) return mem[G];
  if (diff() == 0) {
    return mem[G] = 0;
  }
  //show(); cout << endl;
  int res = INF;
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      if (G[i][j] != 0) continue;
      if (G[i][j-1] == 0) continue;
      if (G[i][j-1] % 10 == 7) continue;
      int target = G[i][j-1] + 1;
      try {
        for (int i2 = 0; i2 < R; ++i2) {
          for (int j2 = 0; j2 < C; ++j2) {
            if (G[i2][j2] == target) {
              swap(G[i][j], G[i2][j2]);
              res = min(res, rec() + 1);
              swap(G[i][j], G[i2][j2]);
              throw 0;
            }
          }
        }
      } catch(...) {}
    }
  }
  return mem[G] = res;
}

int main() {
  int Tc;
  cin >> Tc;
  while (Tc--) {
    for (int i = 0; i < R; ++i) {
      G[i][0] = (i+1)*10 + 1;
      for (int j = 1; j < C; ++j) {
        cin >> G[i][j];
        if (G[i][j] % 10 == 1) G[i][j] = 0;
      }
    }
    mem.clear();
    int res = rec();
    if (res == INF) res = -1;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 25824
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
using namespace std;
const int N=2e5+5;
int n,m,a[N],ans,mx;
bool ck(int x){
	int mx=0,mi2=2e9,mx2=0;
	fo(i,1,x)mx=max(mx,a[i]+a[x*2-i+1]);
	fo(i,x*2+1,(n>>1)+x)mi2=min(mi2,a[i]+a[n+x*2+1-i]),mx2=max(mx2,a[i]+a[n+x*2+1-i]);
	if(mx>=m)return 0;
	if(mi2<m)return 1;
	return 0;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;n<<=1;
	fo(i,1,n)cin>>a[i];
	sort(a+1,a+n+1);
	ans=n>>1;
	for(int l=0,r=n>>1,mi;mi=l+r>>1,l<=r;)
		if(ck(mi))l=mi+1;else r=mi-1,ans=mi;
	mx=0;
	fo(i,1,ans)mx=max(mx,a[i]+a[ans*2-i+1]);
	fo(i,ans*2+1,(n>>1)+ans)mx=max(mx,a[i]+a[n+ans*2+1-i]-m);
	cout<<mx;
}


Measured memory_bytes: 1152
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>

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

#define int long long

using namespace std;

int calc_min(int H, int W)
{
    int ret_min = INT_MAX;

    for (int w=1; w<=W-1; w++) {
        int sub_h1 = ceil(H / 2.0);
        int sub_h2 = floor(H / 2.0);

        int mn = min(H * w, min(sub_h1 * (W - w), sub_h2 * (W - w)));
        int mx = max(H * w, max(sub_h1 * (W - w), sub_h2 * (W - w)));

        ret_min = min(ret_min, mx - mn);

        int sub_w1 = ceil((W - w) / 2.0);
        int sub_w2 = floor((W - w) / 2.0);

        mn = min(H * w, min(H * sub_w1, H * sub_w2));
        mx = max(H * w, max(H * sub_w1, H * sub_w2));

        ret_min = min(ret_min, mx - mn);
    }

    return ret_min;
}

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int H, W;

    cin >> H >> W;

    int tmp = calc_min(H, W);
    int tmp2 = calc_min(W, H);

    cout << min(tmp, tmp2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll ans = 0, i, len, temp;
    string s;
    cin >> s;
    len = s.length();
    for (i = 0, temp = 0; i < len; i++)
    {
        if (s[i] == 'R')
            temp++;
        if (s[i] == 'S')
            temp = 0;
        if (ans < temp)
            ans = temp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int N; cin >> N;
	int ans = 0;
	while (N > 0) {
		ans += (N % 10);
		N /= 10;
	}
	if (ans == 1)cout << 10 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
  int N;
  cin >> N;
  if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
    cout << "hon" << endl;
  } else if(N % 10 == 0 ||N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
    cout << "pon" << endl;
  } else if (N % 10 == 3){
    cout << "bon" << endl;
  }
}
  

Measured memory_bytes: 3624
#include<stdio.h>

//a??¨b?????\??????????????¢??°
void swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b, c;

	//3????????´??°a,b,c?????\???
	scanf("%d %d %d", &a, &b, &c);

	//3????????´??°a,b,c????°????????????????????????????
	if (a > b) {
		swap(&a, &b);
	}
	if (a > c) {
		swap(&a, &c);
	}
	if (b > c) {
		swap(&b, &c);
	}

	//?°???????????????????????????????????????????
	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#define EMAX 2000
#define VMAX 1000

typedef struct edges{
  long int f;
  long int t;
  long int c;
}edge;
edge v[EMAX];
int n,m;
void initial_BF(int e){for(int i=0;i<e;i++)scanf("%ld%ld%ld",&v[i].f,&v[i].t,&v[i].c);}
long int BellmanFord(int f,int t){
  long int l[1001],i,j,tl,a;
  for(int i=0;i<=n;i++){l[i]=1L<<60;}
  l[f]=0;
  for(i=0;i<n*2;i++){
    for(j=0;j<m;j++){
      tl=l[v[j].f]+v[j].c;
      if(l[v[j].f]!=l[0]&&l[v[j].t]>tl)l[v[j].t]=tl;
    }if(i==n)a=l[t];
  }
  if(a!=l[t]){printf("inf");exit(0);}
  return l[t];
}
int main(){
  long int i,a,b,c;
  scanf("%d%d",&n,&m);
  initial_BF(m);
  for(i=0;i<m;i++)v[i].c*=-1;
  a=-BellmanFord(1,n);
  printf("%ld",a);
}


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


#define F first
#define PB push_back
#define MP make_pair

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.length(); i++){
        if(i >= t.length() || s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(t.length() == s.length() + 1){
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){

  int t;

  cin>>t;
  for(int i=0;i<t;i++){
    int n, k, x[100000];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>x[i];

    int d[100000];
    for(int i=0;i<n-1;i++) d[i]=x[i+1]-x[i];

    sort(d, d+n-1, greater<int>());
    int ans=x[n-1]-x[0];
    for(int i=0;i<k-1;i++) ans-=d[i];

    cout<<max(ans, 0)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3940
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	vector<int> cnt(m, 0);
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int a; cin >> a;
			cnt[a-1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (cnt[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i, pi in enumerate(p, 1):
        if root(i) == root(pi):
            cnt += 1
    print(cnt)
        
def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
        elif rank[x] > rank[y]:
            parent[y] = x
        else:
            parent[y] = x
            rank[x] += 1

if __name__ == "__main__":
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    parent = list(range(n+1))
    rank = [0]*(n+1)
    main()


Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

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

    ll ans = 0;
    for (int i = 1; i < N; i++) {
        if(a[i-1] > a[i]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }

    printf("%lld\n", ans);

}

Measured memory_bytes: 4776