akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int start(int n){
  while(n > 9){
    n /= 10;
  }
  return n;
}
int end(int n){
  return n % 10;
}

int main() {
  int n;
  cin >> n;
  int cnt[10][10];
  rep(i, 10)
    rep(j, 10)
      cnt[i][j] = 0;
    

  for(int i = 1; i <= n; i++){
    cnt[start(i)][end(i)]++;
  }

  int res = 0;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      res += cnt[i][j] * cnt[j][i];
    }
  }

  cout << res << ln;
}
    


Measured memory_bytes: 256
//h11-2 古本屋
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define LL long long
#define CINT boost_multiprecision::cpp_int
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int N,K;
int C[2000],G[2000];

vector<int> li[10];
vector<int> li2[10];

int dp[10][2000];

int cul(int now, int nokori){
    if(nokori == 0) return 0;
    if(now == 10) return INT_MIN;
    if(dp[now][nokori] != INT_MIN) return dp[now][nokori];
    int re = INT_MIN;
    for(int i=0; i<li2[now].size(); i++){
        if(i > nokori) break;
        re = max(re, cul(now+1, nokori-i) + li2[now][i]);
    }
    dp[now][nokori] = re;
    return re;
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> C[i] >> G[i];
        li[G[i]-1].push_back(C[i]);
    }
    for(int i=0; i<10; i++){
        sort(li[i].begin(), li[i].end(), greater<int>());
        li2[i].push_back(0);
        for(int j=0; j<li[i].size(); j++){
            li2[i].push_back(li2[i].back() + li[i][j] + 2*j);
        }
    }

    for(int i=0; i<10; i++){
        for(int j=0; j<2000; j++){
            dp[i][j] = INT_MIN;
        }
    }

    int ans = INT_MIN;
    for(int i=0; i<li2[0].size(); i++){
        if(i > K) break;
        ans = max(ans, cul(1, K-i) + li2[0][i]);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3272
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(x+r <= W && x-r >=0){
        if(y+r <= H && y-r >=0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)

int main(){
   long long N,K;
   cin >> N >> K;
   vector<long long> A(N+1000);

   FOR(i,1,N+1){
        cin>>A[i];
    }
    
   FOR(i,K+1,N+1){
        if(A[i]>A[i-K]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }


}


Measured memory_bytes: 4840
N,M = map(int,input().split())
order = {}
if N==1 and M==0:
  print(0)
else:
  for i in range(M):
    s,c = map(int,input().split())
    if order.get(s,57)==57:
        order[s]=c
    elif order.get(s,57)!=57 and order[s]!=c:
        print(-1)
        break
  else:
    moji = [1]+[0]*(N-1)
    for k in order.keys():
        moji[k-1]=order[k]
    if N!=1 and moji[0]==0:
      print(-1)
    else:
      ans = [str(a) for a in moji]
      print(''.join(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

int n, m;
vector<int> xl, yl;

ll calc (vector<int> p) {
    sort(ALL(p));

    ll sum = 0;
    REP1 (i, SZ(p)-1) {
        ll cur = p[i] - p[i-1];
        (sum += cur * (SZ(p)-i) % MOD * i % MOD) %= MOD;
    }

    return sum;
}
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> m;
    REP (i, n) {
        int p;
        cin >> p;
        xl.eb(p);
    }

    REP (j, m) {
        int p;
        cin >> p;
        yl.eb(p);
    }

    debug(calc(xl), calc((yl)));
    cout << calc(xl) * calc(yl) % MOD << endl;
    return 0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 100000
#define MAX_M 100000
#define M 100000

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

ll n, m, s[MAX_N+1], a;

int main(){
  scanf("%lld%lld", &n, &m);
  rep(i, n-1) scanf("%lld", s+i+1);
  REP(i, 2, n) s[i] += s[i-1];

  ll res = 0, now = 0;
  rep(i, m){
    scanf("%lld", &a);
    res += abs(s[now] - s[now+a]);
    res = res % M;
    now += a;
  }
  printf("%lld\n", res);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> data(N, vector<int> (N, -1));
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for(int j = 0; j < a; j++) {
      int x, y;
      cin >> x >> y;
      data.at(i).at(x - 1) = y;
    }
  }
  int ans = 0;
  for(int i = (1 << N) - 1; i >= 0; i--) {
    bitset<15> s(i);
    bool check = true;
    for(int j = 0; j < N; j++) {
      if(s.test(j)) {
        for(int k = 0; k < N; k++) {
          if(data.at(j).at(k) == -1) {
            continue;
          }
          else if(data.at(j).at(k) == 1 && !s.test(k)) {
            check = false;
          }
          else if(data.at(j).at(k) == 0 && s.test(k)) {
            check = false;
          }
        }
      }
    }
    if(check) {
      if(s.count() > ans) {
        ans = s.count();
      }
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long N, long long A, long long B) {
    long long ans = N / (A+B) * A;
    long long X = N % (A + B);
    ans += min(A, X);
    cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(r); sll(d); sll(x);
	rep(i, 0, 10) {
		x = r * x - d;
		pll(x); nl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
 
int main() {
    int n;
    string s;
    cin >> n >> s;
    ll r=0,g=0,b=0,rg=0,rb=0,gb=0,ans=0;
    rep(i,n){
        if (s[i]=='R'){
            r++;
            rg+=g;
            rb+=b;
            ans+=gb;
        }
        if (s[i]=='G'){
            g++;
            rg+=r;
            gb+=b;
            ans+=rb;
        }
        if (s[i]=='B'){
            b++;
            rb+=r;
            gb+=g;
            ans+=rg;
        }
    }
    rep(i,n){
        for (int j=i;j<n;j++){
            if (2*j-i>=n) continue;
            if (s[i]!=s[j] && s[i]!=s[2*j-i] && s[j]!=s[2*j-i]) ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
/**
 * https://atcoder.jp/contests/abc158/submissions/10616288
 * の改造版.
 * S += c;
 * を、
 * S = S + c;
 * にするとTLEするが、
 * S.append(c);
 * はどうか？
 */
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

  string S, T{}, R{};
  int Q;
  cin >> S >> Q;
  int ok = true;
  int N, M;
  string c;
  rep(i,Q){
    cin >> N;
    if(N == 1){
      if(ok){
        ok = false;
      }
      else{
        ok = true;
      }
    }
    else{
      cin >> M >> c;
      if(M == 1){
        if(ok){
          S.insert(0, c);
        }
        else{
          S.append(c);
        }
      }
      else{
        if(ok){
          S.append(c);
        }
        else{
          S.insert(0,c);
        }
      }
    }
  }
  if(ok){
    cout << S << endl;
  }
  else{
    int W = S.size();
    for(int i=W-1;i>=0;i--){
      cout << S[i];
    }
  }
}


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

int main(){
    // input
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);

    // compute
    int max = *max_element(A.begin(), A.end());
    int min = *min_element(A.begin(), A.end());
    int ans = max - min;
    
    // output
    cout << ans << endl;
    
}



Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  if(b==c&&(a==b||c==d)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Contest.cs
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = ReadInt()[0];
			int ans;
			if (n % 2 == 0)
			{
				ans = n;
			}
			else
			{
				ans = n * 2;
			}
			Console.WriteLine(ans);
		}
 
		static string[] ReadStr()
		{
			return Console.ReadLine().Split(' ').ToArray();
 
		}
 
		static int[] ReadInt()
		{
			return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}
	}
}

Measured memory_bytes: 13268
#include <cstdio>
#include <cstdlib>
using namespace std;
#define INF (1e9)

int main()
{
  int n, m, now;
  scanf("%d", &n);
  scanf("%d", &m);
  int a[n], b[n], c[m], d[m], ans[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    scanf("%d", &b[i]);
  }

  for (int i = 0; i < m; i++) {
    scanf("%d", &c[i]);
    scanf("%d", &d[i]);
  }

  for (int i = 0; i < n; i++) {
    now = INF;
    for (int j = 0; j < m; j++) {
      if (now > abs(a[i] - c[j]) + abs(b[i] - d[j])){
        now = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        ans[i] = j + 1;
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    string s; cin >> s;
    int ans = 0;
    for(int i=0; i<N-3+1; i++) {
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", (a < 10 && b < 10) ? a * b : -1);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[m];
        int[] b = new int[m];
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int i = 0; i < m; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i] = Integer.parseInt(sc.next());
            if (a[i] == 1) {
                set1.add(b[i]);
            }
            if (b[i] == n) {
                set2.add(a[i]);
            }
        }

        // 主処理
        int beforeSize = set1.size() + set2.size();
        set1.addAll(set2);
        boolean judge = set1.size() != beforeSize;

        String result = judge ? "POSSIBLE" : "IMPOSSIBLE";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 87000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, i0, n) for (int i = i0; i < n; ++i)
 
int main() {
  double r;
  cin >> r;
  cout << fixed << setprecision(15);
  cout << 2 * 3.14159265 * r << endl;
  return 0; 
}

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

#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };

template<class T>inline bool maxi(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

bool gone[100]={};
int main(){
	setc;

	int a,b,c,cur=0;cin>>a>>b>>c;
	while(1){
		cur=(cur+a)%b;
		if (cur==c){
			co("YES");gc();return 0;
		}
		if (gone[cur])break;
		gone[cur]=1;
	}
	co("NO");
	gc();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


int n, m;
string s;
pair<char, char>p[214514];
signed main() {
	cin >> n >> m >> s;
	rep(i, m)cin >> p[i].first >> p[i].second;
	int left = -1, right = n;
	for (int i = m - 1; i >= 0; i--) {
		if (left < n - 1 && s[left + 1] == p[i].first && p[i].second == 'L')left++;
		else if (left >= 0 && s[left] == p[i].first && p[i].second == 'R')left--;
		if (right && s[right - 1] == p[i].first && p[i].second == 'R')right--;
		else if (right <= n - 1 && s[right] == p[i].first && p[i].second == 'L')right++;
	}
	cout << max(0LL, right - left - 1) << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<int> Da;
ll Ma[1000010];//正順
ll Ca[1000010];//逆順
ll MC[1000010];//逆順

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;

	for (int i = 0;i < N;i++) {
		if (S[i] == 'D')Da.push_back(i);
	}

	if (S[0] == 'M')Ma[0] = 1;
	for (int i = 1;i < N;i++) {
		Ma[i] += Ma[i - 1];
		if (S[i] == 'M')Ma[i]++;
	}

	if (S[N - 1] == 'C')Ca[N - 1] = 1;
	for (int i = N - 2;i >= 0;i--) {
		Ca[i] += Ca[i + 1];
		MC[i] += MC[i + 1];
		if (S[i] == 'C')Ca[i]++;
		if (S[i] == 'M')MC[i] += Ca[i + 1];
	}

	int Q, k;
	ll ans;
	cin >> Q;
	for (int i = 0;i < Q;i++) {
		cin >> k;
		ans = 0;
		for (int j : Da) {
			ans += MC[j + 1];
			if (j + k >= N)continue;
			ans -= MC[j + k];
			ans -= (Ma[j + k - 1] - Ma[j])*(Ca[j + k]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 29048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    REP(i, N) cout << s[i] << t[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
S1 = int(S[:2])
S2 = int(S[2:])

if S1 == 0:
    if S2 > 0 and S2 <= 12:
        print("YYMM")
    else:
        print("NA")
elif S1 <= 12:
    if S2 > 0 and S2 <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if S2==0 or S2 > 12:
        print("NA")
    else:
        print("YYMM")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M;

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

    cin >> N;
    vector<ll> a(N);
    REP(i, N) { cin >> a.at(i); }

    vector<ll> l(N + 1), r(N + 1);

    REP(i, N) { l[i + 1] = l[i] + a[i]; }
    REP(i, N) { r[i + 1] = r[i] + a[N - 1 - i]; }

    ll ans = numeric_limits<ll>::max();
    REP(i, N - 1) { chmin(ans, abs(l[i + 1] - r[N - 1 - i])); }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N, K;
  cin>>N>>K;
  int M = N-2;
  int ans = M/(K-1);
  if(M%(N-1)>0)	ans++;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int i, o, t, j, l, s, z;
	cin >> i >> o >> t >> j >> l >> s >> z;
	int ans = 0;
	ans += o;
	int d = min({ i,j,l });
	int x = 3 * d + (i - d) / 2 * 2 + (j - d) / 2 * 2 + (l - d) / 2 * 2;
	if (d > 0) {
		d--;
		chmax(x, 3 * d + (i - d) / 2 * 2 + (j - d) / 2 * 2 + (l - d) / 2 * 2);
	}
	cout << ans + x << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#define INF 114514810

using namespace std;

int n, m;
int d[510][510];
int main(void)
{
    while(1) {
        scanf("%d %d", &n, &m);
        if(n==0 && m==0) break;
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                d[i][j] = INF;

        int a, b;
        for(int i=0; i<m; i++) {
            scanf("%d %d", &a, &b);
            a--; b--;
            d[a][b] = d[b][a] = 1;
        }
        // Warshall-Floyd
        for(int k=0; k<n; k++)
            for(int i=0; i<n; i++)
                for(int j=0; j<n; j++)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        // the cost from 0 to i == 1or2
        int ans = 0;
        for(int i=1; i<n; i++) {
            if(d[0][i] == 1 || d[0][i] == 2)
                ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 2028
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
sum = 0
right = 0
for left in range(N):
    while right < N and sum ^ A[right] == sum+A[right]:
        sum += A[right]
        right += 1
    ans += right-left
    sum -= A[left]
print(ans)


Measured memory_bytes: 24424
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum = 0;
    long rep = sc.nextLong();

    for (int i = 1; i < n; i++) {
      sum += sc.nextLong();
    }

    if (sum % 2 == rep % 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 58956
import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const A = readToken();
      const B = readToken();
      const C = readToken();
      int ans;
      foreach (i; 0 .. N) {
        if (A[i] == B[i] && A[i] == C[i]) {
          ans += 0;
        } else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) {
          ans += 1;
        } else {
          ans += 2;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  long long int totalA = 0, totalB = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    totalA += a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
    totalB += b[i];
  }

  if(totalB > totalA) cout << -1 << endl;
  else {
    vector<int> surplus;
    long long int demand = 0;
    int ans = 0;
    for(int i=0;i<n;i++) {
      if(a[i] >= b[i]) surplus.emplace_back(a[i]-b[i]);
      else {
        ans++;
        demand += b[i] - a[i];
      }
    }

    sort(surplus.rbegin(), surplus.rend());
    for(int i=0;i<surplus.size();i++) {
      if(demand <= 0) break;
      else {
        demand -= surplus[i];
        ans++;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1660
from collections import Counter

def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2   
    if n != 1: a.append(n)
    #Only odd number is possible
    return a

N = int(input())
D = {}
for i in range(1,N+1) :
    C = dict(Counter(trial_division(i)))
    for j in C :
        if j not in D :
            D[j] = C[j]
        else :
            D[j] += C[j]
ans = 1
for i in D.values() :
    i %= 10**9+7
    ans *= i+1
    ans %= 10**9+7
print(ans)
#print(D)


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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	int t[3] = {0,0,0};
	long long ans = 1;
	for(int i=0; i<n; i++) {
		int a;
		cin >> a;
		int p = -1, cnt = 0;
		for(int j=0; j<3; j++) {
			if(t[j] == a) {
				p = j;
				cnt++;
			}
		}
		ans *= cnt;
		t[p]++;
		ans %= (int)(1e9+7);
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int n = scan.nextInt();
			int[]a = new int[n];
			for(int i = 0;i<n;i++)a[i] = scan.nextInt();
			Arrays.sort(a);
			
			int ma = a[n-1];
			double k = (double)ma/2.0;
			
			double min = Double.MAX_VALUE;
			int mini =0;
			for(int i = 0;i<n-1;i++) {
				double s = Math.abs((double)a[i]-k);
				if(min>s) {
					min = s;
					mini = a[i];
				}
			}
			
			System.out.println(ma+" "+mini);
			
			
			
			
		}
		
		
	}
	

}


Measured memory_bytes: 49608
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	char map[2][6]={"apple","peach"};
	char c[10000]={0};
	for(int i=0;i<1000;i++)
	{
		c[i]=getchar();
		if(c[i]=='\n')break;
	}
	for(int i=0;i<1000;i++)
	{
		if(c[i]=='\0')break;
		int a=0,p=0;
		for(int j=0;j<5;j++)
		{
			if(map[0][j]==c[i+j])a++;
			if(map[1][j]==c[j+i])p++;
		}
		if(a==5)
		{
			printf("peach");
			i+=4;
		}
		else if(p==5)
		{
			printf("apple");
			i+=4;
		}
		else printf("%c",c[i]);
	}
	return 0;
}

Measured memory_bytes: 0
s = gets.chomp!.to_s

ls = s.split("")
#p ls

for i in 0..ls.length do
  if i%2 == 0
    #偶数番んめ
    if ls[i] == "L"
      print("No\n")
      exit
    end
  else
    #奇数番目
    if ls[i] == "R"
      print("No\n")
      exit
    end
  end
end
print("Yes\n")

Measured memory_bytes: 1788
N = int(input())
S = list(str(input()))
result = 0
for i in range(len(S)):
    S[i] = int(S[i])
    
for i in range(10):
    if S.count(i) >= 1:
        val = S.index(i)
        S_2 = S[val+1:]
        for j in range(10):
            if S_2.count(j) >= 1:
                val_2 = S_2.index(j)
                S_3 = S_2[val_2+1:]
                for k in range(10):
                    if S_3.count(k) >= 1:
                        result += 1

print(result)

Measured memory_bytes: 4464
#include <cstdio>
#include <cmath>
using namespace std;

int read() {
    int x = 0, f = 1; char s;
    while((s = getchar()) < '0' || s > '9') if(s == '-') f = -1;
    while(s >= '0' && s <= '9') {x = (x << 1) + (x << 3) + (s ^ 48); s = getchar();}
    return x * f;
}

long long qkpow(long long x, int y) {
    long long r = 1;
    while(y) {
        if(y & 1) r = r * x;
        x = x * x; y >>= 1;
    }
    return r;
}

int main() {
    long long x = read();
    for(long long i = -1000; i <= 1000; ++ i)
        for(long long j = -1000; j <= 1000; ++ j)
    if(qkpow(i, 5) - qkpow(j, 5) == x) {
        printf("%lld %lld\n", i, j);
        return 0;
    }
    return 0;
}//1000000000000000
//  995009990004999


Measured memory_bytes: 1568
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    ll A, B;
    cin >> A >> B;
    ll maxim = min(A, B);
    ll minimum = max(ll{0}, A + B - N);
    cout << maxim << ' ' << minimum << endl;

}

int main(int argc, char *argv[]) {
    string FileName("A"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 256
while True:
    try:
        d = {}
        while True:
            a, b = map(int, input().split())
            if a == 0:
                break
            if a in d:
                d[a] += 1
            else:
                d[a] = 1
            if b in d:
                d[b] += 1
            else:
                d[b] = 1
        if d[1]%2 == 1 and d[2]%2 == 1:
            del d[1], d[2]
            for node in d:
                if d[node]%2 == 1:
                    print("NG")
                    break
            else:
                print("OK")
        else:
            print("NG")
    except:
        break



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
string A,B;
int k;
unordered_map<string,int> mem;
 
string add(string a,int l,int r,int v){
  for(int i=l;i<=r;i++) a[i]=(a[i]-v+10)%10;
  return a;
}
 
int dfs(int idx,string dial){
  if(idx==k)return 0;
  if(mem.count(dial)) return mem[dial];
  int res=1e9;
  for(int i=idx;i<=k;i++)
    res=min(res,dfs(idx+1,add(dial,idx,i,dial[idx]))+(dial[idx]!=0));
  return mem[dial]=res;
}
 
int main(){
  while(cin>>k,k){
    cin>>A>>B;
    for(int i=0;i<k;i++) A[i]=(A[i]-B[i]+10)%10;
    mem.clear();
    cout <<dfs(0,A)<<endl;
  }
  return 0;
}

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

int main() {
    int n;
    cin>>n;
    float a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    float sum=0;
    for(int i=0;i<n;i++) sum+=1/a[i];
    printf("%.8f\n", 1/sum);
}

Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]

ans = 0
sum_height = sum(h)
while sum_height > 0:
    i = 0
    while i < N:
        while i < N and h[i] == 0:
            i += 1
        if i < N:
            ans += 1
        while i < N and h[i] > 0:
            h[i] -= 1
            sum_height -= 1
            i += 1

print(ans)

Measured memory_bytes: 3064
n,k = map(int,input().split())
if abs(n-k) >= n:
    print(n)
elif n > k:
    tmp = n%k
    print(min(tmp,abs(tmp-k)))
elif n==k:
    print(0)
elif n == 0:
    print(0)
else:
    print(abs(n-k))


Measured memory_bytes: 38384
fn main() {
    let n = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let n: usize = buf.trim_end().parse().unwrap();
        n
    };

    let s = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let s = buf.trim_end().to_owned();
        let a = s.chars().map(|x| x).collect::<Vec<char>>();
        a
    };

    for i in 0..1 << 2 {
        let mut l = vec![""; n];
        if i & 1 == 1 {
            l[0] = "S"
        } else {
            l[0] = "W"
        }
        if i >> 1 & 1 == 1 {
            l[1] = "S"
        } else {
            l[1] = "W"
        }
        for i in 1..n - 1 {
            let mut _c = s[i];
            if l[i] == "W" {
                if _c == 'o' {
                    _c = 'x';
                } else {
                    _c = 'o';
                }
            }
            if _c == 'o' {
                l[i + 1] = l[i - 1]
            } else {
                if l[i - 1] == "S" {
                    l[i + 1] = "W"
                } else {
                    l[i + 1] = "S"
                }
            }
        }
        // 0番目のチェック
        let mut _c = s[n - 1];
        if l[n - 1] == "W" {
            if _c == 'o' {
                _c = 'x';
            } else {
                _c = 'o';
            }
        }
        if (_c == 'o' && l[n - 2] != l[0]) || (_c == 'x' && l[n - 2] == l[0]) {
            continue
        }

        let mut _c = s[0];
        if l[0] == "W" {
            if _c == 'o' {
                _c = 'x';
            } else {
                _c = 'o';
            }
        }
        if (_c == 'o' && l[n - 1] != l[1]) || (_c == 'x' && l[n - 1] == l[1]) {
            continue
        }

        // 成功してる
        println!("{}", l.iter().fold(String::new(), |acc, c| acc + c));
        return
    }
    println!("{}", -1);
}


Measured memory_bytes: 3920
#include <stdio.h>
int main(void){
  int n,m,x,f[200001]={},i,j,min=200000,max=0,k,t=0,l,dt[100000],ans=0;
  scanf("%d%d",&n,&m);
  if (n>=m){
    printf("0\n");
    return 0;
  }
  for (i=0;i<m;i++){
    scanf("%d",&x);
    f[x+100000]=1;
    if (x+100000<min) min=x+100000;
    if (x+100000>max) max=x+100000;
  }
  k=min;
  for (i=min+1;i<=max;i++){
    if (f[i]){
      dt[t]=i-k;
      ans+=dt[t];
      k=i;
      t++;
    }
  }
  if (n*2<m){
    for (i=0;i<n-1;i++){
      max=0;
      for (j=0;j<t;j++){
        if (dt[j]>max){
          max=dt[j];
          l=j;
        }
      }
      ans-=max;
      dt[l]=0;
    }
  }else{
    ans=0;
    for (i=0;i<t-n+1;i++){
      min=2000000;
      for (j=0;j<t;j++){
        if (dt[j]<min){
          min=dt[j];
          l=j;
        }
      }
      ans+=min;
      dt[l]=2000000;
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 2007

int N;
char s[MAX_N];
std::vector<int>G[MAX_N];
int f[MAX_N], sum[MAX_N], cnt[MAX_N];

void dfs(int x, int las) {
    cnt[x] = s[x] - '0';
    sum[x] = 0;
    int su = 0, mx = 0, u = 0;
    for (int y : G[x])
        if (y != las) {
            dfs(y, x);
            int tmp = sum[y] + cnt[y];
            sum[x] += tmp;
            cnt[x] += cnt[y];
            su += tmp;
            if (tmp > mx)
                mx = tmp, u = y;
        }
    // printf("%d %d %d %d\n", x, su, mx, u);
    if (su - mx >= mx)
        f[x] = su / 2;
    else {
        f[x] = su - mx + std::min(f[u], (2 * mx - su) / 2);
    }
}

int main() {
    read(N);
    scanf("%s", s + 1);
    // Rep(i, N) printf("%d ", s[i] - '0');
    // puts("");
    int u, v;
    Lep(i, N) {
        read(u), read(v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int res = 1e9;
    Rep(i, N) {
        dfs(i, 0);
        // printf("%d %d %d\n", i, f[i], sum[i]);
        if (f[i] * 2 == sum[i])
            chmin(res, f[i]);
    }
    printf("%d\n", res == 1e9 ? -1 : res);
    return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
int N, M;
cin >> N >> M; 
print((M * 1900 + 100 * (N - M)) * pow(2,M));
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
int K, S;
void solve(){
    int ans = 0;
    REP(x, K+1){
        REP(y, K+1){
            if(0<=S-x-y && S-x-y<=K) ans++;
        }
    }
    printf("%d",ans);
}

int main(){
    scanf("%d",&K);
    scanf("%d",&S);
    solve();
}

Measured memory_bytes: 256