akhauriyash/Code-Regression huggingface dataset:
#include <iostream>                                          
using namespace std;                                         
                                                             
int main(void) {                                             
  int H, W;                                                  
  while (true) {                                             
    cin >> H >> W;                                           
    if (H==0 && W==0) {                                      
      break;                                                 
    }                                                        
    for (int i=0; i<H; i++) {                                
      for (int j=0; j<W; j++) {                              
        cout << "#" << flush;                                
      }                                                      
      cout << endl;                                          
    }                                                        
    cout << endl;                                            
  }                                                          
  return 0;                                                  
}                               

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

int main()
{
  std::string S, T, U;
  int A, B;

  std::cin >> S >> T;
  std::cin >> A >> B;
  std::cin >> U;

  if (S.find(U) != std::string::npos)
    A -= 1;
  if (T.find(U) != std::string::npos)
    B -= 1;

  std::cout << A << " " << B;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi2d vector<vi >
#define vl2d vector<vl >
#define vpll vector<pll >

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rz resize
#define fr(i,n) for(i=0;i<(n);i++)
#define frr(i,n) for(i=(n-1);i>=0;i--)
#define fre(i,n) for(i=0;i<=(n);i++)
#define frre(i,n) for (i=(n);i>=0;i--)
#define frab(i,a,b) for(i=(a);i<(b);i++)
#define freab(i,a,b) for(i=(a);i<=(b);i++)
#define frrab(i,a,b) for(i=(b-1);i>=a;i--)
#define frreab(i,b,a) for(i=(b);i>=a;i--)

#define sz(a) int((a).size())
#define mset(a,b) (memset(a,b,sizeof(a)))
#define max3(a,b,c) (max((a),max((b),(c))))
#define min3(a,b,c) (min((c),min((a),(b))))
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector <ll> sprime;
vector<char> prime (1000000, true);
void sieve(ll n)
{
  //O(nloglogn) time
  sprime.pb(0);
  prime[0] = prime[1] = false;
  ll cnt = 0;
  for (ll i = 2; i <= n; ++i)
  {
    if (prime[i])
    {
      cnt++;
      sprime.pb(i);
      for (ll j = 2 * i; j <= n; j += i)
        prime[j] = false;
    }
  }
}
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p, ll MOD) { if (p == 0) return 1; ll z = fastpowMOD(a, p / 2, MOD); z = (z * z) % MOD; if (p % 2) z = (z * a) % MOD; return z; }
ll fastpow(ll a, ll p) { if (p == 0) return 1; ll z = fastpow(a, p / 2); z = (z * z); if (p % 2) z = (z * a); return z; }

#define mod 1000000007
#define inf LLONG_MAX
#define minf LLONG_MIN
#define pi 3.14
#define ex 2.71

//*********************************************///
const int N = 1e5 + 5;
int i,j;
ll a[3005];
ll dp[3005][3005][2];
ll ans=0;
int n;


















void solve()
{
  cin>>n;
  freab(i,1,n)
    cin>>a[i];
  freab(i,1,n)
    dp[i][i][0]=a[i],dp[i][i][1]=-a[i];
  freab(j,2,n)
  {
    frreab(i,j-1,1)
    {
      dp[i][j][0]=max(a[i]+dp[i+1][j][1],a[j]+dp[i][j-1][1]);
      dp[i][j][1]=min(-a[i]+dp[i+1][j][0],-a[j]+dp[i][j-1][0]);
    }
  }
  cout<<dp[1][n][0]<<endl;
}

int main()
{
  fast;
  int z;
  //cin>>z;
  z=1;
  while(z--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 140672
#include <bits/stdc++.h>
using namespace std;
long long dp[105][100005]={};
long long prefix[105][100005]={};
long long arr[100005];
long long md = 1e9 + 7;
int main(){
	long long n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> arr[i];
	for(int i = 0; i <= n; i++)
		dp[i][0] = 1, prefix[i][0] = 1;
	for(int i = 1; i <= k; i++)
		prefix[0][i] = prefix[0][i-1];
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= k; j++){
			if(j <= arr[i]){
				dp[i][j] = prefix[i-1][j]%md;
			}else{
				dp[i][j] = (md + prefix[i-1][j]%md - prefix[i-1][j-arr[i]-1]%md)%md;
			}
			prefix[i][j] = prefix[i][j-1]%md + dp[i][j]%md;
			prefix[i][j]%=md;
		}
	}
	cout << dp[n][k];
}

