akhauriyash/Code-Regression huggingface dataset:
/**
 *   Author   :  Nguyen Canh Toan 
 *   Created  :  20.05.2020 10:56:38
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> dp(3);
  for (int day = 0; day < n; day++) {
	  vector<int> c(3);
	  for (int i = 0; i < 3; i++) {
			cin >> c[i];
		}
		vector<int> new_dp(3, 0);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i != j) {
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
				}
			}
		} 
		dp = new_dp;
	}
	cout << max({dp[0], dp[1], dp[2]}) << endl; 
  return 0;
}


Measured memory_bytes: 256
A,B,K = map(int,input().split(" "))

for i in range(K):
    if i%2 == 0:
        if A%2 == 1:
            A -= 1
            B += A // 2
            A = A // 2
        else:
            B += A // 2
            A = A // 2
    else:
        if B%2 == 1:
            B -= 1
            A += B // 2
            B = B //2
        else:
            A += B // 2
            B = B // 2
print(A,B)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int pow,ipart;
int inum,irev;
int main () {
	int A,B;
	cin >> A >> B;

	int ans=0,ipali[5];
	for (int i = A; i < B+1; ++i)
	{
		//cout << i << endl;
		inum = i;
		for (int j=0;j<5;++j) {
			pow=1;
			for (int k=0;k<5-j-1; ++k) pow=pow*10;
			if (j==0)
			{
				ipali[j]=inum/pow;
				ipart = inum-ipali[j]*pow;
			} else {
				ipali[j]=ipart/pow;
				ipart=ipart-ipali[j]*pow;
			}
			//cout << ipali[j] << endl;
		}
		irev=0;
		for (int i = 0; i < 5; ++i)
		{
			pow=1;
			for (int k=0;k<i; ++k) pow=pow*10;
			irev += ipali[i]*pow;
			//cout << irev << endl;
		}
		if (inum==irev)
		{
			ans += 1;
		}

 	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  char x,y;
  cin>>x>>y;
  if(x>y){
    cout<<'>'<<endl;
  }else if(x<y){
    cout<<'<'<<endl;
  }
  else{
    cout<<'='<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	int q;
	scanf("%d", &q);
	vector<int> t(q);
	rep(i, q)scanf("%d", &t[i]);
	sort(all(a));
	int ans = 0;
	rep(i, q) {
		ans += binary_search(all(a), t[i]);
	}
	printf("%d\n", ans);

	Please AC;
}



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

int main(void) {
	int n;
	int t[101];
	int m;
	int p[101];
	int x[101];
	int sum[101] = {};
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i];
		cin >> x[i];
	}
	for (int i = 1; i <= m; i++) {
		for (int u = 1; u <= n; u++) {
			if (p[i] == u) {
				sum[i] += x[i];
			}
			else {
				sum[i] += t[u];
			}
		}
		cout << sum[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().strip().split(' ')))
c = list(map(int, input().strip().split(' ')))
l = [0] * n
for i in range(n):
  l[i]=v[i]-c[i]
l.sort(reverse=True)
s = 0
for i in range(n):
  if s < sum(l[0:i+1]):
    s = sum(l[0:i+1])
print(s)

Measured memory_bytes: 3064
a = []
10.times{
  a.push(gets.to_i)
}

def max_idx(a, i)
  max     = a[i]
  max_idx = i
  (i+1..a.length-1).each{|k|
    if a[k] > max
      max     = a[k]
      max_idx = k
    end
  }
  max_idx
end

(0..a.length-1).each{|i|
  max_idx = max_idx(a, i)
  v = a[i]
  a[i] = a[max_idx]
  a[max_idx] = v
}

(0..2).each{|i|
  puts a[i]
}
  

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
using pii = pair<int, int>;

int rem;
int32_t main()
{
    usecppio
    string str;
    cin >> str;
    for (auto it:str)
    {
        rem += (it-'0');
    }
    cout << ((rem%9)?"No":"Yes") << '\n';
}

Measured memory_bytes: 3744
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
  
  // read problem
  long long int N, tmp;
  std::vector<long long int> A;
  
  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp);
  }
  
  // solve problem
  std::vector<long long int> rain(N);
  // make temporary answer
  rain[0] = 0; // assumption
  for(long long int i = 1; i < N; i++){
    rain[i] = 2*(A[i-1]-rain[i-1]/2);
  }
  /*
  std::cerr << "temporary rain:"<< std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << rain[i] << " ";
  }std::cerr << std::endl;*/
  

  
  // correction
  long long int d = (A[N-1] - rain[0]/2 - rain[N-1]/2);
  for(long long int i = 0; i < N; i++){
    if((i+2)%2 == 0){
      rain[i] += d;
    }
    else{
      rain[i] -= d;
    }
  }
  
  std::cerr << "Answer:"<< std::endl;
  for(long long int i = 0; i < N; i++){
    std::cout << rain[i] << " ";
  }std::cerr << std::endl;
  
  
  return 0;
}


