akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  out((n + 999) / 1000 * 1000 - n);
}


Measured memory_bytes: 3632
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let s = line.trim().chars();
    let line = gets();
    let t = line.trim().chars();
    let iter = s.zip(t);
    let mut ans = 0;
    for x in iter {
        let (a, b) = x;
        if a != b {
            ans += 1
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 2e5 + 7;

int c[N];
int ans[N];
vector<int> g[N];

void dfs(int cur, int p, int pp) {
	pp += c[cur];
	ans[cur] = pp;
	for (auto t : g[cur]) {
		if (t != p) dfs(t, cur, pp);
	}
}

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

	int n, q;
	cin >> n >> q;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	while (q--) {
		int v, x;
		cin >> v >> x;
		v--;
		c[v] += x;
	}
	dfs(0, -1, 0);
	for (int i = 0; i < n; i++) {
		cout << ans[i] << ' ';
	}
	cout << endl;
} 


Measured memory_bytes: 24192
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
#include <queue>

using namespace std;

#define int long long

int func(string s) {
    int cnt = 0;
    bool flag = true;
    for(int i = 1; i < s.size(); i++) {
        if(s[i - 1] == s[i] && flag) {
            cnt++;
            flag = false;
        } else {
            flag = true;
        }
    }
    return cnt;
}

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

    string t = s;
    t.erase(unique(t.begin(), t.end()), t.end());
    if(t.size() == 1) {
        cout << s.size() * k / 2 << endl;
        return 0;
    }

    int cnt1 = func(s);
    int cnt2 = func(s + s) - cnt1;
    int ans = cnt1 + cnt2 * (k - 1);

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,c[105];
vector<pair<string,int>>f;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        string s;int p;
        cin>>s>>p;
        c[p]=i+1;
        f.push_back({s,p});
    }
    sort(f.begin(),f.end());
    int cnt=1;
    for(int i=0;i<n;i++){
        if(i!=n-1){
            if(f[i].first==f[i+1].first){
                cnt++;
            }
            else{
                for(int j=i;cnt>0;j--,cnt--){
                     cout<<c[f[j].second]<<endl;
                }
                cnt=1;
            }
        }
        else{
                for(int j=i;cnt>0;j--,cnt--){
                     cout<<c[f[j].second]<<endl;
                }
                cnt=1;
        }
        
    }
}

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

int getCost(int w){
    int cost = 0;
    for (int i = 0; i <= w; i++ ){
	if ( 10 < i && i <= 20 ) cost += 125;
	else if ( 20 < i && i <= 30 ) cost += 140;
	else if ( 30 < i ) cost += 160;
    }
    return 1150 + cost;
}

main(){
    int w;
    while(1){
	cin >> w;
	if ( w == -1 ) break;
	assert( 0 <= w && w <= 100);
	cout << 4280 - getCost(w) << endl;
    }
}

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

