akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        if (a > x || a + b < x) System.out.println("NO");
        else System.out.println("YES");
    }

    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());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
from collections import Counter

N=int(input())
A=list(map(int,input().split()))

ai=[]
aj=[]

for i,a in enumerate(A):
    ai.append(i+1-a)
    aj.append(i+1+a)

ajc=Counter(aj)
ret=0
for x in ai:
    ret+=ajc.get(x,0)

print(ret)


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

int main(){
  int N,K;
  string S;
  cin >> N >> S >> K;
  char a;
  for(int i=0;i<N;i++){
    if(i==K-1){
      a=S.at(i);
    }
  }
  
  for(int i=0;i<N;i++){
    if(S.at(i)==a){
      cout << S.at(i);
    }
    else{
      cout << "*";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3636
n = input()

l = int(n[:2])
r = int(n[2:])

l = l > 0 and l <= 12
r = r > 0 and r <= 12
if l and r:
    print('AMBIGUOUS')
elif l and not r:
    print('MMYY')
elif (not l) and r:
    print('YYMM')
else:
    print('NA')

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

int main(){
    long long N;
    cin >> N;
    priority_queue<long long, vector<long long>, greater<long long>> Q;
    for(long long i = 1; i <= sqrt(N); ++i){
        if(N % i == 0) Q.push(i + N/i);
    }
    cout << Q.top() - 2 << endl;
    return 0;
}

Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
typedef pair<ll, ll>P;
string s[19191];
signed main() {
	ll n;
	cin >> n;
	rep(i, n)cin >> s[i];
	ll ans = 0;
	rep(i, n) {
		rep(j, s[i].size() - 1) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B')ans++;
		}
	}
	ll cnta = 0, cntb = 0, cntc = 0;
	rep(i, n) {
		if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A')cnta++;
		else if (s[i][0] == 'B')cntb++;
		else if (s[i][s[i].size() - 1] == 'A')cntc++;
	}
	ll p = min(cntb, cntc);
	if (cntb == 0 && cntc == 0)cout << max((ll)0, cnta - 1) + ans << endl;
	else if (cntb == 0 || cntc == 0)cout << cnta + ans << endl;
	else cout << cnta + p + ans << endl;
	ggr
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 3e18;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll a,b,c,d;

	cin>>a>>b>>c>>d;

	ll ans = -inf;

	ans=max(ans,a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);

	cout<<ans<<'\n';
	
	return 0;
}

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

import sys, os
def ac_input(*args):
    return map(int, input().split())

def main():
    count = 0
    N, K = ac_input()
    tall = input().split()
    for n in range(N):
        if (int(tall[n]) >= K):
            count = count + 1
    print(count)
        

if __name__ == "__main__" :
    main()



Measured memory_bytes: 9984
#include <cstdio>
#include <iostream>
#include <sstream>

#include <string>

using namespace std;

int main() {
    string s, s1, s2;
    cin >> s;
    s1.assign(s, 0, 4);
    s2.assign(s, 4, 8);

    cout << s1 << ' ' << s2 << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 5;
int a[maxn], b[maxn];
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a + 1, a + 1 + n);
	int num = 0;
	for (int i = 1; i <= n; i++){
		if (a[i] != b[i]) num++;
	}
	if (num == 0 || num == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(43);

char c[4];

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("rps2.in", "r", stdin);
	//freopen("rps2.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> c[0] >> c[1] >> c[2] >> c[3];
	bool ch = (c[0] == c[1]) || (c[1] == c[2]) || (c[2] == c[3]);
	if (ch)
		cout << "Bad";
	else
		cout << "Good";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,a,x,y;
    cin>>n;
    if(n%1000!=0)
        cout<<1000-n%1000;
    else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        System.out.println( solve(N, A) );
    }

    private static String solve(int N, int[] A) {
        StringBuilder b = new StringBuilder();
        if( N % 2 == 0 ) {
            // 4(3) 2(1) 1(0) 3(2)
            for (int i = N-1; i >= 1; i = i-2) {
                if( i != N-1 ) b.append(" ");
                b.append( A[i] );
            }
            for (int i = 0; i < N-1; i = i+2) {
                b.append(" ");
                b.append(A[i]);
            }

        } else {
            // 3(2) 1(0) 2(1)
            for (int i = N-1; i >= 0; i = i-2) {
                if( i != N-1 ) b.append(" ");
                b.append(A[i]);
            }
            for (int i = 1; i < N-1; i = i+2) {
                b.append(" ");
                b.append(A[i]);
            }
        }
        return b.toString();
    }
}


Measured memory_bytes: 73884
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

class UnionFind {
private:
  vector<ll> data;

public:
  UnionFind(ll n): data(n, -1) {}

  ll size(ll i) { return -data[find(i)]; }
  bool root(ll i) { return data[i] < 0; }
  bool same(ll i, ll j) { return find(i) == find(j); }

  ll find(ll i) { return root(i) ? i : (data[i] = find(data[i])); }

  bool unite(ll i, ll j) {
    if(same(i, j)) return false;
    data[find(i)] += data[find(j)];
    data[find(j)] = find(i);
    return true;
  }
};

struct edge {
  ll u, v, d, idx;
  bool active, used;
  bool operator<(const edge &e) const { return d < e.d; }
};

ll mst(ll n, vector<edge> &edges) {
  UnionFind uf(n);
  ll ret = 0;
  sort(edges.begin(), edges.end());
  for(edge &e : edges) if(e.active && uf.unite(e.u, e.v)) {
    ret += e.d;
    e.used = true;
  }
  set<ll> st;
  REP(i, 0, n) st.insert(uf.find(i));
  return st.size() == 1 ? ret : (1LL << 60);
}

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<edge> edges(M);
  REP(i, 0, M) {
    cin >> edges[i].u >> edges[i].v >> edges[i].d;
    edges[i].u--;
    edges[i].v--;
    edges[i].idx = i;
    edges[i].active = true;
    edges[i].used = false;
  }

  ll cost = mst(N, edges);
  vector<ll> candidate;
  for(edge &e : edges) if(e.used) candidate.push_back(e.idx);

  vector<bool> need(M, true);
  for(edge &e : edges) if(!e.used) need[e.idx] = false;

  for(ll k : candidate) {
    for(edge &e : edges) e.active = e.idx != k;
    ll c = mst(N, edges);
    if(c == cost) need[k] = false;
  }

  ll ans = 0, ansc = 0;
  for(edge &e : edges) if(need[e.idx]) {
    ans++;
    ansc += e.d;
  }
  cout << ans << " " << ansc << endl;
}


