akhauriyash/Code-Regression huggingface dataset:
struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

let MOD = 998244353

struct Zn: CustomStringConvertible {
    let n: Int

    init(_ n: Int) {
        self.n = n
    }

    var description: String {
        String(self.n)
    }

    static var zero = Zn(0)
    static var one = Zn(1)

    static func + (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n + rhs.n
        return Zn(n < MOD ? n : n - MOD)
    }

    static func + (lhs: Self, rhs: Int) -> Self {
        return lhs + Zn(rhs)
    }

    static func + (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) + rhs
    }

    static func - (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n - rhs.n
        return Zn(n >= 0 ? n : n + MOD)
    }

    static func - (lhs: Self, rhs: Int) -> Self {
        return lhs - Zn(rhs)
    }

    static func - (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) - rhs
    }

    static func * (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n * rhs.n) % MOD)
    }

    static func * (lhs: Self, rhs: Int) -> Self {
        return lhs * Zn(rhs)
    }

    static func * (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) * rhs
    }

    static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }

    static func += (lhs: inout Self, rhs: Int) {
        lhs = lhs + Zn(rhs)
    }

    static func -= (lhs: inout Self, rhs: Self) {
        lhs = lhs - rhs
    }

    static func -= (lhs: inout Self, rhs: Int) {
        lhs = lhs - Zn(rhs)
    }

    static func *= (lhs: inout Self, rhs: Self) {
        lhs = lhs * rhs
    }

    static func *= (lhs: inout Self, rhs: Int) {
        lhs = lhs * Zn(rhs)
    }

    func pow(_ n: Int) -> Self {
        if n == 0 {
            return Zn(1)
        } else if n % 2 == 1 {
            return self * self.pow(n - 1)
        } else {
            return (self * self).pow(n / 2)
        }
    }

    var inverse: Self {
        self.pow(MOD - 2)
    }
}

var scanner = Scanner()
let N = scanner.nextInt()
let M = scanner.nextInt()

var G = [[Int]](repeating: [], count: N)

for _ in 0 ..< M {
    let u = scanner.nextInt() - 1
    let v = scanner.nextInt() - 1
    G[u].append(v)
    G[v].append(u)
}

var visited = [Bool](repeating: false, count: N)

func dfs(_ v: Int) {
    visited[v] = true
    for c in G[v] where !visited[c] {
        dfs(c)
    }
}

var answer = 0
for i in 0 ..< N where !visited[i] {
    answer += 1
    dfs(i)
}
print(answer - 1)


Measured memory_bytes: 15808
#include <bits/stdc++.h>
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    long long N;
    cin >> N;
    vector<long long> B(N);
    long long ans = 0;
    for(int i = 0; i < N - 1; i++){
        cin >> B[i];
        ans += 2 * B[i];
    }
    for(int i = 0; i < N - 2; i++){
        if(B[i] > B[i+1]){
            ans -= B[i];
        } else {
            ans -= B[i+1];
        }
    }
    cout << ans << endl;





}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = [int(readline()) for _ in range(N)]
    c = Counter(A)
    ans = 0
    for _, v in zip(c.keys(), c.values()):
        if v % 2 == 1:
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 16640
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int n;
vector<int> to[100005];
vector<int> dist(n);

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : to[v]) {
        if (u == p) continue;
        dfs(u,d+1,v);
    }
}

vector<int> calc(int x) {
    dist = vector<int>(n);
    dfs(x);
    return dist;
}

int main() {
    int s, t;
    cin >> n >> s >> t;
    s--; t--;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vector<int> distS = calc(s);
    vector<int> distT = calc(t);

    int ans = 0;
    rep(i,n) {
        if (distS[i] < distT[i]) {
            ans = max(ans, distT[i]-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13660
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] a = new long[n];
		ArrayDeque<Long> b = new ArrayDeque<Long>();
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextLong();
		}
		for(int i = 0; i < n; i++) {
			if(i % 2 != n % 2) {
				b.addFirst(a[i]);
			} else {
				b.addLast(a[i]);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(b.pollFirst());
			if(i < n - 1) {
				System.out.print(" ");
			}
		}
		scan.close();
	}

}


Measured memory_bytes: 102748
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
int n,ans;
char s[500];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1);
	for(ri i=1;i<=n/2;++i)
		ans+=s[i]!=s[n-i+1];
	print(ans);
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    b, c = map(int, input().split())
    bc.append([c, b])
