akhauriyash/Code-Regression huggingface dataset:
/*
 *
 *    I am o0o0oo00.
 *
 */
#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;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define vvll        vector<vll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll n;

ll sum(vvll v)
{
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            ans += v[i][j];
            ans %= p7;
        }
    }
    return ans;
}

vvll mul(vvll a , vvll b)
{
    vvll ans(n, vll(n, 0));
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            for (ll k = 0; k < n; k++)
            {
                ans[i][j] += (a[i][k] * b[k][j]);
                ans[i][j] %= p7;
            }
        }
    }
    return ans;
}

vvll expon(vvll base , ll p)
{
    vvll ans(n, vll(n, 0));
//   cout << "sum : " << sum(base) << endl;
    ans = base;
    // cout << "sum : " << sum(base) << endl;
    p--;
    while (p > 0)
    {
        //    cout << "sum : " << sum(base) << endl;
        if (p & 1)
            ans = mul(ans, base);
        p = p >> 1;
        base = mul(base, base);
    }
    return ans;
}


int32_t main()
{
    ss99();
//    test
    {
        ll k;
        cin >> n >> k;
        vvll v(n, vll(n, 0));
        for (ll i = 0; i < n; i++)
            for (ll j = 0; j < n; j++)
                cin >> v[i][j];
        v = expon(v, k);
        cout << sum(v) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define repp(a,b,c,d) for(int a=b; a<=c; a+=d)
#define rep(a,b,c) repp(a,b,c,1)
#define revv(a,b,c,d) for(int a=b; a>=c; a-=d)
#define rev(a,b,c) revv(a,b,c,1)
typedef long long ll;

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b-a==c-b) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, M = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
if N>1:
    ans+=comb(N,2)
if M>1:
    ans+=comb(M,2)
print(ans)




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

int main(){
  int n;cin >> n;
  v d(n);
  rep(i,n)cin >> d[i];
  
  sort(d.begin(), d.end());
  
  cout << d[n/2] - d[n/2-1] << endl;
  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);
        int N = sc.nextInt();
        long[] T = new long[N];
        for (int i = 0; i < N; i++) {
            T[i] = sc.nextLong();
        }
        System.out.println( solve(N, T) );
    }

    private static long solve(int N, long[] T) {
        long ans = T[0];
        for (int i = 1; i < N; i++) {
            ans = lcm(ans, T[i]);
        }
        return ans;
    }

    private static long lcm(long a, long b) {
        long g = gcd(a, b);
        return (a / g) * (b / g) * g;
    }

    private static long gcd(long a, long b) {
        while(b != 0) {
            long t = b;
            b = a % b;
            a = t;
        }
        return a;
    }
}

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

using namespace std;