Measured memory_bytes: 4688
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  bool f = false;
  rep(i,n){
    if(a[i]&1){
      f = true;
      break;
    }
  }
  cout << (f?"first":"second") << "\n";
  
  return 0;
}


Measured memory_bytes: 640
N = int(input())
a_list = list(map(int,input().split()))
I = N//2
import copy
b_list = copy.deepcopy(a_list)
for i in range(I-1,-1,-1):
#    print2(b_list,i)
    split = N//(i+1)
    wa = 0
    for s in range(split):
        wa += b_list[i+s*(i+1)]
    if wa % 2 != a_list[i]:
        b_list[i] = 1- a_list[i]
#print(b_list)
SUM = sum(b_list)
print(SUM)
if SUM != 0:
    
    for i in range(N):
        if b_list[i] == 1:
            print(i+1, end=" ")
        


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



// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    ll H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--; Cw--; Dh--; Dw--;

    vector<string> S(H);
    rep(i,H) cin >> S[i];

    ll inf = 1e9;
    ll dh[] = {-1, 1, 0, 0};
    ll dw[] = {0, 0, -1, 1};

    vector<vector<ll>> cost(H, vector<ll>(W, inf));
    cost[Ch][Cw] = 0;

    deque<pair<ll, ll>> d;
    d.push_back({Ch, Cw});

    pair<ll, ll> now;
    ll now_h, now_w, next_h, next_w;

    while(!d.empty()){
        now = d.front();
        now_h = now.first; now_w = now.second;
        d.pop_front();

        rep(i,4){
            next_h = now_h+dh[i];
            next_w = now_w+dw[i];

            if(next_h<0||next_h>=H||next_w<0
            ||next_w>=W||S[next_h][next_w]=='#'
            ||cost[next_h][next_w]<=cost[now_h][now_w]) {
                continue;
            }
            cost[next_h][next_w] = cost[now_h][now_w];
            d.push_front({next_h, next_w});
        }

        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                next_h = now_h+i;
                next_w = now_w+j;

                if(next_h<0||next_h>=H||next_w<0
                ||next_w>=W||S[next_h][next_w]=='#'
                ||cost[next_h][next_w]<=cost[now_h][now_w]+1) {
                    continue;
                }
                cost[next_h][next_w] = cost[now_h][now_w]+1;
                d.push_back({next_h, next_w});
            }
        }
    }

    // rep(i,H){
    //     rep(j,W) cout << cost[i][j] << '\t';
    //     cout << endl;
    // }

    if(cost[Dh][Dw]==inf) cost[Dh][Dw] = -1;
    cout << cost[Dh][Dw] << endl;

    return 0;
}

