akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()


int main(){
    double n; cin>>n;
    double st = n / 1.08;
    double en = (n+1) / 1.08;
    int nst = (int)ceil(st);
    int nen = (int)floor(en);
    if (en == nen) nen--;
    if (nst <= nen) cout<<nst<<endl;
    else cout<<":("<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
vector<int> v[maxn];
int num[maxn];
bool vis[maxn];

void solve() {
    int n, m;
    cin >> n >> m;
    while (m--) {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    queue<int> q;
    q.push(1);
    vis[1] = true;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (auto &to:v[now]) {
            if (vis[to])
                continue;
            vis[to] = true;
            num[to] = now;
            q.push(to);
        }
    }
    rep(i, 1, n)if (!vis[i]) {
            cout << "No";
            return;
        }
    cout << "Yes" << '\n';
    rep(i, 2, n)cout << num[i] << '\n';
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 17848
#include<stdio.h>
int main(void)
{
    int H,R,a,b;
    scanf("%d %d",&H,&R);
    a=H+R;
    if(a>0){
        b=1;
    }
    else if(a==0){
        b=0;
    }
    else{
        b=-1;
    }
    printf("%d\n",b);
    return(0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 100;
int arr[N],b[N];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	unordered_map<int, int> pos;
    int n;
    cin >> n;
    for(int i = 1;i <=  n;i++)cin >> arr[i],b[i] = arr[i],pos[arr[i]] = i;
  	sort(b + 1,b + 1 + n);
  	int ans = 0;
  	for(int i = 1;i <= n;i++){
  	    if((i % 2) != (pos[b[i]]) % 2){
  	        ans++;
  	    }
  	}
  	cout << (ans / 2);
  	return 0;
} 

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

int n[10];
char c[10];

bool check(vector<pair<int,char>> v){
    for (int i=0;i<2;++i)
        if (v[i+1].second!=v[i].second)
            return false;
    if (v[0].first==v[1].first&&v[1].first==v[2].first) return true;
    for (int i=0;i<2;++i)
        if (v[i+1].first-v[i].first!=1)
            return false;
    return true;
}

void solve(){
    bool ans=false;
    vector<int> perm(9);
    iota(perm.begin(),perm.end(),0);
    do {
        for (int i=0;i<3;++i){
            vector<pair<int,char>> v;
            for (int j=0;j<3;++j)
                v.emplace_back(n[perm[3*i+j]],c[perm[3*i+j]]);
            sort(v.begin(),v.end());
            if (!check(v)) break;
            if (i==2) ans=true;
        }
    } while(next_permutation(perm.begin(),perm.end()));
    cout << (ans?1:0) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T; cin >> T;
    for (;T--;){
        for (int i=0;i<9;++i) cin >> n[i];
        for (int i=0;i<9;++i) cin >> c[i];
        solve();
    }
}


Measured memory_bytes: 3124
from sys import stdin
import numpy as np

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = []
    for i in range(2 ** n):
        price = 0
        skill = []

        for j in range(1 << n):
            if ((i >> j) & 1) == 1:
                price += a[j][0]
                skill.append(a[j][1:])
        np_skill = np.array(skill)
        skill_sum = np.sum(np_skill, axis=0)\
                        if np_skill.shape[0] > 1 else np_skill

        if skill_sum.size != 0 and (skill_sum >= x).all():
            res.append(price)

    if not res: return print('-1')

    return print(min(res))

if __name__ == '__main__':
    main()


Measured memory_bytes: 27488
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y//be careful from the multiplication while using this define 
#define TC int t;cin>>t;while(t--)
//</DEFINE>
int n, m;
vector<vector<int>>v;
//<FUNCTIONS>
//</FUNCTIONS>	
int main() {
	Fast(), File();
	int n, cpcty;
	cin >> n >> cpcty;
	vector<vector<ll>>dp(n, vector<ll>(cpcty + 1));
	vector<pair<ll, ll>>v(n);
	for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;
	for (int i = v[n - 1].first; i <= cpcty; i++)dp[n - 1][i] = v[n - 1].second;
	for (int i = n - 2; i >= 0; i--) {
		for (int j = 1; j <= cpcty; j++) {
			if (j >= v[i].first)dp[i][j] = max(dp[i + 1][j - v[i].first] + v[i].second, dp[i + 1][j]);
			else dp[i][j] = dp[i + 1][j];
		}
	}
	cout << dp[0][cpcty] << endl;
}

Measured memory_bytes: 82380
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,w=mii()
wei,val=[0],[0]

for i in range(n):
    x,y=mii()
    wei.append(x)
    val.append(y)

dp = [[0]*(w+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,w+1):
        if j >= wei[i]:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-wei[i]]+val[i])
        else:
            dp[i][j] = dp[i-1][j]

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


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

int main()
{
	int sum1 = 0;
	int sum2 = 1;
	int num = 0;
	cin >> num;
	sum1 += num*2;
	sum2 *= num;
	cin >> num;
	sum1 += num*2;
	sum2 *= num;

	cout << sum2 << " " <<sum1<< std::endl;
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

typedef long long ll;

ll pow_mod(ll x,int k) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

ll facd[500005],facv[500005];

void pre(int n) {
  facd[0]=1;
  for(int i=1;i<=n;i++) facd[i]=facd[i-1]*i%MOD;
  facv[n]=pow_mod(facd[n],MOD-2);
  for(int i=n-1;i>=0;i--) facv[i]=facv[i+1]*(i+1)%MOD;
}

inline ll C(int n,int m) {
  return (n<m)?0:facd[n]*facv[m]%MOD*facv[n-m]%MOD;
}

int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  pre(k);
  int ans=0;
  if (!(k&1)&&(k>>1)>=n) {
  	ans=(ans+C(k-1,k>>1))%MOD;
  	ans=(ans-C(k-1,k-n+1)+MOD)%MOD;
  }
  for(int i=1;i<=k;i++)
    if (!((i^k)&1)&&((k+i)>>1)>=n) {
    	ans=(ans+C(k,(k+i)>>1))%MOD;
    	if (i<n) ans=(ans-C(k,k+i-n+1)+MOD)%MOD;
	}
  printf("%d\n",ans);
  return 0;
}

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

if N*10000 == Y:
    print(' '.join(map(str, (N, 0, 0))))
    exit()

for a in range(N):
    for b in range(N+1-a):
        c = N-a-b
        if a*10000 + b * 5000 + c * 1000 == Y:
            print(' '.join(map(str, (a, b, c))))
            exit()
print('-1 -1 -1')

Measured memory_bytes: 3064
n, k = map(int, input().split())
s = [int(x) for x in list(input())]

state = 1
cnt = 0
l = []
for e in s:
    if e != state:
        l.append(cnt)
        cnt = 1
        state = e
    else:
        cnt += 1

if cnt != 0:
    l.append(cnt)

if len(l) % 2 == 1:
    l.append(0)

Add = 2 * k + 1
ruiseki = [0]

for i, e in enumerate(l):
    ruiseki.append(ruiseki[i] + l[i])

answer = 0
for i in range(0, len(l), 2):
    left = i
    right = min(i + Add, len(l))
    tmp = ruiseki[right] - ruiseki[left]
    answer = max(tmp, answer)
 
print(answer)

Measured memory_bytes: 9240
#include<stdio.h>
char a[5];
int main()
{
		int i,n=1,max=1;
		scanf("%s",a);
		for(i=1;i<4;i++)
		{
			if(a[i]==a[i-1])n++;
			else n=1;
			if(n>max)max=n;
		} 
		if(max>=2)printf("Bad\n");
		else printf("Good\n");	    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end(),greater<int>());
  int64_t s=0;
  for(int i=1;i<n;i++)
    s+=a.at(i/2);
  cout<<s<<endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define req(i,n) for(int i = 1;i <= n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define fix  fixed << setprecision(10)
const int MOD = 1000000007;
const ll INF = (1LL << 60);
string t,u; ll n,h, m,k,q, ans =INF, sum, r,p,b;
bool f = true;
int main() {
    cin >> h >> n; vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<ll> dp(h + 10010, INF);
    dp[0] = 0;
    rep(i, h + 1) {
        rep(j, n) {
            dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
        }
    }
    for (int i = h; i <= h + 10000; i++) {
        ans = min(ans, dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}


signed main(){
	IOS
	int n;	cin >> n;
  	vector<int> a(n);
  	rep(i,n) cin >> a[i];
  	rep(i,n){
      	if(a[i] % 2 == 0){
      		if(a[i] % 3 != 0 && a[i] % 5 != 0){
      			cout << "DENIED\n";
      			return 0;

      		}
      	}
    }
    cout << "APPROVED\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
        cout << a * b << endl;
    }
    else
        cout << -1 << endl;
    return 0;
}

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

using namespace std;

pair<int, int> nxt[256][256];

int main()
{
    int h, w;
    vector<pair<int, pair<int, int> > > v;
    
    for (int i = 1; i <= 150; i++){
        for (int j = i + 1; j <= 150; j++){
            v.push_back(make_pair(i * i + j * j, make_pair(i, j)));
        }
    }
    
    sort(v.begin(), v.end());
    
    for (int i = 0; i < v.size() - 1; i++){
        pair<int, int> now = v[i].second, next = v[i + 1].second;
        nxt[now.first][now.second] = next;
    }
    
    while (scanf("%d %d", &h, &w) && w){
        printf("%d %d\n", nxt[h][w].first, nxt[h][w].second);
    }
    
    return (0);
}

Measured memory_bytes: 1832
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

#code-------------------------------------------------
x = ini()
for b in range(-121,121):
    for a in range(b,121):
        if (a ** 5) - (b ** 5) == x:
            break
    else:
        continue
    break
    
print(a,b)

Measured memory_bytes: 63968
S=input()

if S=='RRR':
    print(3)
elif S=='SSS':
    print(0)
elif S=='SRR':
    print(2)
elif S=='RSR':
    print(1)
elif S=='RRS':
    print(2)
elif S=='SSR':
    print(1)
elif S=='SRS':
    print(1)
elif S=='RSS':
    print(1)

Measured memory_bytes: 9120
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    a = int(readline())
    print(a + a * a + a * a * a)
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61680
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list=new ArrayList<String>();
		//int[] array = new int[1000000000*2];
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			String a = sc.next();
			list.add(a);
		}
		Collections.sort(list);
		List<Integer> list_count=new ArrayList<Integer>();
		for(int i=0;n-1>i;i++) {
			int count=0;
			if(list.get(i).equals(list.get(i+1))) {
				count++;
				i++;
				while(true) {
					if(i==n-1)
						break;
					if(!list.get(i).equals(list.get(i+1)))
						break;
					count++;
					i++;
				}
			}
			list_count.add(count);
		}
		int max = Collections.max(list_count);
		List<String> list_answer=new ArrayList<String>();
		if(max==0) {
			for(int i=0;list.size()>i;i++) {
				System.out.println(list.get(i));
			}
			System.exit(0);
		}
		for(int i=0;n-1>i;i++) {
			int count=0;
			if(list.get(i).equals(list.get(i+1))) {
				count++;
				i++;
				while(true) {
					if(i==n-1)
						break;
					if(!list.get(i).equals(list.get(i+1)))
						break;
					count++;
					i++;
				}
			}
			if(count==max)
				list_answer.add(list.get(i));
		}
		for(int i=0;list_answer.size()>i;i++) {
			System.out.println(list_answer.get(i));
		}
	}
}

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

int keisan(char *n);

int main(){
 char n[4];
 cin>>n;
 
 cout<<keisan(n);
 

}

int keisan(char *n){
    char *ptr = n;
    int m = 0,p = 0;
   while(*ptr != '\0'){
    if(*ptr == '+'){
        p++;
    }
    else{
        m--;
    }
    ptr++;
   }
   return p+m;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define done(x) {cout<<x<<"\n";return 0;} 
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    ll gcd=arr[0];
    for(int i=1;i<n;i++) gcd=__gcd(gcd,arr[i]);
    if((k%gcd) || arr[n-1]<k) done("IMPOSSIBLE\n")
    done("POSSIBLE\n") 
}

Measured memory_bytes: 4348
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int N;
    cin>>N;
    map<string, int> strmap;
    vector<string> strarr;
    string tmp;
    for(int i=0;i<N;i++){
        cin>>tmp;
        if(strmap[tmp]==0) strarr.push_back(tmp);
        strmap[tmp]++;
    }

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

    int num=0;
    for(int i=0;i<strarr.size();++i){
        if(strmap[strarr[i]] > num) num = strmap[strarr[i]];
    }

    for(int i=0;i<strarr.size();++i){
        if(strmap[strarr[i]] == num){
            cout<<strarr[i]<<endl;
        }
    }
}


