akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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() {
    ll N, A, B;
    cin >> N >> A >> B;
    if (N == 1 && A != B) {
        cout << 0 << endl;
        return 0;
    } 

    if (A == B) {
        cout << 1 << endl;
        return 0;
    } 

    if (A > B) {
        cout << 0 << endl;
        return 0;
    } 

    ll res = A + B;
    ll min = 0;
    ll max = 0;
    rep(i, 0, N-2) {
        min += A;
        max += B;
    }
    min += res;
    max += res;
    cout << (max-min+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans;
    vector<P> op;
    sort(ALL(a));
    
    // 全て正
    if(a[0] >= 0) {
        if(n == 2){
            cout << a[1] - a[0] << endl;
            cout << a[1] << ' ' << a[0] << endl;
            return 0;
        }
        ans = a[0] - a[1];
        op.push_back(P(a[0], a[1]));
        for(int i = 2; i < n - 1; i++) {
            op.push_back(P(ans, a[i]));
            ans -= a[i];
        }
        op.push_back(P(a[n - 1], ans));
        ans = a[n - 1] - ans;
        cout << ans << endl;
        for(auto i : op) {
            cout << i.first << ' ' << i.second << endl;
        }
        return 0;
    }
    // 全て負
    if(a[n - 1] <= 0) {
        sort(RALL(a));
        ans = a[0] - a[1];
        op.push_back(P(a[0], a[1]));
        for(int i = 2; i < n; i++) {
            op.push_back(P(ans, a[i]));
            ans = ans - a[i];
        }
        cout << ans << endl;
        for(auto i : op) {
            cout << i.first << ' ' << i.second << endl;
        }
        return 0;
    }
    // 正と負両方ある
    vector<int> sei, hu;
    for(int i = 0; i < n; i++) {
        if(a[i] >= 0) {
            sei.push_back(a[i]);
        } else {
            hu.push_back(a[i]);
        }
    }
    sort(ALL(sei));
    sort(ALL(hu));

    for(int i = 1; i < sei.size(); i++) {
        op.push_back(P(hu[0], sei[i]));
        hu[0] -= sei[i];
    }
    ans = sei[0];
    for(int i = 0; i < hu.size(); i++) {
        op.push_back(P(ans, hu[i]));
        ans -= hu[i];
    }
    cout << ans << endl;
    for(auto i : op) {
        cout << i.first << ' ' << i.second << endl;
    }

    return 0;
}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
  return A;
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n = getint(), m = getint();
  const int mx = 40;
  vector<vector<int>> ex(mx);
  for (int i = 0, a, a_; i < n; i++) {
    a = getint();
    a_ = a;
    int cnt = 0;
    while (a > 0) {
      a /= 2;
      cnt++;
    }
    ex[cnt].emplace_back(a_);
  }
  for (int i = mx - 1; i > 0 && m > 0; i--) {
    if ((int)ex[i].size() <= m) {
      for (auto&& e : ex[i]) {
        e /= 2;
        ex[i - 1].emplace_back(e);
        e = 0;
      }
      m -= (int)ex[i].size();
    } else {
      sort(ex[i].begin(), ex[i].end(), greater<int>());
      for (int j = 0; j < m; j++) {
        ex[i][j] /= 2;
      }
      m = 0;
    }
  }
  long long ans = 0;
  for (int i = 0; i < mx; i++) {
    for (auto&& e : ex[i]) {
      ans += e;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 4364
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    C = []
    S = []
    F = []
    for i in range(n - 1):
        c, s, f = nm()
        C.append(c)
        S.append(s)
        F.append(f)
    for i in range(n - 1):
        time = 0
        for j in range(i, n - 1):
            if time <= S[j]:
                time = S[j] + C[j]
            else:
                time = time + (F[j] - (time - S[j]) % F[j]) % F[j] + C[j]
        print(time)
    print(0)


if __name__ == '__main__':
    main()


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int n,k;cin>>n>>k;
	cout << k*(int)pow(k-1,n-1) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

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

ll N, X, M;

void solver_gcd0() {
  ll a = X;
  ll ans = 0;

  for (int i = 0; i < min(N, M); ++i) {
    a += ans;
    a = (a * a) % M;
  }

  cout << ans << endl;
}

void solver_gcd_non0() {
  vector<ll> values;

  ll sum = 0;
  ll a = X;
  bool looped = false;
  map<ll, int> checked;
  for (int i = 0; i < min(N, M); ++i) {
    if (checked[a] >= 1) {
      checked[a]++;
      looped = true;
      break;
    }
    checked[a]++;
    values.push_back(a);

    sum += a;
    a = (a * a) % M;

    if (a == 0) {
      cout << sum << endl;
      return;
    }
  }

  if (!looped) {
    cout << sum << endl;
    return;
  }

  ll head = 0;
  ll head_size = 0;
  ll loop_sum = 0;
  bool in_loop = false;
  vector<ll> loop_values;
  for (int i = 0; i < values.size(); ++i) {
    ll a = values[i];

    if (checked[a] >= 2) {
      in_loop = true;
    }

    if (in_loop) {
      loop_sum += a;
      loop_values.push_back(a);
    } else {
      head_size++;
      head += a;
    }
  }

  ll ans = head;
  ll loop_size = loop_values.size();
  ll loop_cnt = (N - head_size) / loop_size;
  ll remain = (N - head_size) % loop_size;
  fprintf(stderr, "%d: head: %lld, loop_size: %lld, loop_cnt: %lld, remain: %lld, sum: %lld\n",
      looped, head, loop_size, loop_cnt, remain, sum);

  if (loop_cnt == 0) {
    cout << sum << endl;
    return;
  }

  ans += loop_cnt * loop_sum;

  for (int i = 0; i < remain; ++i) {
    ans += loop_values[i];
  }

  cout << ans << endl;
}

int main() {
  cin >> N >> X >> M;

  ll g = gcd(X, M);

  if (g == 0) {
    solver_gcd0();
  } else {
    solver_gcd_non0();
  }

  return 0;
}


Measured memory_bytes: 7488
n = int(input())
s = [int(input()) for _ in range(n)]
dp = [[-1 for _ in range(sum(s)+1)] for _ in range(n+1)]
dp [0][0] = 0
for i in range(n):
    for j in range(sum(s)+1):
        if dp[i][j] != -1:
            dp[i+1][j] = dp[i][j]
            dp[i+1][j+s[i]] = dp[i][j] + s[i]
res = 0
for i in range(sum(s)+1)[::-1]:
    if dp[n][i] > res and i % 10 != 0:
        res = dp[n][i]
        break
print(res)


Measured memory_bytes: 11252
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Globalization.CultureInfo;

public class Program{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var length = Console.ReadLine().Split().Select(int.Parse).OrderBy(o=>o).ToArray();
        var ans = 0;
        for(int i=0; i<n*2-1; i+=2){
            ans+=Math.Min(length[i], length[i+1]);
        }
        Console.WriteLine(ans);
    }
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=n/2;i<n;i++){
		if(s[i]!=s[i-n/2]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;

    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define repvin(n) vint a(n);r(i,n)cin>>a[i];
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60

int n,a,b,c;
vint l(10);
int dfs(int x,int A,int B,int C,int mp){
  if(x==n){
    if(A==0||B==0||C==0)return 999999999;
    else return abs(A-a)+abs(B-b)+abs(C-c)+mp;
  }
  int res1,res2,res3,res4;
  res1=dfs(x+1,A,B,C,mp);
  res2=dfs(x+1,A+l[x],B,C,mp+(A==0?0:10));
  res3=dfs(x+1,A,B+l[x],C,mp+(B==0?0:10));
  res4=dfs(x+1,A,B,C+l[x],mp+(C==0?0:10));
  return (min(min(res1,res2),min(res3,res4)));
}

signed main(){
  cin>>n>>a>>b>>c;
  repi(n)cin>>l[i];
  cout<<dfs(0,0,0,0,0)<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

value_lst = input().split()
for i in range(N):
    value_lst[i] = int(value_lst[i])

cost_lst = input().split()
for i in range(N):
    cost_lst[i] = int(cost_lst[i])

plofit_lst = []
for i in range(N):
    plofit_lst.append(value_lst[i] - cost_lst[i])

plofit_lst.sort(reverse=True)

plofit_max = 0
for i in range(N):
    if plofit_lst[i] <= 0:
        break
    plofit_max += plofit_lst[i]

print(plofit_max)

Measured memory_bytes: 3064
n = int(input())
sp = [list(map(str,input().split())) for _ in range(n)]

c = 1
for i in sp:
    i[1] = int(i[1])
    i.append(c)
    c += 1

sp = sorted(sp, key=lambda x:x[1] ,reverse=True)
sp = sorted(sp, key=lambda x:x[0])

for i in sp:
    print(i[2])

Measured memory_bytes: 3064
<?php
fscanf(STDIN, '%d', $n);
for ($i = 2; $i <= $n; $i++) {
    $pf = primeFactorization($i);
    foreach ($pf as $p => $c) {
        if ($p !== 1) {
            if (isset($cnt_p[$p])) {
                $cnt_p[$p] += $c;
            } else {
                $cnt_p[$p] = $c;
            }
        }
    }
}
$cnt75 = f(75);
$cnt25 = f(25);
$cnt15 = f(15);
$cnt5 = f(5);
$cnt3 = f(3);

$ans = $cnt75 + $cnt25 * ($cnt3 - 1) + $cnt15 * ($cnt5 - 1) + $cnt5 * ($cnt5 - 1) / 2 * ($cnt3 - 2);
echo $ans;

function f($n)
{
    global $cnt_p;
    return count(array_filter($cnt_p, function ($v) use ($n) {
        return $v >= $n - 1;
    }));
}

/**
 * エラトステネスのふるい
 * $maxまでの整数のうち素数のみを格納した配列を返す
 */
function primesArr($max)
{
    $is_prime = isPrimeArr($max);
    $res = [];
    for ($i = 1; $i <= $max; $i++) {
        if ($is_prime[$i]) $res[] = $i;
    }
    return $res;
}

/**
 * エラトステネスのふるい
 * $maxまでの整数が素数かどうかboolを格納した配列を返す
 */
function isPrimeArr($max)
{
    $arr = array_fill(0, $max + 1, true);
    $arr[0]  = $arr[1] = false;
    $rmax = (int) floor(sqrt($max));
    for ($i = 2; $i <= $rmax; $i++) {
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            $arr[$j] = false;
        }
    }
    return $arr;
}

// 素因数分解
function primeFactorization($n)
{
    $res = [];
    $res[1] = 1;
    if ($n === 1) return $res;

    $primes = primesArr((int) sqrt($n) + 1);

    foreach ($primes as $prime) {
        while ($n % $prime === 0) {
            if (isset($res[$prime])) {
                $res[$prime]++;
            } else {
                $res[$prime] = 1;
            }
            $n /= $prime;
        }
    }

    if ($n > 1) {
        if (isset($res[$n])) {
            $res[$n]++;
        } else {
            $res[$n] = 1;
        }
    }

    return $res;
}

Measured memory_bytes: 4728
#include <stdio.h>
int main(void){
    int m,f,r;
    
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        
        if(m==-1&&f==-1&&r==-1)break;
        
        if(m==-1||f==-1) printf("F\n");
        else if(m+f>=80) printf("A\n");
        else if(m+f>=65) printf("B\n");
        else if(m+f>=50) printf("C\n");
        else if(m+f>=30){
            if(r>=50) printf("C\n");
            else printf("D\n");
        }
        else printf("F\n");
    }
    return(0);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string in;
    cin>>in;
    if(in[0] == in[1] || in[1] == in[2] || in[2] == in[3] || in[3] == in[4])
        cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
    return 0;
}

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

int main(){
	
	char a[100][100];
	for(int i=0;i<3;i++){
		scanf("%s", a+i);
	}
	
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(i == j)
			printf("%c", a[i][j]);
		}
	}
	printf("\n");
	return  0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    n,a,b = [int(i) for i in input().strip().split()]
    if (b-a) % 2 == 0:
        print(abs(b - a) // 2)
    else:
        ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
        print(ans)
    return 



if __name__ == "__main__":
    main()

Measured memory_bytes: 61804
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int n,l,t,a[N];
int main(){
    scanf("%d %d %d",&n,&l,&t);
    long long p=1;
    int x,w;
    for(int i=1;i<=n;i++){
        scanf("%d %d",&x,&w);
        if(w==1){
            a[i]=(x+t)%l;
            p=(p+(x+t)/l%n)%n;
        }
        else{
            a[i]=(x-t%l+l)%l;
            p=(p+n-(t+l-1-x)/l%n)%n;
        }
    }
    sort(a+1,a+n+1);
    if(p==0)p=n;
    for(int i=p;i<=n;i++)printf("%d\n",a[i]);
    for(int i=1;i<p;i++)printf("%d\n",a[i]);
}

Measured memory_bytes: 1536
def popcnt(x):
    return bin(x).count("1")

def main():
    N = int(input())
    Xs = input()
    X = int(Xs, 2)
    d = popcnt(X)

    lut = [0] * N
    for i in range(1, N):
        Xi = i % popcnt(i)
        lut[i] = lut[Xi] + 1

    dp = d+1
    dm = d-1
    mp = X % dp
    mm = X % dm if dm else 0
    # print(lut)
    # print(format(X, 'b'))
    
    ans = []
    for i in range(N):
        mask = 1 << (N-i-1)
        Xi = X ^ mask
        _ans = 0
        if Xs[i] == '1':
            if dm:
                m = (mm - pow(2, N-i-1, dm)) % dm
                _ans = lut[m] + 1
            # m = (mm - mask) % dm
        else:
            # m = (mp + mask) % dp
            m = (mp + pow(2, N-i-1, dp)) % dp
            _ans = lut[m] + 1
        ans.append(_ans)
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 15860
/* Simplicity and Goodness */

#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;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 1e6+2;


int main()
{
   int n;
   scn(n);

   ll ans = 0;

   int bit[22] = {0};

   int l = 0;

   rep(i, 1, n + 1) {
      int val;
      scn(val);

      rep(k, 0, 21) {
         if(val >> k & 1) {
            l = max(l, bit[k]);
            bit[k] = i;
         }
      }

      ans += i - l;
   }

   lprin(ans);
}

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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    int l[m],r[m];
    for(int i=0; i<m; i++)
    {
        cin>>l[i]>>r[i];
        l[i]--;
        r[i]--;
    }
    int dp[n];
    dp[0]=0;
    for(int i=1; i<n; i++)
    {
        dp[i]=dp[i-1];
        if(s[i-1]=='A' && s[i]=='C')
        {
            dp[i]++;
        }
    }
    for(int i=0; i<m; i++)
    {
        cout<<dp[r[i]]-dp[l[i]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int ans[100010];

vector<int> G[100010];
vector<int> P[100010];
set<int> visited;

void dfs(int s) {
    //cout << s << endl;
    visited.insert(s);
    rep(i, G[s].size()) {
        ans[G[s][i]] = s;
    }
    rep(i, G[s].size()) {
        auto vis = visited.find(G[s][i]);
        if (vis != visited.end()) continue;
        bool f = true;
        rep(j, P[G[s][i]].size()) {
            auto it = visited.find(P[G[s][i]][j]);
            if (it == visited.end()) {
                f = false;
            }
            //cout << P[G[s][i]].size() << " " << P[G[s][i]][j] << "<-" << G[s][i]  << " " << f<<  endl;
            if(f == false) break;
        }
        //dump(f);
        if(f) dfs(G[s][i]);
    }
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    bool child[100010];
    rep(i, N + M - 1) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        child[t] = true;
        P[t].push_back(s);
    }
    int root = -1;
    REP(i, 1, N) {
        if (!child[i]){
            root = i;
            break;
        }
    }
    dfs(root);
    REP(i, 1, N) {
        cout << ans[i] << endl;
    }
    

    return 0;
}


Measured memory_bytes: 20096
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
using namespace std;

long long x,y;


int main()
{
   long long remx,remy;

   cin>>x>>y;
   remx=x;
   remy=y;

   if(x%y == 0)
   {
       cout<<-1<<endl;
       return 0;
   }
   if(x < y)
   {
       cout<<x<<endl;
       return 0;
   }

   for(int i=2;i*i<=x;i++)
   {
       while(x%i == 0 && y%i == 0)
       {
           x/=i;
           y/=i;
       }
   }

   cout<<(y+1)*remx<<endl;


   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int r = sc.nextInt();
			int[] a = new int[n+1];
			if(r+n==0)break;
			for(int j=1;j<=n;j++) {
					a[n-j] = j;
			}
 			while(r-- != 0) {
 				int p = sc.nextInt()-1;
				int c = sc.nextInt();
				int[] b = new int[p];
				for(int i=0;i<p;i++)b[i] = a[i];
				for(int i=0;i<c;i++)a[i] = a[i+p];
				for(int i=0;i<p;i++)a[i+c] = b[i];	
			}
 			System.out.println(a[0]);
		}
		
	}
}


Measured memory_bytes: 37220
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 1; i <= A; i++) {
			int B = sc.nextInt();
			map.put(String.valueOf(i), B);
		}
		int C = sc.nextInt();
		for (int l = 0; l < C; l++) {
			int D = sc.nextInt();
			int beforeChangeNumber = map.get(String.valueOf(D));
			if (D != A) {
				int afterChangeNumber = map.get(String.valueOf(D + 1));
				if (afterChangeNumber != (beforeChangeNumber + 1) && beforeChangeNumber != 2019) {
					map.put(String.valueOf(D), beforeChangeNumber + 1);
				}
			} else if(beforeChangeNumber != 2019) {
				map.put(String.valueOf(D), beforeChangeNumber + 1);
			}
		}
		for (int i = 1; i <= A; i++) {
			System.out.println(map.get(String.valueOf(i)));
		}

	}

}



