akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

class UnionFind {
    vector<int> p, r, a;
    int find(int i) {
        return i == p[i] ? i : (p[i] = find(p[i]));
    }
public:
    UnionFind(int n) : p(n), r(n), a(n, 1) {
        for (int i = 0; i < n; ++i)
            p[i] = i;
    }
    bool same(int i, int j) {
        return find(i) == find(j);
    }
    void unite(int i, int j) {
        i = find(i);
        j = find(j);
        if (r[i] < r[j]) {
            p[i] = j;
        } else {
            p[j] = i;
            r[i] += i != j && r[i] == r[j];
        }
        if (i != j)
            a[p[i]] = a[i] + a[j];
    }
    int number(int i) {
        return a[find(i)];
    }
};

int main() {
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> a(n - 1);
    for (auto& p : a)
        cin >> p.second.first >> p.second.second >> p.first;
    sort(a.begin(), a.end());
    UnionFind uf(n);
    long long sm = 0;
    for (auto& p : a) {
        auto& q = p.second;
        sm += (long long)p.first * uf.number(q.first) * uf.number(q.second);
        uf.unite(q.first, q.second);
    }
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 7564
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0}, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
typedef struct {
	int x;
	int y;
}cod;
map<string, int> mp;
int co;

string s(8, ' ');

void bfs(void) {
	s = "01234567";
	int z;
	string np;
	queue<string> que;

	que.push(s);
	
	mp[s] = 1;
	while (que.size()) {
		
		string p = que.front();
		np = p;
		que.pop();
		co++;
		//cout<<p;
		//if (p== "01234567") { return mp[p]-1; }
		fori0(8) { if (p[i] == '0') z = i; }
		fori0(4) {
			int x = 0;
			np = p;
			switch (i) {
			case 0:
				if (z >= 4) {
					swap(np[z], np[z - 4]);
					x = 1;
				}
				break;
			case 1:
				if (z != 3 && z != 7) {
					swap(np[z], np[z + 1]);
					x = 1;
				}
				break;
			case 2:
				if (z <= 3) {
					swap(np[z], np[z + 4]);
					x = 1;
				}
				break;
			case 3:
				if (z != 0 && z != 4) {
					swap(np[z], np[z - 1]);
					x = 1;
				}
				break;
			}
			//cout << np;
			if (x == 1 && mp[np] == 0) {
				que.push(np);
				mp[np] = mp[p] + 1;
				//cout << "jjj";
			}
			
		}
	}
	return ;
}

int main() {
	bfs();
	//s[8] = '\0';
	while (1) {
		fori0(8) {
			if (!(cin >> s[i])) return 0;
		}
		 printf("%d\n", mp[s]-1); 
		// cout << co;
		 //printf("%d", mp["hello"]);
	}
	
	//cout << bfs() << endl;
	
	//system("pause");
	//return 0;
}



Measured memory_bytes: 5504
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], b[N], n, m, k;

void solve()
{
     for (int i = 0; i < 4; i++)
          cin >> a[i];

     b[0] = 1;
     b[1] = 0;
     b[2] = -1;

     int s = 0;

     for (int i = 0; i < 3; i++)
     {
          if (a[3] >= a[i])
          {
               a[3] -= a[i];
               s += a[i] * b[i];
          }
          else
          {
               s += a[3] * b[i];
               break;
          }
     }
     cout << s;

}

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


     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 3808
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n = int(input())
    a = Counter([int(input()) for _ in range(n)])
    ans = 0

    for key, value in a.items():
        if value % 2 == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

string a,b;
int len;

int main()
{
	cin>>len;
	cin>>a>>b;
	for(int i=0;i<2*len;++i) {
		if(i%2==0) printf("%c",a[i/2]);
		else printf("%c",b[i/2]);
	}
}

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

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

string S;
int main(){
  cin >> S;
  if (S=="Sunny") cout << "Cloudy" << endl;
  else if (S=="Cloudy") cout << "Rainy" << endl;
  else if (S=="Rainy") cout << "Sunny" << endl;
}



