akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n); for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N;cin>>N;vi p(N);
  rep(i,N){
    cin>>p[i];
    p[i]--;
  }
  int ans =0;
  int cnt=1;
  for(int i=0;i<N-1;i++){
    
    if(p[i]==i&&p[i+1]==i+1){
      cnt++;
    }
    else if(p[i]==i&&p[i+1]!=i+1){
      ans +=(cnt+1)/2;
      cnt=1;
    }
   
  }
  if(p[N-1]==N-1)ans+=(cnt+1)/2;

  cout<<ans<<endl;
}


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

int main(void)
{

	int A,B,M;
    std::cin >> A >> B >>M;
  
  int a[A];
  int b[B];
  int mat[M][3];
  int ma=1E100;
  int mb=1E100;
  
  for(int i=0;i<A;i++)
  {
    std::cin >> a[i];
    if(ma > a[i])
    {
      ma = a[i];      
    }
  }
  for(int i=0;i<B;i++)
  {
    std::cin >> b[i];
    if(mb > b[i])
    {
      mb = b[i];      
    }
  }
  for(int i=0;i<M;i++)
  {
    for(int j=0;j<3;j++)
    {
     std::cin >> mat[i][j];
    }
  }
  
int ret = ma+mb;
  
for(int i=0;i<M;i++)
{
  int tmp = a[mat[i][0]-1]+b[mat[i][1]-1]-mat[i][2];
  if(tmp < ret){
    ret = tmp;
  }
}
  std::cout << ret;
  
return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> red;
  vector<int> white;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') red.push_back(i);
    else white.push_back(i);
  }
  reverse(red.begin(), red.end());
  if (white.empty()) cout << 0 << endl;
  if (red.empty()) cout << 0 << endl;
  else if (white.size()<red.size()) {
    for (int i = 0; i < white.size(); i++) {
      if (red[i] < white[i]) {
        cout << i << endl;
        break;
      }
      else if (i == white.size()-1) cout << i+1 << endl;
    }
  }
  else {
    for (int i = 0; i < red.size(); i++) {
      if (red[i] < white[i]) {
        cout << i << endl;
        break;
      }
      else if (i == red.size()-1) cout << i+1 << endl;
    }
  }
}

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

string T = "AKIHABARA";

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	string S; cin >> S;
	int i=0,j = 0;
	bool flag = true;
	for (; i < S.size() && j<T.size();) {
		if (S[i] != T[j]) {
			if (T[j] == 'A')j++;
			else {
				flag = false;
				break;
			}
		}
		else {
			i++; j++;
		}
	}
	if (i != S.size())flag = false;
	if (j < T.size() - 1)flag = false;

	cout << (flag ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

const long long mod = 998244353;

typedef pair<int, int> P;
typedef pair<P, int> PP;

vector<PP> rem;

int A[50500], B[50500], C[50500];
int M;
int N;

void input(){
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; ++i){
		scanf("%d%d%d", A + i, B + i, C + i);
	}
}

map<P, int> mp;

bool skipped[50500];

long long ex(int a, long long e){
	if(e == 0) return 1;
	long long tmp = ex(a, e / 2);
	tmp = (tmp * tmp) % mod;
	if(e % 2 == 1) tmp = (tmp * a) % mod;
	return tmp;
}