Measured memory_bytes: 26524
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include <numeric>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> k(m), p(m);
	vector<vector<int>> s(m);
	rep(i, m) {
		cin >> k[i];
		s[i].resize(k[i]);
		rep(j, k[i]) {
			cin >> s[i][j]; --s[i][j];
		}
	}
		rep(i, m)cin >> p[i];
		int ans = 0;
		rep(i, 1 << n) {
			bool ok = true;
			rep(j, m) {
				int c = 0;
				for (int id : s[j]) {
					if (i >> id & 1)++c;
				}
				if (c % 2 != p[j]) ok = false;
			}
			if (ok)++ans;
		}
		cout << ans;
	}

	

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n;
int a[1000001];
vector<int> v;
map<int,int> mp;
int isp[1000001];

void buildprime(){
	isp[0]=isp[1]=1;
	forn(i,2,1000001){
		if (isp[i]) continue;
		for (int j=i+i; j<1000001; j+=i)
			isp[j]=1;
	}
	forn(i,2,1000001)
		if (!isp[i])
			v.push_back(i);
}

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

bool ispairwise(){
	vector<int> w;
	forn(i,0,n){
		int x=a[i];
		forn(i,0,v.size()){
			if (v[i]*v[i]>x) break;
			if (x%v[i]==0){
				mp[v[i]]++;
				w.push_back(v[i]);
				while (x%v[i]==0){
					x/=v[i];
				}
			}
		}
		if (x!=1 || x==i){
			mp[x]++;
			w.push_back(x);
		}
	}
	sort(w.begin(),w.end());
	int mx=w[w.size()-1];
	forn(i,0,v.size()){
		if (v[i]>mx) break;
		if (mp[v[i]]>1)
			return false;
	}
	return true;
}