Measured memory_bytes: 13544
#include <iostream>
#include <cmath>
#include <string>
#include <cassert>
using namespace std;
 
const int MAX = 4;
const int NN = 16;
const int GEN = 100;
const int xdo[4] = {0, -1, 0, 1};
const int ydo[4] = {1, 0, -1, 0};
const char hira[4] = {'r', 'u', 'l', 'd'};
int RYOMA[NN][NN];
 
struct Mond {int f[NN], sawa, Atom;};
 
Mond kaku;
int mits;
int tee[GEN];
 
int getsum(Mond pz){
    int sum = 0;
    for (int i = 0; i < NN; i++){
        if (pz.f[i] == NN) continue;
        sum += RYOMA[i][pz.f[i] - 1];
    }
    return sum;
}

bool defa(int fat, int af6){
    if (kaku.Atom == 0) return true;
    if (fat + kaku.Atom > mits) return false;
 
    int sx = kaku.sawa / MAX;
    int sy = kaku.sawa % MAX;
    Mond tmp;
 
    for (int r = 0; r < 4; r++){
        int tx = sx + xdo[r];
        int ty = sy + ydo[r];
        if (tx < 0 || ty < 0 || tx >= MAX || ty >= MAX) continue;
        if (max(af6, r) - min(af6, r) == 2) continue;
        tmp = kaku;
 
        kaku.Atom -= RYOMA[tx * MAX + ty][kaku.f[tx * MAX + ty] - 1];
        kaku.Atom += RYOMA[sx * MAX + sy][kaku.f[tx * MAX + ty] - 1];
        swap(kaku.f[tx * MAX + ty], kaku.f[sx * MAX + sy]);
        kaku.sawa = tx * MAX + ty;
        if (defa(fat + 1, r)){
            tee[fat] = r;
            return true;
        }
        kaku = tmp;
    }
    return false;
}
 
string chekit(Mond in){
    in.Atom = getsum(in);
 
    for (mits = in.Atom; mits <= GEN; mits++){
        kaku = in;
        if (defa(0, -100)){
            string ans = "";
            for (int i = 0; i < mits; i++) ans += hira[tee[i]];
            return ans;
        }
    }
    return "unsolvable";
}
 
int main(){
    for (int i = 0; i < NN; i++){
        for (int j = 0; j < NN; j++){
            RYOMA[i][j] = abs(i / MAX - j / MAX) + abs(i % MAX - j % MAX);
            Mond in;
        }
    }
    Mond in;
    for (int i = 0; i < NN; i++){
        cin >> in.f[i];
        if (in.f[i] == 0){
            in.f[i] = NN;
            in.sawa = i;
        }
    }
    string ans = chekit(in);
    cout << ans.size() << endl;
 
    return 0;
}

Measured memory_bytes: 1208
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    if b > a:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if c > b:
        print('Yes')
        continue
    g = gcd(b, d)
    max_mod_b = b - g + a % g
    if max_mod_b > c:
        print('No')
    else:
        print("Yes")





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

int main() {
  double a, b, c;
  int x;
  cin >> a >> b;
  c = (a + b) / 2;
  x = c;
  if(x == c){
    cout << x;
  }else{
      cout << x + 1;
  }
}
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    string str;
    cin >> a >> str ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a < 3200 ){
        cout << "red" << endl;
    } else {
        cout << str << endl;
    }
    //*/
    
    //cout << vec.at(0) + vec.at(1) << endl;

    return 0; 
}


Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <climits>
 
using namespace std;
 
#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)
 
#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))
 
#define dump(x) cerr << #x << ": " << (x) << endl;
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
 