Measured memory_bytes: 26736
game_time = int(input().strip())
game_cnt = 0
p_Taro = 0
p_Hanako = 0

while game_cnt < game_time:
    game_cnt = game_cnt + 1
    Taro, Hanako = input().split(" ")
    
    if Taro > Hanako:
        p_Taro = p_Taro + 3
    elif Taro < Hanako:
        p_Hanako = p_Hanako + 3
    else:
        p_Taro = p_Taro + 1
        p_Hanako = p_Hanako + 1
    
print(p_Taro, p_Hanako)

Measured memory_bytes: 7660
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

int  dp[100005],a[100005];

void solve(){
	int  n;
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i]; 
	dp[1] = 0,dp[2] = abs(a[2]-a[1]); 
	for (int i=3;i<=n;i++){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2])) ; 
	}
    cout <<  dp[n] << endl ;
}

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

Measured memory_bytes: 1792
n = int(input())
ans = 0
for m in range(1, int(n**0.5)+1):
    if n%m == 0 and m < n//m-1:
        ans += n//m -1
print(ans)
"""
while m <= int(n**0.5):
    if n % m == 0 and m < n // m:
        ans += n // m - 1
    m += 1
print(ans)
"""


Measured memory_bytes: 2940
#include <iostream>

int main() {
    int node_num(0);
    std::cin >> node_num;

    /* Generate Empty Matrix */
    int** graph(nullptr);
    graph = new int*[node_num];
    for (int i(0); i < node_num; ++i) {
        graph[i] = new int[node_num];
        for(int j(0); j < node_num; ++j) {
            graph[i][j] = 0;
        }
    }

    /* Input and Modify Matrix*/
    for(int i(0); i < node_num; ++i) {
        int node_index(0);
        int node_degree(0);
        std::cin >> node_index >> node_degree;
        for(int j(0); j < node_degree; ++j) {
            int tmp(0);
            std::cin >> tmp;
            graph[node_index-1][tmp-1] = 1;
        }
    }

    /* Output 隣接行列 */
    for(int i(0); i < node_num; ++i) {
        for(int j(0); j < node_num; ++j) {
            if(j != 0) {
                std::cout << " ";
            }
            std::cout << graph[i][j];
        }
        std::cout << "\n";
    }

    for(int i(0); i < node_num; ++i ){
        delete graph[i];
    }

    delete graph;

    return 0;
}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>