a.sort()
bc.sort(reverse = True)
x = [0] * n
i, j = 0, 0
while i < n:
    for _ in range(bc[j][1]):
        x[i] = bc[j][0]
        i += 1
        if i == n:
            break
    j += 1
    if j == m:
        break
ans = 0
for i in range(n):
    ans += max(a[i], x[i])
print(ans)

Measured memory_bytes: 28976
n,q = map(int,input().split())
L = [[] for _ in range(n)]

for i in range(q):
    query = input().split()

    if query[0] == "0":
        L[int(query[1])].append(query[2])
    elif query[0] == "1":
        print(*L[int(query[1])])
    else:
        L[int(query[1])] = []


Measured memory_bytes: 42528
#include <bits/stdc++.h>
using namespace std;
int n,a;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&a);
		if(!(a%2))
			if(a%3)
				if(a%5)
				{	
					printf("DENIED");
					return 0;
				}
	}
	printf("APPROVED");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int x){
	for(int j=2;j*j<=x;j++){
		if(x%j==0) return false;
	}
	return true;
}
int main(){
	int n,ans;
	cin>>n;
	for(int i=n;i<=100004;i++){
		if(is_prime(i)){
			ans=i; break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int k,a,b;
    int f=0;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
          f++;
        }
    }
    if(f>0) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}


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

using namespace std;

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int arr[100001], n, cnt[100005] = {};
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
    cnt[ arr[i] ]++;
  }

  int ans = 0;
  for(int i = 1; i <= 100000; ++i) {
    ans = max(ans, cnt[i] + cnt[i - 1] + cnt[i + 1]);
  }

  cout << ans;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(void) {
	int n;
	int maxi = 10000000;
	int now;
	int a[201];

	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = 1; i < n; i++) {
		now = 0;
		while (a[i] % 2 == 0) {
			now++;
			a[i] /= 2;
		}
		if (now < maxi) {
			maxi = now;
		}
	}

	cout << maxi << endl;

	return 0;
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,A[111];

ll i, j, k;

int main(){
    scanf("%lld", &N);
    j = 0;
    rep(i,0,N){
        scanf("%lld", &A[i]);
        if(i%2==0&&A[i]%2==1)
            ++j;
    }
    printf("%lld\n", j);
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
using namespace std;
int gcd(int a, int b){
  if(a < b){
    swap(a,b);
  }
  if(b == 0) return a;
  return gcd(b,a%b);
}
int main(){
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int i = 0; i < N; ++i)
    cin >> A[i];
  int G = A[0], M = 0;
  for(int i = 0; i < N; ++i){
    M = max(A[i],M);
    G = gcd(A[i],G);
  }
  if(K <= M && K%G == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 640
def p_c():
    n, A, B, C = map(int, input().split())
    li = [int(input()) for _ in range(n)]
    INF = 10 ** 9

    def dfs(cur, a, b, c):
        if cur == n:
            return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
        ret1 = dfs(cur + 1, a, b, c)
        ret2 = dfs(cur + 1, a + li[cur], b, c) + 10
        ret3 = dfs(cur + 1, a, b + li[cur], c) + 10
        ret4 = dfs(cur + 1, a, b, c + li[cur]) + 10
        return min(ret1, ret2, ret3, ret4)

    print(dfs(0, 0, 0, 0))
    
p_c()

Measured memory_bytes: 44380
/*ربى اصلح لى شأنى*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define el '\n';
long long  gcd(long long  a, long long  b) { return !b ? a : gcd(b, a % b); }
long long  lcm(long long a, long long  b) { return (a / gcd(a, b)) * b; }
long long  fact(long long  n) { return !n ? 1 : n * fact(n - 1); }
using namespace std;
const  double PI = acos(-1);
/* smile ^_^ */
using lli = long long int;
using namespace std;
void ezzo()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);


}
int main()
{
	ezzo();
	double r; cin >> r;
	cout << 3 * (r*r) << el;
	//memset(a, 0, sizeof a);//تصفير الاراى 
	//cout << fixed << setprecision(9) << a << el;
}

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

using namespace std;

struct Cake
{
	long long x;
	long long y;
	long long z;
};