bool issetwise(){
	int res=a[0];
	forn(i,0,n){
		res=gcd(res,a[i]);
	}
	return res==1;
}

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	buildprime();
	cin>>n;
	forn(i,0,n)
		cin>>a[i];
	bool isp=ispairwise();
	bool iss=issetwise();
	if (isp){
		cout<<"pairwise coprime"<<endl;
		return 0;
	}
	else if (iss){
		cout<<"setwise coprime"<<endl;
		return 0;
	}
	cout<<"not coprime"<<endl;
	return 0;
}

Measured memory_bytes: 85028
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    int a[5];
    rep(i, 5) cin >> a[i];

    int time, round, max_diff = 0;
    rep(i, 5) {
        round = a[i] / 10 + !!(a[i] % 10);
        round *= 10;
        // cout << a[i] << " " << round << endl;
        max_diff = max(max_diff, round - a[i]);
        time += round;
    }

    cout << time - max_diff << endl;
}


Measured memory_bytes: 256
[W,H,x,y,r] = raw_input().split(' ')
W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)
h = False
if x - r >= 0:
    if x + r <= W:
        if y - r >= 0:
            if y + r <= H:
                h = True
if h:
    print 'Yes'
else:
    print 'No'

Measured memory_bytes: 4212
a = list(input().split(" "))
a = [int(i) for i in a]
b = a[2]+a[4]
c = a[2]-a[4]
d = a[3]+a[4]
e = a[3]-a[4]
if 0<=b<=a[0] and 0<=c<=a[0]:
    if 0<=d<=a[1] and 0<=e<=a[1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

int main() {

    string s;

    char c[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

    set<char> se;

    cin >> s;

    for(int i=0;i<s.size();i++){
        se.insert(s[i]);
    }

    for(int i=0;i<26;i++){
        if(se.find(c[i]) == se.end()){
            cout << c[i] << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,mini=1000000000000000;
    cin>>n;
    rrep(i,pow(n,0.5)){
        if(n%i==0){
            if(mini>(i+(n/i)-2)) mini=i+(n/i)-2;
        }
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
const int MAX_N = 200100;
//verifiy@http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
//SegmentTreeMin
template<typename ValueType>
class SegmentTreeMin{
public:
  SegmentTreeMin(){}
  SegmentTreeMin(int n, ValueType max_value){
    this->N = 1;
    this->max_value = max_value;
    while (this->N < n) this->N *= 2;
    this->data.resize(2 * N - 1, this->max_value);
  }
  //init
  void init(int n, ValueType max_value){
    this->N = 1;
    this->max_value = max_value;
    while (this->N < n) this->N *= 2;
    this->data.resize(2 * N - 1, this->max_value);
  }
  // update k th element
  void update(int k, ValueType val){
    k += N - 1;
    data[k] = val;
    while (k > 0){
      k = (k - 1) / 2;
      data[k] = std::min(data[2 * k + 1], data[2 * k + 2]);
    }
  }
  //min [a, b)
  ValueType min(int a, int b) {
    return min(a, b, 0, 0, N);
  }
  ValueType min(int a, int b, int k, int l, int r){
    if (r <= a or b <= l) return max_value;
    if (a <= l and r <= b) return data[k];
    int med = (l + r) / 2;
    return std::min(min(a, b, 2 *k + 1, l, med), min(a, b, 2 * k + 2, med, r));
  }
private:
  std::vector<ValueType> data;
  int N;
  ValueType max_value;
};

SegmentTreeMin<int> seg(MAX_N, INF);
int left_check(int i, int val){
  int left = -1;
  int right = i;
  while (right - left > 1){
    int med = (right + left) / 2;
    int tmp = seg.min(med, i);
    if (tmp < val){
      left = med;
    }else{
      right = med;
    }
  }
  return right;
}
int right_check(int i, int val){
  int left = i;
  int right = N;
  while (right - left > 1){
    int med = (right + left) / 2;
    int tmp = seg.min(i+1, med+1);
    if (tmp < val){
      right = med;
    }else{
      left = med;
    }
  }
  return left;
}
int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  for (int i = 0; i < N; i++){
    seg.update(i, A[i]);
  }
  ll result = 0;
  for (int i = 0; i < N; i++){
    int l = left_check(i, A[i]);
    int r = right_check(i, A[i]);

    result += (ll)A[i] * (i-l+1) * (r-i+1);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll dp[100005];
int main()
{
    ll n,i,j,k,mn;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    if(n==2)
    cout<<abs(a[0]-a[1]);
    else
    {
        for(i=1;i<n;i++)
        {
            mn=abs(a[i]-a[i-1])+dp[i-1];
            for(j=i-2;j>=0&&j>=i-k;j--)
            {
                   /*if(mn>abs(a[i]-a[j])+dp[i-j])
                   {mn=abs(a[i]-a[j])+dp[i-j];
                    x=dp[i-j];y=abs(a[i]-a[j]);}*/
                   //cout<<"jjjjjj";
                   mn=min(mn,abs(a[i]-a[j])+dp[j]);
               // d++;
            }
            //cout<<mn<<"         "<<x<<"            "<<y<<"       ";
                dp[i]=mn;
           
        }
        
        cout<<dp[n-1];
    }
}

Measured memory_bytes: 5196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    set<string> words;
    int n;
    string s;
    char pre;
    cin>>n;
    cin>>s;
    words.insert(s);
    pre=s[s.size()-1];
    for(int i=1;i<n;++i){
        cin>>s;
        if(pre!=s[0]||words.find(s)!=words.end()){
            cout<<"No"<<endl;
            return 0;
        }
        words.insert(s);
        pre=s[s.size()-1];
    }
    cout<<"Yes"<<endl;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
//typedef __int128 long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

const ll M = 1e9 + 7;

const int N = 2e5 + 100;

const int L = 29;


void smain() {


    int n;
    string s;
    cin >> n >> s;
    vl cnt(L, 0);
    fori (i, n) {
        cnt[s[i] - 'a']++;
    }
    ll ans = 1;
    fori (i, L) ans = ans * (cnt[i] + 1) % M;
    ans = (ans - 1 + M) % M;
    cout << ans;
}


Measured memory_bytes: 512
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  writeln(s <= "2019/04/30" ? "Heisei" : "TBD");
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long x,a,b,c,ans=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int z=0;z<=c;z++)
			{
                int k=i*500+j*100+z*50;
                if(k==x)ans++;
                if(k>x)break;
            }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<bool> H(h,false),W(w,false);
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin >> s[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        H[i]=true;
        break;
      }
    }
  }
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      if(s[j][i]=='#'){
        W[i]=true;
        break;
      }
    }
  }
  for(int i=0;i<h;i++){
    if(H[i]){
      for(int j=0;j<w;j++){
        if(W[j])
          cout << s[i][j];
      }
      cout << endl;
    }
  }
}
       

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto cnt = new long[string][](N+1);
    long ans = 0;

    foreach (mask; 0..(1<<N)) {
        string a = "";
        string b = "";
        foreach (i; 0..N) {
            if ((1 << i) & mask) {
                a ~= S[i];
            } else {
                b = S[i] ~ b;
            }
        }
        cnt[mask.popcnt][a~b] += 1;
    }

    foreach (mask; 0..(1<<N)) {
        string a = "";
        string b = "";
        foreach (i; 0..N) {
            if ((1 << i) & mask) {
                a ~= S[i+N];
            } else {
                b = S[i+N] ~ b;
            }
        }
        if ((b ~ a) in cnt[N-mask.popcnt]) {
            ans += cnt[N-mask.popcnt][b ~ a];
        }
    }

    ans.writeln;
}