int main(){
    int h,w;
    cin>>h>>w;
    string str = string(2+w,'#');
    vector<vector<char>> a(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    cout<<str<<endl;
    rep(i, h){
        cout<<"#";
        rep(j,w){
            cout<<a[i][j];
        }
        cout<<"#"<<endl;
    }
    cout<<str<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = map(int, list(IS()))
    if sum(n) % 9 == 0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10504
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = 0, max_index = 0;
long long min_value = MAX, min_index = 0;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

vector<ll> prime_factorization(ll num){
    vector<ll> vec;
    ll a = 2;
    while(num >= a*a){
        if(num%a==0){
            vec.push_back(a);
            num /= a;
        }else{
            a++;
        }
    }
    vec.push_back(num);
    return vec;
}

long long calc(ll a, ll b, ll p){
    if(b == 0) return 1;
    if(b % 2 == 0){
        long long d = calc(a, b/2, p)%p;
        return (d*d)%p;
    }else{
        return (a*calc(a, b-1, p))%p;
    }
}

long long comb(ll n, ll r) {
  ll sum = 1;
  for(ll i=n;i>n-r;i--) sum = (sum*i)%MOD;
  for(ll i=r;i>0;i--) sum = (sum*calc(i, MOD-2, MOD))%MOD;
  sum %= MOD;
  return sum;
}

int main() {
    cin >> N >> M;
    vector<ll> vec = prime_factorization(M);
    ll count = 1, curr = vec[0];
    ll sum = 1;
    rep(i, vec.size()-1){
        if(curr == vec[i+1]) count++;
        else{
            ll temp = comb(count+N-1, count);
            sum = (sum*temp)%MOD;
            curr = vec[i+1];
            count = 1;
        }
    }
    ll temp = comb(count+N-1, count);
    sum = (sum*temp)%MOD;
    sum %= MOD;
    if(M == 1) sum = 1;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    string s; cin >> s;
    ll n = s.size();
    vl alpha(3,0);
    rep(i,n){
        alpha[s[i]-'a']++;
    }
    ll a = alpha[0];
    ll b = alpha[1];
    ll c = alpha[2];
    if(abs(a-c)>1 || abs(b-c)>1 || abs(a-b)>1){
        puts("NO");
        return 0;
    }
    puts("YES");
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m,q;
  cin>>n>>m>>q;
  vector<vector<Int> > G(n);
  auto T=G;
  vector<Int> u(m),v(m);
  vector<map<Int, Int> > R(n);
  for(Int i=0;i<m;i++){
    cin>>u[i]>>v[i];
    u[i]--;v[i]--;
    G[u[i]].emplace_back(v[i]);
    G[v[i]].emplace_back(u[i]);
    R[u[i]][v[i]]=i;
    R[v[i]][u[i]]=i;
  }
  vector<Int> dp(n,-1);
  {
    dp[0]=0;
    queue<Int> qu({0});
    while(!qu.empty()){
      Int v=qu.front();qu.pop();
      for(Int u:G[v]){
	if(~dp[u]) continue;
	dp[u]=dp[v]+1;
	qu.emplace(u);
      }
    }
  }
  vector<Int> b(q),c(m,q);
  for(Int i=0;i<q;i++){
    cin>>b[i];
    b[i]--;
    c[b[i]]=i;
  }
  vector<Int> dp2(n,-1);
  {
    using P = pair<Int, Int>;
    priority_queue<P> qu;
    dp2[0]=q;
    qu.emplace(q,0);
    while(!qu.empty()){
      P p=qu.top();qu.pop();
      Int d=p.first,x=p.second;
      //cout<<x<<":"<<d<<endl;
      if(dp2[x]>d) continue;
      for(Int y:G[x]){
	if(dp[x]+1!=dp[y]) continue;
	if(min(d,c[R[x][y]])<=dp2[y]) continue;
	dp2[y]=min(d,c[R[x][y]]);
	qu.emplace(dp2[y],y);
      } 
    }
  }
  
  vector<Int> a(q+1,0);
  for(Int i=0;i<n;i++) a[dp2[i]]++;
  for(Int i=q;i>0;i--) a[i-1]+=a[i];
  for(Int i=1;i<=q;i++) cout<<n-a[i]<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

void fastIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int ar[101010], br[101010], amin=INT_MAX, bmin=INT_MAX;
int main()
{
    fastIO();
    int a,b,m;
    int p=INT_MAX;
    cin>>a>>b>>m;
    for(int i=0;i<a;i++)
        cin>>ar[i];
    for(int i=0;i<b;i++)
        cin>>br[i];
    for(int i=0;i<a;i++)
        amin=min(amin, ar[i]);
    for(int i=0;i<b;i++)
        bmin=min(bmin, br[i]);
    p=amin+bmin;
    for(int i=0;i<m;i++){
        int x,y,c;
        cin>>x>>y>>c;
        p=min(p, ar[x-1]+br[y-1]-c);
    }
    cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>

const int MAX_N = 102;
const int MAX_M = 102;
int n, m;
char field[MAX_N][MAX_M];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool vis[MAX_N][MAX_M];

void dfs(int x, int y, int flag) {
    vis[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
            if (flag == 1) {
                if (field[nx][ny]== '#'&&!vis[nx][ny])
                    dfs(nx, ny, flag);
            } else if (flag == 2) {
                if (field[nx][ny] == '@' && !vis[nx][ny])
                    dfs(nx, ny, flag);
            } else {
                if (field[nx][ny] == '*' && !vis[nx][ny])
                    dfs(nx, ny, flag);
            }
        }
    }
    return;
}

void solve() {
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (field[i][j] == '#' && !vis[i][j]) {
                ans++;
                dfs(i, j, 1);
            } else if (field[i][j] == '@' && !vis[i][j]) {
                ans++;
                dfs(i, j, 2);
            } else {
                if (!vis[i][j]) {
                    ans++;
                    dfs(i, j, 3);
                }
            }
        }
    printf("%d\n", ans);
}

int main() {
    while (scanf("%d%d", &n, &m) != EOF) {
        if (n == 0 && m == 0)break;
        memset(vis, 0, sizeof (vis));
        for (int i = 0; i < n; i++)
            scanf("%s", field[i]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1524
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B=MI()
    if(A<=B):
        print("unsafe")
    else:
        print("safe")
if __name__ == '__main__':
    main()

Measured memory_bytes: 78076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		if (x.endsWith("s")) {
			x+="es";
		}else {
			x+="s";
		}
		System.out.println(x);

	}

}

Measured memory_bytes: 38544
#include <stdio.h>

int main(void){

	char num[1001];				/* ????????????char??????????????§??¨??? */
	int sum;
	int i,j;

	while(scanf("%s", num)){	/* scanf???????????????%s??¨??????????????? */
		sum=0;
		if (num[0]=='0'){
			break;				/* x???0????????\????????? */
	}

	j=strlen(num);
		for(i=0; i<j; i++){
			num[i]-='0';
			sum += num[i];		/* ????????????????????????i?????°???????????? */
		}
		printf("%d\n",sum);
	}

	return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second

vector<ll>t[200010];
bool b[200010] = { 0 };
vector<ll>ans;
stack<ll>st;

void bf(ll n) {
	bool fl = 0;
	for (auto u : t[n]) {
		if (!b[u]) {
			st.push(u);
			b[u] = true;
			bf(u);
			fl = true;
			break;
		}
	}
	if (!fl) {
		cout << st.size() + ans.size() << endl;
		while (!st.empty()) {
			cout << st.top() << ' ';
			st.pop();
		}
		for (int i = 0;i < ans.size();i++)cout << ans[i] << ' ';
		cout << endl;
	}
}

void bfs(ll n) {
	bool fl = 0;
	for (auto u : t[n]) {
		if (!b[u]) {
			ans.pb(u);
			b[u] = true;
			bfs(u);
			fl = true;
			break;
		}
	}
	if (!fl)bf(1);
	
}

int main() {
	ll n, m;
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		ll a, b;
		cin >> a >> b;
		t[a].pb(b);
		t[b].pb(a);
	}

	b[1] = b[t[1][0]] = true;
	ans.pb(1), ans.pb(t[1][0]);
	if (t[1].size() == 1 && t[t[1][0]].size() == 1 && t[1][0] == t[1][0] && t[t[1][0]][0] == 1) {
		cout << 2 << endl;
		cout << 1 << ' ' << 2 << endl;
		return 0;
	}
	bfs(t[1][0]);


	}


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

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

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	ll a[n];
	rep(i,0,n) cin>>a[i];	
	reverse(a,a+n);
	cnt=1,ans=1;
	rep(i,1,n){
		if(a[i]>=a[i-1]) cnt++;
		else ans=max(ans,cnt),cnt=1;
	}
	ans=max(ans,cnt);
	ret(ans-1)
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, z;
	cin >> x >> y >> z;
	int ans = 0;
	for (int i = 1; i < 50001; i++) {
		int tmp = y * i + z * (i + 1);
		if (tmp > x) {
			ans = i - 1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a;
  scanf("%d",&a);
  if(a<=3){
    puts("1");
    return 0;
  }if(a<=7){
    puts("4");
    return 0;
  }if(a<=8){
    puts("8");
    return 0;
  }if(a<=15){
    puts("9");
    return 0;
  }if(a<=24){
    puts("16");
    return 0;
  }if(a<=26){
    puts("25");
    return 0;
  }if(a<=31){
    puts("27");
    return 0;
  }if(a<=35){
    puts("32");
    return 0;
  }if(a<=48){
    puts("36");
    return 0;
  }if(a<=63){
    puts("49");
    return 0;
  }if(a<=80){
    puts("64");
    return 0;
  }if(a<=99){
    puts("81");
    return 0;
  }if(a<=120){
    puts("100");
    return 0;
  }if(a<=124){
    puts("121");
    return 0;
  }if(a<=127){
    puts("125");
    return 0;
  }if(a<=143){
    puts("128");
    return 0;
  }if(a<=168){
    puts("144");
    return 0;
  }if(a<=195){
    puts("169");
    return 0;
  }if(a<=215){
    puts("196");
    return 0;
  }if(a<=224){
    puts("216");
    return 0;
  }if(a<=242){
    puts("225");
    return 0;
  }if(a<=255){
    puts("243");
    return 0;
  }if(a<=288){
    puts("256");
    return 0;
  }if(a<=323){
    puts("289");
    return 0;
  }if(a<=342){
    puts("324");
    return 0;
  }if(a<=360){
    puts("343");
    return 0;
  }if(a<=399){
    puts("361");
    return 0;
  }if(a<=440){
    puts("400");
    return 0;
  }if(a<=483){
    puts("441");
    return 0;
  }if(a<=511){
    puts("484");
    return 0;
  }if(a<=528){
    puts("512");
    return 0;
  }if(a<=575){
    puts("529");
    return 0;
  }if(a<=624){
    puts("576");
    return 0;
  }if(a<=675){
    puts("625");
    return 0;
  }if(a<=728){
    puts("676");
    return 0;
  }if(a<=783){
    puts("729");
    return 0;
  }if(a<=840){
    puts("784");
    return 0;
  }if(a<=899){
    puts("841");
    return 0;
  }if(a<=960){
    puts("900");
    return 0;
  }if(a<=999){
    puts("961");
    return 0;
  }
  puts("1000");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int a, b;
  char c;
  scanf("%d %c %d", &a, &c, &b);
  if (c == '-') {
    printf("%d\n", a - b);
  } else if (c == '+') {
    printf("%d\n", a + b);
  } else {
    return 1;
  }
  return 0;
}


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

int mod=1000000007;

int dfs(vector<int> &a,int N,int i){
  int res;
  if(i>N||a[i]==0)return 0;
  if(i==N)return 1;
  if(a[i]!=-1)return a[i];
  res=(dfs(a,N,i+1)%mod+dfs(a,N,i+2)%mod)%mod;
  return a[i]=res;
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(N+1,-1);
  for(int i=0;i<M;i++){
    int b;
    cin >> b;
    a[b]=0;
  }
  cout << dfs(a,N,0) << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define max3(a, b, c) max (a, max (b, c));
#define max4(a, b, c, d) max (a, max3 (a, b, c));
#define min3(a, b, c) min (a, min (b, c));
#define min4(a, b, c, d) min (a, min3 (b, c, d));
#define reset (a, val) memset (a, val, sizeof (a));
using namespace std;
typedef long long ll;
const int MAXN = 1 + 1e5;
const ll oo = 1  +1e18;
const ll mod = 7 + 1e9;
typedef pair < int, int > II;
typedef pair < int, II > III;
typedef pair < ll, ll > PLL;
typedef pair < ll, PLL > PLLL;
typedef priority_queue < II, vector < II >, greater < II > > pq;
void file();

string s;

int main(){
    cin >> s;
    int n = s.size(), ans = 0;
    for (int i = 0; i < (n - n % 2) / 2; i++){
        ans += (s[i] != s[n - i - 1]);
    }
    cout << ans;
   
    return 0;
}












void file(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int count,max=-2000000000,min=2000000000,j,i;
    scanf("%d",&count);
    int x[count];
    for(i=0;i<count;i++){
       scanf("%d",&x[i]);
    }
    for(j=0;j<count;j++){
       if(max<x[j]-min){
           max=x[j]-min;
       }
       if(min>x[j]){
         min=x[j];
       }
    }
    printf("%d\n",max);
    return 0;
}

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

#define co(x) cout << x << endl

int main ()
{
    string a , A[] = {"Sunny" , "Cloudy" , "Rainy" } ;

    cin >> a ;

    if (a == A[0])
        {
            co (A[1] ) ;
        }
    else if (a == A[1])
        {
            co (A[2]) ;
        }
    else if (a == A[2])
        {
            co (A[0]) ;
        }

    return 0 ;
}



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


int main(){

int N,L;
cin >> N >> L;

vector<string> list(N);
for (int i=0; i<N; i++){
    cin >>list.at(i);
}

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

string ans = "";

for(int i=0; i<N; i++){
ans += list.at(i);
}

cout << ans <<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000
//#define int long long int

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n*n - a << endl;

  return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  std::vector<int> v(n+1);
  for(int i=1;i<=n;i++){
    cin>>v[i];
  }

  std::vector<int> res(n+1);
  for(int i=n;i>=1;i--){
    int p = 0;
    for(int j=i*2;j<=n;j+=i){
      p += res[j];
    }
    // cout<<"A: "<<i<<':'<<p<<':'<<res[6]<<endl;
    if( v[i] == (p % 2) )
      res[i]=0;
    else
      res[i]=1;
  }

  int m = 0;
  for(int i=1;i<=n;i++){
    m += res[i];
    // cout<<res[i]<<endl;
  }
  cout<<m<<endl;
  if(m>0){
    int a=0;
    for(int i=1;i<=n;i++){
      if (res[i]){
        if(a)cout<<' ';
        cout<<i;
        a++;
      }
    }
    cout<<endl;
  }

  return 0;
}


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

const int N = 5e5+1;

string s;
vector<int> g[N];
int a[N];

bool bio[N];
int dfs(int u) {
    if (bio[u]) return a[u];
    bio[u] = true;
    for (int v: g[u]) {
        a[u] = max(a[u], 1+dfs(v));
    }
    return a[u];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> s;
    int n = s.size()+1;
    for (int i = 0; i < n-1; ++i) {
        if (s[i] == '>') {
            g[i].push_back(i+1);
        } else {
            g[i+1].push_back(i);
        }
    }
    for (int i = 0; i < n; ++i) {
        if (g[i].size() < 2 && i != 0 && i != n-1) continue;
        if ((i == 0 || i == n-1) && g[i].size() == 0) continue;
        dfs(i);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a[i];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 46108
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <algorithm>
#include <map>
using namespace std;
string zip(string s) {
   int counter = 1; 
   int i = 1;
   string S = "";
   int l = s.size();
   while (i <= l) {
       if (s[i] == s[i-1]) {
           counter += 1;
       } else {
           S += to_string(counter);
           counter = 1;
       }
       i++;
   }
   if (counter != 1) S += to_string(counter);
   return S;
}

int main(void){
    string s,t; cin >> s >> t;
    map<char, int> dictT;
    map<char, int> dictS;
    string answer = "Yes";
    int i = 0;
    while (i < s.size()) {
        if (dictS.count(s[i])) {
            dictS[s[i]] += 1;
        } else {
            dictS[s[i]] = 1;
        }
        if (dictT.count(t[i])) {
            dictT[t[i]] += 1;
        } else {
            dictT[t[i]] = 1;
        }
        i++;
    }
    bool flag = false;
    i = 0;
    while (i < s.size()) {
        if (dictS[s[i]] != dictT[t[i]]) flag = true;
        i++;
    }
    if (flag) answer = "No";
    if (zip(s) != zip(t)) answer = "No";

    cout << answer << endl;
}


Measured memory_bytes: 4552
#include <bits/stdc++.h>
#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)
#define sp(n) setprecision(n)
#define mp make_pair
#define mt make_tuple
#define pi 3.14159265358979323846264
#define MOD 1000000007

using namespace std;
int primeFactors(ll n)  
{  ll f=0;
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        f++;
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            f++; 
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        f++;
        
 return f;        
}  
  
bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = ((C[i - 1][j - 1] + C[i - 1][j]))%MOD;}}}
    return C[n][k];
 }
 
ll gcd(ll a, ll b){if (b == 0)
        return a;return gcd(b, a % b);}
 
ll expmod(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}
//define temp-functions below
 
 
//some definitions and global variables
vector<ll> primes;
void storePrime(ll n){
    fori(n){
        if(isPrime(i+1)&&(n%(i+1)==0)){primes.push_back(i+1);}
    }
}
 
int main(){ //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
int x,y,z;
cin>>x>>y>>z;
cout<<z<<" "<<x<<" "<<y;
 
    
      
      
      
    

return 0;}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n; cin>>n;
    ll arr[n],brr[n];
    rep(i,0,n) 
    {
        cin>>arr[i];
        brr[i]=arr[i];
    } 
    sort(arr,arr+n,greater<ll>());
    rep(i,0,n)
    {
        if(brr[i]==arr[0]) cout<<arr[1]<<"\n";
        else cout<<arr[0]<<"\n";
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int m; cin >> m;
    vector<int> b(m);
    for (int &bi: b) cin >> bi;
    cout << includes(a.begin(), a.end(), b.begin(), b.end()) << endl;
    return 0;
}


Measured memory_bytes: 4332
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

ll powll(ll powllnum,ll powlljou){
if(powlljou==1){
return powllnum;
}else if(powlljou==0){
return 1;
}else if(powlljou%2==0){
ll powlltmp=powll(powllnum,powlljou/2);
return powlltmp*powlltmp;
}else{
ll powlltmp=powll(powllnum,powlljou-1);
return powlltmp*powllnum;
}
}

int main(void) {
	ll n,tmp;
	cin>>n;
	for (int i = 0;; i++) {
		if(powll(i,2)>n)break;
		tmp=powll(i,2);
	}
	cout<<tmp<<"\n";

	return 0;
}


Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	string s;cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			string s1="",s2="";
			for(int k=0;k<i;k++){
				s1=s1+s[k];
			}
			for(int k=j+1;k<n;k++){
				s1=s1+s[k];
			}
			for(int k=i;k<=j;k++){
				s2=s2+s[k];
			}
			//cout<<s1<<" "<<s2<<endl;
		if(s1=="keyence"||s2=="keyence")return cout<<"YES",0;			
		}		
	}
	cout<<"NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double n;
  cin >> n;
  
  double a = n / 1.08;
  double b = (n + 1.0) / 1.08;
  bool fin = false;
  
  for(int i = a; i <= b; i++) {
    if (a <= i && i < b) {
      cout << i << endl;
      fin = true;
      break;
    }
  }
  
  if (!fin) {
    cout << ":(" << endl;
  }
}



