akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
	int y , m , d;
	long int num;
	while(scanf("%d %d %d" , &y , &m , &d)!=EOF){
		num = y * 1e4 + m * 100 + d;
		if(num < 18680908){
			printf("pre-meiji\n");
		}else if(num < 19120730){
			printf("meiji %d %d %d\n" , y - 1868 + 1 , m , d);
		}else if(num < 19261225){
			printf("taisho %d %d %d\n" , y - 1912 + 1 , m , d);
		}else if(num < 19890108){
			printf("showa %d %d %d\n" , y - 1926 + 1 , m , d);
		}else{
			printf("heisei %d %d %d\n" , y - 1989 + 1 , m , d);
		}
	}
return 0;
}

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

typedef int64_t i64;

constexpr i64 llinf=4611686018427387903LL;

template <class T_>
class raddq{
public:
    i64 n;
    i64 h;
    T_ *lz;
    void make(i64 N){
        n=1;
        h=0;
        while(n<N){
            n*=2;
            h++;
        }
		lz=new i64[n*2]{};
        for(i64 i=0;i<n*2;i++) lz[i]=(T_)0;
    }
    void update(i64 A,i64 B,T_ X){
        thrust(A+=n);
        thrust(B+=n-1);
        for(i64 l=A,r=B+1;l<r;l/=2,r/=2){
            if(l%2==1){
                lz[l]+=X;
                l++;
            }
            if(r%2==1){
                r--;
                lz[r]+=X;
            }
        }
    }
    T_ query(i64 K){
        thrust(K+=n);
        return lz[K];
    }
    void thrust(i64 K){
        for(i64 i=h;i>0;i--){
            i64 k=K>>i;
            if(lz[k]==(T_)0) continue;
            lz[k*2]+=lz[k];
            lz[k*2+1]+=lz[k];
            lz[k]=(T_)0;
        }
    }
};

int main(void){
    i64 n,q;
    scanf("%lli%lli",&n,&q);
    raddq<i64> raq;
    raq.make(n);
    for(i64 i=0;i<q;i++){
        i64 c;
        scanf("%lli",&c);
        if(c==0){
            i64 s,t,x;
            scanf("%lli%lli%lli",&s,&t,&x);
            raq.update(s-1,t,x);
        }
        else{
            i64 j;
            scanf("%lli",&j);
            printf("%lli\n",raq.query(j-1));
        }
    }
    return 0;
}



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

#define f(i,a,b) for (int i = a; i < b; i++)
#define pb push_back
using vi = vector<int>;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
int n; cin>>n;
int q; cin>>q;
vi adj[n];
f(i,0,n-1) {
int a, b; cin>>a>>b;
adj[--a].pb(--b);
adj[b].pb(a);
}
vi ans(n,0);
function<void(int,int)> dfs = [&](int v, int p) {
if (p != -1) ans[v] += ans[p];
for (int w : adj[v]) if (w != p)
dfs(w,v);
};
f(_,0,q) {
int p, x; cin>>p>>x;
ans[--p]+=x;
}
dfs(0,-1);
f(i,0,n) cout << ans[i] << " ";
cout << endl;
return 0;
}