Measured memory_bytes: 888
def mod_inv(a, m):
    return pow(a, m-2, m)


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


MOD = 10**9+7
N, A, B = map(int, input().split())

N %= MOD
sm = pow(2, N, MOD) % MOD
sm -= 1

a = combination(N, A) % MOD
b = combination(N, B) % MOD

ans = sm - a - b
ans %= MOD
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern

 


signed main() {
	
	int x,k,d;
	cin >> x >> k >> d;
	
	x = abs(x);
	
	int val = x%d;
	
	if((x-val)/d > k){
		cout<<x-k*d;
	}
	else{
		int num = (x - val)/d;
		if((k - num) %2 == 1){
			cout<<min(abs(val - d) , val + d);
		}
		else
			cout<<val;
	}
	
	     
   
   return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe";
    else cout << "safe";
    cout << endl;

    return 0;
}



Measured memory_bytes: 3612
#!python3

# input
N = int(input())
A = list(map(int, input().split()))


def main():
    d = {}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    
    ans = 0
    for key, value in d.items():
        if key > value:
            ans += value
        else:
            ans += value - key
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 17780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC105_C solver = new ABC105_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC105_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // TODO:Unsolve
            long n = in.nextLong();
            StringBuffer sb = new StringBuffer();

            while (true) {
                if (n % 2 != 0) {
                    sb.append(1);
                    n--;
                } else {
                    sb.append(0);
                }
                if (n == 0) {
                    break;
                } else {
                    n /= -2;
                }
            }

            out.print(sb.reverse().toString());


        }

    }
}



Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  string s;
  cin >> a >> b >> s;
  string res = "Yes";
  if(s.length() != a+b+1){
    res = "No";
  }
  for(int i = 0; i < s.length(); ++i){
    if(i == a){
      if(s[i] != '-'){
        res = "No";
      }
    }else{
      if(!isdigit(s[i])){
        res = "No";
      }
    }
  }
  cout << res;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(a) (a).begin(),(a).end()

int a[20][20];

void solve(int n) {
  memset(a, 0, sizeof a);
  int ci = n/2+1, cj = n/2;
  a[ci][cj] = 1;

  int val = 2;
  ci++;
  cj++;
  
  while (val <= n * n) {
    if (ci >= n) {
      ci %= n;
      continue;
    }
    if (cj >= n) {
      cj %= n;
      continue;
    }
    if (cj < 0) {
      cj = n - 1;
      continue;
    }
    if (a[ci][cj] == 0) {
      a[ci][cj] = val++;
      ci++;
      cj++;
      continue;
    }
    ci++;
    cj--;
    continue;
  }
  
  rep(i,n) {
    rep(j,n) printf("%4d", a[i][j]);
    puts("");
  }
}

int main() {
  int n;
  while (cin >> n) {
    solve(n);
  }
  return 0;
}

Measured memory_bytes: 1160
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> p(n), q(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];
    V<int> ord(n); iota(ALL(ord), 1);
    int i = 0;
    do {
        if (p == ord) break;
        i++;
    } while (next_permutation(ALL(ord)));

    iota(ALL(ord), 1);
    int j = 0;
    do {
        if (q == ord) break;
        j++;
    } while (next_permutation(ALL(ord)));

    cout << abs(i - j) << '\n';
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
wd = []
for i in range(n):
    w, d = [int(item) for item in input().split()]
    wd.append((w, d))

l = -1; r = 10**20
while r - l > 1:
    mid = (l + r) // 2
    flower = 0
    for w, d in wd:
        if mid - w >= 0:
            flower += (mid - w) // d + 1
        if flower >= k:
            break
    if flower >= k:
        r = mid
    else:
        l = mid
print(r)


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

using namespace std;