Measured memory_bytes: 3060
using System;

namespace abc148
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();

            if (a == "1" && b == "2") Console.WriteLine("3");
            if (a == "1" && b == "3") Console.WriteLine("2");
            if (a == "2" && b == "1") Console.WriteLine("3");
            if (a == "2" && b == "3") Console.WriteLine("1");
            if (a == "3" && b == "1") Console.WriteLine("2");
            if (a == "3" && b == "2") Console.WriteLine("1");
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,l[13],a,max=0,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>l[i];
    sum+=l[i];
    if(max<l[i]){
      max=l[i];
    }
  }
    sum-=max;
  if(max<sum){
    cout<<"Yes"<<"\n";
  }else{
    cout<<"No"<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}


int32_t main(){

    int m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;++i)for(int j=1;j<=d;++j){
        int a=j/10;
        int b=j%10;
        if(a>=2&&b>=2&&a*b==i){
            ans++;
        }
    }
    cout<<ans<<'\n';

    return 0;
}


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

class UnionFind {
private:
    vector<int> parent;
    vector<int> rank;
public:
    UnionFind(unsigned long n): parent(n), rank(n, 0) {
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
        } else {
            parent[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

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

struct city {
    int num;
    int x, y;
};

int main() {
    int N;
    cin >> N;
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<>> pcities;
    vector<city> cities;
    for (int i = 0; i < N; ++i) {
        city c;
        cin >> c.x >> c.y;
        c.num = i;
        cities.push_back(c);
    }
    sort(cities.begin(), cities.end(), [](const city& a, const city& b) {
        return a.x < b.x;
    });
    for (int i = 1; i < N; ++i) {
        pcities.push(make_tuple(cities[i].x - cities[i-1].x, cities[i-1].num, cities[i].num));
    }

    sort(cities.begin(), cities.end(), [](const city& a, const city& b) {
        return a.y < b.y;
    });
    for (int i = 1; i < N; ++i) {
        pcities.push(make_tuple(cities[i].y - cities[i-1].y, cities[i-1].num, cities[i].num));
    }
    UnionFind uf(N);
    int res = 0;
    while(!pcities.empty()) {
        auto cinfo = pcities.top();
        pcities.pop();
        if (uf.same(get<1>(cinfo), get<2>(cinfo))) continue;
        uf.unite(get<1>(cinfo), get<2>(cinfo));
        res += get<0>(cinfo);
    }
    cout << res << endl;
}


Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
#define INF 1 << 30

/* いんぷっと */
int S, T, U; // S:体力の上限 T:トレーニングの種類 U:一日に行うトレーニングの種類数
int N, O, D; // N:ドーナツの種類 O:1日の回復体力量  D:日数
int e[100], c[100]; // e[i]:トレーニングiに必要な体力 c[i]:トレーニングiの消費カロリー
int h[100], a[100]; // h[i]:i番目の幸福度 a[i]:i番目の摂取カロリー
/* おわり */

/* あうとぷっと */
// D日間で得られる幸福の総和の最大値 */

int main()
{
  cin >> S >> T >> U >> N >> O >> D;
  for(int i = 0; i < T; i++){
    cin >> e[i] >> c[i];
  }
  for(int i = 0; i < N; i++){
    cin >> h[i] >> a[i];
  }

  int dp1[101][101]; // dp[トレーニングの種類数][つかう体力]: 最大消費カロリー
  fill_n( *dp1, 101 * 101, -1);
  dp1[0][0] = 0;
  for(int i = 0; i < T; i++){
    for(int j = U - 1; j >= 0; j--){
      for(int k = 0; k <= S - e[i]; k++){ // 1回i番目のトレーニングをやる
        if(dp1[j][k] == -1) continue;
        dp1[j + 1][k + e[i]] = max( dp1[j + 1][k + e[i]], dp1[j][k] + c[i]);
      }
    }
  }

  int dp2[101 * 101 + 1]; // dp2[摂取カロリー]: 最大幸福度
  fill_n( dp2, 101 * 101 + 1, -1);
  dp2[0] = 0;

  for(int i = 0; i < N; i++){
    for(int j = 0 ; j <= 101 * 101 - a[i]; j++){
      if(dp2[j] == -1) continue;
      dp2[j + a[i]] = max( dp2[j + a[i]], dp2[j] + h[i]);
    }
  }
  for(int i = 1; i <= 101 * 101; i++){
    dp2[i] = max( dp2[i - 1], dp2[i]);
  }

  int dp3[101][101]; // dp3[日数][体力]: 幸福の総和の最大値
  fill_n( *dp3, 101 * 101, -1);
  dp3[0][S] = 0;
  for(int i = 0; i < D; i++){
    for(int j = 0; j <= S; j++){
      for(int k = 0; k <= j; k++){ //消費カロリーはjまでじゃん
        if(dp3[i][j] == -1) continue;
        if(dp1[U][k] == -1 || dp2[dp1[U][k]] == -1) continue;
        dp3[i + 1][min( j + O - k, S)] = max( dp3[i + 1][min( j + O - k, S)], dp3[i][j] + dp2[dp1[U][k]]);
      }
    }
  }

  int ret = -1;
  for(int i = 0; i <= S; i++) ret = max( ret, dp3[D][i]);
  cout << ret << endl;
  return(0);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int n,c[600],s[600],f[600],ans[600],sum[600];
int main(){
    cin >> n;
    for(int i=1;i<n;i++) cin >> c[i] >> s[i] >> f[i];
    for(int i=1;i<n;i++) sum[i] = sum[i-1]+c[i];
    for(int i=1;i<n;i++){
        int tmp = s[i];
        for(int j=i;j<n;j++){
            tmp = max(tmp,s[j]);
            while(tmp%f[j]) tmp++;
            tmp += c[j];
        }
        printf("%d\n",tmp);
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    ll x[n], y[n]; zep(i, 0, n)cin >> x[i] >> y[i];
    
    vector<ll> mx(4, -INF);

    vector<vector<ll>> s = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
    zep(i, 0, n){
        zep(j, 0, 4){
            mx[j] = max(mx[j], x[i] * s[j][0] + y[i] * s[j][1]);
        }
    } 

    ll ans = -INF;

    zep(i, 0, n){
        zep(j, 0, 4){
            ans = max(ans, mx[j] - (x[i] * s[j][0] + y[i] * s[j][1]));
        }
    }
    print(ans)

    return 0;
}

Measured memory_bytes: 6784
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string p0 = "";//0スタート
            int n = s.Length;
            for(int i=0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    p0 += "0";
                }
                else
                {
                    p0 += "1";
                }
            }
            int dif0 = 0;
            for(int i=0; i < n; i++)
            {
                if (s[i] != p0[i]) dif0++;
            }
            Console.WriteLine((int)Math.Min(dif0, n-dif0));
        }
    }
}


Measured memory_bytes: 48388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int MAXN = 2e6;
const ll inf = 1e18;
int n,m;
unordered_set<int> adj[MAXN];
bool vis[MAXN];
int ans,comp;
void dfs(int node) {
    vis[node] = true;
    for(auto &x : adj[node]) {
        if(!vis[x]) {
            dfs(x);
            comp++;
        }
    }
}
int32_t main() {
    fio

    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x,y;
        cin >> x >> y;
        adj[x].insert(y);
        adj[y].insert(x);
    }
    for (int j = 1; j <= n; ++j) {
        if(!vis[j]) {
            dfs(j);
            ans = max(ans,comp);
            comp = 0;
        }

    }
    cout << ans + 1 << endl;



    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 138316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s, count = 0;
  cin >> s;
  if (s / 100 == 1) {
      count += 1;
  }
  if ((s % 100) / 10 == 1) {
      count += 1;
  }
  if (s % 10 == 1) {
      count += 1;
  }
  