#include <iostream>
#include <vector>

std::unordered_map<long, long> mp;
std::vector<int> v;

int main(void) {
  std::string s,t;
  long cnt = 0;

  std::cin >> s >> t;

  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]){
      cnt++;
    }
  }

  std::cout << cnt << std::endl;
  

  return 0;
}

Measured memory_bytes: 3916
M,D = map(int,input().split())
count = 0
for i in range(1,M+1):
  for j in range(1,D+1):
    if j >21:
      a = j//10
      b = j%10
      if i == int(a*b) and a>=2 and b>=2:
        
        count += 1
print(count)

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

#endif


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

    ll X, Y; cin >> X >> Y;

    ll A = X;
    ll ans = 1;
    while(true) {
        A *= 2;
        if (A > Y) break;
        ans++;
    };

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n,greater<ll>());
    vector<ll>cnt;
    for(int i=1;i<=n;i++)
    {
        cnt.pb(a[i]);
        if(i==1)
            continue;
        cnt.pb(a[i]);

    }
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans+=cnt[i];
    }

    cout<<ans<<'\n';









}


Measured memory_bytes: 8204
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(void) {
  vector<int> num;

  for(int i=0; i<4; i++) {
    int tmp;
    cin >> tmp;
    num.push_back(tmp);
  }

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

  string str = "";
  for (int i=0; i<4; i++) {
    str += to_string(num[i]);
  }

  if(str == "1479"){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;

}


Measured memory_bytes: 256
//Country Road
#include <algorithm>
#include <iostream>
using namespace std;
int T, N, K, X[1000000+10], A[1000000+10], sum;
int main() {
  cin >> T; //???????????????????????°???????????????
  for (int t=0; t<T; ++t) {
    cin >> N; //??¶?????°???????????????
    cin >> K; //??????????????°???????????????
    for (int i=0; i<N; ++i) cin >> X[i]; //??¶??????????????\???
    for (int i=0; i+1<N; ++i) A[i] = X[i+1] - X[i]; //??¶??¨??¶??????
    sort(A,A+N-1); //??????A?????´?????????
    sum = 0;
    for (int i=0; i+K<N; ++i) sum += A[i]; //???????????????????¨????
    cout << sum << endl;
  }
}
    

Measured memory_bytes: 5668
#include <iostream>

using namespace std;

int gcd(int n, int m){
    if(n < m) swap(n, m);
    while(m != 0){
        int tmp = m;
        m = n%m;
        n = tmp;
    }
    return n;
}

int main(){
    int N, K;
    int A_max = 0;
    int A[100000];
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A_max = max(A_max, A[i]);
    }
    int m = A[0];
    for(int i = 1; i < N; i++){
        m = gcd(m, A[i]);
    }
    if(K%m == 0 && K <= A_max) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  int a, b, cnt = 0;
  cin >> a >> b;
  for (int i = a; i <= b; i++)
    if (to_string(i).at(0) == to_string(i).at(4)
        && to_string(i).at(1) == to_string(i).at(3))
      cnt++;
  cout << cnt << endl;
}

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