Measured memory_bytes: 26624
s=input()
t=s.replace('x','')
n=len(t)
if not(n==1 or t[:n//2]==t[(n+1)//2:][::-1]):
  print(-1)
  exit()
n=len(s)
r=n-1
l=0
ans=0
while r>l:
  nr,nl=r,l
  while s[r]=='x' and r>0:r-=1
  while s[l]=='x' and l<n-1:l+=1
  ans+=abs(nr-r+nl-l)
  while s[r]==s[l] and l<r:
    r-=1
    l+=1
print(ans)

Measured memory_bytes: 72848
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep1(i,num) for(int i=1;i<=num;i++) 
int main(){
  int num,i;
  ll ans = 1;
  ll mod = 1e9 + 7;
  
  cin >> num;
  
  //rep1(i,num) ans = ans * i % 1000000007;
  
  for(i=1;i<=num;i++){
     ans *= i;
     ans %= mod;
  }
  
  cout << ans << endl;
  
}

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


class UnionFind {
public:
  vector<int> data; // sizeとparを同時に管理する
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  void unite(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px != py) {
      if (data[py] < data[px]) swap(px, py);
      data[px] += data[py]; data[py] = px;
    }
  }

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

  int size(int x) {
    return -data[find(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    uf.unite(x, y);
  }

  /* dataとsizeの確認. data[i]が負の点はroot */
  set<int> s;
  for (int i = 0; i < n; ++i) {
    s.insert(uf.find(i));
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 5376
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x): stderr.write(reduce(add, repr(x)).strip("()\',") + '\n')

n, a = f()
x = f()
s = sum(x)

dp = [[[0 for i in range(n + 1)] for j in range(s + 1)] for k in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 1

for i in range(1, n + 1):
    for j in range(1, s + 1):
        for k in range(1, n + 1):
            dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - x[i - 1]][k - 1]

ans = 0
k = 1
while a * k <= s and k <= n:
    ans += dp[n][a*k][k]
    k += 1
print(ans)


Measured memory_bytes: 111068
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}



Measured memory_bytes: 2744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h) * (W-w) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>                                             
#include <cstdio>                                               
using namespace std;                                            
                                                                
int main() {                                                    
  int N;                                                        
  cin >> N;                                                     
  int A[N];                                                     
  for (int i=0; i<N; i++) {                                     
    cin >> A[i];                                                
  }                                                             
  int ans = 0;                                                  
  for (int i=0; i<N; i++) {                                     
    int minj = i;                                               
    for (int j=i; j<N; j++) {                                   
      if (A[j]<A[minj]) {                                       
        minj = j;                                               
      }                                                         
    }                                                           
    int v = A[i];                                               
    A[i] = A[minj];                                             
    A[minj] = v;                                                
    if (i!=minj) {                                              
      ans++;                                                    
    }                                                           
  }                                                             
  for (int i=0; i<N; i++) {                                     
    cout << (i==0?"":" ") << A[i] << flush;                     
  }                                                             
  printf("\n");                                                 
  cout << ans << endl;                                          
  return 0;                                                     
}                                                               
                                                                
             

Measured memory_bytes: 3096
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize,
        total_weight: u64,
        wv: [(u64, u64); n]
    }
    let w1 = wv[0].0;
    let dw = wv.iter().map(|&(w, _)| (w - w1) as usize) .collect::<Vec<_>>();

    let mut dp = vec_md![0;n+1;3*n+1;n+1];
    for i in 0..n {
        for j in 0..3*n+1 {
            for k in 0..n+1 {
                if j + dw[i] < 3*n + 1 && k + 1 < n + 1 &&
                    (k as u64 +1) * w1 + j as u64 + dw[i] as u64 <= total_weight {
                    dp[i+1][j+dw[i]][k+1] = std::cmp::max(
                        dp[i+1][j+dw[i]][k+1],
                        dp[i][j][k] + wv[i].1
                    );
                }
                dp[i+1][j][k] = std::cmp::max(
                    dp[i+1][j][k],
                    dp[i][j][k]
                );
            }
        }
    }

    let mut max = 0;
    for j in 0..3*n+1 {
        for k in 0..n+1 {
            max = std::cmp::max(
                max,
                dp[n][j][k]
            );
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 30972
s = list(str(input()))

s_set = list(set(s))
if len(s_set) != 2:
    print('No')
else:
    count1 = 0
    for i in range(len(s)):
        if s[i] == s_set[0]:
            count1 += 1
    count2 = 0
    for i in range(len(s)):
        if s[i] == s_set[1]:
            count2 += 1
    if count1 == 2 and count2 == 2:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    lint r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    vector<lint> frac(2000002);
    frac[0] = 1;
    FOR(i, 1, 2000002) {
        frac[i] = frac[i-1] * i % MOD;
    }
    lint ans = 0;
    FOR(i, r1+1, r2+2) {
        ans = (ans + frac[i+c2] * power(frac[i], MOD-2, MOD) % MOD * power(frac[c2], MOD-2, MOD) % MOD) % MOD;
        ans = (ans - frac[i+c1-1] * power(frac[i], MOD-2, MOD) % MOD * power(frac[c1-1], MOD-2, MOD) % MOD + MOD) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())



int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

ll X,Y,Z,K;
ll pmax = 30000000000;
vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }




int main() {




  ll a,b,c;
  cin >>a>>b>>c;

  if(a<c && c<b)cout << "Yes" <<endl;
  else if(a>c && c>b) cout << "Yes" << endl;
  else cout << "No" << endl;

}

















//


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

using namespace std;

int main()
{
    int age;
    cin >> age;
    if(age == 1){
        cout << "Hello World" << endl;
    }else{
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long int lli;

int main(void) {
    lli n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);

    lli now,res=0;
    scanf("%lld",&now);
    for(int i=0; i<n-1; i++) {
        lli x;
        scanf("%lld",&x);
        res += min(a*(x-now), b);
        now = x;
    }
    printf("%lld\n", res);

    return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

// struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); } } initCpp;

signed main() {
  i32 x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<i64> A(x), B(y), C(z);
  cin >> A >> B >> C;
  sort(ALL(A), greater<i64>());
  sort(ALL(B), greater<i64>());
  sort(ALL(C), greater<i64>());
  using T = tuple<i32, i32, i32>;
  using P = pair<i64, T>;
  priority_queue<P> Q;
  Q.push({A[0] + B[0] + C[0], make_tuple(0, 0, 0)});
  set<T> S;
  S.insert(make_tuple(0, 0, 0));
  REP(_, k) {
    i64 p = Q.top().first;
    i32 u, v, w;
    tie(u, v, w) = Q.top().second;
    Q.pop();
    cout << p << endl;
    auto u1 = make_tuple(u + 1, v, w);
    auto v1 = make_tuple(u, v + 1, w);
    auto w1 = make_tuple(u, v, w + 1);
    if (u + 1 < x && !S.count(u1)) { S.insert(u1); Q.push({A[u + 1] + B[v] + C[w], u1}); }
    if (v + 1 < y && !S.count(v1)) { S.insert(v1); Q.push({A[u] + B[v + 1] + C[w], v1}); }
    if (w + 1 < z && !S.count(w1)) { S.insert(w1); Q.push({A[u] + B[v] + C[w + 1], w1}); }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main(){
  string n,a,b,c,d;
  bool ans=0;
  cin>>n;
  a=n.substr(0,1);
  b=n.substr(1,1);
  c=n.substr(2,1);
  d=n.substr(3,1);
  if((a==b&&b==c)||(d==b&&d==c)){ans=1;}
  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
  return 0;
}


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string w; cin >> w;
    transform(w.begin(), w.end(), w.begin(), ::tolower);
    int ans = 0;
    string s; cin >> s;
    while(s != "END_OF_TEXT")
    {
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        if(s == w) ans++;
        cin >> s;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3192
<?php
$card_count = trim(fgets(STDIN));
$card_array_s = array("S 1","S 2","S 3","S 4","S 5","S 6","S 7","S 8","S 9","S 10","S 11","S 12","S 13");
$card_array_h = array("H 1","H 2","H 3","H 4","H 5","H 6","H 7","H 8","H 9","H 10","H 11","H 12","H 13");
$card_array_c = array("C 1","C 2","C 3","C 4","C 5","C 6","C 7","C 8","C 9","C 10","C 11","C 12","C 13");
$card_array_d = array("D 1","D 2","D 3","D 4","D 5","D 6","D 7","D 8","D 9","D 10","D 11","D 12","D 13");
while($input = trim(fgets(STDIN))){
    sscanf($input,'%c %d',$kind,$number);
    switch ($kind) {
        case 'S':
            unset($card_array_s[$number-1]);
            break;
        case 'H':
            unset($card_array_h[$number-1]);
            break;
        case 'C':
            unset($card_array_c[$number-1]);
            break;
        case 'D':
            unset($card_array_d[$number-1]);
            break;
    }
}
if (count($card_array_s)>0) echo join($card_array_s,PHP_EOL),PHP_EOL;
if (count($card_array_h)>0) echo join($card_array_h,PHP_EOL),PHP_EOL;
if (count($card_array_c)>0) echo join($card_array_c,PHP_EOL),PHP_EOL;
if (count($card_array_d)>0) echo join($card_array_d,PHP_EOL),PHP_EOL;

Measured memory_bytes: 15320
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var output = [];
  for( var index=0; index<data.length; index++ ) {
    var nums = data[index].split( ' ' ).map( Number );
    var n = nums[0];
    var x = nums[1];
    if( 0 == n && 0 == x ) { break; }

    var cnt = 0;
    var ave = x/3;
    for( var i=1; i<ave; i++ ) {
      var t = (x-i)/2;
      for( var j=i+1; j<t; j++ ) {
        var k = x-i-j;
        if( j < k && k <= n ) { cnt++; }
      }
    }
    output.push( cnt );
  }
  console.log( output.join( '\n' ) );
});

Measured memory_bytes: 8636
#include<stdio.h>
#include<string.h>
int a[100050];
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int sum=1;
	i=a[1];
	while(i!=2){
		i=a[i];
		sum++;
		if(sum>=100000)
			break;
	}
	if(i==2)
		printf("%d\n",sum);
	else
		printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
INF = 10 ** 9
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
dp = [[INF for _ in range(W)] for _ in range(H)]
if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(H):
    for j in range(W):
        if j != 0:
            cnt = 0
            if s[i][j] == '#' and s[i][j - 1] == '.':
                cnt += 1
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + cnt)

        if i != 0:
            cnt = 0
            if s[i][j] == '#' and s[i - 1][j] == '.':
                cnt += 1
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + cnt)

print(dp[-1][-1])

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

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

    int k, a, b;
    cin >> k >> a >> b;

    cout << (updiv(a, k) * k <= b ? "OK\n" : "NG\n");

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double pi = std::acos(-1);

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
    double a,b,x;cin>>a>>b>>x;
    double l,r;l=0.0;r=pi/2.0;
    double th=(l+r)/2.0;
    double v=0.0;
    while(l+0.00000001<r){
        if(a*sin(th)>=b*cos(th)){
            v=a*b*b/(2.0*tan(th));
        }else{
            v=a*a*b-a*a*a*tan(th)/2.0;
        }
        if(v>=x){
            l=th;
        }else{
            r=th;
        }
        th=(l+r)/2.0;
    }
    cout<<fixed<<setprecision(10)<<l*180/pi<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    bool f = false;
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        f |= x % 2;
    }
    if (f) {
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
    return 0;
}

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


int main() {
string s;
cin>>s;
int a =0, b=0,c=0;
for(int i=0;i<s.length();i++)
{
    if( s[i] =='a')
        a++;
    if( s[i] =='b')
        b++;
    if( s[i] == 'c')
        c++;
}
int ma = max( a , max( b,c));
int mi = min( a , min( b,c));
if( ma -mi >=2 )
{
    cout<<"NO";
}
else cout<<"YES";
}


Measured memory_bytes: 3760
import sys
#階乗
mod=10**9+7
table=[1]*(10**5+100)
for i in range(2,10**5+100):
    table[i]=(table[i-1]*i)%mod
    
#cmb
g1=[1,1]
g2=[1,1]
for i in range(2,10**5+100):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))  
def cmb(n,r,MOD):
    if n<r or n<=0:
        return 0
    else:
        return g1[n]*g2[r]*g2[n-r]%MOD
    