Measured memory_bytes: 55164
#include <iostream>
#include <queue>
#include <cstdlib>
int INF = 1e9;
int main(){
    long long n;
    std::cin >> n;
    std::vector<int> G[n];
    std::vector<int> used(n, 0);
    for(int i = 0; i < n; i++){
        int a, k;
        std::cin >> a >> k;
        a--;
        for(int j = 0; j < k; j++){
            int b;
            std::cin >> b;
            b--;
            G[a].push_back(b);
        }
    }
    std::vector<int> d(n, INF);
    std::queue<int> q;
    q.push(0);
    d[0] =0;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        used[t] = 1;
        for(int i: G[t]){
            if(used[i] == 0){
                q.push(i);
                d[i] = std::min(d[i], d[t] + 1);
            }
        }
    }
    for(int i = 0; i < n; i++) if(d[i] == INF) d[i] = -1;
    for(int i = 0; i < n; i++) std::cout << i + 1 << ' ' << d[i] <<  std::endl;
}


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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  int past = B - A;
  if (past <= 0) {
    cout << "delicious" << endl;
  } else if (past <= X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}



Measured memory_bytes: 384
from collections import Counter

def make_xor_sum(A):
    output = A[0]
    for i in range(1,len(A)):
        output = output ^ A[i]

    if output == 0:
        return True
    else:
        return False