bool isSorted(vector<int> a){
    for(int i = 0; i < a.size(); i++){
        if(a[i] != i+1) return false;
    }
    return true;
}

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> point;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] != i+1){
            point.push_back(i);
        }
    }
    if(point.size() == 2)swap(a[point[0]], a[point[1]]);
    if(isSorted(a)){
        cout <<"YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

#define reps(i,a,b,s) for(int i=(int)(a);i<(int)(b);i+=s)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repi(i,0,n)
using i64 = int64_t;

int a[3];

void solve() {
    sort(a,a+3);
    if(a[0] == a[1] and a[0] == 5 and a[2] == 7) puts("YES");
    else puts("NO");
}

void input() {
    rep(i,3) cin >> a[i];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(12);
    input();
    solve();
    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() {
  string S;
  int x=0;
  vector<int> T(26);
  cin >> S;
  rep(i, S.size()){
    T.at(S.at(i)-'a')++;
  }
  rep(i,26){
    if(T.at(i)==0){
      cout << char(i+'a') << endl;
      x=1;
      break;
    }
  }
  if(x==0) cout << "None" << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int mini = 1e10;
    int mini_index = -1;
    int death = 0;
    while(true){
        rep(i, N){
            if(mini > A[i] && A[i] != 0){
                mini = A[i];
                mini_index = i;
            }
        }
        rep(i, N){
            if(A[i] != 0){
                if(i != mini_index && A[i] % mini == 0){
                    A[i] = 0;
                    death++;
                }
                else if(i != mini_index && A[i] % mini != 0){
                    A[i] %= mini;
                }
            }
        }
        if(death == N-1){
            cout << mini;
            return 0;
        }
    }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int count = 0;

		for (char x : s.toCharArray()) {
			if (x == 'p')
				count++;
		}

		System.out.println(s.length() / 2 - count);
	}

}


Measured memory_bytes: 25584
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll ans = 0;
ll k;
vector<ll> a;
void dfs(ll now,ll cnt){
  if(cnt == k){
    ans += now;
    ans %= MOD;
    return ;
  }

  dfs((now % MOD) * a[cnt] % MOD,cnt+1);
  dfs(now % MOD,cnt+1);
}

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<char,ll> dict;
  for(char c:s)dict[c]++;

  for(auto p:dict){
    a.push_back(p.second);
  }

  k = dict.size();
  dfs(1,0);
  cout << ans - 1 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

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

	ll n,a;
	cin>>n;
	a=0;
	for (int i = 0; i < n; ++i)
	{
		if(((i+1)%3) && (i+1)%5)
			a+=i+1;
	}
	cout<<a<<endl;

	return 0;
}


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

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

    vector<int> t(n);
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
    }

    vector<int> p(m);
    vector<int> x(m);
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> p[i] >> x[i];
    }
    
    for (int i = 0; i < m; i++)
    {
        int ans = 0, tmp = t[p[i]-1];
        t[p[i]-1] = x[i];
        for (int j = 0; j < n; j++)
        {
            ans += t[j];
        }
        t[p[i]-1] = tmp;
        cout << ans << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 512
//ITP1_6_B

#include <stdio.h>

int main(){

	int n,i,j,N;
	char M;
	scanf("%d",&n);
	
	int x[4][13];
	
	//?????????
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			x[i][j]=0;
		}
	}
	
	//??\???
	for(i=0;i<n;i++){
	
		scanf(" %c %d",&M,&N);
	
		if(M=='S'){x[0][N-1]=1;}
		if(M=='H'){x[1][N-1]=1;}
		if(M=='C'){x[2][N-1]=1;}
		if(M=='D'){x[3][N-1]=1;}
	}
	
	//??¨???
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(x[i][j]==0 &&i==0){printf("S %d\n",j+1);}
			if(x[i][j]==0 &&i==1){printf("H %d\n",j+1);}
			if(x[i][j]==0 &&i==2){printf("C %d\n",j+1);}
			if(x[i][j]==0 &&i==3){printf("D %d\n",j+1);}
		}
	}
	
	return 0;

}

Measured memory_bytes: 596
from collections import deque

