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

template <typename T>
struct Matrix {
    vector<vector<T>> mat;
    Matrix(int n, int m, T val = 0) : mat(n, vector<long long>(m, val)) {};
    void init(int n, int m, T val = 0) {mat.assigin(n, vector<long long>(m, val));}
    size_t size() const {return mat.size();}
    inline vector<long long>& operator[](int i) {return mat[i];}
};

long long MOD;

template <typename T>
Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> C(A.size(), B[0].size());
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B[0].size(); ++j) {
            for(int k = 0; k < B.size(); ++k) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] % MOD) % MOD;
            }
        }
    }
    return C;
}

template <typename T>
Matrix<T> pow(Matrix<T> A, long long n) {
    Matrix<T> C(A.size(), A.size());
    for(int i = 0; i < A.size(); ++i) C[i][i] = 1;
    while(n > 0) {
        if(n & 1) C = C * A;
        A = A * A;
        n >>= 1;
    }
    return C;
}

template <typename T>
vector<T> pro(Matrix<T> A, vector<T> X){
    vector<long long> ret(X.size(), 0);

    for(int i=0; i<A.size(); ++i) {
        for(int j=0; j<A[0].size(); ++j) {
            ret[i] = (ret[i] + A[i][j] * X[j] % MOD) % MOD;
        }
    }
    return ret;
}

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

using mat = Matrix<long long>;
using vec = vector<long long>;

int main() {
    long long L, A, B;
    cin >> L >> A >> B >> MOD;

    int start = 0;
    long long tmp = 1;
    for(; start < 18; ++start) {
        if(A >= tmp && A < tmp * 10) break;
        tmp *= 10;
    }

    vec C(18);
    long long prev = A - B, cnt = 0;

    for(int i=start; i<18; ++i) {
       C[i] = ((long long)pow(10, i + 1) - prev) / B;
       if(prev + B * C[i] == (long long)pow(10, i + 1)) --C[i];
       C[i] = min(C[i], L - cnt);
       cnt += C[i];
       if(cnt == L) break;
       prev += B * C[i];
    }

    vec X = {0, A, B};
    mat coeff(3, 3);
    coeff[0] = {1, 1, 0};
    coeff[1] = {0, 1, 1};
    coeff[2] = {0, 0, 1};
    for(int d=0; d<18; ++d) {
        coeff[0][0] = powmod(10, d + 1);
        X = pro(pow(coeff, C[d]), X);
    }

    cout << X[0] % MOD << endl;
}

Measured memory_bytes: 256
1.step 3000 do |i|
  a, b = gets.chop.split(' ').map(&:to_i)
  
  if a == 0 && b == 0
    break
  elsif a < b
    printf "%d %d\n", a, b
  else
    printf "%d %d\n", b, a
  end
end



Measured memory_bytes: 6868
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;

int main(){
    int n; cin>>n;
    if(n<=111) cout<<111;
    else if(n<=222) cout<<222;
    else if(n<=333) cout<<333;
    else if(n<=444) cout<<444;
    else if(n<=555) cout<<555;
    else if(n<=666) cout<<666;
    else if(n<=777) cout<<777;
    else if(n<=888) cout<<888;
    else cout<<999;
}

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