int main() {
    long long a, b, x;
    cin >> a >> b >> x;

    long long ans;
    if(a == 0){
        ans = b / x + 1;
    }else{
        ans = b / x - (a - 1) / x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;


int cnt[26];

signed main()
{
    string S;
    cin >> S;
    
    REP(i,S.length()) {
        cnt[S[i]-'a']++;
        if (cnt[S[i]-'a'] >= 2) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}


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

using namespace std;

int main()
{
  int n,i,j;
  vector <int> v;
  
  cin >> n;
  
  for(i=1;i<=n;i++){
    cin >> j;
    v.push_back(j);
  }
  
  sort(v.begin(),v.end());
  
  for(i=1;i<n;i++){
    if(v[i] == v[i-1]){
      cout << "NO";
      return 0;
    }
  }
  
  cout << "YES";
  
  return 0;
}

Measured memory_bytes: 1400
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var abc="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split(" ");
var def="D E F G H I J K L M N O P Q R S T U V W X Y Z A B C".split(" ");
for(var i=0;i<Arr.length;i++){
var str=Arr[i];
var STR="";
for(var j=0;j<str.length;j++)STR+=abc[def.indexOf(str[j])];
console.log(STR);
}

Measured memory_bytes: 8440
N, K = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(N)]
M = sorted(L, key= lambda x:x[0])
count = 0
ans = 0
for i in range(N):
  ans = M[i][0]
  count += M[i][1]
  if (count >=K ):
    break
print(ans)

Measured memory_bytes: 29504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vvl path(n);
	REP(i, n - 1) {
		ll v, w;
		cin >> v >> w;
		v--, w--;
		path[v].push_back(w);
		path[w].push_back(v);
	}

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	else if (n == 2) {
		cout << "12" << endl;
		return 0;
	}

	vb is_leaf(n, false);
	REP(i, n) if (path[i].size() == 1) is_leaf[i] = true;

	using P = pair<ll, ll>;
	vvl u(3);
	vvl cnt(n);
	REP(i, n) if (!is_leaf[i]) {
		for (ll next : path[i]) { cnt[next].push_back(i); }
	}
	REP(i, n) {
		if (cnt[i].size() > 2) {
			cout << -1 << endl;
			return 0;
		}
		u[cnt[i].size()].push_back(i);
	}

	vl start;
	if (u[2].empty()) {
		if (u[0].size() == 1) {
			// うに
			REP(i, n) if (is_leaf[i]) {
				start.push_back(i);
				break;
			}
		}
		else {
			// ふたまたうに
			REP(i, n) if (!is_leaf[i]) {
				for (ll next : path[i]) if (is_leaf[next]) {
					start.push_back(next);
					break;
				}
			}
		}
	}
	else {
		for (ll v : u[2]) REP(i, 2) if (cnt[cnt[v][i]].size() == 1) {
			for (ll next : path[cnt[v][i]]) if (is_leaf[next]) {
				start.push_back(next);
				break;
			}
		}
	}

	function<vl(ll,ll,ll)> dfs = [&](ll cur, ll prev, ll x) {
		ll x_next = x + path[cur].size() - (prev != -1);
		vl s;
		for (ll next: path[cur]) if(next != prev && !is_leaf[next]) {
			s = dfs(next, cur, x_next);
			break;
		}
		if (s.empty()) {
			s.push_back(x_next);
		}
		s.push_back(x);
		for (ll i = x_next - 1; i > x; i--) s.push_back(i);
		return s;
	};

	vl ans = dfs(start.front(), -1, 1);
	reverse(ALL(ans));
	for (ll s : start) {
		auto t = dfs(s, -1, 1);
		reverse(ALL(t));
		if (t < ans) ans = t;
	}
	REP(i, n) cout << ans[i] << (i == n - 1 ? "" : " ");
	cout << endl;

	return 0;
}


Measured memory_bytes: 25576
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 100;
    int N, a, _max = 0, _min = 1000000001;
    cin >> N;
    REP(i, N) {
        cin >> a;
        amax(_max, a);
        amin(_min, a);
    }
    cout << _max - _min << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()

bw = 0
wb = 0
for i,c in enumerate(s):
	if i%2 == 0:
		if c == '0':
			wb += 1
		else:
			bw += 1
	else:
		if c == '0':
			bw += 1
		else:
			wb += 1

print(min(bw,wb))

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),f[100][10],p[100][11],i,j,k,m=-(1<<30),tmp,c;
	rep(i,n){
		rep(j,10){
			f[i][j]=in();
		}
	}
	rep(i,n){
		rep(j,11){
			p[i][j]=in();
		}
	}
	for(i=1;i<1<<10;i++){
		tmp=0;
		rep(j,n){
			c=0;
			rep(k,10)
				if(i&(1<<k))c+=f[j][k];
			tmp+=p[j][c];
		}
		if(m<tmp)m=tmp;
	}
	print(m);
	return 0;
}

Measured memory_bytes: 128
// C++ program to print connected components in
// an undirected graph
#include <iostream>
#include <list>
using namespace std;

// Graph class represents a undirected graph
// using adjacency list representation
int ans;
class Graph {
  int V; // No. of vertices

  // Pointer to an array containing adjacency lists
  list<int> *adj;

  // A function used by DFS
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V); // Constructor
  ~Graph();
  void addEdge(int v, int w);
  void connectedComponents();
};

// Method to print connected components in an
// undirected graph
void Graph::connectedComponents() {
  // Mark all the vertices as not visited
  bool *visited = new bool[V];
  for (int v = 0; v < V; v++)
    visited[v] = false;

  for (int v = 0; v < V; v++) {
    if (visited[v] == false) {
      // print all reachable vertices
      // from v
      DFSUtil(v, visited);

      // cout << "\n";
      ans++;
    }
  }
  delete[] visited;
}