def main():
    N = int(input())
    a = list(map(int,input().split()))

    if make_xor_sum(a):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 14596
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

#define COUT cout <<
#define SPACE_COUT << " "  <<
#define COMMA_COUT << ", " <<
#define ENDL << endl;

int
main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int total = 0;
    int g = 0, p = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'g') {
            if (p < g) {
                p++;
                total++;
            } else {
                g++;
            }
        } else {
            if (p < g) {
                p++;
            } else {
                g++;
                total--;    
            }
        }
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 512
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int sn = s.size();

  int q;
  cin >> q;

  while (q--) {
    string op, p;
    int a, b;
    cin >> op >> a >> b;

    if (op == "print") {
      for (int i = a; i <= b; i++) putchar(s[i]);
      putchar('\n');
    }
    else if (op == "reverse") {
      for (int i = a, j = b; i < j; i++, j--) swap(s[i], s[j]);
    }
    else if (op == "replace") {
      cin >> p;
      for (int i = 0; i <= b - a; i++) s[a + i] = p[i];
    }
  }
  return 0;
}

Measured memory_bytes: 1192
S = gets.to_s.split("").map(&:to_i)
sum = 0

S.each_with_index do |value,cnt|
  if  cnt < S.length - 2 && S[cnt] == S[cnt + 1]
    S[cnt + 1] = S[cnt + 1] - 1
    S[cnt + 1] = S[cnt + 1].abs
    sum += 1
  end