int main()
{
	int n, m;
	cin >> n >> m;
	
	vector<Cake> v(n);
	for(int i = 0; i < n; i++)
	{
		cin >> v[i].x >> v[i].y >> v[i].z;
	}
	
	long long ans = 0;
	for(int i = 0; i < 2; i++)
	{
		for(int j = 0; j < 2; j++)
		{
			for(int k = 0; k < 2; k++)
			{
				if(i == 0)
				{
					if(j == 0)
					{
						if(k == 0)
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (a.x + a.y + a.z) > (b.x + b.y + b.z);});
							
						}
						else
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (a.x + a.y - a.z) > (b.x + b.y - b.z);});
						}
					}
					else
					{
						if(k == 0)
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (a.x - a.y + a.z) > (b.x - b.y + b.z);});
						}
						else
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (a.x - a.y - a.z) > (b.x - b.y - b.z);});
						}
					}
				}
				else
				{
					if(j == 0)
					{
						if(k == 0)
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (-a.x + a.y + a.z) > (-b.x + b.y + b.z);});
						}
						else
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (-a.x + a.y - a.z) > (-b.x + b.y - b.z);});
						}
					}
					else
					{
						if(k == 0)
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (-a.x - a.y + a.z) > (-b.x - b.y + b.z);});
						}
						else
						{
							sort(v.begin(), v.end(), [](const Cake &a, const Cake &b){return (-a.x - a.y - a.z) > (-b.x - b.y - b.z);});
						}
					}
				}
				
				long long beu = 0;
				long long del = 0;
				long long pop = 0;
				for(int l = 0; l < m; l++)
				{
					beu += v[l].x;
					del += v[l].y;
					pop += v[l].z;
				}
				
				ans = (ans > (abs(beu) + abs(del) + abs(pop))) ? ans : (abs(beu) + abs(del) + abs(pop));
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
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<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int M = 4000;
int a[M][M];
char ans[500][500];
string color = "RYGB";

int main() {
	int h, w, d;
	cin >> h >> w >> d;

	int r = d;

	REP(i,M) REP(j,M){
		int x = i / r;
		int y = j / r;
		a[i][j] = 2 * (x%2) + (y%2);
	}

	// REP(i,30){
	// 	REP(j,30){
	// 		cout << a[i][j];
	// 	}
	// 	cout << endl;
	// }

	REP(i,h) REP(j,w){
		ans[i][j] = color[a[2000+i-j][1000+i+j]];
	}

	REP(i,h){
		REP(j,w){
			cout << ans[i][j];
		}
		cout << endl;
	}


    return 0;
}





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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

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

int a[10];
bool used[11];

int judge(){
  /*  int A = (a[0]+a[1]+a[2])%j, B = (a[3]+a[4]+a[5])%j, C = (a[6]+a[7]+a[8])%j;
  int D = (a[0]+a[3]+a[6])%j, E = (a[1]+a[4]+a[7])%j, F = (a[2]+a[5]+a[8])%j;
  int G = (a[0]+a[4]+a[8])%j, H = (a[2]+a[4]+a[6])%j;
  if(A != B) return 0;
  if(A != B || B != C || C != D || D != E || E != F || F != G || G != H || H != A) return 0;*/

  /*  int A = (a[0]+a[1]+a[2]), B = (a[3]+a[4]+a[5]), C = (a[6]+a[7]+a[8]);
  int D = (a[0]+a[3]+a[6]), E = (a[1]+a[4]+a[7]), F = (a[2]+a[5]+a[8]);
  int G = (a[0]+a[4]+a[8]), H = (a[2]+a[4]+a[6]);
  A %= j; B %= j; C %= j; D %= j; E %= j; F %= j; G %= j; H %= j;
  if((int)A != (int)B) return 0;*/
  //  if(A != B || B != C || C != D || D != E || E != F || F != G || G != H || H != A) return 0;
  /*  rep(i, 3){
    rep(j, 3) printf("%d ", a[i*3+j]);
    puts("");
    }*/
  int mod = a[9];
  int sum = (a[0]+a[1]+a[2])%mod;
  if((a[3]+a[4]+a[5])%mod != sum || (a[6]+a[7]+a[8])%mod != sum) return 0;
  if((a[0]+a[3]+a[6])%mod != sum || (a[1]+a[4]+a[7])%mod != sum || (a[2]+a[5]+a[8])%mod != sum) return 0;
  if((a[0]+a[4]+a[8])%mod != sum || (a[2]+a[4]+a[6])%mod != sum) return 0;
  return 1;
}