const int mxN = 25;
int dis[mxN][mxN];
char grid[mxN][mxN];

int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			cin >> grid[i][j];
	int answer = -1, cur;
	for(int i = 1; i<= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			memset(dis, 0x3F, sizeof dis);
			queue<pair<pair<int, int>, int>> bfs;
			bfs.push({{i, j}, 0});
			cur = dis[0][0];
			while(!bfs.empty()) {
				int x = bfs.front().first.first;
				int y = bfs.front().first.second;
				int cost = bfs.front().second;
				bfs.pop();
				if(dis[x][y] <= cost || x < 1 || x > n || y < 1 || y > m || grid[x][y] == '#')
					continue;
				dis[x][y] = cost;
				bfs.push({{x + 1, y}, cost + 1});
				bfs.push({{x, y + 1}, cost + 1});
				bfs.push({{x - 1, y}, cost + 1});
				bfs.push({{x, y - 1}, cost + 1});
			}
			for(int k = 1; k <= n; ++k) {
				for(int l = 1; l <= m; ++l) {
					if(dis[k][l] != cur)
						answer = max(answer, dis[k][l]);
				}
			}
		}
	}
	cout << answer;
}


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

template <typename Arg1>
void pn(Arg1&& arg1)
{ cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<"\n"; pn(args...); }