H, W = map(int, input().split())
field = tuple([input() for _ in range(H)])

#右上左下
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

n_black = 0

for i in range(H):
    n_black += field[i].count("#")


dist = [[-1 for x in range(W)] for y in range(H)]
dist[0][0] = 1

que = deque()
que.append((0, 0))



while len(que):
    n = que.popleft()
    ny = n[0]
    nx = n[1]

    for i in range(4):
        nny = ny + dy[i]
        nnx = nx + dx[i]

        if nny >= 0 and nny < H and nnx >= 0 and nnx < W and field[nny][nnx] == "." and dist[nny][nnx] == -1:
            dist[nny][nnx] = dist[ny][nx] + 1
            que.append((nny, nnx))

min = dist[H-1][W-1]

if min == -1:
    print(-1)

else:
    print(H * W - min - n_black)


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

int main(){
  int n;
  cin>>n;
  string s;
  int aa = 0,bb = 0,ba = 0,ab = 0;
  for(int i = 0;i<n;i++){
    cin>>s;
    if(s.at(0) == 'B'){
      bb++;
    }
    if(s.at(s.size()-1) == 'A'){
      aa++;
    }
    if(s.at(0) =='B' && s.at(s.size()-1) == 'A'){
      ba++;
      aa--;
      bb--;
    }
    for(int k = 0;k<s.size()-1;k++){
      if(s.at(k) == 'A'){
        if(s.at(k+1) == 'B'){
          ab++;
        }
      }
    }
  }
  int ans = 0;
  if(ba == 0){
    ans = ab + min(aa,bb);
  }
  else{
    if((aa+bb) == 0){
      ans = ab+ba-1;
    }
    else{
      ans = ab+ba+min(aa,bb);
    }
  }
    
  cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef EPIQ_LOCAL
#define DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T> void debug2(T b, T e) { auto it=b; while (it != e) cerr << *it++ << " "; cerr << endl; }
#define TRACE(x) x
#else
#define debug(x)
template<typename T> void debug2(T b, T e) {}
#define TRACE(x)
#endif
#define mp(x, y) make_pair((x),(y))
#define pb(x) push_back(x)
#define eb emplace_back
#define forn(v, b, e) for (auto v = (b); v < (e); v++)
#define SZ(x) ((int)(x).size())
#define st first
#define nd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
const ld pi = acos(-1);
template<typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {os << "[" << p.first << "," << p.second << "]"; return os;}
template<typename T1, typename T2, typename T3>
ostream& operator<< (ostream& os, const tuple<T1,T2,T3>& t) {os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; return os;}

int n, m, q;
vi a, b, c, d;
int s[11];
int res;

void rec(int k, int p, int sum) {
    
    for (int x = p; x <= m; x++) {
        s[k] = x;
        int curr = 0;
        for (int i = 0; i < q; i++) {
            if (b[i] == k && s[b[i]] - s[a[i]] == c[i]) {
                curr += d[i];
            }
        }
        if (k == n) {
            res = max(res, sum + curr);
        } else {
            rec(k + 1, x, sum + curr);
        }
    }
}

void solve() {
    
    cin >> n >> m >> q;
    
    a = vi(q);
    b = vi(q);
    c = vi(q);
    d = vi(q);
    
    forn (i, 0, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    rec(1, 1, 0);
    cout << res << endl;
}

int main()
{
    TRACE(clock_t _t1 = clock();)
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(12);

    solve();

    TRACE(cerr << "Time elapsed: " << (double)(clock() - _t1) / CLOCKS_PER_SEC << endl;)

    return 0;
}


Measured memory_bytes: 3660
import java.util.*;

public class Main {

    /* チェックリスト
     * intの範囲を超えていないか
     * TLEしそうな処理の有無
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int a = Integer.parseInt(ins[0]);
        int b = Integer.parseInt(ins[1]);
        if(a <= 9 && b <= 9){
            System.out.println(a * b);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int w;
	cin>>w;
	vector<long long int > arr(w+1,0);
	
	for(int i=0;i<n;i++){
		int temp,v;
		cin>>temp>>v;
		for(int j=w;j>=0;j--){
			if(j>=temp){arr[j]=max(arr[j],arr[j-temp]+v);}
			}
		
		}
		
		long long int maxi=INT_MIN;
		for(int i=0;i<w+1;i++){
			//cout<<arr[i]<<endl;
			maxi=max(maxi,arr[i]);
			}
		cout<<maxi<<endl;
	
	}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MAX 3005
#define P 998244353
#define INF 0x3f3f3f3f
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, m;
int a[MAX];
ll f[MAX][MAX], s[MAX];

void add(ll &a, ll b){
    a += b;
    if(a >= P) a -= P;
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = m; j > a[i]; j--){
            add(f[i][j], s[j-a[i]]);
            add(s[j], f[i][j]);
        }
        f[i][a[i]] = i;
        add(s[a[i]], i);
        add(ans, f[i][m]*(n-i+1)%P);
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	int k = min(a,b);
	int l = a+b-n;
	if(l <= 0){
		l = 0;
	}
	cout << k << " " << l;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i, n) { cin >> h[i]; }

    if(n == 1) {
        cout << "Yes" << endl;
        return 0;
    }

    // 先頭は下げ確定
    h[0]--;

    // ２番目から見ていく
    // ひとつ前より高ければ下げる
    for(int i = 1; i < n; ++i) {
        if(h[i - 1] < h[i]) {
            h[i]--;
        }
    }
    /*
    rep(i, n) { cout << h[i] << ","; }
    cout << endl;
    */
    int flag = 1;
    for(int i = 1; i < n; ++i) {
        if(h[i - 1] > h[i]) {
            flag = 0;
            break;
        }
    }

    if(flag == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 640
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# a+b+cは一定
# Kが奇数の時、全てKの倍数
# Kが偶数の時、全てKの倍数か、全てK//2 mod K
N, K = lr()
exact = N // K
answer = pow(exact, 3)
if K%2 == 0:
    half = N // (K//2) - exact
    answer += pow(half, 3)
print(answer)
# 29

Measured memory_bytes: 3060
W=input()
A=map(int,raw_input().split())
L=[0]*W
R=[0]*W
now0=-1
for i in xrange(W):
    if A[i]==0:
        now0=i
        nowx=10**6
    if now0==-1: continue
    nowx-=1
    if A[i]<0: nowx=min(nowx,-A[i])
    if A[i]>0: L[i]=min(A[i],nowx)
now0=-1
for j in xrange(W):
    i = W-j-1
    if A[i]==0:
        now0=i
        nowx=10**6
    if now0==-1: continue
    nowx-=1
    if A[i]<0: nowx=min(nowx,-A[i])
    if A[i]>0: R[i]=min(A[i],nowx)
ans=0
for i in xrange(W):
    if max(L[i],R[i])>0: ans+=max(L[i],R[i])
print ans

Measured memory_bytes: 14916
H, W = map(int, input().split())

s = []
s.append(['.']*(W+2))
for _ in range(H):
  s.append(['.'] + list(input()) + ['.'])
s.append(['.']*(W+2))

def f():
  for i in range(1, H+1):
    for j in range(1, W+1):
      if s[i][j] == '#':
        if s[i-1][j] != '#' and s[i+1][j] != '#' and s[i][j-1] != '#' and s[i][j+1] != '#':
          return 'No'
  return 'Yes'

print(f())



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr double INF = 1e12;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  vector<int> nbr;
  vector<double> cost;
  double x;
  double y;
  double r = 0;
  double dist = INF;
  bool vst = false;
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  double xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int N;
  cin >> N;
  REP(i, N+2) V.emplace_back();
  V[N].x = xs;
  V[N].y = ys;
  V[N+1].x = xt;
  V[N+1].y = yt;
  REP(i, N) cin >> V[i].x >> V[i].y >> V[i].r;
  REP(i, N+2) {
    REP(j, N+2) {
      if(i == j) continue;
      V[i].nbr.push_back(j);
      V[i].cost.push_back(max(0.0, sqrt((V[i].x-V[j].x)*(V[i].x-V[j].x)+(V[i].y-V[j].y)*(V[i].y-V[j].y)) - V[i].r - V[j].r));
    }
  }
  V[N].dist = 0;
  while(true) {
    double mindist = 1e12;
    int idx = -1;
    REP(i, N+2) {
      if(!V[i].vst && V[i].dist < mindist) {
        mindist = V[i].dist;
        idx = i;
      }
    }
    if(mindist == 1e12) break;
    V[idx].vst = true;
    REP(i, V[idx].nbr.size()) {
      if(V[idx].dist + V[idx].cost[i] < V[V[idx].nbr[i]].dist) {
        V[V[idx].nbr[i]].dist = V[idx].dist + V[idx].cost[i];
      }
    }
  }
  cout << setprecision(10) << V[N+1].dist << endl;
}

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

int main() {
  int y, m, d;
  scanf("%d/%d/%d", &y, &m, &d);
  
  if ( y > 2019 ) { cout << "TBD" << endl; } else
  if ( y < 2019 ) { cout << "Heisei" << endl; } else
  if ( m > 4 ) { cout << "TBD" << endl; } else
  { cout << "Heisei" << endl; }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


int N, X, M;
bool memo[100000];


signed main()
{
	cin >> N >> X >> M;

	int a = X;

	int number = -1;
	memo[a] = true;
	for (int i = 1; i < N; i++)
	{
		a = a * a % M;
		if (memo[a])
		{
			number = a;
			break;
		}
		memo[a] = true;
	}


	if (number == -1)
	{
		a = X;
		int sum = 0;
		for (int i = 0; i < N; i++)
		{
			sum += a;
			a = a * a % M;
		}
		cout << sum << endl;
	}
	else
	{
		int seq1 = 0;
		a = X;
		int index = 0;
		int index0 = 0;
		while(true)
		{
			if (a == number) break;
			seq1 += a;
			a = a * a % M;
			index++;
		}
		index0 = index;

		int seq2 = 0;
		int loop_size = 0;
		while(true)
		{
			seq2 += a;
			loop_size++;
			a = a * a % M;
			if (a == number) break;
		}

		int seq3 = 0;
		int loop_cnt = (N - index0) / loop_size;
		index = index0 + loop_cnt * loop_size;
		a = number;
		for (; index < N; index++)
		{
			seq3 += a;
			a = a * a % M;
		}

		int ans = seq1 + seq2 * loop_cnt + seq3;
		cout << ans << endl;
	}

}



Measured memory_bytes: 3660
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
A.sort()
# print(A)

# 想定解で解くしかない
res=0
i=0
while i<N:
  c=A[i]
  f=0
  while i<N and A[i]==c:
    f+=1
    i+=1
  res+=f%2
print(res)

Measured memory_bytes: 81092
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long sum=0;
    vector<long> a(n);
    vector<long> b;
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
        sum += a[i];
        if(a[i]%10!=0) {
            b.push_back( a[i] );
        }
    }
    if(sum%10!=0) {
        printf("%ld\n", sum);
    }
    else {
        if (!b.empty()) {
            sort(b.begin(), b.end());
            printf("%ld\n", sum-b[0]);
        }
        else {
            printf("0\n");
        }
    }



    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
li = []
for i in range(0, n-1):
    if s[i] == "R" and s[i+1] == "L":
        li.append(i)

ans = [0] * n
j = 0
is_right = True
for i in range(n):
    if i > li[j] and s[i] == "R":
        j += 1
    if s[i] == "R":
        if (li[j] - i) % 2 == 0:
            ans[li[j]] += 1
        else:
            ans[li[j] + 1] += 1
    elif s[i] == "L":
        if (li[j] - i) % 2 == 0:
            ans[li[j]] += 1
        else:
            ans[li[j] + 1] += 1 
print(" ".join(map(str, ans)))


Measured memory_bytes: 51952
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n, m; cin >> n >> m;
    V<P> v(m);
    rep(i, m) {
        int a, b; cin >> a >> b; a--; b--;
        v[i].first = b;
        v[i].second = a;
    }
    sort(all(v));
    int ans = 0;
    int r = -1;
    rep(i, m) {
        if (r <= v[i].second) {
            r = v[i].first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

  if ((N / 10) % 111 == 0 || (N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 256
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')



Measured memory_bytes: 53300
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

int main(){  
  char s[201], t[101], p[101];
  scanf("%s %s",s ,p);
  strcpy(t, s);
  strcat(s, t);

  if (strstr(s, p) == NULL){
    printf("No\n");
  } else printf("Yes\n");

  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++)
    {
        int c;
        cin>>c;
        v.push_back({c,i+1});
    }
    sort(v.begin(),v.end());
    for(auto i:v)
        cout<<i.second<<" ";


    
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

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

vector<bool> C(26, false);
REP(i, S.size()){
  REP(j, 26){
    if(S.at(i) - 'a' == j) C.at(j) = true;
  }
}
REP(i, 26){
  if(C.at(i) == false) {
    print(char(i + 'a'));
    return 0;
  }
}

print("None");

}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};
// other libs
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}

class dijkstra {
  private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};
template<typename T>
class Union_Find {
  private:
    vector<T> t, s;

  public:
    Union_Find(T max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(T x, T y) {
        if (same(x, y))
            return;
        T tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    T Find(T n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(T x, T y) {
        return Find(x) == Find(y);
    }

    T get_Size(size_t a) {
        return s[a];
    }
};
bool ifPrime(int n){
    if(n==1)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main(signed argc, char* argv[]) {
    int n;
    cin>>n;
    vector<int> b(n-1);
    int ans=0;
    rep(i,n-1){
        cin>>b[i];
        if(i){
            ans+=min(b[i-1],b[i]);
        }
        else{
            ans+=b[i];
        }
    }
    ans+=b[n-2];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <regex>
#include "bits/stdc++.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 = 10;
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>;

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

int prime_factors_num(ll n) {
    int res = 0;
    for(ll p = 2; p*p <= n; p++) {
        //if (is_prime(p)) {
        if (n%p != 0) continue; // p is not n's devisor
        else {
            while(n%p == 0) {
              //fac[p]++;
              n /= p;
            }
            res++;
        }
    }
    if (n > 1) res++; //fac[n]++;
    return res;
}


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

  ll A,B; cin >> A >> B;

  ll C = gcd(A, B);
  
  int ans = prime_factors_num(C) + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin>>S;
  int N=S.length();
  int left=0,right=0,tmp;
  vector<int> ans(N,0);
  REP(i,N){
    if(S[i]=='R'&&S[i+1]=='L'){
      tmp=i;
    }
    if(i==N-1 || (S[i]=='L'&&S[i+1]=='R')){
      right=i;
      if((right-left+1)%2==1){
        if((tmp-left)%2==0){
          ans[tmp]++;
        }else{
          ans[tmp+1]++;
        }
      }
      ans[tmp]+=(right-left+1)/2;
      ans[tmp+1]+=(right-left+1)/2;
      left=i+1;
    }
  }
  REP(i,N-1){
    cout<<ans[i]<<" ";
  }
  cout<<ans[N-1]<<endl;
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
int n,t;

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

	cout << (n-t>=0?n-t:0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s; int k; cin >> s >> k;
	
	rep(i, s.size()){
		if(i + 1 < s.size() && (s[i] == 'a' || 'z' - s[i] + 1 > k)){
			continue;
		}
		int d = i + 1 == s.size() ? k : 'z' - s[i] + 1;
		s[i] = (s[i] - 'a' + d) % 26 + 'a';
		k -= d;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 592