int dfs(int n, bool *used){
  if(n == 10) return judge();
  if(a[n]) return dfs(n+1, used);
  int res = 0;
  REP(i, 1, 11){
    if(used[i]) continue;
    a[n] = i;
    used[i] = 1;
    res += dfs(n+1, used);
    a[n] = 0;
    used[i] = 0;
  }
  return res;
}

int main(){
  while(1){
    bool used[11];
    memset(used, 0, sizeof(used));
    rep(i, 10){
      scanf("%d", a+i);
      if(a[i]) used[a[i]] = 1;
    }
    if(a[0] == -1) break;

    printf("%d\n", dfs(0, used));
  }
  return 0;
}

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

bool stone[2000002];

int main(){

    int k, x;
    cin >> x >> k;

    int begin, end;
    if(k - x + 1 < -1000000) begin = -1000000;
    else begin = k - x + 1;
    if(k + x - 1 > 1000000) end = 1000000;
    else end = k + x - 1;
    
    for(int i = begin; i <= end; i++){
        cout << i << " ";
    }

    cout << endl;

    return 0;
}

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

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

	int N,K;
	cin >> N >> K;
	int s[N] = {0};
	for (int i = 1; i <= K; i++) {
		int d;
		cin >> d;
		while (d--) {
			int k;
			cin >> k;
			s[k-1]++;
		}
	}
	int count = 0;
	for (int i = 0; i < N; i++) {
		if (!s[i]) count++;
	}
	cout << count;
	return 0;
}