end
puts sum


Measured memory_bytes: 7676
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n = 0;
		int taroPoint = 0;
		int hanakoPoint= 0;
		String str =null;
		ArrayList<String> taro = new ArrayList<String>();
		ArrayList<String> hanako = new ArrayList<String>();
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(int j = 0; j < n; ++j){
			for(int i = 0; i < 2; ++i){
				str = sc.next();
				if(i == 0)
				taro.add(str);
				else if(i == 1)
					hanako.add(str);
			}
		}
		for(int a = 0; a < n; ++a){
			int comp = (taro.get(a)).compareTo(hanako.get(a));
			if(comp < 0){
				hanakoPoint += 3;
			}
			else if(comp > 0){
				taroPoint += 3;
			}
			else{
				hanakoPoint += 1;
				taroPoint += 1;
			}
			}
		System.out.println(taroPoint+" "+hanakoPoint);
		sc.close();
	}

}

Measured memory_bytes: 30728
#include <iostream>
#include <algorithm>


const int MAXN = 100;
const int MAXK = 1e5 + 1;

int rm[MAXN];
bool canWin[2][MAXK];
bool seen[2][MAXK];


bool iswinner(int player, int stones, int moves)
{
	if (!seen[player][stones])
	{
		seen[player][stones] = true;
		for (int iMove = 0; iMove < moves && rm[iMove] <= stones; iMove++)
			canWin[player][stones] |= !iswinner(1 - player, stones - rm[iMove], moves);
	}
	
	return canWin[player][stones];
}

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

	int moves, stones;
	std::cin >> moves >> stones;

	for (int iMove = 0; iMove < moves; iMove++)
			std::cin >> rm[iMove];

	if (iswinner(0, stones, moves))
			std::cout << "First\n";
	else
			std::cout << "Second\n";

	return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define LL long long