Measured memory_bytes: 159232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    vector<int> v(n-1);
    for(int i=0;i<n-1;i++)cin>>v[i];
    int ans=v[0]*2;
    for(int i=1;i<n-1;i++){
        if(v[i]>=v[i-1])ans+=v[i];
        else ans-=(v[i-1]-2*v[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int r, c;
    cin >> r >> c;
    auto a = make_vec<int>(r+1, c+1);
    rep(i, r) rep(j, c) cin >> a[i][j];
    rep(i, r) {
        int sum = 0;
        rep(j, c) sum += a[i][j];
        a[i][c] = sum;
    }
    rep(j, c) {
        int sum = 0;
        rep(i, r) sum += a[i][j];
        a[r][j] = sum;
    }
    rep(i, r) a[r][c] += a[i][c];
    rep(i, r+1) rep(j, c+1) cout << a[i][j] << (j == c ? '\n' : ' ');
}



Measured memory_bytes: 3132
import numpy as np

N, M, C = (int(x) for x in input().split())
B = [int(x) for x in input().split()]
A = [input().split() for i in range(N)]
A = np.array(A,dtype='int32')
B = np.array(B,dtype='int32').reshape((M,1))

ans = np.sum(np.dot(A,B) +C > 0)
print(ans)

Measured memory_bytes: 13636
#include <iostream>
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int x, y;
int fact[2000001];
int finv[2000001];

int comb(int n, int k) {
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

signed main() {
	cin >> x >> y;
	
	int i;
	fact[0] = 1;
	finv[0] = 1;
	for (i = 1; i <= 2000000; i++) {
		fact[i] = i * fact[i - 1] % mod;
		finv[i] = powmod(fact[i], mod - 2, mod);
	}
	
	if ((x + y) % 3 != 0) { cout << 0 << endl; return 0; }
	int k = (x + y) / 3;
	
	x -= k;
	y -= k;
	if (x < 0 || y < 0) { cout << 0 << endl; return 0; }
	
	cout << comb(k, x) << endl;
	return 0;
}

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

using namespace std;

const int N = 100'001;
int dp[N][3];

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 3; ++j) {
            int a;
            cin >> a;
            for (int k = 0; k < 3; ++k) {
                if (k != j) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a);
            }
        }
    }

    cout << *max_element(dp[n], dp[n] + 3) << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
int n,x[1010],y[1010],s[2];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", x + i, y + i);
		s[(x[i] + y[i]) & 1]++;
	}
	if (s[0] && s[1]) {
		puts("-1");
		return 0;
	}
	for (int i = 34; i >= 0; i--) v.push_back(1LL << i);
		int t = s[0] ? 5 : 4;
		for (int i = 0; i < t; i++) v.push_back(1);
	printf("%d\n", v.size());
	for (auto &it : v) printf("%lld ", it);
	puts("");
	for (int i = 0; i < n; i++) {
		long long tx=0, ty=0;
		for(auto &it:v) {
			long long dx = x[i]-tx, dy = y[i]-ty;
			if (abs(dx) > abs(dy)) {
				if (dx > 0) {
					putchar('R');
					tx += it;
				}
				else {
					putchar('L');
					tx -= it;
				}
			}
			else {
				if (dy > 0) {
					putchar('U');
					ty += it;
				}
				else {
					putchar('D');
					ty -= it;
				}
			}
		}
		puts("");
	}
	return 0;
}

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

int main(void)
{
  int n,m,k,i,j,time,limit,count=0;
  long long int temp,*a,*b;
  
  scanf("%d",&n);
  scanf("%d",&m);
  scanf("%d",&k);
  
  a=(long long int)malloc(sizeof(long long int)*n+1);
  a[0]=0;
  for(i=1;i<=n;i++)
  {
    scanf("%lld",&temp);
    a[i]=temp+a[i-1];
  }
  
   b=(long long int)malloc(sizeof(long long int)*m+1);
  b[0]=0;
  for(i=1;i<=m;i++)
  {
    scanf("%lld",&temp);
    b[i]=b[i-1]+temp;
  }
  

  limit=m;
  for(i=0;i<=n;i++)
  {
    if(k<a[i])break;
    for(j=limit;b[j]>k-a[i];j--)
    {
      ;
    }
    limit=j;
    if(count<i+j)count=i+j;
  }
  
  printf("%d",count);
  
  free(a);
  free(b);
  
  return 0;
}
  