Measured memory_bytes: 3732
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int[][] map = { { 2 }, { 2, 5 }, { 0, 1, 3, 6 }, { 2, 7 }, { 5 },
				{ 1, 4, 6, 9 }, { 2, 5, 7, 10 }, { 3, 6, 8, 11 }, { 7 },
				{ 5, 10 }, { 6, 9, 11, 12 }, { 7, 10 }, { 10 } };
		String reslt = "0ABCDEFGHIJK0";
		Map<String, Integer> memo = new HashMap<String, Integer>();
		memo.put(reslt, 0);
		int step = 1;
		Deque<String> deque = new ArrayDeque<String>();
		deque.offer(reslt);
		while (step <= 10) {
			int size = deque.size();
			while (size-- > 0) {
				char[] chs = deque.pop().toCharArray();
				for (int i = 0; i < 13; i++) {
					if (chs[i] == '0') {
						for (int j : map[i]) {
							chs[i] = chs[j];
							chs[j] = '0';
							String tmp = String.valueOf(chs);
							if (!memo.containsKey(tmp)) {
								memo.put(tmp, step);
								deque.offer(tmp);
							}
							chs[j] = chs[i];
							chs[i] = '0';
						}
					}
				}
			}
			step++;
		}
		while (true) {
			int n = scanner.nextInt();
			if (n == -1)
				break;
			char[] cs = new char[13];
			cs[0] = n == 0 ? '0' : (char) (n - 1 + 'A');
			for (int i = 1; i < 13; i++) {
				int c = scanner.nextInt();
				cs[i] = c == 0 ? '0' : (char) (c - 1 + 'A');
			}
			step = 0;
			deque.clear();
			String s = String.valueOf(cs);
			deque.offer(s);
			Set<String> set = new HashSet<String>();
			set.add(s);
			String ret = "NA";
			loop: while (step <= 10) {
				int size = deque.size();
				while (size-- > 0) {
					String str = deque.pop();
					if (memo.containsKey(str)) {
						ret = String.valueOf(memo.get(str) + step);
						break loop;
					}
					char[] chs = str.toCharArray();
					for (int i = 0; i < 13; i++) {
						if (chs[i] == '0') {
							for (int j : map[i]) {
								chs[i] = chs[j];
								chs[j] = '0';
								String tmp = String.valueOf(chs);
								if (!set.contains(tmp)) {
									set.add(tmp);
									deque.offer(tmp);
								}
								chs[j] = chs[i];
								chs[i] = '0';
							}
						}
					}
				}
				step++;
			}
			System.out.println(ret);
		}

	}
}