void Graph::DFSUtil(int v, bool visited[]) {
  // Mark the current node as visited and print it
  visited[v] = true;
  // cout << v << " ";

  // Recur for all the vertices
  // adjacent to this vertex
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i])
      DFSUtil(*i, visited);
}

Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
}

Graph::~Graph() { delete[] adj; }

// method to add an undirected edge
void Graph::addEdge(int v, int w) {
  adj[v].push_back(w);
  adj[w].push_back(v);
}

// Driver program to test above
int main() {
  // Create a graph given in the above diagram
  // Graph g(5); // 5 vertices numbered from 0 to 4
  // g.addEdge(1, 0);
  // g.addEdge(2, 3);
  // g.addEdge(3, 4);

  // cout << "Following are connected components \n";
  // g.connectedComponents();

  int n,m;
  cin>>n>>m;
  Graph g(n);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    g.addEdge(u-1,v-1);
  }
  ans = 0;
  g.connectedComponents();
  cout<<ans-1;

  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, m, q; cin >> n >> m >> q;
    vector<vector<ll>> sum(n+1, vector<ll>(n+1, 0));

    rep(i, m) {
        ll l, r; cin >> l >> r;
        sum[l][r]++;
    }
    frep(i, 1, n) {
        frep(j, 1, n) {
            sum[i][j] += sum[i][j-1];
        }
    }
    frep(i, 1, n) {
        frep(j, 1, n) {
            sum[i][j] += sum[i-1][j];
        }
    }

    rep(i, q) {
        ll l, r; cin >> l >> r;
        cout << sum[r][r] + sum[l-1][l-1] - sum[l-1][r] - sum[r][l-1] << endl;
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 5508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
typedef pair<int,int> int_pair;


int main() {
    string S;
    int n = 0,s = 0,w = 0,e = 0;
    cin >> S;
    rep(i,S.length()) {
        if(S[i] == 'N') {
            n++;
        } else if(S[i] == 'S'){
            s++;
        } else if(S[i] == 'W'){
            w++;
        } else if(S[i] == 'E') {
            e++;
        }
    }
    if((n != 0 && s == 0) || (n == 0 && s != 0)) {
        cout << "No" << endl;
    } else if((w != 0 && e == 0) || (w == 0 && e != 0)) {
        cout << "No" << endl;
    } else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	int ans = S.size();
	rep(i, 2){
		int cnt = 0;
		rep(j, (int)(S.size())){
			// if (j % 2 == 0 && S.at(j) == i + '0') //even
			// if (j % 2 != 0 && S.at(j) != i + '0') //odd
			if ((j % 2) ^ (S.at(j) == i + '0')) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
N,M = map(int,input().split())
H = list(map(int,input().split()))
road = [[] for i in range(N+1)]
for i in range(M):
    A,B = map(int,input().split())
    road[A].append(H[B-1])
    road[B].append(H[A-1])
ans = 0
for i in range(N):
    if len(road[i+1]) > 0:
        rival = max(road[i+1])
        if H[i] > rival:
            ans += 1
    else:
        ans += 1
print(ans)

Measured memory_bytes: 22956
import sys
a = list(map(int,input().split()))
n = int(input())

for x in range(n):
    if a[2] <= a[1]:
        a[2] = a[2]*2
    elif a[0] >= a[1]:
        a[1] = a[1]*2
    if a[0] < a[1] < a[2]:
        print("Yes")
        sys.exit()

print("No")

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <deque>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e9 + 100;

vector<ll> pr, xr;
vector<ll> vec, srt;
vector<ll> nw;
vector<pair<ll, ll>> ps;

ll n, k, q, tree[SIZE * 4];

void build(int v, int l, int r) {
    if (l == r - 1) {
        tree[v] = vec[l];
    }
    else {
        int m = (l + r) / 2;
        build(v * 2 + 1, l, m);
        build(v * 2 + 2, m, r);
        tree[v] = min(tree[v * 2 + 1], tree[v * 2 + 2]);
    }
}

ll get(int v, int l, int r, int askl, int askr) {
    if (l >= askr || r <= askl) return INT64_MAX;

    if (l >= askl && r <= askr) return tree[v];

    ll mid = (l + r) / 2;
    return min(get(v * 2 + 1, l, mid, askl, askr), get(v * 2 + 2, mid, r, askl, askr));
}
ll check(ll lft) {
    ll vl = 0;

    ll pr = 0, s = 0, ans= 0;
    ll mx = 0, mn = 0;
    vector<ll> kt;
    vector<ll> added;
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] < lft) {
            sort(kt.begin(), kt.end());
            
            for (int t = 0; t < s - k + 1; t++) {
                added.push_back(kt[t]);
            }
            vl += (s - k + 1);
            s = 0;
            pr = 0;
            kt.clear();
        }
        else {
            s++;
            kt.push_back(vec[i]);
            pr = 1;
        }
    }

    sort(added.begin(), added.end());
    mn = INT64_MAX;
    for (int i = 0; i < q && i < added.size(); i++) {
        mx = max(mx, added[i]);
        mn = min(mn, added[i]);
    }
    if (added.size() >= q) return mx - mn;
    else {
        return -1;
    }
}

int main() {
    fastInp;

    cin >> n >> k;
    vec.resize(n);
  
    for (int i = 0; i < n; i++)cin >> vec[i];

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (vec[i] + vec[i + 1] > k) {
            ll dif = (vec[i] + vec[i + 1]) - k;
            ans += dif;
            ll q = min(vec[i + 1], dif);
            vec[i + 1] -= q;
            dif -= q;
            vec[i] -= dif;
        }
    }

    cout << ans;
    return 0;
}



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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int takahashi=a/d, aoki=c/b;
    if ((a%d)!=0) {
        takahashi++;
    }
    if ((c%b)!=0) {
        aoki++;
    }
    if (takahashi>=aoki) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll a = A*X;
    ll b = B*Y;
    ll res1 = A*X + B*Y;
    ll res2;
    ll res3;
    if (X>=Y) {
        res2 = 2*C*Y+A*(X-Y);
        res3 = 2*C*X;
    } else {
        res2 = 2*C*X+B*(Y-X);
        res3 = 2*C*Y;
    }
    ll mn = min(res1, res2);
    mn = min(mn, res3);
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