long long solve(){
	for(int i = 0; i < M; ++i){
		if(A[i] > B[i]) swap(A[i], B[i]);
		if(mp.count(P(A[i], B[i])) == 0){
			mp[P(A[i], B[i])] = C[i];
		}else{
			int c = mp[P(A[i], B[i])];
			if(B[i] - A[i] > 2){
				if((c + C[i]) % 2 != 0){
					return 0;
				}
			}else if(B[i] == A[i] + 2){
				int req = (c + C[i]) % 2;
				P p = P(A[i] + 1, A[i] + 1);
				if(mp.count(p) == 1){
					if(mp[p] != req) return 0;
				}
				mp[p] = req;
			}else if(B[i] == A[i] + 1){
				skipped[i] = true;
				rem.push_back(PP(P(A[i], B[i]), C[i]));
			}else{
				if(c != C[i]) return 0;
			}
		}
	}
	sort(rem.begin(), rem.end());
	for(int i = 0; i < rem.size(); ++i){
		P p = rem[i].first;
		P p1 = P(p.first, p.first);
		P p2 = P(p.second, p.second);
		int a = mp.count(p1) == 1 ? mp[p1] : (-1);
		int b = mp.count(p2) == 1 ? mp[p2] : (-1);
		int x = rem[i].second ^ (mp[p]);
		if(a == -1){
			mp[P(p.second, p.first)] = rem[i].second;
		}else if(b == -1){
			mp[p2] = x ^ a;
		}else{
			if((a ^ b ^ x) == 1){
				return 0;
			}
		}
	}/*
	for(int i = 0; i < M; ++i){
		if(!skipped[i]) continue;
		P p = P(A[i], A[i]);
		int a = mp.count(p) == 1 ? mp[p] : (-1);
		p = P(B[i], B[i]);
		int b = mp.count(p) == 1 ? mp[p] : (-1);
		int x = C[i] ^ (mp[P(A[i], B[i])]);
		if(a == -1 || b == -1){
			mp[P(B[i], A[i])] = C[i];
		}else{
			if((a ^ b ^ x) == 1){
				return 0;
			}
		}
	}*/
	long long e = (long long)N * (N + 1) / 2 - mp.size();
	long long ans = ex(2, e);
	ans %= mod;
	ans += mod;
	ans %= mod;
	return ans;
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4284
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
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 (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, M;
    LL K;
    cin >> N >> M >> K;
    VL A(N), B(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];

    VL A_sum(N + 1);
    REP(i, N) {
        A_sum[i + 1] = A_sum[i] + A[i];
    }
    VL B_sum(M + 1);
    REP(i, M) {
        B_sum[i + 1] = B_sum[i] + B[i];
    }

    int ans = 0;
    REP(i, N + 1) {
        const LL use_a = A_sum[i];
        if (use_a > K) continue;
        int ok = 0, ng = M + 1;
        while (ng - ok > 1) {
            const int mid = (ok + ng) / 2;
            if (use_a + B_sum[mid] <= K) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        chmax(ans, i + ok);
    }

    cout << ans << endl;
}


Measured memory_bytes: 9592
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_lines n "%d %d" Tuple2.make

let () =
  let a = Array.of_list @@ ListL.map ls ~f:Tuple2.first in
  let b = Array.of_list @@ ListL.map ls ~f:Tuple2.second in
  Array.sort Int.compare a;
  Array.sort Int.compare b;
  (if n mod 2 = 0 then
     b.((n-1)/2) + b.((n-1)/2+1) - (a.((n-1)/2) + a.((n-1)/2+1)) + 1
   else
     b.(n/2) - a.(n/2) +1)
  |> Printf.printf "%d\n"


Measured memory_bytes: 33356
//2020-05-28

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;

int main(){
    ios_base::sync_with_stdio();
    cin.tie(NULL);
    
    ll x;
    cin >> x;
    
    ll tot=100;
    for (int i=1;i<1e7;i++){
        tot = floor(tot*1.01);
        if (tot >= x){
            cout << i;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop() {
    top--;
    return S[top+1];
}

int main(){
    int a, b;
    top = 0;
    char s[100];
    
    while (scanf("%s", s) != EOF ){
        if ( s[0] == '+' ){
            a = pop();
            b = pop();
            push(a + b);
        } else if (s[0] == '-'){
            b = pop ();
            a = pop ();
            push(a-b);
        } else if (s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        } else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}


Measured memory_bytes: 3244
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]

v1 = A[0][0]
v2 = A[1][0] + v1

if N==1:
    print(v2)
    exit()

for j in range(1, N):
    v1 += A[0][j]
    v2 = A[1][j] + max(v2, v1)

print(v2)

Measured memory_bytes: 3064
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**9 + 7


def main():
    N = in_n()
    F = [in_nl() for _ in range(N)]
    P = [in_nl() for _ in range(N)]

    comb = list(itertools.product(range(2), repeat=10))[1:]

    ans = -INF
    for com in comb:
        r = 0
        for i in range(N):
            count = 0
            for j in range(10):
                if F[i][j] == com[j] == 1:
                    count += 1
            r += P[i][count]
        ans = max(ans, r)

    print(ans)


if __name__ == '__main__':
    main()


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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int INF = 1e9;
auto minn(auto& a, auto b){a = min(a, b);}

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

  int n;
  cin >> n;
  vi a(n);
  trav(i, a) cin >> i;
  vi dp(n + 5, INF);
  dp[0] = 0;
  rep(i, 0, n) {
    minn(dp[i + 1], dp[i] + abs(a[i + 1] - a[i]));
    minn(dp[i + 2], dp[i] + abs(a[i + 2] - a[i]));
  }
  cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	int dp[3001]; //合計i[g]の水があるときの最大の砂糖の量

	for (int i = 0; i <= 3000; i++){
		dp[i] = -1;
	}

	dp[0] = 0;

	for (int i = 0; i <= f; i++){
		if (dp[i] != -1){
			if (i+100*a <= f) dp[i+100*a] = max(dp[i+100*a], dp[i]);
			if (i+100*b <= f) dp[i+100*b] = max(dp[i+100*b], dp[i]);
			int max_suger = i/100*e;
			for (int j = 0; j*c <= max_suger; j++){
				for (int k = 0; j*c + k*d <= max_suger; k++){
					if (i + j*c + k*d <= f){
						dp[i] = max(dp[i], j*c + k*d);
					}
				}
			}
		}
	}
	double ans = -1;
	int ansi = -1;

	for (int i = 0; i <= f; i++){
		if (dp[i] != -1){
			if (i + dp[i] <= f){
				if (ans < (double)dp[i]/(double)(i+dp[i])){
					ans = (double)dp[i]/(double)(i+dp[i]);
					ansi = i;
				}
			}
		}
	}
	if (ansi == -1) cout << 0 << endl;
	else cout << ansi+dp[ansi] << " " << dp[ansi] << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    ll dpa[100100], dpb[100100], dpc[100100];

    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];

    REP(i, N - 1)
    {
        dpa[i] = a[i] + max(dpb[i - 1], dpc[i - 1]);
        dpb[i] = b[i] + max(dpa[i - 1], dpc[i - 1]);
        dpc[i] = c[i] + max(dpa[i - 1], dpb[i - 1]);
    }

    cout << max({dpa[N - 1], dpb[N - 1], dpc[N - 1]}) << endl;
}


Measured memory_bytes: 3840
#include <iostream>

#define N 100010

using ll = long long;

int main() {
    ll n, ans = 0LL;
    ll a[N], b[N];

    std::cin >> n;
    for (int i=0; i<=n; ++i) std::cin >> a[i];
    for (int i=0; i<n;  ++i) std::cin >> b[i];

    for (ll i=n-1; i>=0; --i) {
        if (a[i+1] < b[i]) {
            ans += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
        } else {
            ans += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }
        if (a[i] < b[i]) {
            ans += a[i];
            b[i] -= a[i];
            a[i] = 0;
        } else {
            ans += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min (A * N, B) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<long long int> memo(10000,0);
  int N;
  cin>>N;
  memo.at(0)=2,memo.at(1)=1;
  for(int i=2;i<=N;i++){
    if(memo.at(i)==0){
      memo.at(i)=memo.at(i-1)+memo.at(i-2);
    }
  }
  cout<<memo.at(N)<<endl;
}


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

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 69
#endif
	

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);

const int N=500006;

void solve()
{
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    vi pref(n+1);
    pref[1]=a[0];
    int ans=1e9;
    for(int i=2;i<=n;i++)pref[i]=pref[i-1]+a[i-1];
    for(int i=1;i<=n;i++)
    {
		ans=min(ans,abs((pref[n]-pref[i-1])-pref[i-1]));
		}
		cout<<ans;
}




int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//~ cin>>tc;	
	for(int i=0; i<tc; i++)
	{
		solve();
	}

}


int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
  int N, i, j;
  char trumps[4][13];

  /* 初期化 */
  memset(trumps, 0, 4*13);

  /* かーど枚数読取り */
  scanf("%d\n", &N);

  /* かーど情報格納 */
  for (i = 0; i < N; i++) {
    int num, cnum;
    char pict;
    scanf("%c %d\n", &pict, &num);
    if (pict == 'S')      cnum = 0;
    else if (pict == 'H') cnum = 1;
    else if (pict == 'C') cnum = 2;
    else if (pict == 'D') cnum = 3;
    trumps[cnum][--num] = 1;
  }

  /* かーど情報確認 */
  for (i = 0; i < 4; i++) {
    char pict;
    if (i == 0)      pict = 'S';
    else if (i == 1) pict = 'H';
    else if (i == 2) pict = 'C';
    else if (i == 3) pict = 'D';

    for (j = 0; j < 13; j++) {
            if (!trumps[i][j])
      //        printf("%d:", trumps[i][j]);
        printf("%c %d\n", pict, j+1);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

ll d(ll a)
{
    ll ret = 0;
    while (a > 0)
    {
        a /= 10;
        ret++;
    }
    return ret;
}

//エラトステネスの篩
bool is_prime[1000000 + 1];
vector<ll> P;
void Eratosthenes(const ll N)
{
    for (ll i = 0; i <= N; i++)
    {
        is_prime[i] = true; //初期化
    }
    for (ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (ll j = 2 * i; j <= N; j += i)
            {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
}

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

    Eratosthenes(N * 10);

    for (const auto &x : P)
    {
        if (x >= N)
        {
            cout << x << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 2424
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-4 21:05:03
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

  int N;
  string S[100010];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
  ll cnt[26];
  fill(cnt, cnt + 26, 0);
  for (auto i = 0; i < N; i++)
  {
    cnt[S[i][0] - 'A']++;
  }
  ll c[5];
  c[0] = cnt['M' - 'A'];
  c[1] = cnt['A' - 'A'];
  c[2] = cnt['R' - 'A'];
  c[3] = cnt['C' - 'A'];
  c[4] = cnt['H' - 'A'];
  ll ans = 0;
  for (auto i = 0; i < 5; i++)
  {
    for (auto j = i+1; j < 5; j++)
    {
      for (auto k = j+1; k < 5; k++)
      {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> b(N),a;
  rep(i,N){
    cin >> b[i];
  }

  while(b.size() > 0){
    auto it=b.end()-1, mItr=b.end();
    int max = 0;
    int count=b.size();

    while(it-b.begin() >= 0){
      if(count == *it){
        if(max <= *it) {
          mItr = it;
          max = *it;
        }
      }
      count--;
      it--;
    }

    if(mItr == b.end()){
      cout << -1 << endl;
      return 0;
    }

    a.push_back(max);
    b.erase(mItr);
    if(b.size()==0) break;
  }
  rep(i,a.size()){
    cout << a[a.size()-1-i] << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define mod 1000000007
char grid[1001][1001]={0};
int dp[1001][1001];

int main() {
    int h,w;    
    cin>>h>>w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
        }
    }
    // for(int i=0;i<h;++i){
    //     for(int j=0;j<w;j++){
    //         cout<< grid[i][j]<<" ";
    //     }cout<<endl;
    // }
    // cout<<helper(h-1,w-1);
    dp[1][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(grid[i-1][j-1]=='#') dp[i][j]=0;
            else dp[i][j]+=(dp[i-1][j] + dp[i][j-1])%mod;
        }
    }
    // for(int i=0;i<=h;++i){
    //     for(int j=0;j<=w;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[h][w]<<endl;
}


Measured memory_bytes: 8528
import math

a, b, h, m = map(int, input().split())

x = abs(h * 30 +  m * 0.5 - m * 6)

rad = math.radians(x)

ans_pow = a * a + b * b - 2 * a * b * math.cos(rad)

print(math.sqrt(ans_pow))


Measured memory_bytes: 9412
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath> 
using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int cost = 0, min;
    cost = abs(B - A) + abs(C - B); 
    min = cost;
    cost = abs(C - A) + abs(B - C); 
    if(cost < min)
        min = cost;
    
    cost = abs(B - A) + abs(C - A);
    if(cost < min)
        min = cost;
    
    cost = abs(B - C) + abs(C - A);
    if(cost < min)
        min = cost;
    
    cost = abs(C - A) + abs(B - A); 
    if(cost < min)
        min = cost;
    
    cost = abs(B - C) + abs(B - A); 
    if(cost < min)
        min = cost;
    cout << min <<endl;
    return 0;
}

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

class dice
{
  int top,front,back,rightside,leftside,below;
public:
  void north(),south(),east(),west();
  void input(){ cin >> top >> front >> rightside
                    >> leftside >> back >> below;};
  void output(){cout << top << endl;};
};

void dice::north()
{
  int t=top;
  top=front;
  front=below;
  below=back;
  back=t;
}
void dice::south()
{
  int t=top;
  top=back;
  back=below;
  below=front;
  front=t;
}
void dice::east()
{
  int t=top;
  top=leftside;
  leftside=below;
  below=rightside;
  rightside=t;
}
void dice::west()
{
  int t=top;
  top=rightside;
  rightside=below;
  below=leftside;
  leftside=t;
}

int main()
{
  dice dice01;
  dice01.input();
  char ward;
  while(cin >> ward)
    {
      if(ward=='N') dice01.north();
      else if(ward=='S') dice01.south();
      else if(ward=='E') dice01.east();
      else if(ward=='W') dice01.west();
    }
  dice01.output();
  return 0;
}

Measured memory_bytes: 3080
def FallenAsleep():
    playlist = []
    timelist = []
    N = int(input())
    for _ in range(N):
        s, t = input().split()
        playlist.append(s)
        timelist.append(int(t))
    X = input()
    num = playlist.index(X)
    if num == N:
        print(0)
        return()
    else:
        print(sum(timelist[num + 1:]))
        return()



FallenAsleep()


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

int main(){
    string data;

    cin >> data;

    int n = data.size();

    bool ans = true;

    rep(i, n){

        if(i%2==0){
            if(data.at(i)=='L'){
                    ans = false;
            }
        }else{
                if(data.at(i)=='R'){
                    ans = false;
                }
        }
    }

    cout << (ans? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(clippy::needless_range_loop)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct Bits(usize);

impl Bits {
    fn at(&self, index: usize) -> bool {
        self.0 & 1 << index > 0
    }

    fn set_bits(&self) -> usize {
        let mut n = self.0;
        let mut count = 0;
        while n != 0 {
            n &= n - 1;
            count += 1;
        }
        count
    }
}

macro_rules! n_bits_range {
    ($bits:expr) => {
        (0..(1 << $bits)).map(Bits)
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        s: [chars; h]
    }

    let mut ans = 99999999;
    for bits in n_bits_range!(h - 1) {
        let indices = (0..h).scan(0, |state, x| {
            let current = *state;
            *state += bits.at(x) as usize;
            Some(current)
        }).collect::<Vec<_>>();
        let mut sum = vec![0; h];
        let mut cnt = bits.set_bits();
        'quit: for x in 0..w {
            for y in 0..h {
                sum[indices[y]] += (s[y][x] == '1') as usize;
                if sum[indices[y]] > k {
                    sum = vec![0; h];
                    for i in 0..h {
                        sum[indices[i]] += (s[i][x] == '1') as usize
                    }
                    let max = *sum.iter().max().unwrap();
                    if max > k {
                        cnt = 1000000000;
                        break 'quit;
                    }
                    cnt += 1;
                    break;
                }
            }
        }

        ans = std::cmp::min(ans, cnt);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2220
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    res = 1
    D = Counter(s)
    for v in D.values():
        res *= (v + 1)
        res %= mod
    print(res - 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9572
sx,sy,tx,ty = map(int,input().split())

ans = ""

ans += "U"*(ty-sy)
ans += "R"*(tx-sx)
ans += "D"*(ty-sy)
ans += "L"*(tx-sx)

ans += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
ans += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"

print(ans)

Measured memory_bytes: 9112
#include<iostream>
#include<algorithm>

using namespace std;

int main(){

    while(1){
        int n;
        cin>> n;
        if(!n) break;

        char c[n];
        for(int i=0; i<n; i++) cin>> c[i];
        int d[26]={};
        for(int i=0; i<n; i++){
            d[c[i]-'A']++;
        }
        int e=*max_element(d, d+26);
        char f='?';
        int g=0;
        for(int i=0; i<26; i++){
            if(d[i]==e){
                if(f=='?'){
                    f=(char)(i+'A');
                }else{
                    g=1;
                }
            }
        }
        if(g){
            cout<< "TIE"<< endl;
            continue;
        }
        int D[26]={};
        int s=0;
        for(int i=0; i<n; i++){
            D[c[i]-'A']++;
            if(c[i]!=f) s=max(s, D[c[i]-'A']);
            if(s+(n-i-1)<D[f-'A']){
                cout<< f<< " "<< i+1<< endl;
                break;
            }
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

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

    vector<ll> A(N + 2);
    for(int i = 1; i <= N + 1; i++) {
        cin >> A[i];
    }

    vector<ll> B(N + 1);
    for(int i = 1; i <= N; i++) {
        cin >> B[i];
    }

    ll ans = 0;
    ll _B = 0;

    for(int i = N + 1; i >= 1; i--) {
        if(A[i] - _B < B[i - 1]) {
            ans += A[i];

            if(A[i] - _B < 0) {
                _B = B[i - 1];
            } else {
                _B = B[i - 1] - (A[i] - _B);
            }
        } else {
            ans += _B + B[i - 1];
            _B = 0;
        }
    }

    cout << ans << endl;

    // vector<ll> ans_arr;

    // for(int bit = 0; bit < (1 << N + 1); bit++) {
    //     ll _ans = 0;
    //     vector<ll> _B = B;

    //     for(int i = 0; i < N + 1; i++) {
    //         if(bit & (1 << i)) {
    //             if(A[i + 1] < _B[i + 1]) {
    //                 _ans += A[i + 1];
    //                 _B[i + 2] += _B[i + 1] - A[i + 1];
    //             } else {
    //                 _ans += B[i + 1];
    //             }
    //         } else {

    //         }
    //     }
    // }
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
typedef struct{
	double x,y,key;
}point;
point pnt[101];
int n;
int cmp(const void*a,const void*b){
	const point*c=a,*d=b;
	return c->key>d->key?-1:c->key<d->key;
}
double outer(int q,int r,int s){
	return pnt[q].x*(pnt[r].y-pnt[s].y)+pnt[r].x*(pnt[s].y-pnt[q].y)+pnt[s].x*(pnt[q].y-pnt[r].y);
}
int main(void){
	int i,m,tb[100],j;
	double k,t;
	point bs;
	for(;~scanf("%d",&n),n;){
		for(m=i=0;i<n;i++){
			scanf("%lf,%lf",&pnt[i].x,&pnt[i].y);
			if(pnt[m].y>pnt[i].y)m=i;
		}
		bs = pnt[m];
		pnt[m] = *pnt;
		*pnt = bs;
		
		pnt[100].x = bs.x;
		pnt[100].y = bs.y + 1.0;
		
		for( i = 1; i < n; i++ ){
			k = outer( 0, i, 100 );
			t = (pnt[i].x-bs.x)*(pnt[i].x-bs.x) + (pnt[i].y-bs.y)*(pnt[i].y-bs.y);
			k *= k / t;
			if( bs.x>pnt[i].x ) k = -k;
			pnt[i].key = k;
		}
		
		qsort( pnt+1, n-1, sizeof(point), cmp );
		
		tb[0]=0;
		tb[1]=1;
		tb[2]=j=2;
		for( i = 3; i < n; i++ ){
			for(;outer(tb[j-1],tb[j],i)<=0;j--);
			tb[++j] = i;
		}
		
		printf("%d\n", n - j - 1 );
	}
	return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

out = 0
for i in range(2 ** n):
    i2 = bin(i)[2:].zfill(n)
    flag = True

    for j in range(m):
        k = int(ks[j][0])
        s = ks[j][1:]
        _p = p[j]

        total = 0
        for _s in s:
            total += int(i2[_s - 1])

        if total % 2 != _p:
            flag = False

    if flag:
        out += 1
print(out)


Measured memory_bytes: 43120
N = gets.to_i
as = gets.split.map(&:to_i)

count = Array.new(10**5 + 1, 0)
as.each do |a|
    count[a - 1] += 1 if a > 0
    count[a] += 1
    count[a + 1] += 1
end

puts count.max

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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef vector<vector<pair<long long,long long>>> vvpl;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

ll gcd(ll n,ll m){
    if (n==0)return m;
    return gcd(m%n,n) ;
}

long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}

int main() {
   string s,t;
   cin >> s >>t;

   int count=0;
    for (int i = 0; i <s.size() ; ++i) {
        if(s[i]==t[i])count++;
    }
    cout <<count;
    return 0;
}



Measured memory_bytes: 256
from math import gcd

n, X = map(int, input().split())
x = list(map(int, input().split()))

def lgcd(l):
    res = l[0]
    for i in range(1, len(l)):
        res = gcd(res, l[i])
        
    return res

x.append(X)
x.sort()
d = []
for i in range(n):
    d.append(x[i + 1] - x[i])
    
print(lgcd(d))

    

Measured memory_bytes: 20324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
	int a,b,c;
	cin >> a >> b;
	c = (int)(to_string(b).length());
	c = pow(10,c);
	int x = a * c + b;
	if(sqrt(x) == int(sqrt(x))) cout << "Yes";
	else cout << "No";
	
	return 0;
}

Measured memory_bytes: 256
res = 'ABC'
ar = []
ar.append(raw_input())
ar.append(raw_input())
ar.append(raw_input())
cur_idx = 0
while True:
	if len(ar[cur_idx]) == 0:
		print res[cur_idx]
		break
	ch = ar[cur_idx][0]
	ar[cur_idx] = ar[cur_idx][1:]
	if ch == 'a':
		cur_idx = 0
	elif ch == 'b':
		cur_idx = 1
	else:
		cur_idx = 2

Measured memory_bytes: 2568
class PotUnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数
        self.diff_p = [0 for i in range(size)]#親ノードを基準としたポテンシャル

    def root(self, x): #root(x): xの根ノードを返す
        if self.parent[x] < 0:
            return x
        else:
            rx = self.root(self.parent[x]) #xをxの根rxに直接つなぎたい
            self.diff_p[x] += self.diff_p[self.parent[x]] #そのために，diff(rx,x)を計算
            self.parent[x] = rx #xをrxに直接つなげる
            return rx

    def merge(self, x, y, dxy): #ポテンシャル差の条件p(y)-p(x)=dxyでxとyのグループをまとめる
        dxy = self.diff_p[x] + dxy - self.diff_p[y] #dxyをdiff(rx,ry)で置き換え
        x = self.root(x) #rxを新たにxと名づける
        y = self.root(y) #ryを新たにyと名づける
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
            dxy = -dxy
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        self.diff_p[y] = dxy #yの相対ポテンシャルを更新
        return True

    def issame(self, x, y): #issame(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def diff(self,x,y): #diff(x,y): xを基準としたyのポテンシャルを返す 
        if self.root(x) == self.root(y): #この時点でxの親はroot(x)
            return self.diff_p[y] - self.diff_p[x]
        else:
            return None

    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]
#>>>>>>>>>>>>>>EhdCutHere>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

n,m = list(map(int,input().split()))

uf = PotUnionFind(n)
ans = True
for i in range(m):
    l,r,d=list(map(int,input().split()))
    l-=1;r-=1;
    if uf.issame(l,r):
        ans = d==uf.diff(l,r)
    else:
        uf.merge(l,r,d)
    if ans == False:
        break

if ans == False:
    print('No')
else:
    print('Yes')
#print([uf.root(i) for i in range(n)])
#print([uf.parent[i] for i in range(n)])
#print([uf.size(i) for i in range(n)])



Measured memory_bytes: 10796
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+2;j++)
        {
            dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
map<ll, int > prime_factor(ll n) {
  map<ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  map<ll,int> mp=prime_factor(N);
  ll ans = 0;
  for(auto x:mp){
    ll i = 1;
    while(1){
      x.second-=i;
      if(x.second<i+1){
        break;
      }
      i++;
    }
    ans+=i;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int gcd(int x,int y){
    if(x<y) swap(x,y);
    int r;
    while(y>0){
    r=x%y;
    x = y;
    y = r;
    }
    return x;
}
int main() {
    int x,y;
    cin >> x >> y ;
    x=gcd(x,y);
    cout << x << endl;
}



Measured memory_bytes: 3080
C = readlines.map{|l| l.split.map(&:to_i)}

# (ai, bi) => (ai+x, bi-x) => a1 = 0
a = [0, nil, nil]
b = [nil] * 3
(0 .. 2).each{|i| b[i] = C[0][i] - 0}
(1 .. 2).each{|i| a[i] = C[i][0] - b[0]}
puts [1, 2].product([1, 2]).all?{|i, j| a[i] + b[j] == C[i][j]} ? 'Yes' : 'No'

Measured memory_bytes: 1916
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 100001
#define INF   1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
char c[MAX_N];

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

    ll N, K, R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    //for(ll i = 0; i < N; i++) cin >> a[i];
    //fill(a, a + MAX_N, '');

    ll score = 0;

    for(ll i = 0; i < N; i++){
      if(T[i] == 'r')      {c[i] = 'p'; score += P;}
      else if(T[i] == 's') {c[i] = 'r'; score += R;}
      else if(T[i] == 'p') {c[i] = 's'; score += S;}
    }


    for(ll i = 0; i < N; i++){
      if(i - K >= 0) {
	if(c[i-K] == c[i]) {
	  if(c[i] == 'r')      {score -= R; c[i] = 'n';}
	  else if(c[i] == 's') {score -= S; c[i] = 'n';}
	  else if(c[i] == 'p') {score -= P; c[i] = 'n';}
	}
      }
    }

    cout << score << endl;

    return 0;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
const int NINF = -1e9;
const double eps = 1e-12;

int n, m, v, p;
int a[MAXN];

bool check(int x)
{
    LL sum = a[x]+m;
    if (sum < a[p]) return false;
    LL les = 1LL*m*v;
    les -= 1LL*(p-1)*m;
    les -= 1LL*(n-x+1)*m;
    for (int i = p;i < x;i++)
        les -= min(1LL*m, sum-a[i]);
    return les <= 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    scanf("%d%d%d%d", &n, &m, &v, &p);
    for (int i = 1;i <= n;i++)
        scanf("%d", &a[i]);
    sort(a+1, a+1+n, greater<int>());
    int l = p, r = n;
    int ans = p;
    while(l <= r)
    {
        int mid = (l+r)/2;
        if (check(mid))
        {
            ans = mid;
            l = mid+1;
        }
        else
            r = mid-1;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
//bayemirov                                       
#include <bits/stdc++.h>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef long long ll;
 
#define pb push_back
 
const int MOD = 1e9 + 7;
const int N = 1e5;
 
int dp[N][100];
 
void add(int& x, int y) {
	x += y;
	if (x > MOD) x -= MOD;
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string a;
	cin >> a;
	int b;
	cin >> b;
	int k = a.size();
	dp[0][0] = 1;
	for (int i = 1; i < k; i++) 
		for (int j = 0; j < b; j++) 
			for(int x = 0; x < 10; ++x)
				add(dp[i][j], dp[i - 1][((j - x) % b + b) % b]);
	int ans = 0;
	int sum = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < (a[i] - '0'); j++)
			add(ans, dp[k - i - 1][((b - sum - j) % b + b) % b]);
		sum += (a[i] - '0');
		sum %= b;
	}
	if(sum == 0)
		ans++;
	cout << ans - 1;
	return 0;
}                    
// ez

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

  

int main() {
  int N;
  string S;
  cin>>N>>S;
  
  for(int i=0;i<S.size();i++){
    int a=S.at(i)+N;
    if(a>90) a=a-26;
    char b=a;
    cout<<b;
  }
  cout<<endl;
  
  
}


Measured memory_bytes: 256
"
長さNの整数列 a0,a1,…,aN−1a0,a1,…,aN−1 が与えられる。
この整数列の連続する区間であって、
その区間内の値の総和が0になるものが何個あるか答えよ。
"


def nC2(n)
  n*(n-1)/2
end

# 入力
N = gets.to_i
a = []
a = gets.split.map(&:to_i)

# aの累積和をsに入れる(sはaより1だけ長い)
sum = 0
s = []
s[0] = 0
N.times do |i|
  s[i+1] = s[i] + a[i] 
end

# a[i]からa[j]までの和(i<=j, i,j=0,,,N-1)はs[j+1]-s[i]で求まる
# s[j+1]-s[i] == 0となる組み合わせの数を求めればOK
ans = 0

#s内の出現回数を数えるためのハッシュ
count = {}

# 出現回数を数える
# sの各要素.to_sをキーとするハッシュの値を+1する
s.each do |t|
  if count[t.to_s].nil?
    count[t.to_s] = 1
  else
    count[t.to_s] = count[t.to_s] + 1
  end
end

#countの各要素についてnC2を計算し合計すると組み合わせが求まる
ans = count.map{ |key, val| nC2(val) }.inject(:+)
puts ans


# 下の方法だと2重ループでTLEなる
# N.times do |i|
#   i.upto(N-1) do |j|
#     if s[j+1] == s[i]
#       ans = ans + 1
#     end
#   end
# end
#puts ans

Measured memory_bytes: 49992
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let x : u64 = read();
    let div = (x/11) * 2;
    let mut rem = if x % 11  ==  0 {
        0
    } else if x % 11 <= 6{
        1
    } else {
        2
    };
    println!("{}",div + rem);
}

Measured memory_bytes: 4352
import math

a, b, c, d = map(int, input().split())

gcd = (c * d) // math.gcd(c, d)

r = b // c + b // d - b // gcd
l = (a - 1) // c + (a - 1) // d - (a - 1) // gcd

print((b - a) - (r - l) + 1)


Measured memory_bytes: 9084