Measured memory_bytes: 103104
#include<stdio.h>

long long int lcm(long long int a, long long int b){
    long long int x, tmp, r;
    x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
 
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;

    }
    return x/b;
}

int main(void){
    long long int a,b, c, d, common, ncan, ans;
    long long int  Ac, Bc, Ad, Bd, Acd, Bcd;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    common = lcm(c,d);

    Ac = (a-1)/c;
    Bc = b/c;
    Ad = (a-1)/d;
    Bd = b/d;
    Acd = (a-1)/(common);
    Bcd = b/(common);

    ncan = (Bc - Ac) + (Bd - Ad) - (Bcd - Acd);
    ans = (b-a+1) - ncan;
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        int minusCount = 0;
        for (int i = 0; i < a.length; i++) {
            int num = Integer.parseInt(sc.next());
            if (num < 0) {
                minusCount++;
                num *= -1;
            }
            a[i] = num;
        }
        sc.close();

        // 主処理
        long sum = Arrays.stream(a).mapToLong(i -> i).sum();
        int min = Arrays.stream(a).mapToInt(i -> i).min().orElse(0);
        long result = minusCount % 2 == 0 ? sum : sum - min * 2;

        // 出力
        System.out.println(result);
    }
}


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

int N;
vector<int> p;

int main() {
    cin>>N;
    p.resize(N);
    int cnt=0;
    for (int i=0; i<N; i++) {
        cin>>p[i];
        if (p[i]!=i+1) cnt++;
    }
    if (cnt<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[4];
  for(int i=0;i<n;i++){
    String p=sc.next();
  po[p.equals("AC")?0:p.equals("WA")?1:p.equals("TLE")?2:3]++;
  }
  System.out.println("AC x "+po[0]);
  System.out.println("WA x "+po[1]);
  System.out.println("TLE x "+po[2]);
  System.out.println("RE x "+po[3]);
}
}