Measured memory_bytes: 4980
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

foreach ($data as &$line) {
    $line = array_map(function($val) { return (int)$val; }, $line);
}

$W = $data[0][0];
$H = $data[0][1];
$x = $data[0][2];
$y = $data[0][3];

$square = $W * $H / 2;
$centerX = $x === $W / 2;
$centerY =  $y === $H / 2;

$multi = $centerX && $centerY;
$num = ($multi) ? 1 : 0;

printf('%F %d', $square, $num);

?>


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<n; i++) {
            sb.append(sc.next());
        }
        System.out.println(sb.toString().indexOf('Y')>=0?"Four":"Three");
    }

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// 0 indexed
int n;
int bit[1000010];
void add(int a, int w) {
  for (int x = a; x < n; x |= x + 1) bit[x] += w;
}
int sum(int a) { // [0, a)
  int ret = 0;
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[x];
  }
  return ret;
}

void solve() {
  int p;
  cin >> n >> p;
  string s;
  cin >> s;

  if (p == 2) {
    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      if ((s[i] - '0') % 2 == 0) add(i, 1);
      ans += sum(n) - sum(i);
    }
    cout << ans << endl;
    return;
  } else if (p == 5) {
    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      if ((s[i] - '0') == 0 || (s[i] - '0') == 5) add(i, 1);
      ans += sum(n) - sum(i);
    }
    cout << ans << endl;
    return;
  }

  vector<int> v(n + 1);
  v[n] = 0;

  int x = 0;
  int ten = 1;
  for (int i = n - 1; i >= 0; --i) {
    (x = x + (s[i] - '0') * ten) %= p;
    (ten *= 10) %= p;
    /* debuged, これあかんらしい
    (x *= 10) %= p;
    (x += s[i] - '0') %= p;
    */
    v[i] = x;
  }
  // cout << v << endl;

  map<int, int> mp;
  rep(i, sz(v)) mp[v[i]]++;
  // for (auto e : mp) cout << e.F << " " << e.S << endl;

  ll ans = 0;
  for (auto e : mp) {
    if (e.S < 2) continue;
    // cout << e.S * (e.S - 1) / 2 << endl;
    (ans += 1LL * e.S * (e.S - 1) / 2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1684
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

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

    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    long ans = 0;
    long sign = 1;
    for(int i = 0; i < n; i++){
        ans += sign * (long)a[i];
        sign = -sign;
    }

    for(int i = 0; i < n; i++){
        cout << ans << " ";
        ans = -ans + (long)a[i]*2;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin >> n;
    cout << v[n-1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
  if(b==0)return a;
  if(a>b)return gcd(b,a%b);
  else return gcd(a,b%a);
}
ll lcm(ll a,ll b)
{
  ll g=gcd(a,b);
  ll ans=a/g;
  return ans*b;
}
  
int main()
{
  int n;
  cin>>n;
  ll ans=1;
  for(int i=0;i<n;i++)
  {
    ll d;
    cin>>d;
    ans=lcm(ans,d);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{

    ll i,j,k=0,c1=0,c2=0;
    ll n;
    cin>>n;
    vector<pair<ll,ll>>v(n);
    for(i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        v[i]=mp(x,i+1);
    }
    sort(v.begin(),v.end());
    for(auto x:v)
    {
        cout<<x.se<<" ";
    }
    cout<<endl;
}


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

const int maxN = 2e5+5;

void solve(){
    int n; cin >> n;
    cout << (1000-(n%1000))%1000 << "\n";

}


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

    bool multitest = false;
    //multitest = true;
    if(multitest){
        int t; cin >> t;
        while(t--)
            solve();
    }
    else
        solve();
}






Measured memory_bytes: 3648
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	int n, p, v[2000], ct = 0;
	cin >> n >> p;
	rep(i, n) { cin >> v[i]; if (v[i] % 2 != 0)++ct; }
	if (ct != 0)cout << (ll)pow(2, n - 1) << endl;
	else if (p == 0)cout << (ll)pow(2, n) << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n,a,b;
    cin >> n >> a >> b;
    int sum = 0;

    for(int i = 1;i <= n;++i){
        int q = 0;
        int p = i;
        while(p > 0){
            q += p%10;
            p/=10;
        }
        if(q >= a && q <= b)sum += i;
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int x=1;x<=n;x+=2){
    int cnt=0;
    for(int i = 1 ; i*i <= x ; ++i){
        if(x%i == 0){
            cnt++;
            if(i*i != x){
                cnt++;
            }
        }
    }
    if(cnt==8)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
/* Trico */
#include <iostream>
#include <bits/stdc++.h>
#define inf 1e18
#define ll long long
#define x first
#define y second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mll map<ll, ll>
#define mii map<int, int>
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define p push
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, x, curr = 0, ans = 1;
    cin>>n;
    cin>>curr;
    for(int i = 1;i<n;i++){
        cin>>x;
        if(x >= curr) ans++;
        curr = max(x, curr);
    }
    cout<<ans;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int h, m, s;
    int h2, m2, s2;
    int ah[3], am[3], as[3];

    for (int i = 0; i < 3; i++) {
        cin >> h >> m >> s;
        cin >> h2 >> m2 >> s2;

        ah[i] = h2 - h;
        am[i] = m2 - m;
        as[i] = s2 - s;

        if (as[i] < 0) {
            am[i]--;
            as[i] = (60 - (-1*as[i]));
        }
        if (am[i] < 0) {
            ah[i]--;
            am[i] = (60 - (-1*am[i]));
        }
    }

    for (int i = 0; i < 3; i++) {
        cout << ah[i] << " " << am[i] << " " << as[i] << endl;
    }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int H, W, D, Q;
map<int, P> mp;

int main(void){
    
    scanf("%d %d %d", &H, &W, &D);
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            int a; scanf("%d", &a);
            mp[a] = make_pair(i, j);
        }
    }
    
    map<int, int> v;
    for(int i = 1; i <= H * W; ++i){
        if(i < D + 1) v[i] = 0;
        else v[i] += v[i - D] + abs(mp[i - D].first - mp[i].first) + abs(mp[i - D].second - mp[i].second); 
    }
     
    scanf("%d", &Q);
    for(int i = 0; i < Q; ++i){
        int L, R; scanf("%d %d", &L, &R);
        printf("%d\n", v[R] - v[L]);
    }
    
    return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }

    rep(i, n){
        h -= a[i];
    }

    if(h <= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for (int i = 1; i <= c; i++){
        if (c % i == 0 && a <= i && i <= b){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3112
stu = 0
def g(val):
    global stu
    stu += 1
    return [stu, int(val)]

n = int(input())
a = list(map(g, input().split()))
a.sort(key=lambda x: x[1])

op = str(a[0][0])
for i in range(1,n):
    op += " " + str(a[i][0])
print(op)


Measured memory_bytes: 25912
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int a, b, c; cin >> a >> b >> c;
  cout << (b - a == c - b ? "YES\n" : "NO\n");
  return 0;
}


Measured memory_bytes: 3624
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


def calc_dis(A,B,li,N):
    dis = 0
    for i in range(N):
        dis += abs(A-li[i][0]) + abs(li[i][0]-li[i][1]) + abs(B-li[i][1])
    return dis

def main():
    N,M = map(int,input().split())
    S = [list(map(int,input().split())) for _ in range(M)]
    S = [S[i][1:] for i in range(M)]
    P = list(map(int,input().split()))

    ans = 0
    for i in range(1<<(N)):
        li = [0 for i in range(M)]
        for j in range(N):
            if (i>>j)&1: #スイッチがon
                for k in range(M):
                    if (j+1) in S[k]:
                        li[k] += 1
        # print(bin(i),li)
        for j in range(M):
            if li[j]%2!=P[j]:
                break
        else:
            # print(bin(i))
            ans += 1
        # print(i)

    print(ans)



    

main()










Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
#include<list>
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const llong MOD = 1000000007;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int N;
list<llong> A;
list<llong> B;
llong ANS = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		llong a;
		cin >> a;
		A.push_back(a);
	}

	A.sort();
	B.push_back(A.front());
	A.pop_front();
	B.push_back(A.back());
	A.pop_back();
	ANS += abs(B.front() - B.back());

	while (!(A.empty())) {
		llong tmp[4] = { A.front() - B.front(), A.front() - B.back(), A.back() - B.front(), A.back() - B.back() };
		for (int i = 0; i < 4; i++) {
			tmp[i] = abs(tmp[i]);
		}

		if (tmp[0] == max({tmp[0], tmp[1], tmp[2], tmp[3]})) {
			llong x = B.front();
			llong y = A.front();
			ANS += abs(x - y);

			B.push_front(A.front());
			A.pop_front();
		}
		else if (tmp[1] == max({ tmp[0], tmp[1], tmp[2], tmp[3] })) {
			llong x = B.back();
			llong y = A.front();
			ANS += abs(x - y);

			B.push_back(A.front());
			A.pop_front();
		}
		else if (tmp[2] == max({ tmp[0], tmp[1], tmp[2], tmp[3] })) {
			llong x = B.front();
			llong y = A.back();
			ANS += abs(x - y);

			B.push_front(A.back());
			A.pop_back();
		}
		else if (tmp[3] == max({ tmp[0], tmp[1], tmp[2], tmp[3] })) {
			llong x = B.back();
			llong y = A.back();
			ANS += abs(x - y);

			B.push_back(A.back());
			A.pop_back();
		}
	}

	cout << ANS;
	return 0;
}

Measured memory_bytes: 3328
N, X = map(int, input().split())
L = [0] + list(map(int, input().split()))

s = 0
S = []
for i in range(N+1):
    s += L[i]
    S.append(s)

c = 0
for s in S:
    if s <= X:
        c += 1
print(c)


Measured memory_bytes: 61744
n = gets.to_i
arr = []
n.times{arr << gets.to_i}
max = arr.max
arr2 = []
1.upto(Math.sqrt(max)){|x|
    if max % x == 0
        arr2 << x
        arr2 << max / x if max / x != x
    end
}
arr2.sort!
sum = 0
arr.each{|x|
    z = arr2.bsearch{|y| x <= y}
    sum += z - x
}
puts sum


Measured memory_bytes: 7796
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();
    let t:Vec<char> = read::<String>().chars().collect();

    let mut ans:u32 = 0;
    for i in 0..3 {
        let i = i as usize;
        if s[i] == t[i] { ans += 1; }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vi A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    double m = A[0];
    for (int i = 1; i < N; i++) {
        m = (m + double(A[i])) / 2;
    }

    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    ll N;
    cin >> N;
    ll b = N;
    ll a = 0;
    for (int i = 0; i < 8; i++) {
        a += b % 10;
        b = b / 10;
    }
    if (N % a == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
   int n,m,k; cin>>n>>m>>k;

   vector<int> A(n+1),B(m+1);
   A[0]=0; B[0]=0;
   for(int i=1;i<=n;i++){
       int ai; cin>>ai;
       A[i]=ai+A[i-1];
   }
   for(int i=1;i<=m;i++){
       int bi;cin>>bi;
       B[i]=bi+B[i-1];
   }

   int ans=0,j=m;

   for(int i=0;i<=n;i++){
       if(k<A[i]) break;
       while(B[j]>k-A[i]){
           j--;
       }
       ans=max(ans,i+j);
   }

   cout<<ans<<endl;
}  

Measured memory_bytes: 6404
n,q,*t=map(int,open(0).read().split())
e=[[]for _ in[0]*n]
s=[0]
d=s*n
f=[1]+s*n
for a,b in zip(*[iter(t[:-q-q])]*2):
  e[a-1]+=b-1,
  e[b-1]+=a-1,
for p,x in zip(*[iter(t[-q-q:])]*2):d[p-1]+=x
while s:
  v=s.pop()
  for w in e[v]:
    if f[w]:continue
    f[w]=1
    d[w]+=d[v]
    s+=w,
print(*d)

Measured memory_bytes: 94828
import sys

if __name__ == '__main__':
    for line in sys.stdin:
        line = line.rstrip('\r\n')

    pronun_dict = {'0':'pon','1':'pon','6':'pon','8':'pon','3':'bon',
                   '2':'hon','4':'hon','5':'hon','7':'hon','9':'hon'}
    print(pronun_dict[line[-1]])


Measured memory_bytes: 9040
#include <stdio.h>
#include <string.h>
#define MAX 50

int main(void) {
    int i, n, t, p, ary[MAX] = {};
    while(scanf("%d %d", &n, &p), n || p) {
        memset(ary, 0, sizeof(ary));
        for(i = ~-n, t = p; ary[i = -~i % n] != p;) {
            t ? t--, ary[i]++ : (t += ary[i], ary[i] = 0);
        }
        printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 600
N,A = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
dp = Array.new(N+1){Array.new(2501,0)}
dp[0][1250] = 1

N.times do |i|
	2501.times do |j|
		dp[i+1][j+x[i]-A] += dp[i][j] if j+x[i]-A >= 0 && j+x[i]-A < 2501
		dp[i+1][j] += dp[i][j]
	end
end

p dp[N][1250]-1



Measured memory_bytes: 2812
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

string[] M;
long H, W;
bool[][] used;
void main()
{
    scan(H, W);
    used = new bool[][](H, W);
    foreach (_; 0 .. H)
        M ~= readln().chomp;

    long sum;
    foreach (y; 0 .. H)
        foreach (x; 0 .. W)
        {
            auto t = dfs(y, x);
            sum += t[0] * t[1];
        }
    writeln(sum);
}

Tuple!(long, long) dfs(long y, long x)
{
    if (used[y][x])
        return Tuple!(long, long)(0, 0);
    used[y][x] = true;

    long w, b;
    if (M[y][x] == '.')
        w = 1;
    else
        b = 1;

    if (0 <= y - 1 && !used[y - 1][x] && M[y][x] != M[y - 1][x])
    {
        auto tmp = dfs(y - 1, x);
        w += tmp[0];
        b += tmp[1];
    }
    if (y + 1 < H && !used[y + 1][x] && M[y][x] != M[y + 1][x])
    {
        auto tmp = dfs(y + 1, x);
        w += tmp[0];
        b += tmp[1];
    }
    if (0 <= x - 1 && !used[y][x - 1] && M[y][x] != M[y][x - 1])
    {
        auto tmp = dfs(y, x - 1);
        w += tmp[0];
        b += tmp[1];
    }
    if (x + 1 < W && !used[y][x + 1] && M[y][x] != M[y][x + 1])
    {
        auto tmp = dfs(y, x + 1);
        w += tmp[0];
        b += tmp[1];
    }
    return Tuple!(long, long)(w, b);
}


Measured memory_bytes: 25724
N = int(input())
node = list(map(int,input().split()))
dp = [10**30 for i in range(N)]
def chmin(now_point,next_point):
    if dp[next_point] > dp[now_point] + abs(node[now_point] - node[next_point]):
        dp[next_point] = dp[now_point] + abs(node[now_point] - node[next_point])

dp[0] = 0
for i in range(0,N-1,1):
    chmin(i,i+1)
    if i < N-2:chmin(i,i+2)
print(dp[-1])


Measured memory_bytes: 13976
using System;

namespace AOJ.Volume0
{
    public class TicTacToe
    {
        public static void Main()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                string[] box = new string[9];
                for (int i = 0; i < 9; i++) { box[i] = input.Substring(i, 1); }

                string win = "d";
                bool end = false;
                // 縦に並んでいるか
                for (int i = 0; i <= 2; i++)
                {
                    if (box[i] != "s" && box[i] == box[i + 3] && box[i + 3] == box[i + 6])
                    {
                        win = box[i];
                        end = true;
                        break;
                    }
                }
                // 横に並んでいるか
                if (!end)
                {
                    for(int i = 0;i<=6;i=i+3)
                    {
                        if (box[i] != "s" && box[i] == box[i + 1] && box[i + 1] == box[i + 2])
                        {
                            win = box[i];
                            end = true;
                            break;
                        }
                    }
                }
                // 斜めに並んでいるか
                if (!end)
                {
                    if (box[0] != "s" && box[0] == box[4] && box[4] == box[8]) { win = box[0]; }
                    else if (box[2] != "s" && box[2] == box[4] && box[4] == box[6]) { win = box[2]; }
                }

                Console.WriteLine(win);
            }
        }
    }
}

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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	int num = d;
	int cnt = 0;
	while(num <= r) {
		if(num >= l)
			cnt++;
		num += d;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 4
int ansArr[N][N]={{ 1, 2, 3, 4},
                  { 5, 6, 7, 8},
                  { 9,10,11,12},
                  {13,14,15, 0}};
int x[N*N]={3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2};
int y[N*N]={3,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3};
int heuristic[N*N][N*N];
int curMinCost=46;
int tempArr[N][N];
void searchMinCost(int[N][N],int,int);
int main(void)
{
  int i,j;
  for(i=0;i<N*N;i++)
    {
      for(j=0;j<N*N;j++)
        {
          heuristic[i][j]=abs(y[i]-y[j])+abs(x[i]-x[j]);
        }
    }
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      scanf("%d",&tempArr[i][j]);
  searchMinCost(tempArr,0,0);
  printf("%d\n",curMinCost);
  return 0;
}
void searchMinCost(int tempArr[N][N],int lastMove,int curCost)
{
  int h=0;
  int i,j;
  int blankI,blankJ;
  int index;
  int nextArr[N][N];
  for(i=0;i<N;++i)
    {
      for(j=0;j<N;++j)
        {
          nextArr[i][j]=tempArr[i][j];
          if(tempArr[i][j]==0)
            {
              blankI=i;
              blankJ=j;
            }
          else if(tempArr[i][j]!=ansArr[i][j])
            {
              h+=heuristic[tempArr[i][j]][ansArr[i][j]];
            }
        }
    }
  if(h==0)
    {
      if(curCost<curMinCost) curMinCost=curCost;
      return;
    }
  if(curCost+h>curMinCost) return;
  if(blankI>0&&lastMove!=3)
    {
      index=blankI-1;
      nextArr[blankI][blankJ]=nextArr[index][blankJ];
      nextArr[index][blankJ]=0;
      searchMinCost(nextArr,1,curCost+1);
      nextArr[index][blankJ]=nextArr[blankI][blankJ];
      nextArr[blankI][blankJ]=0;
    }
  if(blankJ>0&&lastMove!=4)
    {
      index=blankJ-1;
      nextArr[blankI][blankJ]=nextArr[blankI][index];
      nextArr[blankI][index]=0;
      searchMinCost(nextArr,2,curCost+1);
      nextArr[blankI][index]=nextArr[blankI][blankJ];
      nextArr[blankI][blankJ]=0;
    }
  if(blankI<N-1&&lastMove!=1)
    {
      index=blankI+1;
      nextArr[blankI][blankJ]=nextArr[index][blankJ];
      nextArr[index][blankJ]=0;
      searchMinCost(nextArr,3,curCost+1);
      nextArr[index][blankJ]=nextArr[blankI][blankJ];
      nextArr[blankI][blankJ]=0;
    }
  if(blankJ<N-1&&lastMove!=2)
    {
      index=blankJ+1;
      nextArr[blankI][blankJ]=nextArr[blankI][index];
      nextArr[blankI][index]=0;
      searchMinCost(nextArr,4,curCost+1);
    }
}


Measured memory_bytes: 2104
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

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

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string S; cin >> S;
    
    int n=0;
    bool was_zero, reverse=false;
    REP(i, S.size()-1)
    {
        was_zero=reverse ? !(S[i]=='0') : S[i]=='0';
        reverse=false;
        if ((was_zero && S[i+1]=='0') || (!was_zero && S[i+1]=='1'))
        {
            reverse=true;
            n++;
        }
    }
    cout << n << endl;
  
    return 0;
}



Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def count_combinations(n):
    answer = 0
    for i in range(1, n // 2 + 1):
        current_sum = i
        for j in range(i + 1, n // 2 + 2):
            current_sum += j
            if current_sum == n:
                answer += 1
                break
            elif current_sum > n:
                break
            else:
                continue
    return answer


if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        else:
            print(count_combinations(n))

Measured memory_bytes: 7632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);




int main()
{
   ll k,n,i;
   cin>>k>>n;
   vector<ll>v,arr;
   for(i=0;i<n;i++)
   {
       ll a;
       cin>>a;
       v.pb(a);
       arr.pb(a);
   }

   vector<ll>a;

   for(i=0;i<n;i++)
   {
       a.pb((k-arr[i])*-1);
   }
   for(i=0;i<n;i++)
   {
       a.pb(v[i]);
   }
//
//   for(i=0;i<a.size();i++)
//   {
//       cout<<a[i]<<" ";
//   }
//   cout<<endl;

   ll ans = INT_MAX;
   ll x=0;
   for(i=1;i<n;i++)
   {
       x = x + abs(a[i]-a[i-1]);
   }
   ans = min(ans,x);
   ll j=0;
//   cout<<x<<endl;

   for(i=n;i<a.size();i++)
   {
       x = x+ abs(a[i]-a[i-1]);
       x -= abs(a[j]-a[j+1]);
       j++;



       ans = min(ans,x);
   }

   cout<<ans<<endl;
}



Measured memory_bytes: 9444
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int T, card[16];

bool is_same_number(int a, int b, int c){
  return (a == b && b == c);
}

bool is_sequence(int a, int b, int c){
  return (a + 2 == c && a + 1 == b);
}

bool is_good_set(int a, int b, int c){
  return is_same_number(a, b, c) || is_sequence(a, b, c);
}

bool is_all_good_set(int a[]){
  return is_good_set(a[0], a[1], a[2]) && is_good_set(a[3], a[4], a[5]) && is_good_set(a[6], a[7], a[8]);
}

int win(int a[]){
  sort(a, a+9);
  do {
    if (is_all_good_set(a)) return 1;
  } while (next_permutation(a, a+9));
  return 0;
}

int main(){
  cin >> T;
  for (int t=0; t<T; ++t){

    for (int i = 0; i<9; i++){
      cin >> card[i];
    }

    string color;
    for (int i = 0; i < 9; i++){
      cin >> color;
      if (color == "G") card[i] += 10;
      else if (color == "B") card[i] += 20;
    }

    cout << win(card) << endl;

  }

  return 0;
}



Measured memory_bytes: 3176
#include<cstdio>
int main(void) {
	long long n, x, y, z, s, ans;
	while (true) {
		scanf("%lld", &n);
		if (n == 0)return 0;
		ans = -1;
		for (long long i = 1; (i*i) <= n; i++) {
			if (n%i == 0) {
				x = i;
				y = n / i;
				if (x % 2 == 1) {
					z = (x + 1) / 2;
					if (y >= z) {
						if (ans < x) {
							ans = x;
							s = y - z + 1;
						}
					}
				}
				z = x;
				x = y;
				y = z;
				if (x % 2 == 1) {
					z = (x + 1) / 2;
					if (y >= z) {
						if (ans < x) {
							ans = x;
							s = y - z + 1;
						}
					}
				}
			}
		}
		for (long long i = 1; (i*i) <= (2*n); i++) {
			if ((2*n)%i == 0) {
				x = i;
				y = (2*n)/ i;
				if (x % 2 == 1) {
					if (y<=x) {
						if (ans < y) {
							ans = y;
							s = x / 2;
							s -= (y / 2);
							s++;
						}
					}
				}
				z = x;
				x = y;
				y = z;
				if (x % 2 == 1) {
					if (y <= x) {
						if (ans < y) {
							ans = y;
							s = x / 2;
							s -= (y / 2);
							s++;
						}
					}
				}
			}
		}
		printf("%lld %lld\n", s, ans);
	}
}


Measured memory_bytes: 2588
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(;;){
			int l=sc.nextInt();
			if(l==0){
				break;
			}
			int k=0;
			for(int i=0; i<12; i++){
				int m=sc.nextInt();
				int n=sc.nextInt();
				l-=m-n;
				if(k==0&&l<=0){
					k=i+1;
				}
			}
			println(""+(k==0?"NA":k));
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
input = raw_input
S = input()
n = len(S) # N-1
s = S


up_count = 0
down_count = 0

start_i = None
for i, c in enumerate(S):
    if c == "<":
        start_i = i
        break
    down_count += 1

if start_i is None:
    start_i = n

nums = []
for num in reversed(range(down_count+1)):
    nums.append(num)

up = True
for c in S[start_i:]: 
    if c == "<":
        if not up: # down->up
            if up_count >= down_count:
                for num in range(1, up_count+1):
                    nums.append(num)
                for num in reversed(range(0, down_count)):
                    nums.append(num)
            else:
                for num in range(0, up_count):
                    nums.append(num)
                for num in reversed(range(1, down_count+1)):
                    nums.append(num)
                 
            down_count = 0
            up_count = 1
            up = True
        else:
            up_count += 1
    else:
        if up:
            up = False
            down_count = 1
        else:
            down_count += 1
        

if up:
    for num in range(up_count+1):
        nums.append(num)
else:
    if up_count >= down_count:
        for num in range(1, up_count+1):
            nums.append(num)
        for num in reversed(range(0, down_count)):
            nums.append(num)
    else:
        for num in range(0, up_count):
            nums.append(num)
        for num in reversed(range(1, down_count+1)):
            nums.append(num)

out = sum(nums)
print(out)

Measured memory_bytes: 67564