typedef pair<long long, long long> pll;
long long N, L, T;
vector<pll> X;

int main(){
	cin >> N >> L >> T;
	X.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> X[n].first >> X[n].second;
		X[n].second = 3 - 2 * X[n].second;
	}
	vector<pll> Xafter(X);
	for (int n = 0; n < N; n++) {
		Xafter[n].first += Xafter[n].second * T;
		Xafter[n].first %= L;
		Xafter[n].first += L;
		Xafter[n].first %= L;
	}
	sort(Xafter.begin(), Xafter.end(), [](pll a, pll b) {
		if (a.first != b.first)return a.first < b.first;
		else return a.second < b.second;
	});
	//あり0が順当に行けばどこにいたか求める
	int expected = 0;
	for (int n = 0; n < N; n++) {
		if (Xafter[n].first == ((X[0].first + T * X[0].second) % L + L)%L &&
			Xafter[n].second == X[0].second) {
			expected = n;
			break;
		}
	}
	//衝突回数
	long long counter = 0;
	for (int n = 1; n < N; n++) {
		if (X[n].second == X[0].second)continue;
		long long bottom = X[0].first - X[n].first;
		long long top = X[0].first - X[n].first;
		if (X[0].second == 1)top += 2 * T;
		else bottom -= 2 * T;
		counter += floor((long double)top / L) - ceil((long double)bottom / L) + 1;
	}
	for (int n = ((expected - X[0].second * counter) % N + N)%N, c = 0; c < N; c++, n = (n+1)%N) {
		cout << Xafter[n].first << endl;
	}
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int a[N],b[N][2],c[555];
bool cmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	int n=read();
	int s=1<<n; a[s]=-1;
	for (int i=0;i<s;i++) a[i]=read();
	b[0][0]=0; b[0][1]=s;
	for (int i=1;i<s;i++){
		b[i][0]=i; b[i][1]=s;
		for (int j=0;j<n;j++){
			if (i&(1<<j)){
				int x=i^(1<<j);
				c[0]=b[i][0],c[1]=b[i][1],c[2]=b[x][1],c[3]=b[x][0];
				sort(c,c+4,cmp);
				b[i][0]=c[3]; if (c[3]==c[2]) b[i][1]=c[1]; else b[i][1]=c[2];
			}
		}
	}
	int ans=0;
	for (int i=1;i<s;i++){
		ans=max(ans,a[b[i][0]]+a[b[i][1]]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 11264
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_144
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            for(int i = 1; i <= 9; i++)
            {
                if (n % i == 0 && n / i <= 9)
                {
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=1;i<=N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
int h,w;
cin>>h>>w;
char maze[h+2][w+2];

rep(i,h){
    rep(k,w){
        cin>>maze[i][k];
    }
}
rep(i,h)maze[i][0]=maze[i][w+1]='A';

rep(k,w)maze[0][k]=maze[h+1][k]='A';

bool ans=true;
rep(i,h){
    rep(k,w){
        if(maze[i][k]=='#'){
            if(maze[i-1][k]!='#'&& maze[i+1][k]!='#'&&maze[i][k+1]!='#'&&
            maze[i][k-1]!='#'){
            ans=false;
            }
        }
        /*else if(maze[i][k]=='.'){
            if(maze[i-1][k]=='#'&& maze[i+1][k]=='#'&&maze[i][k+1]=='#'&&
            maze[i][k-1]=='#'&&)ans=false;
        }*/
    }
}
if(ans){
    cout<<"Yes";
}
else{
    cout<<"No";
}
 return 0;
}
/*
3 3
.#.
###
.#.

Yes

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

No

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Yes
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

int main() {

	string s;
	cin >> s;
	vector<ll> wpos;
	rep(i, 0, s.length()) {
		if (s[i] == 'W') {
			wpos.push_back(i);
		}
	}
	ll wsum = 0;

	rep(i, 0, wpos.size()) {
		wsum += wpos[i];
	}

	wsum -= ((wpos.size() - 1) * wpos.size()) / 2;


	cout << wsum << endl;

	return 0;
}



Measured memory_bytes: 2552
#include <bits/stdc++.h>
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
 
const int N = (int)1e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
           
int kol;
       
ll ans;

ll n;              

int main()
{
	cin >> n;
	ans = n * (n - 1);
	ans /= 2ll;
	cout << ans; 			
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    vector<int> a(5);
    for(int i=0; i<5; i++) cin>>a[i];
    sort(a.begin(), a.end());

    int ans=1e9;
    do{
        int sum=0;
        for(int i=0; i<5; i++){
            sum += a[i];
            if(i == 4) break;
            while(sum % 10 != 0) sum++;
        }

        chmin(ans, sum);
    }while(next_permutation(a.begin(), a.end()));

    cout << ans << endl;
}

Measured memory_bytes: 256
def f(d,s):  #s=[0,1,2,3,4]
    global ans
    #print(d,s)
    if d==26:
        a=len(s)
        ans+=a*(a-1)//2
        return
    s1=[[s[0]]]
    for i in range(1,len(s)):
        b=1
        for j in range(len(s1)):
            a=0
            if m[s1[j][0]][d]==m[s[i]][d]:
                s1[j]+=[s[i]]
                a=1
            if a:
                b=0
                break
        if b:
            s1+=[[s[i]]]
    #print(d,s1)
    for i in range(len(s1)):
        if len(s1[i])>1:
            f(d+1,s1[i])

            






n=int(input())
m=[[0 for i in range(26)]for j in range(n)]
a=ord("a")
for i in range(n):
    s=input()
    for j in range(10):
        m[i][ord(s[j])-a]+=1
  
#for i in range(n):
#  print(m[i])

s=[i for i in range(n)]
#print(s)
ans=0
f(0,s)

print(ans)



Measured memory_bytes: 120968
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;

using namespace std;

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  int B[M];
  int A[N][M];


  for (int i = 0; i < M; i++) cin >> B[i];
  for (int i = 0; i < N; i++) {
    for (int j =0; j < M; j++) {
      cin >> A[i][j];
      //cout << A[i][j] << " ";
    }
  }
  
  int ans = 0;

  for (int i = 0; i < N; i++) {
    int s = 0;
    for (int j =0; j < M; j++) {
      //cout << A[i][j] << "**" << B[j] << "** "; 
      s += A[i][j] * B[j];
    }
    s += C;
    //cout << s << endl;
    if (s > 0) ans++;
  }
  cout << ans << endl;
}


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

int kaijo(int a){
  int i,ans=1;
  for(i=1;i<=a;i++){
  ans*=i;
  }
  return ans;
}

int mathC(int a,int b){

  int i,ans=1;
  if(b>a/2) b=a-b;
  for(i=1;i<=b;i++){
    ans*=(a-i+1);
    ans/=i;
  }
  
  return ans;
}

int max(int x[],int N){
  int i,max=x[0];
	for(i=1;i<N;i++){
      if(max<x[i]) max=x[i];
    }
  return max;
}

int min(int x[],int N){
  int i,min=x[0];
	for(i=1;i<N;i++){
      if(min>x[i]) min=x[i];
    }
  return min;
}

int main(void){
  
  long int ans=0;
  long int a,b;
	long int N=0;
	
  cin >>a >>b;
  
  while(1){
    if(floor(ans*0.08)==a) N++;
    if(floor(ans*0.1)==b) N++;
    if(N==2) break;
    if(ans>10000){
      ans=-1;
      break;
    }
    N=0;
    ans++;
  }
  
  cout << ans <<endl;
	return 0; 
}

Measured memory_bytes: 256
n=int(input())
a= list(map(int, input().split()))


mod=pow(10,9)+7

b=[0]*(n+1)
b[-1]=0
for i in range(n):
    b[n-1-i]=(a[n-1-i]+b[n-i])%mod

ans=0
for i in range(n-1):
    ans+=a[i]*b[i+1]%mod
ans%=mod
print(ans)

Measured memory_bytes: 94056
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n, m;
    cin >> n >> m;

    vector<string> in(n);
    for (int i = 0; i < n; ++i)
        cin >> in[i];

    vector<vector<int>> dp(n, vector<int>(m));
    dp[0][0] = (in[0][0] == '#');

    auto upd = [&](int old, int dp, char x, char y) {
        if (x == '.' and y == '#')
            ++dp;

        return min(old, dp);
    };
    
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (i == 0 and j == 0) {}
            else {
                dp[i][j] = 1000000;
                if (i != 0)
                    dp[i][j] = upd(dp[i][j], dp[i - 1][j], in[i - 1][j], in[i][j]);
                if (j != 0)
                    dp[i][j] = upd(dp[i][j], dp[i][j - 1], in[i][j - 1], in[i][j]);
            }

    cout << dp.back().back() << "\n";
    
    return 0;
}


Measured memory_bytes: 384
n,y = list(map(int, input().split()))
ans = [-1,-1,-1]
for i in range(n+1):
    for j in range(n+1-i):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            ans = [i,j,n-i-j]

print(" ".join(list(map(str, ans))))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var ab = Input.arL;
        if (ab[0] == 0)
        {
            WriteLine(ab[1] ^ 0);
            return;
        }
        ab[0] -= 1;
        var str = new[]{Convert.ToString(ab[0], 2),
            Convert.ToString(ab[1],2) };
        var ar = new[] { new long[str[0].Length], new long[str[1].Length] };
        for(var i = 0; i < 2; i++)
        {
            if (ab[i] <= 2)
            {
                for (var j = 0; j < ab[i]; j++)
                    ar[i][j]++;
            }
            else if (str[i][str[i].Length - 1] == '1') 
                ar[i][0] += ((ab[i] + 1) / 2) % 2;
            else
            {
                for (var j = str[i].Length - 1; j >= 0; j--)
                    if (str[i][j] == '1')
                        ar[i][str[i].Length - j - 1]++;
                ar[i][0] += (ab[i] / 2) % 2;
            }
        }
        var res = "";
        for (var i = ar[1].Length - 1; i >= 0; i--)
            if (i < ar[0].Length)
                res += (ar[1][i] + ar[0][i]) % 2;
            else res += ar[1][i] % 2;
        WriteLine(ToInt64(res, 2));
    }
    /*private static long[] Get(string str)
    {
        var num = ToInt64(str, 2);
        var Fl = (int)Floor(Log(num, 2));
        var ar = new long[Fl];
        ar[0] += (num - (long)Pow(2, Fl) + 1) / 2;
        for(var i = 1; i < str.Length; i++)
        {
            var n = ToInt64(str.Substring(i), 2);
            ar[Fl - i] += n + 1;
        }

        return ar;
    }*/
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 11348
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int MAX = 3 * 100000;
constexpr long long int MOD = 1000000007;
#define int long long int

int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

int COM(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
  int N, M, K;
  cin >> N >> M >> K;
  COMinit();

  int ans = 0;
  for (int d = 1; d < N; d++) {
    ans = (ans + d * COM(N * M - 2, K - 2) * (N - d) * M * M) % MOD;
  }

  for (int d = 1; d < M; d++) {
    ans = (ans + d * COM(N * M - 2, K - 2) * (M - d) * N * N) % MOD;
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;
 
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll ar[5]={};
    ll ans=0;
    cin >> n;
    vector<string> vi(n);
    REP(i,n) cin >> vi[i];
 
    REP(i,n){
        if(vi[i][0] == 'M') ++ar[0];
        else if(vi[i][0] == 'A') ++ar[1];
        else if(vi[i][0] == 'R') ++ar[2];
        else if(vi[i][0] == 'C') ++ar[3];
        else if(vi[i][0] == 'H') ++ar[4];
    }
 
    REP(i,5){
        FOR(j,i+1,5){
            FOR(k,j+1,5){
                ans += ar[i]*ar[j]*ar[k];
            }
        }
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;
int main()
{
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    string str1;
    string str2;
    string str3;
    cin>>str1>>str2;
    int size =max(str1.size(),str2.size());
    while(str1.size()<size)
      str1 ='0'+str1;
    while(str2.size()<size)
      str2 ='0'+str2;
    int c = 0;//桁上り
    for(int j = size-1;j >=0;j--){
      char ch = ((str1[j]-'0')+(str2[j]-'0')+c)%10+'0';
      c =((str1[j]-'0')+(str2[j]-'0')+c)/10;
      str3 =ch+str3;
  }
    if(c){
      char cs =c+'0';
      str3 = cs+str3;
    }
    while(str3.size()>1 &&str3[0] =='0')
      str3.erase(str3.begin());
    if(str3.size() >80)
      cout <<"overflow"<<endl;
    else
      cout <<str3<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
Dance = input()
i = 0
flag = 0
for char in Dance:
  if i%2 == 1:
    if char == "R":
      flag = 1
      break
  else:
    if char == "L":
      flag = 1
      break
  i+=1
  
if flag == 0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key=0;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for(i = 1; i <= n; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j + 1] = A[j];
      j --;
    }
    A[j + 1] = key;
    trace(A,n);
  }

  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>

int32_t main(){ fast;
	string s; cin>>s;
	int t = 0;
	for(char ch: s){
		t += (ch - '0');
	}
	cout<<(t % 9 == 0 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3712
#!/usr/bin/env python3
import sys, heapq
sys.setrecursionlimit(300000)


def solve(N: int, M: int, A: "List[int]"):
    h = []
    for i in range(N):
        heapq.heappush(h, -A[i])
    for i in range(M):
        tmp = -(heapq.heappop(h))
        tmp //= 2
        heapq.heappush(h, -tmp)
    ret = sum(h)
    ret = -ret
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19328
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    Ss = [input().strip("\n") for i in range(N)]
    hist_ana = {}
    for s in Ss:
        hist = [0]*27
        for c in s:
            hist[ord(c)-ord("a")]+=1
        hist = tuple(hist)
        if hist in hist_ana:
            hist_ana[hist]+=1
        else:
            hist_ana[hist]=1
    return sum([l*(l-1)//2 for k,l in hist_ana.items()])
    
print(main())


Measured memory_bytes: 129244
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.absoluteValue
import kotlin.math.min

object CMain{
    fun solve(){
        val n = nextInt()
        val a = LongArray(n){ nextLong()}
        var ans = 0L
        var max = a[0]

        for (i in 1 until n){
            if(a[i] < max){
                ans += max - a[i]
            }else{
                max = a[i]
            }
        }

        println(ans)
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun NextDouble() = next().toDouble()
}

fun main(){
    CMain.solve()
}



Measured memory_bytes: 37712