const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main(void) {
	int a,b,c; cin >> a >> b >> c;

	printf("%d %d %d\n", c, a, b);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    vector<ll>a(1LL<<n);
    rep(i,1LL<<n){
        cin>>a[i];
    }
    vector<pll>dp(1LL<<n);
    rep(i,1LL<<n){
        dp[i]=mp(a[i],-1);
    }
    rep(j,n){
        rep(i,1LL<<n){
            if(i&(1LL<<j)){
                pll a=dp[i];
                pll b=dp[i-(1LL<<j)];
                if(a.first<b.first){
                    a.second=max(a.first,b.second);
                    a.first=b.first;
                }else{
                    a.second=max(a.second,b.first);
                }
                dp[i]=a;
            }
        }
    }
    ll ans=0;
    REP(i,1,1LL<<n){
        ans=max(ans,dp[i].first+dp[i].second);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 9420
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  double n;
  cin >> n;
  double border = n/1.08 - floor(n/1.08);
  if (border > 0 && border <= 1 - 1/1.08) {
    cout << ":(" << endl;
  } else {
    cout << ceil(n/1.08) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}
int v[200001];
int main()
{
    int n;
    cin >> n;
    int x = 0;
    FOR(i, n)
    {
        cin >> v[i];
        x ^= v[i];
    }
    FOR(i, n)
    {
        cout << (v[i] ^ x) << " ";
    }
}

Measured memory_bytes: 4320
MOD = 1_000_000_007

lines = readlines.map(&:chop)

N, M = lines.shift.split.map(&:to_i)
brokens = lines.map(&:to_i)
brokens << -1

dp = [0] * (N + 2)
dp[1] = 1

2.upto(N + 1) do |i|
  if i == brokens[0] + 1
    brokens.shift
    next
  end
  dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
end

puts dp[-1]


Measured memory_bytes: 14460
s = gets.chomp
a = "#{s[0]}#{s[1]}".to_i
b = "#{s[2]}#{s[3]}".to_i

yy = false
mm = false

if 0 < a and a < 13
  yy = true
end
if 0 < b and b < 13
  mm = true
end

if yy and mm
  puts "AMBIGUOUS"
elsif yy
  puts "MMYY"
elsif mm
  puts "YYMM"
else
  puts "NA"
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	ll N, K;
	cin >> N >> K;

	vector<ll> p(N);
	rep(i, N) {
		cin >> p[i];
	}

	vector<ll> s(N);
	s[0] = p[0];
	repk(i,1, N) {
		s[i] = s[i - 1] + p[i];
	}

	ll summax = s[K - 1];
	ll sum;
	repk(i,1, N-K+1) {
		sum = s[i + K - 1] - s[i - 1];
		if (summax < sum) {
			summax = sum;
		}
	}

	double ans = (summax + K) / (double)2;
	printf("%.11lf\n", ans);

	return 0;
}


Measured memory_bytes: 3456
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 100005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

void setIO(string a){
#ifndef LOCAL
	freopen((a + ".in").c_str(), "r", stdin);
	freopen((a + ".out").c_str(), "w", stdout);
#else
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
#endif
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int fa[N * 5], sz[N * 5];
int n, a[N], b[N], pos[N], tot, X, seq;
map<int, int> A, B, C;

int get(int x){
	if(fa[x] == x) return fa[x];
	return fa[x] = get(fa[x]);
}

int Cnt(int x){
	if(B.find(x) == B.end()) return 0;
	return B[x];
}

int main(){

	scanf("%d", &n);
	REP(i, 1, n){
		scanf("%d", a + i);
		X ^= a[i];
		A[a[i]] ++;
		if(!C[a[i]]) C[a[i]] = ++seq;
	}
	REP(i, 1, n){
		scanf("%d", b + i);
		B[b[i]] ++;
		if(!C[b[i]]) C[b[i]] = ++seq;
	}

	if(!C[X]) C[X] = ++seq;

	int flag = 1;
	REP(i, 1, n) if(a[i] != b[i]) flag = 0;
	if(flag){
		cout << 0 << endl;
		return 0;
	}

	A[X] ++;
	int ok = -1;
	for(auto x : A) if(Cnt(x.fi) + 1 == x.se){
		ok = x.fi;
		break;
	}

	if(ok == -1){
		cout << -1 << endl;
		return 0;
	}


	int oke = 1;
	for(auto x : A) if(x.fi != ok && Cnt(x.fi) != x.se){
		oke = -1;
		break;
	}

	if(oke == -1){
		cout << -1 << endl;
		return 0;
	}

	REP(i, 1, seq) fa[i] = i;
	REP(i, 1, n) if(a[i] != b[i]){
		int u = C[a[i]], v = C[b[i]];
		fa[get(u)] = get(v);
		++ tot;
	}

	REP(i, 1, seq) sz[get(i)] ++;

	REP(i, 1, seq) if(get(i) == i && sz[i] != 1) tot ++;
	tot --;
	if(A[X] == 1 && ok == X) tot ++;


	printf("%d\n", tot);


#ifdef LOCAL
	cerr << endl << endl << "Time Spec = " << clock() / 1000. << "ms" << endl;
#endif
	return 0;
}






















Measured memory_bytes: 18688
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
int main() {
    int n;
    long long X=0,x=0,ans=1000000000000000000LL;
    cin>>n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
    cin>>a[i];
    X+=a[i];
    }
    for(int i=0;i<n;i++){
    x+=a[i];
    if(i+1<n)ans=min(ans,abs(X-2*x));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t,i,j,remainder,sum,num;
    remainder = 7;
    sum = 0;
    cin >> t;
    if(t%2==0||t%10==5) cout << -1;
    else{
        for(i=1;i<=t+1;i++){
            remainder = (remainder % t);
            if(remainder == 0){
                cout << i;
                return 0;
            }
            remainder = remainder * 10 + 7;
        }
        cout << "out of bound";
    }
    
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    int minH = 1000;
    for(int i = 0; i < n; i++){
        std::cin >> h[i];
        minH = std::min(minH, h[i]);
    }

    int cost = minH;
    for(int i = 0; i < n; i++) h[i] -= minH;
    // 区間が最大になるようにとる
    while(1){
        int left = 0, right = 0;
        int maxLeft = 0, maxRight = 0;
        for(int i = 0; i < n; i++){
            if(h[i] == 0){
                right = i;
                int tmpInterVal = right - left;
                int maxInterVal = maxRight - maxLeft;
                if(tmpInterVal > maxInterVal){
                    maxLeft = left, maxRight = right;
                }
                left = right + 1;
            }
        }
        // 最後用
        right = n;
        int tmpInterVal = right - left;
        int maxInterVal = maxRight - maxLeft;
        if(tmpInterVal > maxInterVal){
            maxLeft = left, maxRight = right;
        }

        // その区間の高さ最小
        int minH = 1000;
        for(int i = maxLeft; i < maxRight; i++){
            minH = std::min(minH, h[i]);
        }

        
        if(minH == 1000){
            break;
        }else{
            cost += minH;
            for(int i = maxLeft; i < maxRight; i++) h[i] -= minH;
        }
    }

    std::cout << cost << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if (0 <= x-r && x+r <= W&&0 <= y-r && y+r <= H) cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3100
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if not arr:
        arr.append([n, 1])
    return arr


N = int(input())

l = [2]
for i in range(1, 9):
    l.append(l[i-1] + 2 + i)

l_N = factorization(N)
ans = []
for j in l_N:
    for k in range(len(l)):
        if j[0] == 1:
            continue
        if j[1] <= l[k]:
            ans.append(len(l[:k+1]))
            break
print(sum(ans))


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, k;
    cin >> n >> k;
    ll sum = 0, mn = 0, mx = 0;
    REP(i, 0, k) {
        mn += i;
        mx += n-i;
    }
    ll l = k, r = n-k;
    REP(i, k, n+2) {
        sum = (sum + (mx - mn + 1)) % M;
        mn += l;
        mx += r;
        l++;
        r--;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _175B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine() ?? string.Empty);
            var L = Console.ReadLine()?.Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            Array.Sort(L ?? Array.Empty<long>());

            var answer = 0;

            for (int i = 0; i < L.Length; i++)
            {
                for (int j = i+1; j < L.Length ; j++)
                {
                    for (int k = j + 1; k < L.Length; k++)
                    {
                        if (L[i] + L[j] > L[k] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k])
                        {
                           // Console.WriteLine("{0},{1},{2}", L[i], L[j], L[k]);
                            answer += 1;
                        }
                    }
                }
            }

            Console.WriteLine(answer);


        }
    }
}