  cout << count << endl;
}

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

int main(){
  int n; cin >> n;
  char S[n], T[n];
  for(int i = 0; i < n; i++){
    cin >> S[i];
  }
  for(int i = 0; i < n; i++){
    cin >> T[i];
  }
  for(int i = 0; i < n; i++){
    cout << S[i] << T[i];
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	int a[4];
	cin >> a[1] >> a[2] >> a[3];
	sort(a+1,a+3+1);
	cout << a[1]+a[2];
	return 0;
}


Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: m,n,l,x,i,match
character(len=10) :: c

read(*,*) m,n
read(*,*) c

! ここに計算式

l=m+1
x=m+n+1
match=0

do i=1,x
 if(c(i:i)=="-")then
  match=match+1
 end if
end do

if(match/=1)then
 write(*,*) 'No'
else if(c(l:l)=="-")then
 write(*,*) 'Yes'
else
 write(*,*) 'No'
endif

! ここに出力結果


END PROGRAM ATCODER

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
#define lc (x << 1)
#define rc (x << 1 | 1)
#define mid ((l + r) >> 1)
typedef long long LL;
#define int LL

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc();
  while (ch < '0' || ch > '9') ch = gc();
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
}

int const MAXN = 2e5 + 5;
int a[MAXN];
LL min1[MAXN * 4], min2[MAXN * 4], ans[MAXN * 4], add[MAXN * 4];