int main(){
    int n,ans=0,tmp=1;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a!=tmp)ans++;
        else tmp++;
    }
    if(ans==n)cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
	char s[20005],s1[20005];
	cin>>s>>s1;
	sort(s,s+strlen(s));
	sort(s1,s1+strlen(s1));
	if(strcmp(s,s1)==0)printf("No\n");
	else if(s1[strlen(s1)-1]>s[0])cout<<"Yes"<<endl;
	else if(strlen(s)>strlen(s1))cout<<"No"<<endl;
	else
	{
		int a[27],b[27];
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0;i<strlen(s);i++)
			a[s[i]-97]++;
		for(int i=0;i<strlen(s1);i++)
			b[s1[i]-97]++;
		for(int i=0;i<27;i++)
		{
			if(a[i]==strlen(s))
			{
				for(int j=0;j<27;j++)
					if(b[j]==strlen(s1))
					{
						cout<<"Yes"<<endl;
						return 0;
					}
			}
		}
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    ll N;
    cin >> N;

    ll A[N];
    ll s[1000001];
    ll ans = 0;
    rep(i, N){
        cin >> A[i];
    }
    sort(A, A + N);
    rep(i, 1000001){
        s[i] = 1;
    }

    ll p, pSum;
    rep(i, N){
        p = A[i];
        if(s[p] == 1){
            if(A[i] != A[i + 1]){
                ans++;
            }
            pSum = p;
            while(pSum < 1000001){
                s[pSum] = 0;
                pSum += p;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13016
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  std::string t{s.rbegin(), s.rend()};
  // debug(s,t);
  int n = s.length();
  int ans = 0;
  rep(i,0,n) {
    ans += s.at(i) != t.at(i);
  }
  assert(ans % 2 == 0);
  ans /= 2;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int xx, yy;
    xx = 10 * int(S[0] - '0') + int(S[1] - '0');
    yy = 10 * int(S[2] - '0') + int(S[3] - '0');

    if (xx > 12 or xx == 0){
        if (yy > 0 and yy < 13) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
    else {
        if (yy > 0 and yy < 13) cout << "AMBIGUOUS" << endl;
        else if (yy > 12 or yy == 0) cout << "MMYY" << endl;
    }
}

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

int main(){
  vector<char> A(3),B(3);
  int count=0;
  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<3;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<3;i++){
    if(A.at(i)==B.at(i)){
      count++;
    }
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
from math import factorial
def nc2(n):
	if n<2:
		return 0
	else:
		return (n*(n-1))//2

n = int(input())
arr = list(map(int,input().split()))
d = {}
for i in range(n):
	try:
		d[arr[i]].append(i)
	except KeyError:
		d[arr[i]] = [i]

pick2 = {}
pick1 = {}
for i in d.keys():
	pick2[i] = nc2(len(d[i]))
	pick1[i] = nc2(len(d[i])-1)

sum_pick2 = sum(pick2.values())

done = {}

for i in d.keys():
	done[i] = (sum_pick2 - pick2[i] + pick1[i])

for i in arr:
	print(done[i])
	



Measured memory_bytes: 121676
#include <numeric>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int w = getInt();
  const int h = getInt();

  vector<int> xs(w);
  vector<int> ys(h);

  REP(i,n){
    const int x = getInt();
    const int y = getInt();
    const int d = getInt();

    xs[max(0, x - d)]++; if(x + d < w) xs[x + d]--;
    ys[max(0, y - d)]++; if(y + d < h) ys[y + d]--;
  }

  REP(i,w-1) xs[i + 1] += xs[i];
  REP(i,h-1) ys[i + 1] += ys[i];

  // REP(i,w) printf("%d", !!xs[i]); puts("");
  // REP(i,h) printf("%d", !!ys[i]); puts("");

  if(any_of(xs.begin(), xs.end(), [](int x){ return x == 0; }) &&
     any_of(ys.begin(), ys.end(), [](int x){ return x == 0; })){
    puts("No");
  }else{
    puts("Yes");
  }

  return 0;
}

Measured memory_bytes: 1528
import java.util.Scanner;
import java.util.Arrays;

public class Main
{

	public static void main(String[] args)
	{	Scanner s = new Scanner(System.in);
                int n = s.nextInt();
                if(n<1200){
                    System.out.println("ABC");
                }else if(n>= 1200 && n<2800){
                    System.out.println("ARC");
                }else{
                    System.out.println("AGC");
                }
                
	}
}


Measured memory_bytes: 24148
s = int(input())
a = [s]

counter = 2
while True:
    if a[-1] % 2 == 0:
        temp = int(a[-1] / 2)
    else:
        temp = int(3 * a[-1] + 1)
    
    if temp in a:
        break
        
    counter += 1
    a.append(temp)
    
print(counter)

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

struct DisjointSet{
    vector<int> p;
    DisjointSet(int n) : p(n){
        rep(i,n) p[i] = i;
    } 

    int root(int x){
        if(p[x] == x) return x;
        return p[x] = root(p[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        p[rx] = ry;
    }

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

int main()
{
    ll n, m; cin >> n >> m;
    int a[m], b[m];
    rep(i,m){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    reverse(a, a+m);
    reverse(b, b+m);    

    DisjointSet dis = DisjointSet(n);

    vector<ll> num(n);
    rep(i,n) num[i] = 1;

    ll ans[m];
    ans[0] = n*(n-1)/2;

    rep(i,m-1){
        // printf("%d, %d\n", dis.root(a[i]), dis.root(b[i]));
        int ori_a = dis.root(a[i]);
        int ori_b = dis.root(b[i]);
        if(ori_a == ori_b){
            ans[i+1] = ans[i];
        }else{
            ans[i+1] = ans[i] - num[ori_a]*num[ori_b];
            dis.unite(a[i], b[i]);
            num[ori_a] = num[ori_b] = num[ori_a]+num[ori_b];
        }
    }
    /*
    rep(i,m-1){
        int rootb = dis.root(b[i]);
        int roota = dis.root(a[i]);
        if(roota == rootb){
            // dis.unite(a[i], b[i]);
            ans[i+1] = ans[i];
        }else{
            ans[i+1] = ans[i] - num[rootb]*num[roota];
            num[rootb] += num[roota];
            num[roota] = 0;
            dis.unite(a[i], b[i]);
        }
    }
    */
    reverse(ans, ans+m);
    rep(i,m) cout << ans[i] << endl;
}

Measured memory_bytes: 5932
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Prelude hiding (putStrLn, getLine, getContents)
import Data.Text as T (splitOn, pack, unpack)
import Data.Text.IO
import qualified Data.List as L
import Debug.Trace (trace)


main = do
    n:_ <- (map (read . unpack)) . (splitOn " ") <$> getLine :: IO [Int]
    ds <- (map (read . unpack)) . splitOn " " <$> getLine :: IO [Int]
    putStrLn $ showT $ solve n ds

-- | solve
-- >>> solve 1000 [1,3,4,5,6,7,8,9]
-- 2000
-- >>> solve 9999 [0]
-- 9999
-- >>> solve 1000 [0]
-- 1111
-- >>> solve 2 [2..9]
-- 10
-- >>> solve 9998 [9]
-- 10009
solve :: Int -> [Int] -> Int
solve x ds =
    let eIndex = L.findIndex (flip elem ds) $ reverse $ digits x
    in case eIndex of
--        Just i -> solve ((10 ^ i) + x) ds
        Just i -> solve (x+1) ds
        Nothing -> x

showT = pack.show

debug x = trace (show x) x

-- | get digets of 10x number
-- >>> digits 123
-- [1,2,3]
--
digits :: Int -> [Int]
digits = reverse . f
  where
    f 0 = []
    f x = h:(f t)
      where (t, h) = x `divMod` 10

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

int main(){
    double L;
    cin >> L;
    double sum;
    sum = L/(3.0);
    sum = sum*L/(3.0);
    sum = sum *L/(3.0);
    cout << fixed <<  setprecision(12)  << sum << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    for(ll i=1;i<=n-1;i++){
        ll cnt=0;
        map<char,ll> m;
        set<char> t;
        rep(j,i){
            m[s[j]]++;
        }
        for(ll j=i;j<n;j++){
            t.insert(s[j]);
        }
        for(auto x:t){
            if(m.count(x)) cnt++;
        }
        ans=max(ans,cnt);
    }
    cout << ans << endl;
} 


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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{

	int n;
    cin >> n;
    vector<dl> v(n);
    vector<vector<dl>> dp(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        dp[i].resize(2*n+1);
    }
    dp[0][n-1]=v[0];
    dp[0][n+1]=1-v[0];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<2*n;j++)
        {
            dp[i][j]+=v[i]*dp[i-1][j+1];
        }
        for(int j=1;j<=2*n;j++)
        {
            dp[i][j]+=(1-v[i])*dp[i-1][j-1];
        }

    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<2*n+1;j++)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    
    dl ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=dp[n-1][i];
    }
    cout <<setprecision(10) <<fixed<< ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 140928
n,m,c = gets.chomp.split().map(&:to_i)
b = gets.chomp.split().map(&:to_i)
a = []
n.times do
  a.push gets.chomp.split().map(&:to_i)
end

ans = 0
n.times do |i|
  sum = 0
  m.times do |j|
    sum += a[i][j] * b[j]
  end
  if sum + c > 0
    ans += 1
  end
end

puts ans

Measured memory_bytes: 1788
/**
*	created: 22.09.2020 01:48:16
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define len(x) ll(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
using ll = long long;
using P = pair<int,int>;
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
inline void print(P a) {cout << a.first << " " << a.second << endl;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// Segment Tree
// query : f[a,b), Ο(log(n))
template <typename X> struct SegTree {
    using F = function<X(X, X)>;
    int n; F f; const X ex; vector<X> dat;
    SegTree(int n_, F f_, X ex_) : n(),f(f_),ex(ex_),dat(n_*4, ex_) {
        int x = 1; while (n_ > x) {x *= 2;} n = x;
    }
    void set(int i, X x) {dat[i+n-1] = x; return;}
    void build() {
        rrep(k,n-1) dat[k] = f(dat[2*k+1], dat[2*k+2]);
        return;
    }
    void update(int i, X x) {
        i += n - 1; dat[i] = x; // subject to change
        while(i) {i = (i-1)/2; dat[i] = f(dat[i*2+1], dat[i*2+2]);}
        return;
    }
    X query(int a, int b) {return query_sub(a, b, 0, 0, n);}
    private:
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return ex;
        else if (a <= l && r <= b) return dat[k];
        else {
            X vl = query_sub(a, b, k*2+1, l, (l+r)/2);
            X vr = query_sub(a, b, k*2+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

signed main() {
    int n, q; string s;
    cin >> n >> s >> q;

    using X = int;
    auto f = [](X x1, X x2) -> X {return x1 | x2;};
    X ex = 0;
    SegTree<X> seg(n, f, ex);

    auto toi = [] (char c) {
        int d = c - 'a';
        int ret = 1ll << d;
        return ret;
    };

    rep(i,n) seg.set(i,toi(s[i]));
    seg.build();

    rep(i,q) {
        int t; cin >> t;
        if (t == 1) {
            int a; char c;
            cin >> a >> c;
            a--;
            seg.update(a,toi(c));
        }
        if (t == 2) {
            int a, b; cin >> a >> b;
            a--;
            cout << pcnt(seg.query(a,b)) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 19584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define put(n) cout<<(n)<<endl
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()


int main(){
    int N,Q;
    cin>>N>>Q;
    vector<long long> A(N);
    FOR(i,0,N) cin>>A[i];

    FOR(i,0,Q){
        long long X,right=0,cnt=0,sum=0;
        cin>>X;

        for(int left = 0; left < N; ++left){
            while(right < N && X >= (sum + A[right])){
                sum += A[right];
                ++right;
            }
            cnt += (right - left);
            if(right == left) ++right;
            else sum -= A[left];
        }
        put(cnt);
    }
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int find(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(void){
    int n;cin>>n;
    if(n%find(n)==0)cout<<"Yes"<<endl;else cout<<"No"<<endl;
}

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

int main() {
    int k, s;
    cin >> k >> s;

    int x, y, z;
    int cnt = 0;

    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            z = s - (x + y);
            if (z < 0) {
                break;
            }
            if (0 <= z && z <= k) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
int main()
{
	string str;
	ll c,i,j,k,n;
	cin>>str;
	n=str.length();
	ll p=1e9+7;
	ll dp[str.length()+10][14]={0};
	dp[0][0]=1;
	for(i=0;i<n;i++)
	{
		if(str[i]=='?')
		c=-1;
		else
		c=str[i]-'0';
		for(j=0;j<10;j++)
		{
			if(c!=-1 and c!=j)
			continue;
			for(k=0;k<13;k++)
			{
				dp[i+1][(k*10+j)%13]+=dp[i][k];
			}
		}
		for(j=0;j<13;j++)
		dp[i+1][j]=(dp[i+1][j]%p);
	}
	cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 11392
#include<stdio.h>
int c[20];
int d[20];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		for(int i=0;i<a;i++)scanf("%d",c+i);
		for(int i=0;i<b;i++)scanf("%d",d+i);
		int ret=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(c[i]==d[j]){
					ret+=c[i];
					c[i]=-1;
					d[j]=-1;
					break;
				}
			}
		}
		for(int i=0;i<a;i++)if(~c[i])ret+=c[i];
		for(int i=0;i<b;i++)if(~d[i])ret+=d[i];
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1028
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))
A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    AB = A.searchsorted(b, side='left')
    CB = len(B) - C.searchsorted(b, side='right')
    ans += AB * CB

print(ans)




Measured memory_bytes: 25596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	if (n+1)/2 >= k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main() {
	cin.tie(nullptr); ios_base::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) cin >> s[i];
	mcf_graph<int, int> g(n*m+2);
	int S = n*m, T = n*m+1;
	int potent = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '#') continue;
			g.add_edge(i*m+j, T, 1, n*m-i-j);
			if (s[i][j] == 'o') {
				g.add_edge(S, i*m+j, 1, 0);
				potent += n*m-i-j;
			}
			if (i < n-1 and s[i+1][j] != '#') g.add_edge(i*m+j, (i+1)*m+j, 100, 0);
			if (j < m-1 and s[i][j+1] != '#') g.add_edge(i*m+j, i*m+j+1, 100, 0);
		}
	}
	cout << potent - g.flow(S, T).second << "\n";
	return 0;
}

Measured memory_bytes: 4152
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 402
using namespace std;
typedef long long ll;
const int Mod = 998244353;

inline ll fsp(ll x, int p) {
    ll res = 1;
    while (p) {
        if (p & 1) (res *= x) %= Mod;
        (x *= x) %= Mod;
        p >>= 1;
    }
    return res;
}

int n, a[N];
ll sum[N], f[N][N * N], g[N][N * N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i), sum[i] = sum[i - 1] + a[i];
    f[0][0] = 1, g[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= sum[n]; ++j) {
            f[i + 1][j] += f[i][j] * 2 % Mod;
            g[i + 1][j] += g[i][j];
            (f[i + 1][j + a[i + 1]] += f[i][j]) %= Mod,
            (g[i + 1][j + a[i + 1]] += g[i][j]) %= Mod;
        }
    ll ans = (fsp(3, n) - 3 * fsp(2, n) % Mod) % Mod;
    for (int j = (sum[n] + 1) / 2; j <= sum[n]; ++j)
        (ans -= (f[n][j] - 2 * g[n][j]) * 3) %= Mod;
    cout << (ans % Mod + Mod) % Mod;
    return 0;
}


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

int main(){
  int debt = 100000;

  int n; cin>>n;
  for(int i=0;i<n;++i){
    debt *= 1.05;
    int tmp = (debt/1000)*1000;
    if(debt>tmp){
      tmp += 1000;
      debt = tmp;
    }
  }

  cout<<debt<<endl;

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = list(input())
	M = len(S)
	for i in range(M):
		S[i] = chr((ord(S[i]) - 65 + N) % 26 + 65)
	print("".join(S))

# #大文字
# L = [chr(i) for i in range(65, 91)]
# #小文字
# L = [chr(i) for i in range(97, 123)]
# a = ord() #文字を数値に変換


if __name__ == '__main__':
	main()

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

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, 60){
        ll x = 0;
        rep(j, n)if(a[j] >> i & 1) x++;
        ll memo = 1;
        rep(j, i){
            memo *= 2;
            memo %= mod;
        }
        memo *= x;
        memo %= mod;
        memo *= (n - x);
        memo %= mod;
        ans += memo;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int x = scanner.nextInt();
		
		int h = 0;
		
		int m = 0;
		
		int s = 0;
		
		if(x >= 3600) {
			h = x / 3600;
			x = x % 3600;
		}
		
		if(x >= 60) {
			m = x / 60;
			s = x % 60;
		}else {
			s = x;
		}
		
		System.out.println(h + ":" + m + ":" + s);
		
		scanner.close();
		
	}

}


Measured memory_bytes: 26404
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int n) {
  int a = n % 10;
  int b = to_string(n)[0] - '0';
  return P(a, b);
}

int main() {
  int N; cin >> N;
  map<P, int> mp;
  for(int i = 1; i <= N; i++) {
    P p = f(i);
    mp[p]++;
  }

  int ans = 0;
  for(int i = 1; i <= N; i++) {
    P q; q.first = f(i).second, q.second = f(i).first;
    ans += mp[q];
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> A(N);
    vector<int> ans(N-1);
    vector<int> cnt(N);
    
    rep(i,N-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[a].push_back(make_pair(b,i));
        A[b].push_back(make_pair(a,i));
        cnt[a]++; cnt[b]++;
    }
    
    int M = 0;
    rep(i, N) M = max(M, cnt[i]);
    cout << M << endl;
    
    queue<int> q;
    vector<int> check(N);
    q.push(0);
    check[0] = 1;
    
    while(q.size() != 0){
        int x = q.front(); q.pop();
        int k = -1;
        rep(i, A[x].size()){ //DFSなので頂点は一回しか探索されず
            if(check[A[x][i].first] == 0){
                q.push(A[x][i].first);
                check[A[x][i].first] = 1;
            } else k = ans[A[x][i].second];
        }
        int now = 1;
        rep(i, A[x].size()){
            if(ans[A[x][i].second] != 0) continue;
            if(now == k) now++;
            ans[A[x][i].second] = now; now++;
        }
    }
    rep(i,N-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7808
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>

#define mod 104857601
#define pb push_back
#define ep emplace_back
#define fr first
#define sc second
#define linf  (((1ll << 62) - 1) << 1)
#define inf (((1 << 30) - 1) << 1)

const double eps = 0.000000001;
#define ll long long
#define leps 1e-18
#define mkp make_pair
#define mpi unordered_map<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) begin(v), end(v)
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

// Utils
random_device rd;
mt19937 mt(rd());

const int N_ = 100001;
vector<int> primes;
int *least_prime;
void cieve() {
  least_prime = new int[N_];
  fill(least_prime, least_prime + N_, -1);

  for (int i = 2; i < N_; i++) {
    if (least_prime[i] == -1) {
      least_prime[i] = i;
      primes.pb(i);
    }
    for (auto &c: primes) {
      if (c * i >= N_ || c > least_prime[i]) break;
      least_prime[c * i] = c;
    }
  }
}

template<typename NType>
NType gcd(NType a, NType b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template<typename NType>
NType lcm(NType a, NType b) { return a / gcd(a, b) * b; }
template<typename NType>
NType phi(NType n_) {
  NType ans = n_;
  for (NType i = 2; i * i <= n_; i++) {
    if (n_ % i == 0) {
      while (n_ % i == 0) n_ /= i;
      ans -= ans / i;
    }
  }
  if (n_ > 1) ans -= ans / n_;
  return ans;
}

int binpow(ll a, int n, const int M = mod) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      res = (a * res) % M;
      n--;
    } else {
      a = (a * a) % M;
      n >>= 1;
    }
  }
  ((res %= M) += M) %= M;
  return res;
}
// End of Utils

//ofstream cout("/Users/user/Desktop/test.txt");

void solve(int T) {
  int n, k, x;
  cin >> n >> k;

  vector<int> v(n);

  for(int i = 0; i < n; i ++)
    cin >> v[i];

  int l = 1, r = 1e9 + 1, m;

  while(l < r - 1){

    m = ((l + r) >> 1);

    int cnt = 0;

    for(int i : v){
      int tmp = (i + m - 1) / m - 1;
      cnt += tmp;
    }
    if(cnt <= k) r = m + 1;
    else l = m + 1;

    if(l == r - 2){
      m = l;
      cnt = 0;
      for(int i : v){
        int tmp = (i + m - 1) / m - 1;
        cnt += tmp;
      }
      if(cnt <= k) r = m + 1;
      else l = m + 1;
    }
  }

  cout << l << endl;
}

#define MULTIPLE_TEST 0
#define PRECALC_CIEVE 0
int main(int argc, char const *argv[]){
  if (PRECALC_CIEVE) cieve();
  int t{1};
  if (MULTIPLE_TEST) scanf("%d\n", &t);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int i = 1;
  while (t-- > 0) {
    solve(i++);
  }
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  string s[2];
  while(true){
    cin >> s[0] ;
    if(s[0] == ".") break;
    cin >> s[1];
    if(s[0] == s[1]) cout << "IDENTICAL" << "\n";
    else{
      vector<string> ss;
      int cnt = 0;
      int prev = 0;
      int prev2 = 0;

      string firstSS = "";
      string lastSS = "";
      rep(i,s[0].size()){
        if(s[0][i] == '"'){
          cnt++;
          if(cnt % 2 == 1) prev = i;
          if(cnt == 1 && i != 0){
            firstSS = s[0].substr(0,i);
          }
          if(cnt > 1 && cnt % 2 == 0){
            ss.push_back(s[0].substr(prev,i-prev+1));
            prev2 = i;
          }
        }
      }
      if(prev2 != (int)s[0].size() - 1){
        lastSS = s[0].substr(prev2,(int)s[0].size()-prev2);
      }
      // cout << firstSS << ' ' << lastSS << "\n";
      // rep(i,ss.size()){
      //   cout << ss[i] << endl;

      vector<string> ss2;
      cnt = 0;
      prev = 0;
      prev2 = 0;
      string firstSS2 = "";
      string lastSS2 = "";

      rep(i,s[1].size()){
        if(s[1][i] == '"'){
          cnt++;
          if(cnt % 2 == 1) prev = i;
          if(cnt == 1 && i != 0){
            firstSS2 = s[1].substr(0,i);
          }
          if(cnt > 1 && cnt % 2 == 0){
            ss2.push_back(s[1].substr(prev,i-prev+1));
            prev2 = i;
          }
        }
      }
      if(prev2 != (int)s[1].size() - 1){
        lastSS2 = s[1].substr(prev2,(int)s[1].size()-prev2);
      }

      if(firstSS2 != firstSS || lastSS2 != lastSS || ss2.size() != ss.size()){
        cout << "DIFFERENT" << "\n";
      }else{
        int cnt = 0;
        rep(i,ss.size()){
          if(ss[i] == ss2[i]) continue;
          else cnt++;
        }
        if(cnt == 1) cout << "CLOSE" << "\n";
        else cout << "DIFFERENT" << "\n";
      }
    }
  }
  return 0;
}



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

using namespace std;

int main()
{
   int n,m,c;
   cin>>n>>m>>c;
   vector<int>b(m);
   for(int i=0;i<m;i++)
   {
       cin>>b[i];
   }
   int ans=0,a;
   for(int i=0;i<n;i++)
   {
        int t=0;
       for(int j=0;j<m;j++)
       {
           cin>>a;
           t+=a*b[j];
       }
       if(t+c>0)
        ans++;
   }
cout<<ans<<endl;
}


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

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

  if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(0))
    puts("Yes");
  else
    puts("No");
}

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

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

int n;
vector <pii> ad[100007];
bool vis[100007];
bool col[100007];

void dfs(int a,bool c){
    col[a]=c;
    for (auto x : ad[a]){
        if (vis[x.fi]) continue;
        vis[x.fi]=1;
        if (x.se&1){
            dfs(x.fi,!c);
        } else {
            dfs(x.fi,c);
        }
    }
}

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

    cin >> n;
    memset(vis,0,n+3);
    memset(col,0,n+3);
    for (int i=1;i<n;i++){
        int a,b,w;
        cin >> a >> b >> w;

        ad[a].pb(mp(b,w));
        ad[b].pb(mp(a,w));
    }

    vis[1]=1;
    dfs(1,0);

    for (int i=1;i<=n;i++) cout << (col[i]) << el;

    return 0;
}

Measured memory_bytes: 8192
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> already(0);
  int n = 1;
  while(true) {
    if(n * a % b == c) {
      cout << "YES" << endl;
      return 0;
    }
    else {
      REP(i,(int)already.size()) {
        if(n * a % b == already[i]) {
          cout << "NO" << endl;
          return 0;
        }
      }
      already.push_back(n * a % b);
    }
    n++;
  }
  return 0;
}
//templete by private_yusuke

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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);  
    for(int i = 0; i < N; i++){
        cin >> V.at(i);
    } 
    for(int i = 0; i < N; i++){
        cin >> C.at(i);
    }
    int sum;
    sum = 0;
    for(int i = 0; i < N; i++){
        if(V.at(i) >= C.at(i)){
            sum += V.at(i) - C.at(i);
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  long int c, k;
  cin >> c >> k;
  vector<long int> t(n);
  for(int i = 0; i < n; i++){
    cin >> t.at(i);
  }
  sort(t.begin(), t.end());
  int rag = k;
  int count = 0;
  int bus = 0;
  for(int i = 0; i < n; i++){
    if(count == c){
      rag = k;
      count = 0;
    }
    if(rag == k){
      rag += t.at(i);
      bus++;
      count++;
      continue;
    }
    if(t.at(i) <= rag){
      count++;
    }else if(t.at(i) > rag){
      count = 1;
      rag = k + t.at(i);
      bus++;
    }
  }
  cout << bus;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  rep(i, S.size()){
    if(S.at(i) + N <= 'Z'){
      S.at(i) += N;
    }
    else{
      S.at(i) += N;
      S.at(i) -= 26;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
   int A[101][101];
   int i,j,r,c,m;
   scanf("%d %d",&r,&c);
   
	for(i=0;i<r+1;i++){
		for(j=0;j<c+1;j++){
		  A[i][j]=0;
		}
	}
	for(i=0;i<=r;i++){
	  for(j=0;j<=c;j++){
	  	if(j==c){
	  		if(i!=r){
	  		  A[r][c]+=A[i][j];
	  		}
	    }
	    else if(i!=r){
	      scanf("%d",&m);
	  	  A[i][c]+=m;
	  	  A[r][j]+=m;
	  	  A[i][j]=m;
	    }
	  }
	}
	for(i=0;i<r+1;i++){
	  for(j=0;j<c+1;j++){
	  	printf("%d",A[i][j]);
	  	if(j!=c){
	  		printf(" ");
	  	}
	  }
	  printf("\n");
	}
	return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0, ans1 = 0, ans2 = 0, acum = 0;
    REP(i, n) cin >> a[i];

    // a[0] > 0
    acum = a[0];
    if(a[0] <= 0) {
        acum = 1;
        ans1 += 1 - a[0];
    }
    FOR(i, 1, n-1) {
        if(i%2==0) {
            if(acum + a[i] > 0) {
                acum += a[i];
            } else {
                ans1 += 1 - (acum + a[i]);
                acum = 1;
            }
        } else {
            if(acum + a[i] < 0) {
                acum += a[i];
            } else {
                ans1 += 1 + (acum + a[i]);
                acum = -1;
            }
        }
        // cout << "i = " << i << " acum = " << acum << " ans1 = " << ans1 << endl;
    }

    // a[0] < 0
    acum = a[0];
    if(a[0] >= 0) {
        acum = -1;
        ans2 += a[0] + 1;
    }
    FOR(i, 1, n-1) {
        if(i%2==1) {
            if(acum + a[i] > 0) {
                acum += a[i];
            } else {
                ans2 += 1 - (acum + a[i]);
                acum = 1;
            }
        } else {
            if(acum + a[i] < 0) {
                acum += a[i];
            } else {
                ans2 += 1 + (acum + a[i]);
                acum = -1;
            }
        }

        // cout << "i = " << i << " acum = " << acum << " ans2 = " << ans2 << endl;
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

void solve(string S, string T) {
  int cnt{};

  for(auto i = 0; i!=3; ++i) {
    if (S[i] == T[i]) ++cnt;
  }
  cout << cnt << endl;
}

int main() {
  string S;
  cin >> S;
  string T;
  cin >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scn=new Scanner(System.in);
        int k=scn.nextInt();
        String s=scn.next();
        if(s.length()>k){
            System.out.println(s.substring(0,k)+"...");
        }else{
            System.out.println(s);
        }
    }
}


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

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


template <class Monoid>  class SegmentTree {
  private:
    using T = typename Monoid::T;
    using size_type = std::size_t;
    size_type n;
    std::vector<T> data;
    void prop(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }

  public:
    SegmentTree() : n(0) {}

    SegmentTree(int n, T initial = Monoid::identity()) : n(n) {
      data.resize(n * 2, initial);
      for(int i = n - 1; i > 0; i--) data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
    }

    template <class InputIter, class = typename std::iterator_traits<InputIter>::value_type>
    SegmentTree(InputIter first, InputIter last) : SegmentTree(distance(first, last)) {
      std::copy(first, last, data.begin() + n);
      for(int i = n - 1; i > 0; i--) prop(i);
    }

    SegmentTree(std::vector<T> v) : SegmentTree(v.begin(), v.end()) {}

    SegmentTree(std::initializer_list<T> v) : SegmentTree(v.begin(), v.end()) {}

    void set(size_t i, const T &v) {
      data[i += n] = v;
      while(i >>= 1) prop(i);
    }

    void add(size_t i, const T &v) {
      data[i += n] += v;
      while(i >>= 1) prop(i);
    }

    T get(size_t i) {
      return data[i + n];
    }

    T fold(int l, int r) {
      if(l < 0) l = 0;
      if(l >= r) return Monoid::identity();
      if(r > int(n)) r = n;
      T tmpL = Monoid::identity(), tmpR = Monoid::identity();
      for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if(l & 1) tmpL = Monoid::op(tmpL, data[l++]);
        if(r & 1) tmpR = Monoid::op(data[--r], tmpR);
      }
      return Monoid::op(tmpL, tmpR);
    }

    size_type size() { return n; }
};


template < class U = long long >
struct RangeMax {
  using T = U;
  static T op(const T &a, const T &b) { return std::max< T >(a, b); }
  static constexpr T identity() { return std::numeric_limits<T>::min(); }
};

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int h, w, m; std::cin >> h >> w >> m;
  std::vector<int> x(m), y(m); rep(i,m) std::cin >> x[i] >> y[i];
  rep(i,m) x[i]--, y[i]--;

  std::vector<int> indx(m); rep(i,m) indx[i] = i;
  std::sort( all(indx), [&](auto i, auto j) { return x[i] < x[j]; } );

  std::vector<int> sx(h), sy(w);
  rep(i,m) {
    sx[x[i]]++;
    sy[y[i]]++;
  }

  SegmentTree<RangeMax<ll>> sg(w);
  rep(i,w) sg.set(i,sy[i]);


  ll ans = 0;
  int s = 0, t = 0;
  for(int i=0; i<h; i++) {
    for(; t<m; t++) {
      if ( x[indx[t]] > i ) break;
      sg.add(y[indx[t]],-1);
    }
    ans = std::max<ll>(ans, sx[i] + sg.fold(0,w+1));
    for(int j=s; j<t; j++) sg.add(y[indx[j]],+1);
    s = t;
  }
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 13780
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def naive(n, as)
  max = as.max
  res = 0
  (max*1000).times{|i|
    temp = 0
    as.each{|a|
      temp += i%a
    }
    res = temp > res ? temp : res
  }
  return res
end

n = i()
as = li()

puts as.sum - n



Measured memory_bytes: 1916