#dfsで進んでいき、3回目以降は親とその親以外の色、kー2通りから考える。
n,k=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
if k==2:
    if n<=2:
        print(2)
    else:
        print(0)
    sys.exit()
if k==1:
    if n==1:
        print(1)
    else:
        print(0)
    sys.exit()
flag=[0]*(n+1)
ans=1
ans=cmb(k,len(data[1])+1,mod)*table[len(data[1])+1]%mod
que=data[1]
flag[1]=1
for u in data[1]:
    flag[u]=1
while que:
    h=[]
    for u in que:
        count=0
        for v in data[u]:
            if flag[v]==0:
                flag[v]=1
                h.append(v)
                count+=1
        ans=(ans*cmb(k-2,count,mod)*table[count])%mod
    que=h
print(ans)

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

using namespace std;

map<int,bool> m;

int main(){

    int n,t;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        if(m[t]==1)m.erase(t);
        else m[t]=1;
    }

    cout<<m.size();

    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<utility>
#define MAX_N 101
#define MP make_pair
using namespace std;
typedef pair<int, int> P;

P red[MAX_N], blue[MAX_N];
bool is_checked[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> red[i].first >> red[i].second;
    for (int i = 0; i < N; i++) cin >> blue[i].first >> blue[i].second;
    sort(blue, blue + N);
    for (int i = 0; i < N; i++) {
        int xb = blue[i].first, yb = blue[i].second;
        int max_y = -1, max_red_idx = -1;
        for (int j = 0; j < N; j++) {
            int xr = red[j].first, yr = red[j].second;
            if (xr < xb && yr < yb && max_y < yr && !is_checked[j]) {
                max_y = yr;
                max_red_idx = j;
            } 
        }
        if (max_red_idx == -1) continue;
        is_checked[max_red_idx] = true;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (is_checked[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    rep(i, 3) {
        if (s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     2019
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
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...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif

}

int dp[3005][3005];
string s,t;


int fun(int idx_s,int idx_t)
{
	
	//db(idx_s,idx_t);
	if((idx_s==s.size())||(idx_t==t.size()))
		return dp[idx_s][idx_t]=0;
	if(dp[idx_s][idx_t]!=-1)
		return dp[idx_s][idx_t];
	int &ans=dp[idx_s][idx_t];
	if(s[idx_s]==t[idx_t])
		ans=1+fun(idx_s+1,idx_t+1);
	ans=max(ans,fun(idx_s+1,idx_t));
	ans=max(ans,fun(idx_s,idx_t+1));

	return ans;
}

int32_t main()
{
	fastIO
	//inp_out();
	//string s,t;
	memset(dp,-1,sizeof(dp));
	cin>>s>>t;
	fun(0,0);
	string ans="";
	int idx_s=0,idx_t=0;
	while (idx_s<s.size() and idx_t<t.size())
	{
	    if ((dp[idx_s+1][idx_t+1]==dp[idx_s][idx_t]-1) and (s[idx_s]==t[idx_t]))
	    {
	    	ans+=s[idx_s];
	        idx_s+=1;
	        idx_t+=1;
	    }
	    else if (dp[idx_s][idx_t]==dp[idx_s+1][idx_t])
	        idx_s+=1;
	    else
	        idx_t+=1;
	}
	cout<<ans;


	return 0;
}


Measured memory_bytes: 71040
using System;
public class Class1
{
	public static void Main()
	{
		string dataSet =Console.ReadLine();
		string[] data=dataSet.Split();
		int n=int.Parse(data[0]);//row
		int m=int.Parse(data[1]);//column		
		int[] columnSum=new int[m];
		int sum=0;
		
		for (int i =0; i < n; i++)
		{
			string matrixSet =Console.ReadLine();
			string[] matrix=matrixSet.Split();
			
			int rowSum=0;
			for(int j =0;j<m;j++)
			{       int a;
				a=int.Parse(matrix[j]);
				rowSum+=a;
				columnSum[j]+=a;
			}	
			Console.WriteLine(matrixSet+" "+rowSum);
			sum+=rowSum;			
		}
	
		for(int k=0;k<m;k++)
		{				
				Console.Write(columnSum[k]+" ");				
		}
		Console.Write(sum+"\r\n");		
	}		
}

Measured memory_bytes: 9208
s = input()
ans = []
dp = [""]*(len(s))
if s[0] != "B":
    dp[0] = s[0]
else:
    dp[0] = ""

for i in range(len(s)-1):
    if s[i+1] != "B":
        dp[i+1] = dp[i] + s[i+1]
    else:
        dp[i+1] = dp[i][:len(dp[i])-1]
print(dp[len(s)-1])

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e13;

int n;
long long dp[401][401];
int arr[405];

long long sum (int l, int r) {
	long long ans = 0;
	for (int i = l; i <= r; i++)
		ans += arr[i];
	return ans;
}

int main () {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R)
				dp[L][R] = 0;
			else {
				dp[L][R] = INF;
				for (int i = L; i <= R - 1; i++)
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R));
			}
		//	cout << " L = " << L  << " R =  " << R << "\n";
		/*	for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (dp[i][j] == INF)
						cout << "INF ";
					else {
						printf("%3lld ", dp[i][j]);
					}
				}
				cout << "\n";
			}
			cout << "\n****************************************\n\n";
		*/
		}
	}
	cout << dp[0][n - 1] << "\n";
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
string ans[2]={"Bob","Alice"};

int main()
{
ll n;
cin >> n ;
vector<vector<ll>> g(n);
rep(i, n-1)
{
  ll a, b;
  cin >> a >> b;
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1); 
}
ll root=0;
vector<vector<ll>> child(n);
vector<ll> par(n);
vector<ll> gu(n);
queue<ll> q;
queue<ll> qq;
q.push(root);
par[root]=-1;
//親の定義と葉を見つける
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1 && p!=root){qq.push(p);}
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  child[par[p]].push_back(p);//親に値を追加する
  //根の時は例外処理
  if(child[par[p]].size()==g[par[p]].size()){
    //child[par[p]]に子の値が入ってる
    for(auto r:child[par[p]]){
      gu[par[p]]^=(gu[r]+1);
    }
  }
  //全ての葉が親に追加し終わった
  if(child[par[p]].size()==g[par[p]].size()-1 && par[p]!=root){
    //child[par[p]]に子の値が入ってる
    for(auto r:child[par[p]]){
      gu[par[p]]^=(gu[r]+1);
    }
    qq.push(par[p]);
  }
}
cout << ans[(bool)gu[0]] << endl;
return 0;
}