inline void Update(int x) {
  min1[x] = min(min1[lc], min1[rc]);
  min2[x] = min(min2[lc], min2[rc]);
  ans[x] = min(ans[lc], ans[rc]);
}
inline void Add(int x, int num) {
  min1[x] += num;
  min2[x] += num;
  add[x] += num;
  ans[x] += num;
}
inline void Pushdown(int x) {
  if (add[x]) {
    Add(lc, add[x]);
    Add(rc, add[x]);
    add[x] = 0;
  }
}
void Build(const int x, const int l, const int r, const int &num) {
  if (l == r) return ans[x] = abs(num - l), min1[x] = ans[x] - l, min2[x] = ans[x] + l, void();
  Build(lc, l, mid, num), Build(rc, mid + 1, r, num);
  Update(x);
}
void Modify(const int x, const int l, const int r, const int &pos, const int &num) {
  if (l == r) return ans[x] = min(ans[x], 1ll * num), min1[x] = ans[x] - l, min2[x] = ans[x] + l, void();
  Pushdown(x);
  if (pos <= mid) Modify(lc, l, mid, pos, num);
  else Modify(rc, mid + 1, r, pos, num);
  Update(x);
}
LL Query(const int x, const int l, const int r, const int i, const int j, const int op) {
  if (i <= l && r <= j) return op ? min1[x] : min2[x];
  Pushdown(x);
  LL re = 0x7f7f7f7f7f7f7f7f;
  if (i <= mid) re = min(re, Query(lc, l, mid, i, j, op));
  if (j > mid) re = min(re, Query(rc, mid + 1, r, i, j, op));
  return re;  
}

signed main() {
//  freopen("move.in", "r", stdin);
//  freopen("move.out", "w", stdout);
  int n, Q, A, B;
  read(n), read(Q), read(A), read(B);
  for (RI i = 1; i <= Q; ++i) read(a[i]);
  a[0] = A;
  Build(1, 1, n, B);
  for (RI i = 1; i <= Q; ++i) {
    int Min = std :: min(Query(1, 1, n, 1, a[i], 1) + a[i], Query(1, 1, n, a[i], n, 0) - a[i]);
    Add(1, abs(a[i] - a[i - 1]));
    Modify(1, 1, n, a[i - 1], Min);
  }
  printf("%lld\n", ans[1]);
  return 0;
}


Measured memory_bytes: 27776
def ge(k,array,ind):
    return array[ind]>=k

def lower_bound(k, array, func=ge):
    """
    k 以上を満たす最小のインデックスを返す
    もしなかったら要素数を返す
    """
    lb=-1
    ub=len(array)
    while ub-lb>1:
        mid = (lb+ub)//2
        if func(k,array,mid):
            ub=mid
        else:
            lb=mid
    return ub

def lt(k,array,ind):
    return array[ind]<k