template <typename Arg1>
void ps(Arg1&& arg1)
{ cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void ps(Arg1&& arg1, Args&&... args)
{ cout<<arg1<<" "; ps(args...); }

template <typename Arg1>
void pvs(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)ps(arg1[i]); }
template <typename Arg1>
void pvn(Arg1&& arg1, ll n)
{ for(ll i=0;i<n;i++)pn(arg1[i]); }

ll lcm(ll a,ll b) 
{ return (a*b)/__gcd(a,b); }

ll mulmod(ll a,ll b,ll mod) 
{ ll res=0; a=a%mod; 
    while(b>0)
    { if(b%2==1) res=(res+a)%mod; 
      a=(a*2)%mod; b/=2; }
    return res % mod; } 

ll mulpow(ll x,ll y,ll p) 
{ ll res=1; x=x%p;
    while(y>0) 
    { if (y&1) res=(res*x)%p; 
      y=y>>1; x=(x*x)%p; } 
    return res; } 

ll modInverse(ll n, ll p) 
{ return mulpow(n, p-2, p); } 

ll log(ll n, ll b)
{ ll c=0;
	while(n>(b-1))
	{ c++; n/=b; } return c; }

ll fib(ll n) 
{ double phi=(1+sqrt(5))/2; 
  return round(pow(phi,n)/sqrt(5)); } 

vector<bool> prime;
void sieve(int n)
{ prime.resize(n,true);
	for(int p=2;p*p<=n;p++)
		if(prime[p])
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false; }