Measured memory_bytes: 12800
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;

    int ans = 0;    
    FOR(i,1,N+1) {
        if (to_string(i).size() % 2 == 0) continue;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  int sum=0;
  int x=N;
  while(x>0) {
    sum += x%10;
    x /= 10;
  }
  if (N%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  int maxi(0);
  for (int i(0);i<n-1;i++){
    int cnt(0);
    int l[30]={0},r[30]={0};
    for (int j(0);j<=i;j++){
      l[s[j]-'a']++;
    }
    for (int j(i+1);j<n;j++){
      r[s[j]-'a']++;
    }
    for (int j(0);j<30;j++){
      if (l[j]!=0&&r[j]!=0)cnt++;
    }
    maxi=max(maxi,cnt);
  }
  cout << maxi << endl;
  return 0;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();

		if(isOverlap(S)){
			System.out.println("no");
		}
		else{
			System.out.println("yes");
		}

		sc.close();
	}

	static boolean isOverlap(String S){
		HashSet<Character> set = new HashSet<Character>();
		for(char c: S.toCharArray()){
			if(set.contains(c)){
				return true;
			}
			else{
				set.add(c);
			}
		}
		return false;
	}

}


Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static class FastReader{
		BufferedReader br ;
		StringTokenizer st;
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static long log(long x, long b)
	{
	    return (long) (Math.log(x) / Math.log(b));
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		long h =ob.nextLong();
		int k=0;
		long count=0;
		while(h>0) {
			count+=(long)Math.pow(2, k);
			h=h/2;
			k++;
			
		}
		System.out.println(count);
	}
	

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=410;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,A,B,dp[N/10+1][N][N];
struct Node { int a,b,c; }q[N];
signed main()
{
    n=read(), A=read(), B=read();
    for(ri int i=0;i<n;i++) q[i].a=read(), q[i].b=read(), q[i].c=read();
    memset(dp,0x3f,sizeof(dp));
    dp[0][0][0]=0;
    for(ri int i=0;i<n;i++)
    for(ri int j=0;j<=400;j++)
    for(ri int k=0;k<=400;k++)
    {
        if(dp[i][j][k]==dp[N/10][N-1][N-1]) continue;
        dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
        dp[i+1][j+q[i].a][k+q[i].b]=min(dp[i+1][j+q[i].a][k+q[i].b],dp[i][j][k]+q[i].c);
    }
    int res=8e18;
    for(ri int i=1;i<=400;i++)
    for(ri int j=1;j<=400;j++) if(i*B==j*A) res=min(res,dp[n][i][j]);
    
    if(res>=dp[N/10][N-1][N-1]) puts("-1");
    else printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 58876
n,k = map(int,input().split())
lis = list(map(int,input().split()))
num = 0
ans = 0
cou = 0
co = 0
for i in range(n):num += max(0,lis[i])
li = [0 for i in range(n-k+1)]
for i in range(k-1):
  cou += max(0,lis[i])
  co += max(0,-lis[i])
for i in range(n-k+1):
  cou += max(0,lis[i+k-1])
  co += max(0,-lis[i+k-1])
  if cou >= co:ans = max(ans,num-co)
  else:ans = max(ans,num-cou)
  cou -= max(0,lis[i])
  co -= max(0,-lis[i])
print(ans)

Measured memory_bytes: 14844
class BinaryHeap
  attr_reader :size

  def initialize
    @heap = []
    @size = 0
  end

  def add(n)
    i = @size
    while i > 0 do
      parent_index = (i - 1) / 2
      break if n < @heap[parent_index]

      @heap[i] = @heap[parent_index]
      i = parent_index
    end

    @heap[i] = n
    @size += 1
  end

  def pop
    return if @size <= 0
    min_n = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size do
      child_index1 = i * 2 + 1
      child_index2 = i * 2 + 2
      if child_index2 < @size && @heap[child_index2] >= @heap[child_index1]
        child_index1 = child_index2
      end
      break if @heap[child_index1] < n

      @heap[i] = @heap[child_index1]
      i = child_index1
    end
    @heap[i] = n
    min_n
  end

  def min; @heap[0] end
  def values; @heap.first(@size) end
  def inspect; "Heap: #{values}" end
end

bh = BinaryHeap.new
N, M = gets.chomp.split.map(&:to_i)

h = Hash.new{ |h,k| h[k] = [0]}

N.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  h[a] << b
end

ans = 0
1.upto(M) do |m|
  h[m].each { |c| bh.add(c) } if h[m]
  top = bh.pop()
  ans += top if top
end

p ans


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

using namespace std;

//#define MD 10

int main(){
    long long int a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+'){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll m;cin >> m;
  vector<ll> d(m),c(m);
  ll sum=0,sc=0;
  for(int i=0;i<m;i++){
    cin >> d[i] >> c[i];
    sum+=d[i]*c[i];
    sc+=c[i];
  }
  if(sum%9==0){
    cout << sc-1+sum/9-1 << endl;
    return 0;
  }
  cout << sc-1+sum/9 << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	string s;
	cin >> s;

	ll K;
	cin >> K;

	char ans = '1';

	rep(i,K){
		if (s[i] != '1') { ans = s[i]; break; }
	}

	cout << ans;

	
	system("PAUSE");
}

Measured memory_bytes: 504
#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 ll long long
#define INF 999999999
using namespace std;
int main() {
  std::string s,t;
  cin>> s >> t ;
  t.pop_back();
  if (s == t) {
    cout<< "Yes" <<endl;
  }
  else{
    cout<< "No" <<endl;
  }
}


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

int main(){
    int N; cin >> N;
    bool mem[200001] ={0};
    vector<int> A(N), res;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = N -1; i >= 0; i--){
        if((mem[i+1]^A[i]) == 1){
            res.push_back(i+1);
            for(int j = 1; j * j <= i + 1; j++){
                if((i + 1) % j == 0){
                    int k = (i + 1) /j;
                    mem[j] = !mem[j];
                    if( k != j) mem[k] = !mem[k]; 
                    //cout << i + 1 <<" " << j << " "<< k << endl;
                }
            }
        }
    }
    if(res.empty()){
        cout << 0 << endl;
    }
    else{
        cout << res.size() << endl;
        for(int i = 0; i < res.size(); i++){
            if(i != 0) cout << " ";
            cout << res[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 2552
#!/bin/bash

while true;
do
        read line1

        if [ -z "$line1" ]; then
                break
        fi

        charlen=`echo "$line1" | wc -c`
        halfLen=`echo $(( charlen/2 ))`
        hugCount=0

        for i in `seq 1 $halfLen`;
        do
                revNum=`echo $(($charlen - $i))`

                headLetter=`echo ${line1} | cut -c $i`
                tailLetter=`echo ${line1} | cut -c $revNum`
                if [ ! $headLetter = $tailLetter ]; then
                        hugCount=`echo $(($hugCount + 1))`
                fi
        done

        echo $hugCount
done


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

int main() {
  int N;
  cin>>N;
  string S;
  S="ACL";
  if (N==1){
    cout<<S<<endl;
  }
  else if (N==2){
    cout<<S<<S<<endl;
  }
  else if (N==3){
    cout<<S<<S<<S<<endl;
  }
  else if (N==4){
    cout<<S<<S<<S<<S<<endl;
  }
  else if (N==5){
    cout<<S<<S<<S<<S<<S<<endl;
  }
}



Measured memory_bytes: 3480
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

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


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

int main(){
  ll N;
  cin >> N;
  bool l = 1;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll m = A[0], M = A[N-1];
  if(M % 2 == 0){
    if(m != M/2) l = 0;
    if(A[0] == A[1]) l = 0;
    for(ll i = m+1; i <= M; i++){
      ll cnt = 0;
      rep(j, N) if(A[j] == i) cnt++;
      if(cnt < 2) l = 0;
    }
  }else{
    if(m != M/2 + 1) l = 0;
    ll cnt2 = 0;
    rep(j, N) if(A[j] == m) cnt2++;
    if(cnt2 != 2) l = 0;
    for(ll i = m+1; i <= M; i++){
      ll cnt = 0;
      rep(j, N) if(A[j] == i) cnt++;
      if(cnt < 2) l = 0;
    }
  }
  if(l) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll H,W;
    cin >>H>>W;
    //ll sy,sx,gy,gx;
    
    vector<vector<char> > S(H,vector<char>(W));

    rep(i,H){
        rep(j,W){
            cin >> S[i][j];
        }
    }
    ll ans = 0;
    rep(sy,H){
    rep(sx,W){
    rep(gy,H){
    rep(gx,W){
        if(S[sy][sx] == '#' || S[gy][gx] == '#') continue;
        vector<vector<ll>> dist(H,vector<ll>(W,-1));
        queue<pair<ll,ll>> que;
        ll dis=0;
        dist[sy][sx] = 0;
        que.push(make_pair(sy,sx));
        while(!que.empty()){
            //cout << "lp"<<endl;
            pair<ll,ll> v =que.front();
            que.pop();
            if(v.first == gy && v.second == gx){
                dis = dist[v.first][v.second];
                break;
            }
            rep(dir,4){
                
                ll ny = v.first + dy[dir] ;
                ll nx = v.second + dx[dir] ;
                
                if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
                if(S[ny][nx] == '#') continue;
                if(dist[ny][nx] != -1) continue;
                dist[ny][nx] = dist[v.first][v.second]+1;
                que.push(make_pair(ny,nx));

            }
        }
        chmax(ans,dis);
     
    }
    }
    }
    }
    
    cout << ans << endl;

    return 0;
    

}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

uint64_t N;
vector<int64_t> As;

uint64_t count(int initial_sig) {

  int sig = initial_sig;
  int64_t sum = 0;
  uint64_t ret = 0;

  for (const auto a : As) {
    sum += a;

    if (0 < sig && sum <= 0) {
      ret += -1 * sum + 1;
      sum = 1;
    } else if (sig < 0 && 0 <= sum) {
      ret += sum + 1;
      sum = -1;
    }

    sig = -1 * sig;
  }

  return ret;
}

int main() {

  cin >> N;

  As.reserve(N);
  for (uint64_t i = 0; i < N; ++i) {
    int64_t n;
    cin >> n;
    As.push_back(n);
  }

  uint64_t a = count(1);
  uint64_t b = count(-1);

  cout << min(a, b) << endl;

  return 0;
}


Measured memory_bytes: 1024