akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int from, int to) {
        int rx = root(from);
        int ry = root(to);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

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

    int treeSize(int x) {


        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}

long long modCombination(long long left, long long right, long long int mod) {
    long long answer = 1;
    for (long long i = 0; i < right; i++) {
        answer = (answer * (left - i)) % mod;
        answer = moddiv(answer, (i + 1), mod);
    }

    return answer;
}

bool IsPrime(long long N) {
    if (N == 1) {
        return false;
    }
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }

    return true;
}



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

long long euclid(long long a, long long b) {
    if (a > b) {
        long long temp = b;
        b = a;
        a = temp;
    }
    if (b % a == 0) {
        return a;
    }
    else {
        return euclid(a, b - a);
    }
}


int main() {
    int answer = 0;
    for (int i = 1; i <= 5; i++) {
        int temp;
        cin >> temp;
        if (temp == 0) {
            answer = i;
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3628
list = []
while True:
    a = [int(i) for i in input().split()]
    if a[0] == 0 and a[1] == 0:
        break
    else:
        list.append(a)

for i in range(len(list)):
    for j in range(list[i][0]):
            print("#"*list[i][1])
    print("")



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

int main(){
  long N,T,A;
  long H[100010];
  cin >> N >> T >> A;
  for (int i=1;i<=N;i++){
    cin >>H[i];
  }
  long p,dif=0;

  for (int i=1;i<=N;i++){
    long t=abs(A*1000-(T*1000-H[i]*6));
    if (t<dif||i==1){p=i;dif=t;}
  }
  cout << p << endl;
  return 0;
}


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

const int N=1e5+10;
const ll MOD=998244353;
int cnt[N];

void solve(){
    int n;
    scanf("%d",&n);
    for(int i=1,x;i<=n;i++){
        scanf("%d",&x);
        if(i==1 && x!=0){
            printf("0\n");
            return ;
        }
        cnt[x]++;
    }
    if(cnt[0]!=1){
        printf("0\n");
        return ;
    }
    int used=1;
    ll ans=1;
    for(int i=1;;i++){
        if(cnt[i]==0){
            if(used!=n) ans=0;
            break;
        }
        used+=cnt[i];
        int t=cnt[i];
        while(t--) ans=ans*cnt[i-1]%MOD;
    }
    printf("%lld\n",ans);
}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;



int32_t main()
{
  
   
    crap;
    int n,k;
    cin>>n>>k;

    int p = n%k;

    int ans = min(p, abs(p-k));
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int bubbleSort(int a[], int n) {
  int result = 0;
  int flag;
  flag = 1;
  for (int j = 0; flag; j++) {
    flag = 0;
    for(int i = n - 1; i >= j + 1; i--) {
      if (a[i] < a[i - 1]) {
        swap(a[i], a[i - 1]);
        flag = 1;
        result++;
      }
    }
  }
  return result;
}

signed main() {
	int n, a[100], result;
  cin >> n;
  rep(i, n) cin >> a[i];
  
  result = bubbleSort(a, n);

  rep(i, n) {
    if (i == n - 1) {
      cout << a[i] << endl;
      break;
    }
    cout << a[i] << " ";
  }
  cout << result << endl;
}


Measured memory_bytes: 3172
for i in range(3000):
    list = map(int, raw_input().split())
    x = list[0]
    y = list[1]
    if ((x == 0) and (y == 0)):
        break
    else:
        if x <= y:
            print '%d %d'%(x, y)
        else:
            print '%d %d'%(y, x)

Measured memory_bytes: 6344
#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm> 
using namespace std;
const int maxn=500010,inf=1e9;
int n,ans;
int a[maxn],b[maxn];
inline void read(int &k)
{
	int f=1;k=0;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
void dfs(int dep)
{
	if(dep>n)
	{
		bool flag=0;
		for(int i=1;i<=n;i++)
		if((b[i]&1)==0){flag=1;break;}
		ans+=flag;
		return;
	}
	b[dep]=a[dep]-1;
	dfs(dep+1);
	b[dep]=a[dep];
	dfs(dep+1);
	b[dep]=a[dep]+1;
	dfs(dep+1);
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	dfs(1);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
P = rl()

# Aでxの根を求める
def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A, x) > find(A, y):
        bx, by = find(A, y), find(A, x)
    else:
        bx, by = find(A, x), find(A, y)
    # 根をbx(値の小さい方)に統一 
    A[by] = bx

V = [i for i in range(N+1)]
for i in range(M):
    x, y = rl()
    if find(V, x) != find(V, y):
        union(V, x, y)
index_set = [set() for _ in range(N+1)]
p_set = [set() for _ in range(N+1)]
answer = 0
for i in range(1, N+1):
    root = find(V, i)
    index_set[root].add(i)
    p_set[root].add(P[i-1])

for i in range(1, N+1):
    answer += len(index_set[i] & p_set[i])
print(answer)
# 長時間経過

Measured memory_bytes: 72348
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

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

    int small = min(A, B);
    int big = max(A, B);

    int diff = big - small;
    if (diff % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    cout << small + (diff / 2) << endl;

    return 0;
}


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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    long long k, changel = 0, changet = 0, changer = 0;
    bool flag = false;
    string s, st;
    cin >> s;
    cin >> k;
    for(int i = 1 ; i < (int)s.size() ; i++){
        if(s[i] == s[i-1]){
            if(i == (int)s.size()-1) flag = true; 
            changel++;
            i++;
        }
    }
    if(!flag) st = s[(int)s.size()-1] + s;
    else st = s;
    flag = false;
    for(int i = 1 ; i < (int)st.size() ; i++){
        if(st[i] == st[i-1]){
            if(i == (int)st.size()-1) flag = true; 
            changet++;
            i++;
        }
    }

    if(!flag) s = s[(int)s.size()-1] + s;

    for(int i = 1 ; i < (int)s.size() ; i++){
        if(s[i] == s[i-1]){
            changer++;
            i++;
        }
    }
    k--;
    cout << changel + changet*(k-(k/2)) + changer*(k/2) << endl;
    return 0;
}	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String O = sc.nextLine();
		String E = sc.nextLine();
		String result = "";
		boolean isEqule = (O.length()==E.length());
		for (int i=0;i<O.length();i++){
			if (i==O.length()-1&&!isEqule){
				result = result + O.charAt(i);
			}
			else{
				result = result + O.charAt(i);
				result = result + E.charAt(i);
			}			
		}
		System.out.println(result);
	}	
}

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

using namespace std;

inline bool
is_valid(const string& S, const string T, int offset) {
    if(S.length() - offset < T.length()) return false;
    for(int i = 0; i < T.length(); i++) {
        if(S[offset + i] != T[i] && S[offset + i] != '?') {
            return false;
        }
    }
    return true;
}

inline string
dic_min(const string& str1, const string& str2) {
    for(int i = 0; i < str1.length(); i++) {
        if(str1[i] < str2[i]) {
            return str1;
        } else if(str1[i] > str2[i]) {
            return str2;
        }
    }
    return str1;
}

int main() {
    string ans("UNRESTORABLE");

    string S, T; cin >> S >> T;
    if(S.length() < T.length()) {
        cout << ans << endl;
        return 0;
    }

    for(int offset = 0; offset <= S.length() - T.length(); offset++) {
        if(is_valid(S, T, offset)) {
            string valid_S = S;
            valid_S.replace(
                valid_S.begin() + offset,
                valid_S.begin() + offset + T.length(),
                T
            );
            for(int i = 0; i < valid_S.length(); i++) {
                if(valid_S[i] == '?') valid_S[i] = 'a';
            }
            ans = ans == "UNRESTORABLE"? valid_S : dic_min(valid_S, ans);
        }
    }
    cout << ans << endl;
}
//
// Dubious Document 2
// https://abc076.contest.atcoder.jp/tasks/abc076_c
// 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;

vector<bool> visited, tree;
vector<vector<pint>> G;


void dfs(int i){
    if(visited[i]) return ;
    visited[i] = true;
    for(int j=0;j<G[i].size();j++){
        if(visited[G[i][j].first]) continue;
        else if(G[i][j].second%2 == 0){
            tree[G[i][j].first] = tree[i];
        }
        else{
            tree[G[i][j].first] = !(tree[i]);
        }
        dfs(G[i][j].first);
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    visited = vector<bool>(N, false);
    tree = vector<bool>(N, false);
    G = vector<vector<pint>>(N);
    rep(i, N-1){
        int v, u, w; cin >> v >> u >> w;
        v--; u--;
        G[v].pb(mp(u, w));
        G[u].pb(mp(v, w));
    }
    rep(i, N){
        dfs(i);
    }
    rep(i, N) cout << int(tree[i]) << endl;
    return 0;
}



Measured memory_bytes: 7936
from collections import defaultdict
from bisect import bisect_left

S = input()
T = input()

count = defaultdict(list)
for i, s in enumerate(S):
    count[s] += [i]

idx = 0
cnt = 0
for t in T:
    idxs = count[t]
    if not idxs:
        print(-1)
        exit()
    i = bisect_left(idxs, idx)
    if i < len(idxs):
        idx = idxs[i] + 1
    else:
        idx = idxs[0] + 1
        cnt += 1

ans = cnt * len(S) + idx
print(ans)


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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


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

	int four=0,two=0,one=0;
	for (int i = 0; i < n; i++){
		int a;
		cin>>a;
		if(a%4==0){
			four++;
		}else if(a%2==0){
			two++;
		}else{
			one++;
		}
	}

	if(two==0){
		if(one<=four+1)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}else{
		if(one<=four)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main(){
  ll n,m; cin >> n >> m;
  vector<ll> h(n);
  rep(i,n) cin >> h.at(i);
  map<int,vector<int>> ab;

  rep(i,m){
    int a,b; cin >> a >> b;
    ab[a-1].push_back(b-1);
    ab[b-1].push_back(a-1);
  }

  ll ans =0;

  rep(i,n){
    bool check = true;
    for(auto p:ab[i]){
      if(h.at(i)<=h.at(p)) check = false;
    }
    if(check) ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 14608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (int i = init; i < (n); i++)
#define repd(i, n, init) for (int i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (int bit = init; bit < (1 << n); ++bit)

vector<ll> fact, invfact;
int modpower(int x, int n, int mod)
{
    int res = 1;
    while (n)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int inv(int n)
{
    return modpower(n, MOD - 2, MOD);
}
void COMinit(int k)
{ //空っぽの配列を二つ
    k++;
    fact.resize(k, 0);
    invfact.resize(k, 0);
    fact[0] = 1;
    repi(i, k, 1)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invfact[k - 1] = inv(fact[k - 1]);
    repd(i, k - 2, 0)
    {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}
int nCk(vector<ll> &fact, vector<ll> &invfact, int n, int k)
{ //この関数を使う前にCOMinit
    if (k < 0 || n < k)
        return 0LL;
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
int com(int n, int k)
{
    int iv = 1;
    int fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    map<ll, ll> mp;
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    repi(i, n, 0)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    if (mp[1] > 0)
    {
        if (mp[1] > 1)
            cout << 0 << endl;
        else
            cout << 1 << endl;

        return 0;
    }
    // sort(a.begin(), a.end());
    int ans = 0;
    for (int c : a)
    {
        bool ok = true;
        if (mp[c] > 1)
            continue;
        bool prime = true;
        for (int i = 2; i * i <= c; i++)
        {
            if (c % i == 0)
            {
                prime = false;
                break;
            }
        }

        if (!prime)
        {
            for (int i = 2; i * i <= c; i++)
            {
                if (c % i == 0)
                {
                    // div.push_back(i);
                    if (mp[i])
                    {
                        ok = false;
                        break;
                    }
                    if (i * i != c)
                    {
                        if (mp[c / i])
                        {
                            ok = false;
                            break;
                        }
                    }
                    // div.push_back(c / i);
                }
            }
        }
        // for (auto d : div)
        // {
        //     if (mp[d])
        //     {
        //         ok = false;
        //         break;
        //     }
        // }
        if (ok)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 43236
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d,e,f,g;
    cin>>a>>b>>c>>d>>e>>f>>g;
    ll ans=0;
    ans+=a/2*2;
    ans+=d/2*2;
    ans+=e/2*2;
    ans+=b*1;
    ll res=3;
    a--;
    d--;
    e--;
    res+=a/2*2;
    res+=d/2*2;
    res+=e/2*2;
    res+=b*1;
    if(a<0||d<0||e<0) res=0;
    cout <<max(ans,res)<<"\n";
}

Measured memory_bytes: 256
using namespace std;
#include<iostream>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<string>
#include<cctype>
#include <algorithm>
#include<cassert>
struct Ticket{
	int x;
	int y;
	int c;
};
int main(void){

	int A, B, M;
	cin >> A >> B >> M;
	
	vector<int> a(A), b(B);
	vector<Ticket> m(M);
	for (int i = 0; i < A; ++i){ cin >> a[i]; }
	for (int i = 0; i < B; ++i){ cin >> b[i]; }
	for (int i = 0; i < M; ++i){ cin >> m[i].x >> m[i].y >> m[i].c; }

	vector<int> as(a), bs(b);
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
	int min = as[0] + bs[0];

	for (int i = 0; i < M; ++i){
		min = std::min(a[m[i].x-1] + b[m[i].y-1] - m[i].c, min);
	}
	cout << min << endl;

	return 0;
}


Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,f[111][12]={},p[111][12]={},ans;
	cin>>n;
	FOR(i,0,n)FOR(j,0,10)cin>>f[i][j];
	FOR(i,0,n)FOR(j,0,11)cin>>p[i][j];
	FOR(pat,1,((1<<10))){
		int c[111]={};
		FOR(t,0,10){
			if(!(pat&(1<<t)))continue;
			FOR(i,0,n)c[i]+=f[i][t];
		}
		LL sc=0;
		FOR(i,0,n){
			sc+=1LL*p[i][c[i]];
		}
		if(pat==1){
			ans=sc;
		}else{
			if(ans<sc)ans=sc;
		}

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


Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

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

ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, m;
        string s, t;
        cin >> n >> m >> s >> t;
        ll xlen = lcm(n, m);
        for (int i = 0; i * xlen / min(n, m) < max(n, m); ++i) {
            if (s[i * xlen / m] != t[i * xlen / n]) {
                cout << -1 << endl;
                return 0;
            }
        }
        cout << xlen << endl;
        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 512
#import<iostream>
#import<map>
#import<string>
using namespace std;int D[501][501],n,m,d,t,N;int main(){for(string S,P,G,A,B;cin>>n>>m,n;){map<string,int>M;fill(*D,*D+251001,1e9);for(cin>>S>>P>>G;m--;D[M[A]][M[B]]=D[M[B]][M[A]]=d/40+t)cin>>A>>B>>d>>t,M[A]?:M[A]=++N,M[B]?:M[B]=++N;for(;N;N--)for(d=t=n;!t?t=n,--d:1;t--)D[d][t]=min(D[d][t],D[d][N]+D[N][t]);cout<<D[M[S]][M[P]]+D[M[P]][M[G]]<<endl;}}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = scanInt()
	}
	sort.Ints(L)

	ans := 0
	for i := 0; i < N; i++ {
		a := L[i]
		for j := i + 1; j < N; j++ {
			b := L[j]
			index := sort.SearchInts(L, a+b)
			ans += (index - j - 1)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<int, int>;
ll mod = 1000000007;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
signed main() {
	ll a, b; cin >> a >> b;
	int ans = 0;
	while (a <= b)a *= 2, ans++;
	cout << ans << endl;
}

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

int main() {
    int a, p;
    cin >> a >> p;

    cout << (a*3+p)/2;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i * j == n) {
                puts("Yes");
                return 0;
            }
        }
    }

    puts("No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

long long int N, M, a[364364], r;

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(long long int &x){int k,m=0;x=0;for(;;){k=gc();if(k==45){m=1;break;}if(48<=k&&k<=57){x=k-48;break;}}for(;;){k=gc();if(k<48||k>57)break;x=x*10+k-48;}if(m)x=-x;}

int main(){
    read(N);
    M = N + (N << 1);
    for(int i = 0; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<long long int>());
    N <<= 1;
    ++N;
    for(int i = 1; i ^ N; i += 2){
        r += a[i];
    }
    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>

class Dice{
public:
    int face[6], facetmp[6];

    Dice(void){
        for (int i = 0; i < 6; i++){
            face[i] = 0;
            facetmp[i] = 0;
        }
    }

    void move(char ch){
        for (int i = 0; i < 6; i++) {
            facetmp[i] = face[i];
        }

        if (ch == 'E') {
            facetmp[0] = face[3];
            facetmp[2] = face[0];
            facetmp[3] = face[5];
            facetmp[5] = face[2];
        }

        else if (ch == 'W') {
            facetmp[0] = face[2];
            facetmp[2] = face[5];
            facetmp[3] = face[0];
            facetmp[5] = face[3];
        }

        else if (ch == 'N') {
            facetmp[0] = face[1];
            facetmp[1] = face[5];
            facetmp[4] = face[0];
            facetmp[5] = face[4];
        }

        else if (ch == 'S') {
            facetmp[0] = face[4];
            facetmp[1] = face[0];
            facetmp[4] = face[5];
            facetmp[5] = face[1];
        }

        for (int i = 0; i < 6; i++){
            face[i] = facetmp[i];
        }

    }

    void print(){
        cout << face[0] << endl;
    }

};

int main() {
    Dice d1;
    int num;
    string order;
    for (int i = 0; i < 6; i++){
        cin >> num;
        d1.face[i] = num;
    }

    cin >> order;

    for (int i = 0; i < order.size(); i++){
        d1.move(order[i]);
    }

    d1.print();

    return 0;
}

Measured memory_bytes: 3180
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
using namespace std;

signed main() {
	int n, m, x, y; cin >> n >> m >> x >> y;
	int a = INT_MIN, b = INT_MAX;
	for (int i = 0; i < n; i++) {
		int c; cin >> c;
		a = max(a, c);
	}
	for (int i = 0; i < m; i++) {
		int c; cin >> c;
		b = min(b, c);
	}
	if (a < b&&a<y&&b>x)puts("No War");
	else puts("War");
}


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

int main(){

	 array<int, 3> temp;
	 int N;

	 cin >> N;
	 
	 for (int i = 0; i < N; ++i) {
		 for (auto& a : temp) {
			 cin >> a;
		 }
		 sort(temp.begin(), temp.end());

		 if (temp[0] * temp[0] + temp[1] * temp[1] == temp[2] * temp[2]) {
			 cout << "YES" << endl;
		 }
		 else {
			 cout << "NO" << endl;
		 }
	 }
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <ctype.h>
#include <algorithm>
using namespace std;
int gcd(int a, int b) {
    if(b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
 
int num  = 1000000007;

long long ex(long long x, int n) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) { res *= x; }
        x *= x;
        x %= num;
        n >>= 1;
        res %= num;
    }
    return res;
}

int main() {
    long long m,x,y;
    int n;
    cin >> m >> n;
    x = ex(m , n);
    y = x%num;
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int ans = 0;
  rep(i,n-1){
    if(a.at(i) == a.at(i+1)){
      a.at(i+1) = -1;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
o = list()
top = -1
for s in input().split():
    if s.isdigit():
        o.append(int(s))
        top += 1
    else:
        if s is "+":
            n = o[top]+o[top-1]
            o.pop(top)
            top-=1
            o.pop(top)
            top-=1
            o.append(n)
            top+=1
        if s is "-":
            n = o[top-1] - o[top]
            o.pop(top)
            top -= 1
            o.pop(top)
            top -= 1
            o.append(n)
            top+=1
        if s is "*":
            n = o[top]*o[top-1]
            o.pop(top)
            top -= 1
            o.pop(top)
            top -= 1
            o.append(n)
            top+=1


print(o[0])

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a <= b) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int MOD = 10000;

	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N = sc.nextInt();	//日数
		int K = sc.nextInt();	//制限の数
		int[] seigen=new int[101];
		Arrays.fill(seigen, 0);
		for(int i=0; i<K; i++) {
			int day=sc.nextInt();
			int mono=sc.nextInt();
			seigen[day]=mono;
		}
		int[][][] dp=new int[101][3][3];
		for(int i=0; i<=100; i++) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					dp[i][j][k]=0;
				}
			}
		}
		if(seigen[1]==0 && seigen[2]==0) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					dp[2][j][k]=1;
				}
			}
		}
		else if(seigen[1]==0 && seigen[2]!=0) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					if(k==seigen[2]-1) {
						dp[2][j][k]=1;
					}
				}
			}
		}
		else if(seigen[1]!=0 && seigen[2]==0) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					if(j==seigen[1]-1) {
						dp[2][j][k]=1;
					}
				}
			}
		}
		else if(seigen[1]!=0 && seigen[2]!=0) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					if(j==seigen[1]-1 && k==seigen[2]-1) {
						dp[2][j][k]=1;
					}
				}
			}
		}

		for(int i=3; i<=100; i++) {
			if(seigen[i]==0) {//制限が無い時
				for(int a=0; a<3; a++) {
					for(int b=0; b<3; b++) {
						for(int c=0; c<3; c++) {
							if(a==b && b==c) {
								continue;
							}
							else {
								dp[i][b][c]+=dp[i-1][a][b];
							}
						}
					}
				}
			}
			else if(seigen[i]>0) {
				for(int a=0; a<3; a++) {
					for(int b=0; b<3; b++) {
						if(a==b && b==seigen[i]-1) {
							continue;
						}
						else {
							dp[i][b][seigen[i]-1]+=dp[i-1][a][b];
						}
					}
				}
			}
			for(int j=0; j<3; j++) {
				for(int k=0; k<3; k++) {
					dp[i][j][k]%=MOD;
				}
			}
		}
		int sum=0;
		for(int i=0; i<3; i++) {
			for(int k=0; k<3; k++) {
				sum+=dp[N][i][k];
				sum%=MOD;
			}
		}
		pl(sum);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


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