#define MOD 1000000007 //10^9+7
#define pi 3.14159265358979323846
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fd(i,n) for(i=n-1;i>=0;i--)
#define fn(i,s,d) for(i=s;i<d;i++)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define vl vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vvl vector<vl>
#define vs vector<string>
#define vvs vector<vs>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define vpl vector<pl>
#define vpd vector<pd>
#define vvpl vector<vpl>
#define ff first
#define ss second
#define um unordered_map
#define dsort(v) sort(v); reverse(v);


void solve()
{
	ll i,j;
	ll n,m,k;
	cin>>n>>m>>k;
	ll nn= n /k;
	ll mm=m/k;
	ll ans=mm-nn;
	if(n%k==0)
		ans++;
	pn(ans);
	return;
}

int main()
{
	#ifdef Deeksha
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
	std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	solve();/* 
	ll t;
	cin>>t;
	for(ll tt=1;tt<=t;tt++)
	{
		//cout<<"Case #"<<tt<<": ";
		solve();
	}
	//*/
}



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

#define ll  			int

ll dp[2][100005];
ll n, k, arr[101];

// 0 - winner is taro  // 1 - winner is jiro

void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	for (ll stones = 0; stones <= k; stones++) {
		for (int turn = 0; turn < 2; turn++) {
			dp[turn][stones] = (turn ? 0 : 1);
			for (int i = 0; i < n; i++) {
				if (stones - arr[i] < 0) {
					continue;
				}
				if (turn == 0) {
					ll ans = dp[!turn][stones - arr[i]];
					if (ans == 0) {
						dp[turn][stones] = 0;
					}
				}
				else {
					dp[turn][stones] = dp[turn][stones] || dp[!turn][stones - arr[i]];
				}
			}
		}
	}

	ll ans = dp[0][k];
	cout << (dp[0][k] ? "Second" : "First");
}

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


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

const int MAX = 500;

int main() {
	int H, W;
	int a[MAX][MAX];
	vector<pair<pair<int, int>, pair<int, int>>> ans;
	
	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			if (a[i][j] & 1) {
				ans.push_back(make_pair(make_pair(i, j), make_pair(i, j + 1)));
				a[i][j]--;
				a[i][j + 1]++;
			}
		}
	}

	for (int i = 0; i < H - 1; i++) {
		if (a[i][W - 1] & 1) {
			ans.push_back(make_pair(make_pair(i, W - 1), make_pair(i + 1, W - 1)));
			a[i][W - 1]--;
			a[i + 1][W - 1]++;
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].first.first + 1 << " ";
		cout << ans[i].first.second + 1 << " ";
		cout << ans[i].second.first + 1 << " ";
		cout << ans[i].second.second + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll prime_factor_num(ll n) {
    ll ret = 0;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            ret += 1;
            while (n % i == 0) n /= i;
        }
    }
    if (n != 1) ret += 1;
    return ret;
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll g = __gcd(A, B);
    cout << prime_factor_num(g) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>
#include <ctype.h> //toupper case
#include <tuple>


using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
const ll W = 1000000007;
const int alphacount = 26;
const string atcoyes = "Yes";
const string atcono = "No";



void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
}

class Main{
public:
    
    ll N; ll ans;
    Main(){
        std::cin>>N;
    }
    
    std::vector<int> getsoinsuu(ll child) {
        std::vector<int> ret;
        for(int i = 2 ; i<=sqrt(child); ++i){
            if(child%i == 0){
                child/=i;
                ret.push_back(i); i--; continue;
            }
        }
        if(child>=2) ret.push_back((int)child);
        return ret;
    }
    
    bool isOK(std::vector<int> &soinsuu , ll N, int W, int K){
        for(std::vector<int>::iterator it = soinsuu.begin();
            it<soinsuu.end();
            ++it){
            if(N%*it == 0){N/=*it; it = soinsuu.erase(it);}
        }for(std::vector<int>::iterator it = soinsuu.begin();
             it<soinsuu.end();
             ++it){
            if(W%*it == 0){W/=*it; it = soinsuu.erase(it);}
        }for(std::vector<int>::iterator it = soinsuu.begin();
             it<soinsuu.end();
             ++it){
            if(K%*it == 0){K/=*it; it = soinsuu.erase(it);}
        }
        ans = N * W * K;
        return soinsuu.empty();
    }
    void run(){
        const int maxval = 3500;
        for(int i = 0 ; i< maxval; i++){
            for(int j = 0; j < maxval; ++j){
                const int w = i; const int k = j;
                const ll child  = 4 * w * k - N * (w + k);
                if(child<=0) continue;
                std::vector<int> soinsuu = getsoinsuu(child);
                if(isOK(soinsuu,N,w,k)){
                    std::cout<<w<<" "<<k<<" "<<ans<<std::endl;
                    return ;
                }
            }
        }
    }
};