def upper_bound(k, array, func=lt):
    """
    k 未満を満たす最大のインデックスを返す
    もしなかったら-1を返す
    """
    lb=-1
    ub=len(array)
    while ub-lb>1:
        mid = (lb+ub)//2
        if func(k,array,mid):
            lb=mid
        else:
            ub=mid
    return ub-1
def main():
    l = int(input())
    ans = []
    array = [i for i in range(60)]
    ind = upper_bound(l, array, lambda k,array,mid:2**mid<=k)
    r = array[ind]
    n = r+1
    for i in range(1,n):
        ans.append((i,i+1,0))
        ans.append((i,i+1,2**(i-1)))
    for t in range(n-1,0,-1):
        if l-2**(t-1)>=2**r:
            ans.append((t,n,l-2**(t-1)))
            l-=2**(t-1)
    print(n,len(ans))
    for f,t,c in ans:
        print(f,t,c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
  long long i, n;
  long long min = 0;
  cin >> n;
  for(i = sqrt(n); i*i > 0; i--){
    if(n%i == 0){
        min = n/i + i - 2;
        break;
    }
  }
  
  cout << min << endl;
  return 0;
  
}


Measured memory_bytes: 256
x = gets.to_i

pows = {}
(-200..200).each_with_object(pows) { |num, result| result[num ** 5] = num}

answer = pows.keys.repeated_permutation(2).find { |a_5, b_5| a_5 - b_5 == x }

puts answer.map { |n| pows[n] }.join(' ')


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