Measured memory_bytes: 28248
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define INF (int)1e5+5
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N (int)1e6+2
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// look for  all edge cases
//search for a pattern

const int max_n = 1e7+2;
vector<int> prime(max_n, 1);

	
signed main(){
	fast;
	
	for(int i= 2 ; i < max_n ; i++){
		for(int j = i ; j< max_n ; j += i){
			prime[j] += 1; 
		}
	}
	
	
	//debug(prime[1],prime[2])
	
	int n;
	cin >> n;
	
	int ans  =0;
	
	for(int i =1 ; i <=n ; i++){
		ans += i*prime[i];
	}
	
	cout<<ans;
	

	return 0;
}

	



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

int main(){
  int n;
  cin>>n;
  int h[n][3];
  for(int i=0;i<n;i++)
     cin>>h[i][0]>>h[i][1]>>h[i][2];
     
  int dp[n][3];
  
  for(int i=0;i<n;i++){
     for(int j=0;j<3;j++){
        dp[i][j]=0;
     }
  }
    
  for(int i=0;i<n;i++){
   
     if(i-1>=0){
       dp[i][0]=max(max(dp[i][0],dp[i-1][1]),dp[i-1][2])+h[i][0];
       dp[i][1]=max(max(dp[i][1],dp[i-1][0]),dp[i-1][2])+h[i][1];
       dp[i][2]=max(max(dp[i][2],dp[i-1][0]),dp[i-1][1])+h[i][2];
     }
    else{
      dp[i][0]=h[i][0];
      dp[i][1]=h[i][1];
      dp[i][2]=h[i][2];
    }
  }
  printf("%d\n",max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
  return 0;
}
             
                          

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxc = 1e6 + 10;
const int mod = 998244353;

int num[maxc];
int cal[maxc];

vector<int> p;
int low[maxc], f[maxc];
int pw(int a, int n) {
	int res = 1;
	while(n) {
		if(n & 1) res = 1LL * res * a % mod;
		a = 1LL * a * a % mod, n >>= 1;
	}
	return res;
}
int INV(int a) {return pw(a, mod - 2);}
void pre() {
	f[1] = 1;
	for(int i = 2; i < maxc; i++) {
		if(!f[i]) {
			p.push_back(i);
			low[i] = i;
			int _p = INV(i);
			f[i] =  1LL * (mod - i + 1) * _p % mod;//-(p - 1) / p
		}
		for(int j = 0; j < int(p.size()) && 1LL * i * p[j] < maxc; j++) {
			if(i % p[j] == 0) {
				low[i * p[j]] = low[i] * p[j];
				if(low[i] == i) {
					f[i * p[j]] = 1LL * (mod - p[j] + 1) * INV(i * p[j]) % mod; // -(p - 1) / p^k
				}
				else {
					f[i * p[j]] = 1LL * f[i / low[i]] * f[p[j] * low[i]] % mod;
				}
				break;
			}
			f[i * p[j]] = 1LL * f[i] * f[p[j]] % mod;
			low[i * p[j]] = p[j];
		}
	}
//	for(int i = 1; i <= 30; i++) 
//		printf("f[%d] = %d\n", i, f[i]);
}
void add(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
void sub(int& a, int b) {
	a -= b;
	if(a < 0) a += mod;
}
int main() {
	pre();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		num[x]++;
	}
	for(int i = 1; i < maxc; i++) {
		int a = 0, b = 0;
		for(int j =	i; j < maxc; j += i) {
			add(a, 1LL * j * num[j] % mod);
			add(b, 1LL * j * j % mod * num[j] % mod);
		}
		a = 1LL * a * a % mod;
		sub(a, b);
		cal[i] = a;
	}
	int ans = 0;
	for(int i = 1; i < maxc; i++) {
		add(ans, 1LL * cal[i] * f[i] % mod);
	}
	ans = 1LL * ans * INV(2) % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 16248
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> c(n -1), s(n - 1), f(n - 1);
    rep(i, n -1){
        cin >> c[i] >> s[i] >> f[i];
    }
    for(int stop = 0; stop < n; ++stop){
        ll t = 0;
        for(int i = stop; i < n - 1; ++i){
            if(t <= s[i]){
                t = s[i];
            }else{
                t = ((t - s[i] - 1) / f[i] + 1) * f[i] + s[i];
            }
            t += c[i];
        }
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    n = int(input().strip())
    S = input().strip()
    eprint(S[0:n//2])
    if n%2!=0:
        print("No")
    else:
        if S[0:n//2]*2==S:
            print("Yes")
        else:
            print("No")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 65388
n=int(input())
a=list(map(int,input().split()))
q=int(input())
l=[0]*10**6
s=sum(a)
for i in range(n):
    l[a[i]]+=1
for i in range(q):
    b,c=map(int,input().split())
    s+=(c-b)*l[b]
    l[c]+=l[b]
    l[b]=0
    print(s)


Measured memory_bytes: 23868
import numpy as np

n, m, x = map(int, input().split())
a = [None] * n
cost = 0
ans = float("inf")
for i in range(n):
    a[i] = list(map(int, input().split()))
for bit in range(1, 1 << n):
    ptn = []
    psum = [0]
    for i in range(n):
        if bit & 1 << i:
            ptn.append(a[i])
            psum = np.sum(ptn, axis=0)
    cost = psum[0]
    if np.min(psum[1:]) >= x:
        ans = min(ans, cost)
print(-1) if ans == float("inf") else print(ans)


Measured memory_bytes: 27116
N,Y=map(int,input().split())

for x in range(Y//10000+3):
  for y in range(Y//5000+3):
    z = N-x-y
    if z < 0:break
    SUM = 10000*x + 5000*y + 1000*z
    if SUM == Y:
      print(x,y,z)
      exit()
    elif SUM > Y:break
print(-1,-1,-1)

Measured memory_bytes: 9136
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

const int NUMBER = 100000;

int partition(int a[],int b[],int p,int r)
{
    int i = p-1;
    int x = a[r];
    for (int j = p;j < r;j++){
        if (x >= a[j]){
            swap(a[i+1],a[j]);
            swap(b[i+1],b[j]);
            i++;
        }
    }
    swap(a[r],a[i+1]);
    swap(b[r],b[i+1]);
    return i+1;
}

void quicksort(int a[],int b[],int p,int r)
{
    if (p < r){
        int q = partition(a,b,p,r);
        quicksort(a,b,p,q-1);
        quicksort(a,b,q+1,r);
    }
}


int main()
{
    int n;
    int x[NUMBER];
    int l[NUMBER];
    int tail[NUMBER];
    int head[NUMBER];
    
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> x[i] >> l[i];
        tail[i] = x[i]+l[i];
        head[i] = x[i]-l[i];
    }
    
    quicksort(tail,head,0,n-1);
    
    int c = 1;
    int last = tail[0];
    for (int i = 1;i < n;i++){
        if (last <= head[i]){
            c++;
            last = tail[i];
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector<int> active(n), ans(n, 1);
	int last = -c-1;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'o'){
			if(last + c < i){
				last = i;
				active[i] = 1;
				cnt++;
			} else {
				ans[i] = 0;
			}
		} else {
			ans[i] = 0;
		}
	}
	if(cnt < k){
		return 0;
	}
	vector<int> suffix(n + c + 1, 0);
	for(int i = n - 1; i >= 0; i--){
		suffix[i] = suffix[i + 1];
		if(s[i] == 'o'){
			suffix[i] = max(suffix[i], suffix[i + c + 1] + 1);
		}
	}
	int p = 0;
	for(int i = 0; i < n; i++){
		if(active[i]){
			if(p + suffix[i + 1] >= k){
				ans[i] = 0;
			}
			p += 1;
		}
	}
	for(int i = 0; i < n; i++)
		if(ans[i])
			cout << i + 1 << endl;
	return 0;
}


Measured memory_bytes: 4244
#include<iostream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int Cint;
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<Cint> x;
	while(cin){
		Cint a;
		cin>>a;
		x.push_back(a);
	}
		Cint sum=0;
		Cint ans1=0;
	for(int i=0;i<n;i++){
			sum+=x[i];

			if(i%2==0){
				if(sum<=0){
					ans1+=1-sum;
					sum=1;
				}
			}else{
				if(sum>=0){
					ans1+=1+sum;
					sum=-1;
				}			
			}
		}
	sum=0;
	Cint ans2=0;
	for(int i=0;i<n;i++){
			sum+=x[i];
			if(i%2==1){
				if(sum<=0){
					ans2+=1-sum;
					sum=1;
				}
			}else{
				if(sum>=0){
					ans2+=1+sum;
					sum=-1;
				}			
			}
		}
	
	if(ans1<ans2){
		cout<<ans1<<endl;
	}else{
		cout<<ans2<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 6384
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>

//void Aoj_learning1();
//void Aoj_learning2();
//void Aoj_learning3();
//void Aoj_learning4();
void Aoj_learning5();

int main()
{
	Aoj_learning5();
}

void Aoj_learning5()
{
	std::string sInput;
	int intInputNum = 0;
	std::istringstream ss;	// 汎用文字列ストリーム

	// 入力個数の取得
	std::cin >> sInput;
	ss = std::istringstream(sInput);
	ss >> intInputNum;
	if (intInputNum > 100 || 1 > intInputNum)
	{
		exit(0);
	}

	// 数列を取得
	std::string sInputNum[100];
	for (int count = 0; count < intInputNum; count++)
	{
		std::cin >> sInputNum[count];
	}

	// バブルソート
	int flag = 1;			
	int number1, number2;	// 比較元,比較対象
	int changeCount = 0;	// 交換回数
	for(int i = 0; i < intInputNum; i++)
	{
		for (int count = intInputNum-1; count > 0; count--)
		{
			ss = std::istringstream(sInputNum[count]);
			ss >> number1;
			ss = std::istringstream(sInputNum[count-1]);
			ss >> number2;
			if (number1 < number2)
			{
				sInputNum[count - 1] = std::to_string(number1);
				sInputNum[count] = std::to_string(number2);
				changeCount++;
			}
		}
	}

	// 整列した数列を表示
	for (int k = 0; k < intInputNum; k++)
	{
		std::cout << sInputNum[k];
		if (k == intInputNum - 1)
		{
			std::cout << std::endl;
		}
		else
		{
			std::cout << " ";
		}
	}
	// 交換回数を表示
	std::cout << changeCount << std::endl;
}


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

using namespace std;

#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)
#define ll long long int

void solve()
{
    char a;
    cin>>a;
    cout<<(char)((int)a+1);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

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

Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <vector>

int main()
{
    using namespace std;
    vector<string> list;
    string s;
    while(getline(cin, s)){
        list.push_back(s);
    }
    for(int i = 0; i < 26; ++i){
        char c = 'a' + i;
        char C = 'A' + i;
        int sum = 0;
        for(int j = 0; j < list.size(); ++j){
            const string& s = list[j];
            for(int k = 0; k < s.size(); ++k){
                if(s[k] == c || s[k] == C) sum++;
            }
        }
        cout << c << " : " << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
A,B,C,D = list(input())

def dfs(depth=0,op=""):
    if depth == 3:
        res = A + op[0] + B + op[1] + C + op[2] + D
        if eval(res) == 7:
            ans = res + "=7"
            print(ans)
            exit()
        return
    dfs(depth+1,op+"+")
    dfs(depth+1,op+"-")

dfs()

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

using namespace std;

int main() {
  int h, w;

  string s;
  cin >> h >> w;
  getline(cin, s);

  for(int i = 0; i < h; i++){
    string s;
    getline(cin, s);
    cout << s << endl << s << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll k;
  cin >> k;
  ll s1 = k / 2;
  ll s2 = k / 2 + k % 2;
  cout << s1 * s2 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

vector<pair<long long, long long>> prime_factorize(long long N)
{
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    ll cnt = 1;
    const auto &res = prime_factorize(p);
    for (auto itr : res)
    {
        for (int i = 0; i < itr.second / n; ++i) 
            cnt *= itr.first;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	int ac=0,tle=0,wa=0,re=0;
	while(t--){
		string s;
		cin>>s;
		if(s=="AC") ++ac;
		else if(s=="TLE") ++tle;
		else if(s=="WA") ++wa;
		else if(s=="RE") ++re;
	}
	cout<<"AC x "<<ac<<'\n';
	cout<<"WA x "<<wa<<'\n';
	cout<<"TLE x "<<tle<<'\n';
	cout<<"RE x "<<re<<'\n';
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <strings.h>
using namespace std;

int main()
{
    int N,M,D;
    int *A;

    cin >> N >> M;
    A=new int[M];
    D=0;
    int i;
    


    for(i=0;i<M;i++){
        cin >> A[i];
        D=D+A[i];
    }
    D=N-D;
    if(D<0){
        cout << -1;
    }else{
        cout << D;
    }
    return 0;
}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(x,b) (0<=(x)&&(x)<(b))
#define F first
#define S second
#define INF 1 << 30

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

vi p(8);
int dx[] = {0,-1,0,1}, dy[] = {-1,0,1,0};

vi goal(8);
map<vi, int>m;

void bfs(){
  int res = 0;
  rep(i, 8) goal[i] = i;
  queue<vi>q;
  q.push(goal);
  m[goal] = res;
  while(!q.empty()){
    int qsize = (int)q.size();
    rep(i, qsize){
      vi now  = q.front(); q.pop();
      rep(j, 8){
	if(now[j] != 0) continue;
	int ny = j/4, nx = j%4;
	rep(d, 4){
	  int nexty = ny + dy[d], nextx = nx + dx[d];
	  if(nexty < 0 || nexty >= 2 || nextx < 0 || nextx >= 4) continue;
	  vi next = now;
	  int t = next[nexty*4+nextx];
	  next[nexty*4+nextx] = next[j];
	  next[j] = t;

	  if(m.count(next) == 0){
	    q.push(next);
	    m[next] = res+1;
	  }
	}
      }
    }
    res++;
  }
  return;
}


int main(){
  bfs();
  while(~scanf("%d", &p[0])){
    REP(i, 1, 8) scanf("%d", &p[i]);
    
    printf("%d\n", m[p]);
  }
  return 0;
}

Measured memory_bytes: 3752