Measured memory_bytes: 3640
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N;
  invec<int> P(N);
  int min = 999999999;
  int r = 0;
  
  REP(i,N) {
    if (min > P[i]) {
      min = P[i];
      r++;
    }
  }

  return r;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, m;
    cin >> n >> m;
    int s = 0;
    fr(i, 0, m) {
        int x; cin >> x; s += x;
    }
    cout << max(-1LL, n - s);
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
int prime[800];
int c;
int isPrime(int n){
	int i;
	for(i=0;i<c && prime[i]<n;i++){
		if(n==prime[i]){
			return 1;
		}
		if(n%prime[i]==0){
			return 0;
		}
	}
	for(i=3;i<n/2;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int num,i,j;
	prime[0]=2;
	prime[1]=3;
	prime[2]=5;
	prime[3]=7;
	c=4;
	int bf,af;
	for(i=8;i<500;i++){
		if(isPrime(i)){
			prime[c]=i;
			c++;
		}
	}
	for(;scanf("%d",&num)!=EOF;){
		for(i=2;i<num;i++){
			if(isPrime(i))bf=i;
		}
		for(i=num+1;1;i++){
			if(isPrime(i)){
				af=i;
				break;
			}
		}
		printf("%d %d\n",bf,af);
	}
	return 0;
}

Measured memory_bytes: 404
x = list(map(int,input().split()))
sum = 0
for i in range(1,x[0]+1):
    if i == 10000:
        b=1
    else:
        a3 = int(i/1000)
        a2 = int((i-1000*a3)/100)
        a1 = int((i-1000*a3-100*a2)/10)
        a0 = i-1000*a3-100*a2-10*a1
        b = a0+a1+a2+a3
    if b>=x[1] and b<=x[2]:
        sum += i
print(sum)

Measured memory_bytes: 3060
import math
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

mli = [A % 10 if A % 10 != 0 else 999, B % 10 if B % 10 != 0 else 999, C % 10 if C % 10 != 0 else 999,
      D % 10 if D % 10 != 0 else 999, E % 10 if E % 10 != 0 else 999]

last=mli.index(min(mli))

li=[A,B,C,D,E]

for i in range(len(li)):
      if last==i:
            pass
      else:
            li[i]=math.ceil(float(li[i]/10))*10
print(sum(li))




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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_NOde_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
	#ifdef LOCAL_TEST
	freopen("in.txt","r",stdin);
	//freopen("out.txt", "w", stdout);
	#else
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	#endif

	ll n;
	cin>>n;
	vector<pair<string,ii> > v;
	for(int i=1;i<=n;i++)
	{
		string s;
		ll p;
		cin>>s>>p;
		//cout << s << " " << p << " ";
		v.pb(mp(s,mp(-p,i)));
	}

	sort(all(v));

	for(int i=0;i<v.size();i++)
	{
		cout << v[i].second.second << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
import sys, math
line = [s.rstrip("\n") for s in sys.stdin.readlines()][0]
a_point, a_offence, b_point, b_offence = [int(n) for n in line.split(" ")]
j = math.ceil(float(b_point) / a_offence)
k = math.ceil(float(a_point) / b_offence)
if j <= k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9100
#include <iostream>
#include <map>
using namespace std;
int main(){
  int N,X,Y; cin>>N>>X>>Y;
  map<int,int> mp;
  for(int i=1;i<=N;++i){
    for(int j=1;j<i;++j){
      int d1,d2;
      d1 = i-j;
      d2 = abs(j-X) + abs(i-Y) + 1;
      ++mp[min(d1,d2)];
    }
  }
  for(int k=1;k<=N-1;++k){
    cout << mp[k] <<"\n";
  }
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int k; cin >> k;
    int x = 0;
    int ans = 1;
    for (int i = 0; i<1001001; ++i) {
        x = (x*10+7)%k;
        if (x == 0) {
            cout << ans << endl;
            return 0;
        }
        ++ans;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll res = a[n-1];
    for (int i = 0; i < (n-2) / 2; ++i) {
        res += a[n-2-i] * 2;
    }
    if (n % 2) res += a[n-2-(n-2)/2];
    cout << res << endl;
}

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

int main() {
	// your code goes here
	int a[5],sum=15;
	for(int i=0; i<5; i++){
		cin>>a[i];
	}
	for(int i=0;i<5;i++){
		sum=sum-a[i];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    int N;cin>>N;
    vector<char> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    vector<char> T(N/2);
    if(N%2!=0){
        cout<<"No";
        return 0;
    }
    for(int i=0;i<N/2;i++){
        if(S[i]!=S[N/2+i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#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++)


const int mod = 1e9 + 7;

int bittoint(vector<bool> bits)
{
    int ret, lb;
    ret = 0;
    lb = bits.size();
    rep(i, lb)
    {
        if (bits[i])
            ret += pow(2, lb - 1 - i);
    }
    return ret;
}

vector<int> bit_or_candidate(int k)
{
    int lk, x;
    vector<int> ret;
    vector<bool> bits, bits2;
    ret.push_back(k);

    x = k;
    lk = 0;
    while (x > 0)
    {
        bits.push_back(x % 2);
        lk++;
        x /= 2;
    }

    reverse(bits.begin(), bits.end());
    bits2.resize(lk);

    rep(i, lk)
    {
        rep(j, i)
        {
            if (j >= 0)
                bits2[j] = bits[j];
        }

        if (bits[i])
        {
            bits2[i] = 0;
            rep2(j, i + 1, lk)
                bits2[j] = 1;
        }
        else
        {
            rep2(j, i, lk)
                bits2[j] = bits[j];
        }
        ret.push_back(bittoint(bits2));
    }
    return ret;
}

ll orsum(vector<int> num, vector<int> value, int k)
{
    ll ret = 0;
    int n = num.size();
    rep(i, n)
    {
        if ((num[i] | k) == k)
            ret += value[i]; 
    }
    return ret;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, a, b;
    cin >> n >> k;
    ll ans = 0;
    vector<int> num, value, candidate;
    rep(i, n)
    {
        cin >> a >> b;
        num.push_back(a);
        value.push_back(b);
    }

    candidate = bit_or_candidate(k);

    for (auto z : candidate)
    {
        ans = max(ans, orsum(num, value, z));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ldb;
typedef unsigned int ui;
typedef unsigned long ul;
 
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
typedef priority_queue<pi> pq;
typedef priority_queue<int,vector<int>,greater<int>> pqg;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound


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

int n;
string s;
cin>>n>>s;

int l=0, r=n-1, counter=0;
while(l<r){
	if(s[l]=='R') l++;
	else if(s[r]=='W') r--;
	else{
		counter++;
		l++;
		r--;
	}
}

cout<<counter;
return 0; 
}


Measured memory_bytes: 3676
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))

for i,a in enumerate(A):
    if a == 1:
        MINI = a
        idx = i
ans = 2 ** 30 - 1

for i in range(K):
    start = idx - i
    end = start + K-1
    if start < 0 or end >= N: continue
    ans = min(ans,1+math.ceil(start/(K-1))+math.ceil((N-end-1)/(K-1)))
    
print(ans)

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


int main(){
  long long int num;
 string s;
 cin>>num;
 cin>>s;
 if(num%2!=0){
  cout<<"No"<<endl;
 }else{
  if(s.substr(num/2,num/2)+s.substr(num/2,num/2)==s){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
 }
}




Measured memory_bytes: 256
n,y=map(int,input().split())
flag=True
for i in range(n+1):
    if flag:
        for j in range(n-i+1):
            k=n-i-j
            if 10000*i+5000*j+1000*k==y:
                print('{} {} {}'.format(i,j,k))
                flag=False
                break
    else:
        break
if flag:
    print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;

    int slen = s.length();
        
    s = "#" + s + "#";

    reps(i, a, d-1){
        if(s[i] == '#' && s[i+1] == '#'){
            ans(false);
            return 0;
        }
    }

    if(c < d) ans(true);
    else{
        reps(i, b, d){
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
                ans(true);
                return 0;
            }
        }
        ans(false);
    }

    return 0;
}


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

 int main() {
   int A, B;
   cin >> A >> B;
   bool S = true;
   for (size_t i = min(A, B); i <max(A, B) ; i++) {
    if (A - i == i - B) {
      cout << i << '\n';
      S = false;
      break;
    }
  }
  if (S) {
     cout << "IMPOSSIBLE" << '\n';
  }
 }


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

// Input number
func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func main() {
	X := scanIntNum()
	money := 100
	var tmp float64

	for i := 1; ; i++ {
		tmp = float64(money) * 1.01
		money = int(tmp)
		if money >= X {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 1760
N, P = gets.split.map(&:to_i)
S = gets.chomp.split("").map(&:to_i).reverse
=begin
N=2*10**5
P=9973
ss=[]
N.times do
  ss<<rand(0..9)
end
S=ss
=end

if P == 2 || P == 5
  ans = 0
  N.times do |i|
    if S[i] % P == 0
      ans += N-i
    end
  end
  puts ans

  
else

  rui = Array.new(N+1, 0)
  amaris = Array.new(P, 0)
  
  ten = 1
  N.times do |i|
    a = (S[i]*ten) % P
    rui[i+1] = (rui[i] + a) % P
    ten = (ten * 10) % P
    amaris[rui[i+1]] += 1
  end
  
  ans = amaris[0]
  amaris.each do |amari|
    ans += amari*(amari-1)/2
  end
  puts ans
end


Measured memory_bytes: 17532
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<cstdlib>
#include<unordered_map>
#include<time.h>
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 999999999999999999;
using namespace std;
int h, w, n;
int a[10000];
int ans[100][100];
signed main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int y = 0, x = 0;//今の位置
	int t = 0;//使っている色
	for (int i = 0; i < h*w; i++) {
		ans[y][x] = t + 1;
		a[t]--;
		if (y % 2 == 0 && x == w - 1)
			y++;
		else if (y % 2 == 0)
			x++;
		else if (y % 2 == 1 && x == 0)
			y++;
		else
			x--;
		if (a[t] == 0)
			t++;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)
			if (j == 0)
				cout << ans[i][j];
			else
				cout << " " << ans[i][j];
		cout << endl;
	}
	getchar(); getchar();
}

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

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

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

    // start
    int n, k;
    cin >> n >> k;
    rep(i, n)
    {
        char s;
        cin >> s;
        if (i + 1 == k)
            cout << (char)tolower(s);
        else
            cout << s;
    }
    cout << endl;
    // end

    return 0;
}


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

int main() {
	int64_t X, Y;
	cin >> X >> Y;
	int ans = 0;
	while (true) {
		if (X > Y) {
			cout << ans << endl;
			return 0;
		}
		X *= 2;
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int nf=1e9+7;

const int maxn=1e5+10;

int ans[maxn];

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	string str;
	
	while(cin>>str)
	{
		memset(ans,0,sizeof(ans));
		
		vector<int>v;
		
		v.clear();
		
		int place=str.find("RL",0);
		
		while(place!=-1)
		{
			v.push_back(place);
			
			place=str.find("RL",place+2);
		}
		
		int nowR,nowL;
		for(int i=0;i<v.size();i++)
		{
			nowR=v[i];
			nowL=v[i]+1;
			
			ans[nowR]++;
			ans[nowL]++;
			
			int now=0;
			for(int j=nowR-1;j>=0;j--)
			{
				if(ans[j]||str[j]=='#')
					break;
				
				if(str[j]=='R')
				{
					if(now==0)
					{
						ans[nowL]++;
						now=1;
					}
					else
					{
						ans[nowR]++;
						now=0;
					}
					str[j]='#';
				}
				else
					break;	
			}
			
			now=0;
			for(int j=nowL+1;j<str.size();j++)
			{
				if(ans[j]||str[j]=='#')
					break;
				
				if(str[j]=='L')
				{
					if(now==0)
					{
						ans[nowR]++;
						now=1;
					}
					else
					{
						ans[nowL]++;
						now=0;
					}
					str[j]='#';
				}
				else
					break;	
			}	
		}
		
		cout<<ans[0];
		for(int i=1;i<str.size();i++)
			cout<<" "<<ans[i];
		cout<<endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1232
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

//1-indexed
class BIT {
public:
    ll n; //データの長さ
    vector<ll> bit; //データの格納先
    BIT(ll n):n(n),bit(n+1,0){} //コンストラクタ

    //k & -kはLSB

    //bit_iにxをO(log(n))で加算する
    void add(ll i,ll x){
        if(i==0) return;
        for(ll k=i;k<=n;k+=(k & -k)){
            bit[k]+=x;
        }
    }

    //bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    ll sum(ll i){
        ll s=0;
        if(i==0) return s;
        for(ll k=i;k>0;k-=(k & -k)){
            s+=bit[k];
        }
        return s;
    }

    //a_1 + a_2 + … + a_i >= x となるような最小のiを求める(a_k >= 0)
    //xが0以下の場合は該当するものなし→0を返す
    ll lower_bound(ll x){
        if(x<=0){
            return 0;
        }else{
            ll i=0;ll r=1;
            //最大としてありうる区間の長さを取得する
            //n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
            while(r<n) r=r<<1;
            //区間の長さは調べるごとに半分になる
            for(int len=r;len>0;len=len>>1) {
                //その区間を採用する場合
                if(i+len<n && bit[i+len]<x){
                    x-=bit[i+len];
                    i+=len;
                }
            }
            return i+1;
        }
    }
};

int main(){
    int N,Q;
    cin>>N>>Q;
    BIT a(N+10);
    REP(i,N){
        ll tmp;
        cin>>tmp;
        a.add(i+1,tmp);
    }

    REP(i,Q){
        ll x,y,z;
        cin>>x>>y>>z;
        if(x==0){
            a.add(y+1,z);
        }else{
            cout<<a.sum(z)-a.sum(y)<<endl;
        }
    }

}

Measured memory_bytes: 8216
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
#define iii pair<int, ii>
#define fi first
#define se second

int n, m;
string grid[110];
int dist[110][110];

int dijkstra()
{
	memset(dist, 63, sizeof(dist));
	priority_queue<iii> pq;
	dist[0][0] = 0;
	pq.push({0, {0, 0}});
	while(!pq.empty())
	{
		int x, y;
		tie(x, y) = pq.top().se;
		int d = -pq.top().fi;
		pq.pop();
		if(dist[x][y] < d) continue;
		if(x + 1 < n)
		{
			int cost = grid[x][y] != grid[x + 1][y];
			if(dist[x + 1][y] > d + cost)
			{
				dist[x + 1][y] = d + cost;
				pq.push({-dist[x + 1][y], {x + 1, y}});
			}	
		}
		if(y + 1 < m)
		{
			int cost = grid[x][y] != grid[x][y + 1];
			if(dist[x][y + 1] > d + cost)
			{
				dist[x][y + 1] = d + cost;
				pq.push({-dist[x][y + 1], {x, y + 1}});
			}	
		}
	}
	dist[n - 1][m - 1] += (grid[0][0] == '#'); 
	dist[n - 1][m - 1] += (grid[n - 1][m - 1] == '#'); 
	return dist[n - 1][m - 1] / 2;
}

int32_t main()
{
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cin >> grid[i];
	cout << dijkstra() << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}
 
 
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) r = (r * a) % mod;
		a = (a * a) % mod;
		n >>= 1;
	}
	return r;
}
 
void solve(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(1) {
		c -= b;
		a -= d;
		if (c <= 0) {
			cout << "Yes";
			return;
		}
		if (a <= 0) {
			cout << "No";
			return;
		}
	}
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    for(int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{

    public static boolean has3(int x){
        while(x>0){
            if(x%10==3) return true;
            x/=10;
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=1; i<=n; i++){
            if(i%3==0 || has3(i)){
                System.out.print(" "+i);
            }
        }
        System.out.println("");
    }
}


Measured memory_bytes: 28868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int p[] = new int[50];
		for (int i = 0; i < n; i++) {
			p[i] = scan.nextInt();
		}
		int ans = 0;
		for (int i = 1; i < n - 1; i++) {
			if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) {
				ans++;
			} else if ((p[i - 1] > p[i] && (p[i] > p[i + 1])))
				ans++;

		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

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

    if(a % 2 == b % 2) {
        cout << "Alice" << endl;
        return 0;
    }

    cout << "Borys" << endl;
    return 0;
}


Measured memory_bytes: 256
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let Read() = Console.ReadLine()
let Reads () = Console.ReadLine().Split()
let ReadInt () = Read() |> int
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ReadIntQuadruple () = ReadQuadruple() |> FuncQuadruple int int int int
let ReadIntTriple () = ReadTriple () |> FuncTriple int int int
let ReadIntDouble () = ReadDouble () |> FuncDouble int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"


// The main contents of this submission are below this line.

let n = ReadInt()
[
    for _ in 1..n do
        let l, r = ReadIntDouble()
        yield r - l + 1
] |> Seq.sum |> puts


Measured memory_bytes: 11348
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
monster = 0
for i in range(n):
  if b[i] <= a[i]:
    monster += b[i]
  elif b[i] <= a[i] + a[i+1]:
    monster += b[i]
    a[i+1] -= b[i] - a[i]
  else:
    monster += a[i] + a[i+1]
    a[i+1] = 0
print(monster)

Measured memory_bytes: 18624
#include<stdio.h>
int main()
{
    int a,ab,cd;
    scanf("%d",&a);
    ab=a/100;
    cd=a%100;
   if(ab>=1 && ab<=12)
   {
       if(cd>=1 && cd<=12)
       {
           printf("AMBIGUOUS\n");
       }
       else printf("MMYY\n");
   }
   else
   {
    if(cd>=1 && cd<=12)
           printf("YYMM\n");
   else printf("NA\n");
   }
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
using namespace std;
#include<string>
 
int main(){
  string s1, s2, s3;
  cin >> s1 >> s2;
  for (int i=0; i<s1.size(); i++){
    s3[s1.size()-i-1] = s1[i];
  }
  int co = 0;
  for(int i=0; i<s1.size(); i++){
     if(s3[i] == s2[i]){
         co++;
     }
  }
  if (co==3){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
typedef long long ll;
using namespace std;
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
bool subset(int s, int t) { return (s & t) == s; }
const int mod = 1e9+7;
int main() {
    int n, x, y, z; scanf("%d%d%d%d", &n, &x, &y, &z);
    int l = x+y+z-1;
    int mask = (1<<l)-1;
    int forbidden = (1 << (x+y+z-1)) | (1 << (y+z-1)) | (1 << (z-1));
    vector<vector<ll> > dp = vectors(0ll, n+1, 1<<l);
    dp[0][0] = 1;
    repeat (i,n) {
        repeat_from (a,1,10+1) {
            repeat (s,1<<l) {
                int t = (s << a) | (1 << (a-1));
                if (subset(forbidden, t)) continue;
                dp[i+1][t & mask] += dp[i][s];
            }
        }
        repeat (s,1<<l) dp[i+1][s] %= mod;
    }
    ll ans = 1; repeat (i,n) ans = ans * 10 % mod;
    repeat (s,1<<l) ans -= dp[n][s];
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 21888