int main() {
  string A, B;
  cin >> A >> B;
  if(A.size() > B.size()) {
    cout << "GREATER";
  }
  else if(A.size() < B.size()) {
    cout << "LESS";
  }
  else {
    for(int i = 0; i < A.size(); i++) {
      if(A.at(i) - '0' > B.at(i) - '0') {
        cout << "GREATER";
        break;
      }
      else if(A.at(i) - '0' < B.at(i) - '0') {
        cout << "LESS";
        break;
      }
      else {
        if(i == A.size() - 1) {
          cout << "EQUAL";
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    rep(i, h) cin >> A[i];
    bool ans = true;
    rep(i, h) {
        rep(j, w) {
            if(i == h - 1 && j == w - 1) continue;
            if(i + 1 >= h || j + 1 >= w) continue;

            if(A[i + 1][j] == '#' && A[i][j + 1] == '#') ans = false;
        }
    }

    if(ans) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll A[3] = {2,3,5},cost[3];
main() {
	int t; cin >> t;
	while (t--) {
		ll n,D;
		cin >> n >> cost[0]>>cost[1]>>cost[2] >> D; // 2 3 4 +-1
		set<pair<ll,ll> > s;
		s.insert({0,n});
		map<ll,ll> mp;
		ll ans = 2e18;
		mp[n] = 0;
		while (!s.empty()) {
			ll v = s.begin()->second;ll val = s.begin()->first;
			if (v == 1) {
				ans = min(ans, val + D);
				break; 
			}
			s.erase(s.begin());
			if (sqrt(v)*sqrt(D) <= 1E9)
			ans = min(ans,val + v*D);
			for (int i = -5; i <= 5; i++) {
			//	if (i == 0) continue;
				if (v + i > 0) {
					for (int g = 0; g < 3; g++){
					if ((v + i)%A[g]  == 0)  {
					ll r = mp[ ( v + i)/A[g]];	
					if (( v + i)/A[g] != n && (r == 0 || r > val + D*abs(i) + cost[g])) {
						s.erase({r,( v + i)/A[g]});
						mp[( v + i)/A[g]] = val + D*abs(i) + cost[g];
						s.insert ({val + D*abs(i) + cost[g],( v + i)/A[g] });
					}
				}
				}
			}
		}
	} cout << ans<<'\n';
	}
	
	}
		
		
		
		
	


Measured memory_bytes: 7264
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

#include <iostream>

using namespace std;

void scans(string & str) {
	char c;
	scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", max(0, a - 2 * b));

 	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

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

const int maxn=100000;

int n,pre[maxn*2+10],now[maxn+10],son[maxn*2+10],tot,f[maxn+10];

int ins(int a,int b)
{
  pre[++tot]=now[a];
  now[a]=tot;
  son[tot]=b;
  return 0;
}

int search(int u,int fa)
{
  for(int i=now[u]; i; i=pre[i])
    {
      int v=son[i];
      if(v==fa)
        {
          continue;
        }
      search(v,u);
      f[u]^=(f[v]+1);
    }
  return 0;
}

int main()
{
  n=read();
  for(int i=1; i<n; ++i)
    {
      int a=read(),b=read();
      ins(a,b);
      ins(b,a);
    }
  search(1,0);
  puts(f[1]?"Alice":"Bob");
  return 0;
}


Measured memory_bytes: 7168
class Dice():
    
    state = [0 for _ in range(6)]

    def __init__(self, dice_list):
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    L = list(map(int, input().split()))
    actions = list(input())

    dice = Dice(L)

    for action in actions:
        if action == 'N':
            dice.north()

        if action == 'W':
            dice.west()

        if action == 'S':
            dice.south()

        if action == 'E':
            dice.east()

    print(dice.state[0])


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int k;
  cin>>k;
  queue<ll> q;
  for(ll i = 1; i <= 9; i++)
  q.push(i);
  ll ans;
  for(int i = 0; i < k; i++){
  	ans = q.front();
    q.pop();
    if(ans%10!=0) q.push((ans*10 + ans%10 - 1));
    q.push((ans*10+ans%10));
    if(ans%10!=9) q.push((ans*10 + ans%10 + 1));
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
double stdev(int s[], int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum = sum + s[i];
    }
        double m = (double)sum / n;
        double sum2 = 0;
        for (int i = 0; i < n; i++)
        {
            sum2 = sum2 + pow(s[i] - m, 2);
        }
        double v = sum2 / n;
        return sqrt(v);
}

int main()
{
    int n, s[1000];
    do
    {
        scanf("%d", &n);
        if (n > 0)
        {
            for (int i = 0; i < n; i++)
            {
                scanf("%d", &s[i]);
            }
            double sd = stdev(s, n);
            printf("%.6lf\n", sd);
        }

    } while (n > 0);

    return 0;
}


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

int main()
{
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int cnt = 0;
    int Ai = 0;
    vector<int> cnt_first(N, -1);
    map<int, int> m;
    while (cnt_first.at(Ai) < 0)
    {
        cnt_first.at(Ai) = cnt;
        m[cnt] = Ai;
        Ai = A.at(Ai) - 1;
        ++cnt;
    }
    if (K < cnt)
    {
        cout << m.at(K) + 1 << endl;
        return 0;
    }
    int l = cnt - cnt_first.at(Ai);
    int t = cnt_first.at(Ai) + (K - cnt_first.at(Ai)) % l;
    cout << m.at(t) + 1 << endl;
}

Measured memory_bytes: 13956
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <complex>
#include <cstdio>
#include <cmath>

using namespace std;

typedef complex<double> P;

const int MAX_N = 100;
const int MAX_M = 100;

const int MAX_V = MAX_N + MAX_M + 5;
const int INF = 1<<24;

struct Edge { int to, cap, rev; };

int V;
vector<Edge> G[MAX_V];
bool vis[MAX_V];

void add_edge(int from, int to, int cap) {
  G[from].push_back((Edge){to, cap, G[to].size()});
  G[to].push_back((Edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  vis[v] = true;
  for(int i = 0; i < G[v].size(); ++i) {
    Edge &e = G[v][i];
    if(!vis[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(true) {
    fill(vis, vis+V, false);
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

const double EPS = 1e-8;

bool equals(double a, double b) { return fabs(a - b) < EPS; }

int N, M;
P T[MAX_N], B[MAX_M];
double sp[MAX_N];


double norm(P a) { return a.real()*a.real() + a.imag()*a.imag(); }
double abs(P a) { return sqrt(norm(a)); }

void makeGraph(double t) {
  V = N + M + 2;
  for(int i = 0; i < V; ++i) G[i].clear();
  for(int i = 0; i < N; ++i) add_edge(N+M, i, 1);
  for(int j = 0; j < M; ++j) add_edge(N+j, N+M+1, 1);

  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < M; ++j) {
      double a = norm(T[i] - B[j]);
      double b = t*t*sp[i]*sp[i];
      if(equals(a, b) || a < b) add_edge(i, N+j, 1);
    }
  }
}

int main() {
  while(cin >> N >> M && (N || M)) {
    for(int i = 0; i < N; ++i)
      cin >> T[i].real() >> T[i].imag() >> sp[i];
    for(int i = 0; i < M; ++i)
      cin >> B[i].real() >> B[i].imag();

    vector<double> D;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < M; ++j) {
	D.push_back(abs(T[i] - B[j])/sp[i]);
      }
    }
    sort(D.begin(), D.end());

    int l = 0;
    int r = D.size();
    int ans = (int)D.size()-1;
    while(l < r) {
      int m = (l+r)/2;
      makeGraph(D[m]);
      if(max_flow(N+M, N+M+1) == M) {
	r = m;
	ans = min(ans, m);
      } else {
	l = m+1;
      }
    }
    printf("%.8f\n", D[ans]);
  }
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    int N;
    cin >> N;
 
    long long money = 1000;
    long long stock = 0;
 
    vector<int> A(N);
 
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
 
    for(int i = 0; i < N-1; i++) {
        if(A[i] < A[i+1]) {
            stock += money / A[i];
          	money -= money / A[i] * A[i];
                
        } else if(A[i] > A[i+1]) {
      		money += stock * A[i];
      		stock = 0;
            
        }
    }
 
    money += stock * A[N-1];
    stock = 0;
 
    cout << money << endl;    
	return 0;
}

Measured memory_bytes: 3596
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<LL> a(n);
		vector<LL> b(n);
		REP(i,n) cin >> a[i]; 
		REP(i,n) cin >> b[i];
		REP(i,n) a[i] -= b[i];
		LL cnt2 = 0, cnt1 = 0;
		LL sum = 0;
		REP(i,n) {
			sum += a[i];
			if(a[i] > 0) {
				cnt1 += a[i];
			} else {
				cnt1 += (a[i]%2+2)%2;
			}
		}
		dpite(ALL(a));
		DEBUG(sum); DEBUG(cnt1);
		if(sum <= 0 and cnt1 <= -sum) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
		
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};
const static int INF = 1 << 30;

int w, h, mas[20][20];
Pi S, G;

bool In(int x, int y)
{
  return(0 <= x && x < w && 0 <= y && y < h);
}

int rec(int x, int y, int d, int cost)
{
  if(cost > 10) return(INF);
  if(make_pair(x, y) == G) return(cost);
  int ret = INF;
  if(d == -1) {
    for(int i = 0; i < 4; i++) {
      if(!In(x + dx[i], y + dy[i])) continue;
      if(In(x + dx[i], y + dy[i]) && mas[y + dy[i]][x + dx[i]] == 1) continue;
      ret = min(ret, rec(x + dx[i], y + dy[i], i, cost + 1));
    }
  } else {
    x += dx[d], y += dy[d];
    if(In(x, y)) {
      if(mas[y][x] == 1) {
        mas[y][x] = 0;
        ret = rec(x - dx[d], y - dy[d], -1, cost);
        mas[y][x] = 1;
      } else {
        ret = rec(x, y, d, cost);
      }
    }
  }
  return(ret);
}

int main()
{
  while(cin >> w >> h, w) {
    S = make_pair(-1, -1);
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> mas[i][j];
        if(mas[i][j] == 2) {
          S = make_pair(j, i);
        } else if(mas[i][j] == 3) {
          G = make_pair(j, i);
        }
      }
    }
    int ret = rec(S.first, S.second, -1, 0);
    if(S == make_pair(-1, -1) || ret == INF) cout << -1 << endl;
    else cout << ret << endl;
  }
}

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

char s[100001];
int K;

main(){
    cin >> s;
    cin >> K;
    int len = strlen(s);
    for(int i = 0; i < len; i++){
        if(s[i] != 'a'){
            if(K >= 123 - s[i]){
                K -= 123 - s[i];
                s[i] = 'a';
            }
        }
        if(i == len - 1){
            s[i] = 97 + (s[i] - 97 + K) % 26;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int kekka[2];
int prime_or_not[1001];
int prime_list[1001];
int prime_num[1001];
int prime_counter = 0;
void sosuubunnpu(){
    for (int i = 1; i <= 1000; ++i)
    {
        prime_or_not[i] = 0;
    }
    for (int i = 2; i <= 1000; ++i)
    {
        for (int j = 2; j <= 1000/i; ++j)
        {
            if(prime_or_not[i]==0){
                prime_or_not[i*j] = 1;
            }
        }
    }
    for (int i = 2; i <= 1000; ++i)
    {
        if(prime_or_not[i]==0){
            prime_list[prime_counter] = i;
            prime_counter+=1;
        }
    }
}
void innsuubunnkai(int N,int n){
    int time = 0;
    while(1){
        if(N%n == 0){
            N = N/n;
            time++;
        }else{
            break;
        }
    }
    kekka[0] = time;
    kekka[1] = N;
}

int main()
{
    sosuubunnpu();
    int N;
    cin >> N;
    int innsuu[11];
    int A[N+1][11];
    for (int i = 0; i <= 1000; ++i)
    {
        prime_num[i] = 0;
    }
    unsigned long long result = 1;
    for (int current_num = 2; current_num <= N; ++current_num)
    {
        kekka[1] = current_num;
        for (int i = 0; i < prime_counter; ++i)
        {
            innsuubunnkai(kekka[1],prime_list[i]);
            prime_num[i]+=kekka[0];
        }
    }
    for (int current_num = 2; current_num <= N; ++current_num){
        for (int i = 0; i < 11; ++i){
            innsuu[i] += A[current_num][i];
        }
    }
    for (int i = 0; i < prime_counter; ++i){
        result = (result*(prime_num[i]+1))%1000000007;
    }
    cout << result << endl;
    
    return 0;
}

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

int main() {
    ll N, B, R, C, D, E, ans;
    cin >> N >> B >> R;
    C = B + R;
    
    if (C != 0) {
        D = N / C;
        E = N % C;
    } else if (C == 0) {
        D = 0;
        E = 0;
    }
    
    ans = D * B + min(E, B);
    cout << ans << endl;
}

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

int func(const string& s, int i, int j)
{
    if (i>=j) return 0;
    if (s[i]==s[j]) return func(s, i+1, j-1);
    if (s[i]!='x' and s[j]!='x') return INT_MIN;
    if (s[i]!='x') return func(s, i, j-1)+1;
    return func(s, i+1, j)+1;
}

int main()
{
    string s; cin>>s;
    int res=func(s, 0, s.size()-1);
    cout<<(res<0 ? -1 : res)<<endl;
}



Measured memory_bytes: 512
fun main(args: Array<String>){
  val input = readLine()!!.split(" ")
  val a = input[0].toInt()
  val b = input[1].toInt()
  
  val tasu = a + b
  val hiku = a - b
  val kake = a * b
    
  var max = -100000
  
  if(tasu < hiku){
    max = hiku
  }
  else{
    max = tasu
  }
  
  if(max < kake){
    max = kake
  }
  println(max)
}

Measured memory_bytes: 37992
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

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


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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     pii              pair<int, int>
#define     pll             pair<long long int, long long int>
#define     vll             vector<long long int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()
//__builtin_popcount(n)

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

unsigned int logn(unsigned int n, unsigned int r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }

ll pw[32];

void cal(){ pw[0] = 1; rep(i, 1, 32)pw[i] = 2*pw[i-1]; }


void solve()
{
    map<string, int> mp;
    ll n; cin>>n;
    string s;
    rep(i, 0, n){
        cin>>s;
        mp[s]++;
    }
    cout<<mp.sz<<nl;
}


int main()
{
    // boost;
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 19176
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
void solve()
{   ll X,Y,Z;
    cin>>n>>k;
    ll x=(n/k);
    ll ans=min(abs(n-(x*k)),abs(n-(x+1)*k));
    ans=min(abs(n-(x-1)*k),ans);
    cout<<ans;
    
}

int main()
{   //seive();
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  // tmp0 = input[0].split(" ")
  // N = Number(tmp0[0])
  S = input[0]
  N = S.length
  S = S.split("")
  prev = S[0]
  var ans = 0
  for(var i=1; i < N; i++)
  {
    if(prev === S[i]){
      ans++
      S[i] = S[i] === '0' ? '1' : '0'
    }
    prev = S[i]
  }

  console.log(ans)

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("10010010\n")

Measured memory_bytes: 9292
// fibonacci number.
#include<stdio.h>

int main()
{
    int n;
    int A[45];
    scanf("%d", &n);
    A[0] = 1; A[1] = 1;
    for(int i = 2; i <= n; i++) A[i] = A[i - 1] + A[i - 2];
    printf("%d\n", A[n]);
    return 0;
}

Measured memory_bytes: 1024