int N,Q;
const int maxn = 200005;
//int nums[maxn];

int get_int(){int x;scanf("%d",&x);return x;}
double get_double(){double x;scanf("%lf",&x);return x;}
long long get_long(){long long x;scanf("%lld",&x);return x;}
vector<char> vc;
vector<char> id;
vector<char> inst;

void tests(){
    ;
}

bool not_out_l(int pos){
    char ch = vc[pos];
    _for(i,0,Q){
        //printf("%d\n",pos);
        if(id[i] == ch){
            if(inst[i] == 'L'){
                pos--;
            }
            else{
                pos++;
            }
            if(pos < 0 || pos >= N) return false;
            ch = vc[pos];
        }
    }
    return true;
}

bool not_out_r(int pos){
    char ch = vc[pos];
    _for(i,0,Q){
        //printf("%d\n",pos);
        if(id[i] == ch){
            if(inst[i] == 'L'){
                pos--;
            }
            else{
                pos++;
            }
            if(pos >= N || pos < 0) return false;
            ch = vc[pos];
        }
    }
    return true;
}



int searchl(){
    int l = 0,r = N;

    while(r-l > 1){
        int m = (r+l)/2;
        //printf("%d %d\n",l,r);
        if(not_out_l(m)){
            l = m;
        }
        else{
            r = m;
        }
    }
    return l;
}