#ifndef gtest
int main(){
    omajinai();
    Main().run();
    return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n ; cin >> n;
    string s1,s2; cin >> s1 >> s2;
    ll ans = 1;
    ll idx = 0;
    ll is_tate = false;
    if(s1.at(0)==s2.at(0)){
        ans = 3; idx++;
        is_tate = true;
    }else{
        ans = 6; idx+=2;
        is_tate = false;
    }
    while(idx<n){
        if(s1.at(idx)==s2.at(idx)){
            if(is_tate){
                ans = ans * 2 % mod;
            }
            idx++;
            is_tate = true;
        }else{
            if(is_tate){
                ans = ans * 2 % mod;
            }else{
                ans = ans * 3 % mod;
            }
            idx+=2;
            is_tate = false;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  int a;
  vector<int> p(3);
  cin>>a;
  p[2]=a%10;
  p[1]=(a/10)%10;
  p[0]=(a/100)%10;
  a/=1000;
  vector<char> q(3);

  //——————————————bit全探索——————————————
  rep(i,8){
    int sum=a;
    rep(j,3){
      if(i & (1<<j)){
      sum+=p[j];
      q[j]='+';
      }
      else {
        sum-=p[j];
        q[j]='-';
      }
    }
    if(sum==7) {
      cout << a << q[0] << p[0] << q[1] << p[1] << q[2] << p[2] << "=7" << endl;
      return 0;
    }
  }

  //——————————————————————————————————————

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, A[60], B[60], v[60], P[60][60], U[65536][60];
bool Pos(long long s) {
	int i, j, k;
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= 50; j++)P[i][j] = 0;
		P[i][A[i]] = 1;
	}
	for (i = 50; i >= 1; i--) {
		if ((s >> i) & 1) {
			for (j = 1; j <= n; j++) {
				for (k = 0; k <= 50; k++)if (P[j][k])P[j][k%i] = 1;
			}
		}
	}
	for (i = 1; i <= n; i++)if (!P[i][B[i]])return false;
	return true;
}
int main() {
	int i, j, k;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 1; i <= n; i++)scanf("%d", &B[i]);
	long long s = 0;
	if (!Pos((1ll << 51) - 1)) {
		printf("-1\n");
		return 0;
	}
	for (i = 50; i >= 1; i--) {
		if (!Pos(s + (1ll << i) - 1)) {
			s += (1ll << i);
		}
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 128
import math
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: -int(x),input().split()))
heapq.heapify(a)
for i in range(m):
    a_max = heapq.heappop(a)
    heapq.heappush(a,-(-a_max//2))
print(-sum(a))

Measured memory_bytes: 14380
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	

	bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}


bool itta[300000];

int main() {
	
	cin >> N;

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

	a = 0;
	b = 1;
	c = 0;
	d = 0;
	for (int i = 0; i < N; i++) {
		a += A[i];
		if (b > 0) {
			if (a <= 0) {
				c += b - a;
				a = b;
			}
		}
		else {
			if (a >= 0) {
				c += a-b;
				a = b;
			}
		}

		b *= -1;
	}

	a = 0;
	b = 1;

	for (int i = 0; i < N; i++) {


		b *= -1;
		a += A[i];
		if (b > 0) {
			if (a <= 0) {
				d += b - a;
				a = b;
			}
		}
		else {
			if (a >= 0) {
				d += a - b;
				a = b;
			}
		}

	}

	cout << min(c, d) << endl;

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}


Measured memory_bytes: 8192
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program
{
    public static long ReadInt()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] ReadInts()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var s = ReadInt();
        bool x = 1 <= s % 100 && s % 100 <= 12;
        bool y = 1 <= s / 100 && s / 100 <= 12;
        if (x && y)
            Console.WriteLine("AMBIGUOUS");
        else if (!x && y)
            Console.WriteLine("MMYY");
        else if (x && !y)
            Console.WriteLine("YYMM");
        else
            Console.WriteLine("NA");


        Console.Out.Flush();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a[5];
  int ans;
  for(int i=0;i<2;i++){
    cin>>a[i];
  }
  sort(a,a+2);
  ans=a[1];
  a[1]--;
  sort(a,a+2);
  ans+=a[1];
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
void fun(vi v,int p,int t){
	int s=0;
	REP(i,0,v.size()-1){
		if(i==p-1){
			s+=t;
		}
		else s+=v[i];
	}
	cout<<s<<"\n";
}
//--main function
int main(){
	int n,m,p,t;
	cin>>n;
	vi v(n);
	REP(i,0,n-1)cin>>v[i];
	cin>>m;
	REP(i,1,m){
		cin>>p>>t;
		fun(v,p,t);
		
	}
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
def check(i)
#  puts "i=#{i}"
#  puts "gs[i]=#{$gs[i]}"
  $gs[i][1] = 1
  $gs[i][0].each{|temp|
#    puts "next_color:#{$gs[temp][1]}"
    if $gs[temp][1] == 1
#      puts "next:#{$gs[temp][1]}"
      $cflag = true
    elsif $gs[temp][1] == 0
      check(temp)
    end
  }
  $gs[i][1] = -1
end

$gs = []
$cflag = false
v,e = gets.split.map(&:to_i)
v.times{
  $gs << [[],0]
}
e.times do
  s,t = gets.split.map(&:to_i)
  $gs[s][0] << t
end
$gs.each_with_index{|g,i|
  if g[1] == 0
    check(i)
  end
}
if $cflag
  puts "1"
else
  puts "0"
end



Measured memory_bytes: 8912
n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for j in range(1,n+1):
        if i - j < 0 or i + j >= n:
            break
        if s[i-j] != s[i] and s[i] != s[i+j] and s[i+j] != s[i-j]:
            ans -= 1

print(ans)

Measured memory_bytes: 9204
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;
typedef long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)

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

	int N;
	cin >> N;

	int k = 2;
	bool found = false;
	while(true)
	{
		int number = k*(k-1)/2;
		if ( number < N )
		{
			k++;
			continue;
		}
		if (number > N)
		{
			break;
		}
		if (number == N)
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
		cout << k << endl;
		int a[k][k - 1];
		memset(a, 0, sizeof(int) * k * (k-1));
		for (int i = 0; i < k; i++)
		{
			int step = 1;
			int v_step = i - 1;
			int v_times = i - 1;
			for (int j = 0; j < k - 1; j++)
			{
				if (i == 0)
				{
					if (j == 0)
					{
						a[i][j] = 1;
						cout << k - 1 << " ";
					}
					else
					{
						cout << " ";
						a[i][j] = a[i][j-1] + step;
						step++;
					}
					cout << a[i][j];
					
				}
				else
				{
					if (v_times > 0)
					{
						a[i][j] = a[i-1][j] + v_step;
						v_times--;
					}
					else if (v_times == 0)
					{
						a[i][j] = a[i-1][j];
						v_times--;
					}
					else
					{
						a[i][j] = a[i-1][j] + 1;
					}
					if (j > 0)
					{
						cout << " ";
					}
					else if (j == 0)
					{
						cout << k - 1 << " ";
					}
					cout << a[i][j];
				}
			}
			cout << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 2176
x = int(input())
alist = list(map(int, input().split()))
tallest=alist[0]
sums=0
for i in range(1,len(alist)):
    if alist[i]<=tallest:
        sums+=tallest-alist[i]
    else:
        tallest=alist[i]
print(sums)

Measured memory_bytes: 32380
#include<bits/stdc++.h>
    #define M 1000000007
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define mem0(a) memset(a,0,sizeof(a))
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    using namespace std;
    int main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=0;
    	string s;
    	cin>>s;
    	if(s[2]==s[3] && s[4]==s[5])
    		cout<<"Yes";
    	else
    		cout<<"No";
    	return 0;
    }

Measured memory_bytes: 256