// 足し算と引き算の入力を受けて、計算結果を返す
// >> 1 + 2
// 3
// >> 5 - 7
//  -2
int main() {
    int a, b;
    char op;

    cin >> a >> op >> b;

    if(op == '+')
        cout << a + b << endl;
    else if(op == '-')
        cout << a - b << endl;
}

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

#define l long long
l N;
l h[100006];
l memo[100006];
bool flag[100006];


l DP(l pos){
	if(pos == N)return 0;
	if(pos == N-1)return abs(h[pos]-h[pos+1]);
	
	if(flag[pos])return memo[pos];
	int	h1 = abs(h[pos+1]-h[pos]);
	int h2 = abs(h[pos+2]-h[pos]);

	l ans = min(h1+DP(pos+1),h2+DP(pos+2));
	
	memo[pos] = ans;
	flag[pos] = true;
	return ans;
}

int main() {
	// your code goes here
	cin>>N;
	for(l i=1;i<=N;i++){
		cin>>h[i];
	}
	l ans = DP(1);
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#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;
using ll = long long;
using P = pair<int, int>;

int main()
{
  double N;
  cin >> N;
  double ans;
  double count;
  rep1(i, N) {
    if (i % 2 == 1) {
      count++;
    }
  }
  ans = count / N;
  cout << std::setprecision(10) << scientific << ans << endl;
}

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

const int INF = 1001001001001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H, W; long long K; cin >> H >> W >> K;
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;

	vector<vector<char>> c(H, vector<char>(W));
	for(int i=0; i<H; ++i) {
	    for(int j=0; j<W; ++j) cin >> c[i][j];
	}

	vector<vector<int>> dist(H, vector<int>(W, INF));
	dist[x1][y1] = 0;
	queue<pair<int, int>> Q;
	Q.emplace(x1, y1);

	while(!Q.empty()) {
	    auto [x, y] = Q.front(); Q.pop();
		for(int i=0; i<4; ++i) {
		    for(int j=1; j<=K; ++j) {
			    int nx = x + dx[i] * j, ny = y + dy[i] * j;
				if(nx < 0 || nx >= H || ny < 0 || ny >= W || c[nx][ny] == '@' || dist[nx][ny] <= dist[x][y]) break;
				if(dist[nx][ny] == INF) {
				    dist[nx][ny] = dist[x][y] + 1;
				    Q.emplace(nx, ny);
				}
			}
		}
	}
	cout << (dist[x2][y2] == INF ? -1 : dist[x2][y2]) << '\n';
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 080 A / Link: http://abc080.contest.atcoder.jp/tasks/abc080_a  ----- */


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

	LL N, A, B; cin >> N >> A >> B;


	LL ans = min(N*A,B);
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int H,W,i,j;
    while(1){
    scanf("%d %d",&H,&W);
        if(H == 0 && W == 0)break;
        for(i=1;i <= H;i++){
        for(j=1;j <= W;j++){
            if(i%2==1 && j%2==0){
            printf(".");
            }
            else if(i%2==0 &&j%2==1){
            printf(".");
            }else{
            printf("#");
            }
            }
            printf("\n");
        }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

const int MAX = 505;

int d[MAX + 1];

void init() {
    for(int i = 1; i <= MAX; ++i){
        d[i] = i;
    }
}

int find(int n) {
    return (d[n] == n) ? d[n] : d[n] = find(d[n]);
}

bool Union(int a, int b) {
    int x = find(a);
    int y = find(b);
    if(x != y) d[x] = y;
    return x != y;
}

struct E {
    E(int len = 0, int node1 = 0, int node2 = 0):len(len), node1(node1), node2(node2){}
    int len, node1, node2;

};

bool cmp(const E& l, const E& r){
    return l.len < r.len;
}

vector<E> edge, mst;

pair<int, int> kruskal(vector<E>& v, bool make_mst = false)
{
    init();
    sort(v.begin(), v.end(), cmp);
    int res = 0, num = 0;
    for(auto& e : v){
        if(Union(e.node1, e.node2)){
            if(make_mst) mst.push_back(e);
            res += e.len;
            num++;
        }
    }
    return make_pair(res, num);
}

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    int N, M;
    cin >> N >> M;
    int S, D, C;
    for(int i = 0; i < M; ++i){
        cin >> S >> D >> C;
        edge.push_back(E(C, S, D));
        edge.push_back(E(C, D, S));
    }
    int mst_len = kruskal(edge, true).first;
    int num = 0, len = 0;
    for(auto& e : mst){
        vector<E> v;
        for(auto& i : edge){
            if((e.node1 == i.node1 && e.node2 == i.node2) ||
               (e.node1 == i.node2 && e.node2 == i.node1)) continue;
            v.push_back(i);
        }
        auto res = kruskal(v);
        if(res.second < N - 1 || res.first > mst_len){
            num++;
            len += e.len;
        }
    }
    cout << num << " " << len << endl;
}

Measured memory_bytes: 6568
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> p(n);
  for(Int i=0;i<n;i++) cin>>p[i];
  sort(p.rbegin(),p.rend());
  Int ans=0;
  for(Int i=0;i<n;i++) ans+=p[i];
  ans-=p[0]/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<deque>
#include<tuple>
#include<stdio.h>
#include<iomanip>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int b[100000];

int main(){
	string s, t;
	cin>>s>>t;
	int a=0;
	rep(i, s.size()){
		if(s[i]!=t[i]){
			a++;
		}
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),SA(N+1),SB(N+1);
    rep(i,N){
        cin >> A[i];
    }
    ll cnt1 = 0;
    rep(i,N){
        SA[i+1] = SA[i] + A[i];
        if(i%2 == 0 && SA[i+1] > 0 || i%2 == 1 && SA[i+1] < 0){
            continue;
        }else if(i%2==0){
            cnt1 += abs(SA[i+1]) + 1;
            SA[i+1] = 1;
        }else{
            cnt1 += abs(SA[i+1]) + 1;
            SA[i+1] = -1;
        }
    }
    ll cnt2 = 0;
    rep(i,N){
        SB[i+1] = SB[i] + A[i];
        if(i%2 == 1 && SB[i+1] > 0 || i%2 == 0 && SB[i+1] < 0){
            continue;
        }else if(i%2==1){
            cnt2 += abs(SB[i+1]) + 1;
            SB[i+1] = 1;
        }else{
            cnt2 += abs(SB[i+1]) + 1;
            SB[i+1] = -1;
        }
    }
    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int str1 = sc.nextInt();

		if(str1 < 1200) System.out.println("ABC");
		if(str1 >= 1200) System.out.println("ARC");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
    const int N  = 1e5 + 5 ;
    vector < int > adj [ N ] ;
        bool visited[ N ]  ;
         int deg [ N] , dis[N];

         void dfs (int node ){
                if (!visited[node])
                    visited[node] = true;

                for ( int X : adj[node]){
                    dis[X] = max(dis[X] , dis[node] +1);
                    deg[X]--;
                    if (deg[X]==0)
                        dfs(X);
                }

         }

int main () {

            int n , m ; cin >> n >> m;

            while (m--){
                int a , b ;
                 cin >> a >> b ;
                  adj[a].push_back(b);
                  deg[b]++;

            }
            for ( int i = 1 ; i <= n ; i++){
                if (!visited[i] && deg[i] == 0)
                    dfs(i);
            }
            int answer = 0 ;
            for ( int i = 1 ; i <= n ; i++ ) {
                answer = max (answer,dis[i]);
            }
            cout << answer<<endl;



 return 0;
}




Measured memory_bytes: 9728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramA
    {
        static void Main()
        {
            int a = NextInt, b = NextInt, c = NextInt;
            System.Console.WriteLine(Math.Max(0, c - a + b));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

int dp[3005][3005];
int main(void){
    int n, t;
    std::cin >> n >> t;
    std::vector<std::pair<int, int>> ab(n);
    for(int i = 0; i < n; i++){
        std::cin >> ab[i].first >> ab[i].second;
    }
    std::sort(ab.begin(), ab.end());
    int ans = 0;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < t; j++){
            dp[i+1][j] = std::max(dp[i][j], dp[i+1][j]);
            int nj = j + ab[i].first;
            if(nj < t){
                dp[i+1][nj] = dp[i][j] + ab[i].second;
            }
        }
        ans = std::max(ans, dp[i][t-1] + ab[i].second);
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 38848
#include<iostream>
#include<string>
using namespace std;

const long long M = 1046527;
string Hash[M];

int getchar(char ch)
{
	if ('A' == ch)
		return 1;
	else if ('C' == ch)
		return 2;
	else if ('G' == ch)
		return 3;
	else if ('T' == ch)
		return 4;
	else
		return 0;
}
long long get_key(string str)
{
	long long sum = 0, p = 1, i;
	for (i = 0; i < str.length(); i++)
	{
		sum += p*getchar(str[i]);
		p *= 5;
	}
	return sum;
}

long long hash1(long long key)
{
	return key % M;
}
long long hash2(long long key)
{
	return 1 + (key%(M - 1));
}

bool find(string str)
{
	long long key, i, index;
	key = get_key(str);
	for (i = 0;; i++)
	{
		index = (hash1(key) + i*hash2(key)) % M; 
		if (i > M)
		{
			
			return 0;
		}
		else if (Hash[index]==str)
			return 1;
		else if (Hash[index].length() == 0)       
			return 0;
	}
	return 0;
}


void insert(string str)
{
	long long key, i, index;
	key = get_key(str);
	for (i = 0; ; i++)
	{
		index = (hash1(key) + i*hash2(key)) % M;
		if (i > M)
		{
			
			break;
		}
		else if (Hash[index].length() == 0)
		{
			Hash[index] = str;
			break;
		}
	}
}

int main()
{
	

	int n;
	cin >> n; 
	string commond;
	for (int i = 0; i < n; i++)
	{
		cin >> commond;
		if (commond == "insert")
		{
			cin >> commond;
			insert(commond);
		}
		else
		{
			cin >> commond;
			if (find(commond))
			{
				cout << "yes" << endl;
			}
			else
			{
				cout << "no" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 42868