int searchr(){
    int l = -1,r = N-1;
    while(r-l > 1){
        int m = (r+l)/2;
        //printf("%d %d\n",l,r);
        if(not_out_r(m)){
            r = m;
        }
        else{
            l = m;
        }
    }
    return r;
}

int main()
{
    //ios::sync_with_stdio(false);
    scanf("%d %d",&N,&Q);getchar();
    _for(i,0,N){
        char ch = getchar();
        vc.push_back(ch);
    }
    getchar();

    //_for(i,0,N) nums[i] = 1;

    _for(i,0,Q){
        char ch = getchar();
        getchar();
        char instr = getchar();
        getchar();
        id.push_back(ch);
        inst.push_back(instr);
    }

    int l = searchl();
    int r = searchr();


    //printf("%d %d\n",l,r);
    printf("%d\n",max(0,l-r+1));

    return 0;
}


Measured memory_bytes: 1060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <cmath>

using ll = long long;

//各種nil
template <class T>
constexpr T nil = static_cast<T>(-1);

constexpr int nil_i = nil<int>;
constexpr int nil_ll = nil<ll>;
constexpr double nil_d = nil<double>;

//vector
template <class T>
using vec = std::vector<T>;

void solve()
{
    using namespace std;
    int a, b, c, d;
    
    cin >> a >> b >> c >> d;
    

    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
double calc(double a, double b) { return (a - b) * (a - b); }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(3);
    int n;
    while(cin >> n, n)
    {
        vector<double> x(n), y(n), z(n), r(n);
        for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i] >> r[i];
        double ans = 0.0;
        priority_queue<P, vector<P>, greater<P>> que;
        bool used[n] = {};
        que.push(P(0, 0));
        while(que.size())
        {
            P p = que.top(); que.pop();
            int v = p.second;
            if(used[v]) continue;
            ans += p.first;
            used[v] = true;
            for(int u = 0; u < n; u++)
            {
                if(used[u]) continue;
                double dist = sqrt(calc(x[v], x[u]) + calc(y[v], y[u]) + calc(z[v], z[u])) - (r[v] + r[u]);
                que.push(P(max(dist, 0.0), u));
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3368
#include<iostream>
#define PI 3.141592653589
using namespace std;

int main(){
	while(1){
		int H,W;
		cin >> H >>W;
		
		if(H==0 && W==0)break;
		for(int y=0;y<H;y++){
			for(int x=0;x<W;x++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

ll N,K;
//dp[i]はiからコインふって勝つ確率
vector<double> dp(100005,-1);
double F(ll e){
    if(e>=0&&e<=100003&&dp[e]!=-1){return dp[e];}
    if(e>=K){return 1.0;}
    if(e<=0){return 0.0;}
    else return dp[e]=0.5*F(2*e);
}

int main(){
    cin >> N;
    cin >> K;
    double ans=0;
    for(ll i=1;i<=N;i++){
        ans+=F(i)/N;
    ;}
    cout << fixed << setprecision(12);
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1024