Measured memory_bytes: 58604
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<int,int>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}

  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
void solve()
{
    int a,f=0;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
        if(a%i==0)
        {
            if(i<=9)
            {
                if(a/i<=9)f=1;
            }
        }
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}  
int main()
{
 
    FastIO;
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef unsigned int  UI;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;

template <typename T> using VT = vector<T>;
template <typename T> using VVT = VT<VT<T>>;
template <typename T> using VVVT = VT<VT<VT<T>>>;
template <typename T> using VVVVT = VT<VT<VT<VT<T>>>>;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#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, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int n;
VT<int> xs;

LL solve(bool flg) {
    LL a = 0;
    LL res = 0;

    rep(i, n) {
        a += xs[i];

        if (flg) { // expect: positive
            if (a == 0) {
                a = 1;
                res += 1;
            } else if (a < 0) {
                LL b = 1 - a;
                a = 1;
                res += b;
            }
        } else { // expect: negative
            if (a == 0) {
                a = -1;
                res += 1;
            } else if (a > 0) {
                LL b = a + 1;
                a = -1;
                res += b;
            }
        }

        flg = !flg;
    }

    return res;
}

int main(void) {
    cin >> n;
    xs.resize(n);
    rep(i, n) cin >> xs[i];

    cout << min(solve(false), solve(true)) << endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
   int n,m;
   cin>>n>>m;
   cout<<(n-1)*(m-1);

    return 0;

}


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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, s, n) for(int i = s; i < n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define FOREACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//global-----------------------------------------------------------------------------------------------------------------------
char str[100];

//function---------------------------------------------------------------------------------------------------------------------
int main(){
	while (scanf("%s", str) != EOF){
		int n = strlen(str);
		rep(i, n){
			if (str[i] == '@'){
				rep(j, str[i + 1] - '0')
					printf("%c", str[i + 2]);
				i += 2;
			}
			else
			{
				printf("%c", str[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	int ans = 0;

	cin >> N;

	vector<int>d(N);

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

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

	if (N % 2 == 1) {
		ans = 0;
	}
	else {
		if (d[N / 2 - 1] < d[N / 2]) {
			ans = d[N / 2] - d[N / 2 - 1];
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 640
n = int(input())
a = []

dp = [[0]*3 for i in range(n)]

for i in range(n):
    p,q,r = map(int,input().split())
    a.append([p,q,r])

dp[0][0] = a[0][0]
dp[0][1] = a[0][1]
dp[0][2] = a[0][2]

for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            else:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i+1][k])
print(max(dp[-1]))

Measured memory_bytes: 72556
#include <bits/stdc++.h>
static const int MAX = 16;
static const int dx[2] = {-1, 0};
static const int dy[2] = {0, 1};
int W, H, gx, gy;
int map[MAX][MAX];

int bfs() {
    int sx = H-1, sy = 0;
    int ans = 0;
    std::queue<std::pair<int, int> > q;
    q.push({sx, sy});
    while(!q.empty()) {
        std::pair<int, int> p = q.front(); q.pop();
        if (p.first == gx && p.second == gy) { ans++; continue; }
        for (int i = 0; i < 2; i++) {
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if (nx >= 0 && nx < H && ny >= 0 && ny < W && map[nx][ny] != 1) {
                q.push({nx, ny});
            }
        }
    }
    return ans;
}

int main() {
    int N, px, py;
    for (; ;) {
        std::scanf("%d %d", &W, &H);
        if (W == 0 && H == 0) break;
        gx = 0, gy = W-1;
        std::memset(map, 0, sizeof (map));
        std::scanf("%d", &N);
        for (int i = 0; i < N; i++) {
            std::scanf("%d %d", &py, &px);
            map[H-px][py-1] = 1;
        }
        std::cout << bfs() << std::endl;
    }
    return 0;
}



Measured memory_bytes: 9300