akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
const int N = (int)2e5+5;
const int inf = (int)1e17+7;
int F[N+50],L[N+50];
int gcdExtended(int a, int b, int *x, int *y); 
  
// Function to find modulo inverse of a 
int modinv(int a, int m) 
{ 
    int x, y; 
    int g = gcdExtended(a, m, &x, &y); 
   
        // m is added to handle negative x 
        int res = (x%m + m) % m; 
       	return res;
} 
  
// C function for extended Euclidean Algorithm 
int gcdExtended(int a, int b, int *x, int *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    int x1, y1; // To store results of recursive call 
    int gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 
void solve(){

	int n,k;
    cin >> n >> k;
    n++;
    mem(F,0);
    mem(L,0);
    REP(i,1,n+1){
        F[i] = i+F[i-1];
        F[i] %= MOD;
    }
    int j=1;
    RER(i,n,1){
        L[j] = L[j-1]+i;
        L[j] %= MOD;
        j++;
    }
    int tot = 0;
    REP(i,k,n+1){
        //cout << i << ' ' << L[i] << ' ' << F[i] << endl;
        tot += (L[i]-F[i]+1+MOD)%MOD;
        tot %= MOD;
    }
    cout << tot << endl;
}
int32_t main(){

	
	FASTIO;
	solve();
    return 0;

}

Measured memory_bytes: 6780
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int y, x;
	while(scanf("%d%d", &x, &y), x||y){
		vector<vector<bool> > able(10, vector<bool>(10, false));
		able[y][x] = true;
		
		int n;
		scanf("%d", &n);
		
		pii sprinkler;
		bool exists;
		rep(i, n){
			scanf("%d%d", &sprinkler.second, &sprinkler.first);
			vector<vector<bool> > tmp(10, vector<bool>(10, false));
			exists = false;
			rep(j, 10) rep(k, 10){
				if(!able[j][k])
					continue;

				const int dy[] = {-2, -2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1};
				const int dx[] = {-1, 0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2};
				rep(l, 12){
					int py = j + dy[l];
					int px = k + dx[l];
					if(py<0 || 10<=py || px<0 || 10<=px)
						continue;
					if(abs(py-sprinkler.first) <= 1 &&  abs(px-sprinkler.second) <= 1){
						tmp[py][px] = true;
						exists = true;
					}
				}
			}
			able = tmp;
		}
		
		puts(exists ? "OK" : "NA");
	}

	return 0;
}

Measured memory_bytes: 0
n, d = map(int, input().split())
xy =[list(map(int,input().split())) for i in range(n)]

dd = d*d
counter = 0

for j in range(n):
  if int(xy[j-1][0])**2 + int(xy[j-1][1])**2 <= dd:
    counter += 1

print(counter)

Measured memory_bytes: 45320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		long max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			if (A[i] > max) {
				max = A[i];
			}
		}
		long maxhalf = Long.MAX_VALUE;
		for (int i = 0; i < N; i++) {

			if (A[i] != max && Math.abs(max / 2 - A[i]) < Math.abs(max / 2 - maxhalf)) {
				maxhalf = A[i];
			}
		}

		System.out.println(max + " " + maxhalf);

	}
}


Measured memory_bytes: 63224
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    multiset<ll> st;
    rep(i,n) {
        ll a; cin>>a;
        if (st.empty()) st.insert(a);
        else {
            auto itr = st.lower_bound(a);
            if (itr == st.begin()) st.insert(a);
            else {
                st.erase(prev(itr));
                st.insert(a);
            }
        }
    }
    
    cout << st.size() << '\n';
    return 0;
}

Measured memory_bytes: 4992
//aea ctmr https://codeforces.com/contest/1271/submission/66946806
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
    
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 105000;
const ll mod = 1e9 + 7;
using namespace std;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
 
vector <pair <int, int>> xd;

int main(){

    int n; cin >> n;
    string s, s2;
    cin >> s >> s2;

    for(int i = 0; i < n; i++) cout << s[i] << s2[i]; cout << endl;

    return 0;
 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using uint1024_t = mp::uint1024_t;
using namespace std;


int main() {
	ll D; ll G;
	cin >> D >> G;
	vector<pair<ll,ll>>a(D);
	rep(i, D) {
		ll p, c;
		cin >> p >> c;
		a[i].first = p;
		a[i].second =(ll) (i + 1) * 100 * p + c;
	}
	ll ans = 1e10;
	ll i = 0;
	while (i < pow(2, D)) {
		ll sum = 0;
		ll count = 0;
		int rest_max = 0;
		rep(j, D) {
			if (i&(1LL << j)) {
				sum += a[j].S;
				count += a[j].F;
			}
			else {
				rest_max = j;
			}
		}
		bool flag = false;
		if (sum < G) {
			int count1 = 0;
			while (sum < G) {
				sum += (rest_max + 1) * 100;
				count1++;
			}
			if (count1 < a[rest_max].F) {
				count += count1;
				flag = true;
			}
		}
		else {
			flag = true;
		}
		if (flag) {
			ans = min(ans, count);
		}
		i++;
	}
	cout << ans << endl;
}

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

using ll = long long;

#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 pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }


inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N, K; cin >> N >> K;
	vector<ll> n(K);
	ll p = 0;
	REP(i, N) {
		n[p]++;
		p++;
		if (p == K) p = 0;
	}
	ll ma=0, mi=INT32_MAX;
	REP(i, K) chmax(ma, n[i]), chmin(mi, n[i]);
	cout << ma - mi << endl;

	return 0;
}

//*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long bit[300000], n, a[300000], b[300000], ans, _size;
void add(long long x, long long k) {
	while (x <= _size) {
		bit[x] += k;
		x += x&-x;
	}
}
long long sum(long long x) {
	long long cnt = 0;
	while (x >= 1) {
		cnt += bit[x];
		x -= x&-x;
	}
	return cnt;
}
int main() {
	cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = i; }
	for (int i = 1; i <= 20; i++) {
		if (n + 10 <= (1 << i)) { _size = (1 << i); break; }
	}
	for (long long i = 1; i <= n; i++) {
		long long _L = 0, _R = 0;
		long long L, R, M, P;

		//binary search LEFT.
		L = 1; R = b[i] + 1; P = sum(b[i]);
		for (long long j = 0; j < 100; j++) {
			M = (L + R) / 2;
			long long S1 = sum(M - 1), S2 = sum(M);
			if (S1 < P && S2 == P)break;
			if (S1 == P)R = M; if (S2 < P)L = M;
		}
		_L = M + 1; if (P == 0)_L = 1;

		//binary search RIGHT.
		L = b[i]; R = n + 1; P = sum(b[i]);
		for (long long j = 0; j < 100; j++) {
			M = (L + R) / 2;
			long long S1 = sum(M), S2 = sum(M + 1);
			if (S1 == P && S2 > P)break;
			if (S2 == P)L = M; if (S1 > P)R = M;
		}
		if (M > n)M = n; _R = M;

		ans += (_R - b[i] + 1)*(b[i] - _L + 1)*i; 
		add(b[i], 1LL);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long

int main(void)
{
  ll a;
  long double b, c;
  scanf("%lld%Lf", &a, &b);
  c = a * b;
  printf("%lld\n", (ll)c);
  return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,p=0,i;
    char s[10000];
    scanf("%d",&n);
    scanf("%s",s);
    if(n%2==0)
    {
        for(i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+(n/2)])
            {
               p=1;
            }
        }
        if(p==0)
            printf("Yes");
        else
            printf("No");
    }
    else
        printf("No");

    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

ct = 0
s = 0
xor = 0
r = 0
for l in range(N):
    while r < N and s+A[r] == xor ^ A[r]:
        xor ^= A[r]
        s += A[r]
        r += 1
    # print(l,r)
    ct += r-l
    s -= A[l]
    xor ^= A[l]
    # print(s,xor)
print(ct)


Measured memory_bytes: 92164
#include <iostream>
#include <stdio.h>

int main(){
  char s[3], t[3];
  std::cin >> s >> t;

  int cnt = 0;
  for(int i = 0; i < 3; i++)
    if(s[i] == t[i]) cnt ++;

  std::cout << cnt << "\n";

  return 0;
}


Measured memory_bytes: 256
/*
  AOJ 2518
  Title:　B2D
  @kankichi573
*/
#include <stdio.h>
// #include <stdlib.h>
#include <string.h>
// #include <math.h>
// #include <float.h>
// #include <stdlib.h>

int N;
int total_len;
char buf[1024];

// ABCABC ABCDABCD etc => true
int pattern(char * s,int len)
{
  return(0==strncmp(s,s+len,len));
}
display(char *p,int len)
{
  int i;

  for(i=0;i<len;i++,p++)
      printf("%c",*p);
  printf("\n");
}

int count_shurui(int level)
{
  int i,j;
  int cnt;
  int nc;

  nc=1<<level;

  for(i=0,cnt=0;i<total_len;i += nc)
    {
      //display(buf+i,nc);

      if(pattern(buf+i,1<<(level-1)))
	continue;
      for(j=0;j<i-1;j += nc)
	{
	  if(0==strncmp(buf+i,buf+j,nc))
	    goto NEXT;
	}
      cnt++;
    NEXT:
      ;
    }

  return(cnt);
}
int solve()
{
  int i,cnt,ret;

  for(i=1,cnt=0;i<=N;i++)
    {
      ret = count_shurui(i);
      //printf("%d %d\n",i,ret);
      cnt += ret;
    }
  return(cnt);
}
main()
{
 
  int i,ret;

  scanf("%d",&N);
  total_len = 1<<N;
  scanf("%s",buf);

  //printf("%d\n",b2n(buf,4));
  //printf("p166=%d\n",pattern(166,4));

  ret=solve(buf);
  //printf("ANS=");
  printf("%d\n",ret);
    
  return(0);
 
}

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

int main(void){
	char a, b;
	bool aCD, tCD;

	cin >> a >> b;

	if (a == 'H') aCD = true;
	else aCD = false;
	if (b == 'H') tCD = true;
	else tCD = false;

	if (aCD == false) tCD = !tCD;

	if (tCD == true) cout << 'H' << endl;
	else cout << 'D' << endl;

	return 0;
}

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

int main() {
	string taro,hanako;
    int n,taros,hanakos;
    taros = 0;
    hanakos = 0;
    cin >> n;
    for(int i = 0;i < n;i++){
    	cin >> taro >> hanako;
    	if(taro > hanako)
    		taros += 3;
    	else if(taro < hanako)
    		hanakos +=3;
    	else{
    		taros ++;
    		hanakos ++;
    	}
    }
    cout << taros << " " << hanakos << endl;
	return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define se second
#define fi first
using namespace std;
main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a1=0,a2=0;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]==')')a1++;
    else{
      if(a1)a1--;
    }
  }
  r(i,s.size()){
    if(s[i]=='(')a2++;
    else{
      if(a2)a2--;
    }
  }
  r(i,a1)cout<<'(';
  cout<<s;
  r(i,a2)cout<<')';
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string str[10],in;

void init(){
  str[0] = "* = ****";
  str[1] = "* =* ***";
  str[2] = "* =** **";
  str[3] = "* =*** *";
  str[4] = "* =**** ";
  str[5] = " *= ****";
  str[6] = " *=* ***";
  str[7] = " *=** **";
  str[8] = " *=*** *";
  str[9] = " *=**** ";
}

void solve(string s,int count){
  if(count) cout << endl;

  int len = (int)s.size();
  string ans[5];  

  if(len == 5){
    for(int i = 0 ; i < len ; i++)
      ans[i] = str[s[i]-'0'];
  }
  else{
    for(int i = 0 ; i < 5-len ; i++){
      ans[i] = str[0];
    }
  
    int t = 0;
    for(int i = 5-len ; i < 5 ; i++)
      ans[i] = str[s[t++]-'0'];
  }

  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 5 ; j++){
      cout << ans[j][i];
    }
    cout << endl;
  }
}

int main(){
  init();

  int count = 0;
  while(cin >> in){
    solve(in,count);
    count++;
  }

  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a=n/1000;
    int b=(n%1000)/100;
    int c=(n%100)/10;
    int d=n%10;
    if(a+b+c+d == 7){
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a+b+c-d == 7){
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a+b-c+d == 7){
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a+b-c-d == 7){
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a-b+c+d == 7){
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a-b+c-d == 7){
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a-b-c+d == 7){
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a-b-c-d == 7){
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
}

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

using namespace std;

#define int long long

int dp[11][11], n, m, ans = 0;

struct node {
  int a, b, c, d;
  node(){}
  node(int x, int y, int z, int zz) {
    a = x;
    b = y, c = z, d = zz;
  }
};

vector<node> Q;

int get(vector<int> &v) {
  int x = 0;
  for (const auto &[a, b, c, d]: Q) {
    if (v[b] - v[a] == c) x += d;
  }
  return x;
}

void go(int id, int last, vector<int> &v) {
  if (id == n) {
    ans = max(ans, get(v));
    return;
  }
  int ans = 0;  
  for (int i = last; i <= m; ++i) {
    v.push_back(i);
    go(id + 1, i, v);
    v.pop_back();
  }
}

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // memset(dp, -1, sizeof dp);
  vector<int> v(1);
  int q;
  cin >> n >> m >> q;
  Q.resize(q);
  for (auto &[a, b, c, d]: Q) {
    cin >> a >> b >> c >> d;
  }
  go(0, 1, v);
  cout << ans << '\n';

  return 0;
}       

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
struct Card{char suit,value;};

void bubble(struct Card A[],int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
        Card t=A[j];
        A[j]=A[j-1];
        A[j-1]=t;
      }
    }
  }
}
void selection(struct Card A[],int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j].value<A[minj].value)minj=j;
    }
    Card t=A[i];
    A[i]=A[minj];
    A[minj]=t;
  }
}
void print(struct Card A[],int N){
  for(int i=0;i<N;i++){
    if(i>0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}
bool isStable(struct Card C1[],struct Card C2[],int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit)return false;
  }
  return true;
}
int main(){
  Card C1[100],C2[100];
  int N;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }
  for(int i=0;i<N;i++)C2[i]=C1[i];
  bubble(C1,N);
  selection(C2,N);
  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }
  else{
    cout << "Not stable" << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;
const int max_n = 1e6 + 5;
int deg[25];

int main() {
	FOR(i,0,3) {
		make2(a, b);
		deg[a]++;
		deg[b]++;
	}
	int ile = 0;
	FOR(i,1,5) {
		ile += (deg[i]%2);
	}
	(ile == 4) ? puts("NO") : puts("YES");
}




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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int

#define mod 1000000007

unsigned long long power(unsigned long long x, int y, int p) 
{ 
    unsigned long long res = 1; 
  
    x = x % p; 
  
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % p; 
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 

vector<int> fac(1000005); 

unsigned long long nCrModPFermat(unsigned long long n, int r, int p) 
{ 
    if (r == 0) 
        return 1; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 

void fun()
{
    fac[0] = 1; 
    for (int i = 1; i <= 1000005; i++) 
        fac[i] = (fac[i - 1] * i) % mod; 
}

int calc(int n, int r)
{
    return nCrModPFermat(n+r-1, r-1, mod);
}

void solve(int caseNo)
{
    fun();
    int s;
    cin >> s;
    int ans = 0;
    for(int i=1;i<=s;i++)
    {
        int t = s;
        if(t-i*3 < 0)   break;
        t -= i*3;
        ans += calc(t, i);
        ans %= mod;
    }
    cout << ans << endl;
    return;
}

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int cases;
    cases = 1;
    for(int i=1;i<=cases;i++)
    {
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 11020
#include <cstdio>
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
    ll number = 1000000000000;
    cin >> number;
    
    ll result = 0;
    for(ll i = 1; i * i <= number; ++i) {
        if((number - i) % i == 0) {
            ll j = (number - i) / i;
            if(j == 0) { continue; }
            if(number / j == number % j) {
                result += j;
            }
        }
    }
    
    cout << result << endl;
    return 0;
}

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

#define NIL -1
#define MAX 250

int heap[MAX];

int main(){

  int H;
  scanf("%d", &H);

  for(int i=0; i<H; i++){
    scanf("%d", &heap[i]);
  }

  for(int i=0; i<H; i++){
    printf("node %d: ", i+1);
    printf("key = %d, ", heap[i]);

    if((i+1)/2 > 0){
      printf("parent key = %d, ", heap[(i+1)/2 - 1]);
    }

    int c = (i+1)*2 - 1;
    if(c < H) printf("left key = %d, ", heap[c]);
    if(++c < H) printf("right key = %d, " , heap[c]);
    printf("\n");
  }

  return 0;
}



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

int main()
{
    int n = 0, i;
    while (cin >> n, n)
    {
        double sum = 0, a = 0, m;
        int s[n];
        for (i = 0; i < n; i++)
        {
            scanf("%d", &s[i]);
            sum += s[i];
        }
        m = sum / n;
        for (i = 0; i < n; i++)
        {
            a += (s[i] - m) * (s[i] - m);
        }
        a = sqrt(a / n);
        printf("%lf\n", a);
    }
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(){
  string Number;
  while(1){
    cin >> Number;
    if(atoi(Number.c_str()) == 0)break; 
    int Len=Number.size();
    int N[Len][11];
    for(int n=0;n<Len;++n){
      for(int m=0;m<11;++m){
	N[n][m]=0;
      }
    }
    if(atoi(Number.substr(0,1).c_str())!=0)N[0][atoi(Number.substr(0,1).c_str())]=1;
    Number.erase(0,1);
    for(int n=1;n<Len;++n){
      int k;
      k=atoi(Number.substr(0,1).c_str());
      if(k!=0)N[n][k]+=1;
      for(int m=0;m<11;++m){
	if(N[n-1][m]!=0){
	  N[n][(m*10+k)%11]+=N[n-1][m];
	}
      }
      Number.erase(0,1);
    }
    int Ans=0;
    for(int n=0;n<Len;++n){
      Ans+=N[n][0];
    }
    cout << Ans << endl;
  }
}

Measured memory_bytes: 4784
#include<stdio.h>
int main()
{  int k,n,a[200000],i,l,lx;
   scanf("%d%d",&k,&n);
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   lx=a[0]+k-a[n-1];
   for(i=1;i<n;i++)
   {  l=a[i]-a[i-1];
      if(l>lx) lx=l;
   }
   printf("%d",k-lx);
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int maxdist, maxnode;
vector<int> adj[500001];
vector<int> dist(500001);
 
void dfs(int now, int prev) {
      dist[now] = dist[prev] + 1;
      if (dist[now] > dist[maxnode]) maxnode = now;
 
      for (auto u: adj[now]) {
            if (u != prev) dfs(u, now);
      }
}
 
signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
 
	int n; cin >> n;
	for (int i = 1; i < n; i++) {
            int x, y;
            cin >> x >> y;
            adj[x].push_back(y);
            adj[y].push_back(x);
	}
	dfs(1, 0);
	dfs(maxnode, 0);
 
	if ((dist[maxnode] - 1) % 3 == 1) {
	    cout << "Second";
	} else {
	    cout << "First";
	}
 
	return 0;
}

Measured memory_bytes: 29568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> g;
int n, U, V;


vector<int> bfs(int u){
    vector<int> d(n,0);
    queue<int> q;
    d[u] = 1;
    q.push(u);
    while (!q.empty()){
        int s = q.front();
        q.pop();
        for (int v: g[s])
            if (!d[v]){
                d[v] = d[s] + 1;
                q.push(v);
            }
    }


    return d;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    g.resize(n);

    cin >> U >> V;
    U--, V--;
    for (int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    vector<int> dist_U = bfs(U);
    vector<int> dist_V = bfs(V);
    
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (dist_U[i] < dist_V[i])
            ans = max(ans, dist_V[i]);

    cout << ans - 2;        
    return 0;
}

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

using namespace std;

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < N; i++) {
    cout << s[i];
  }
}

Measured memory_bytes: 256
// 2017/04/21 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int partition(int A[], int p, int r)
{
	int x = A[r];
	int i = p-1;

	for(int j=p; j<=r-1; j++){
		if(A[j]<=x){
			i++;
			swap(A[i], A[j]);
		}
	}

	swap(A[i+1], A[r]);

	return i+1;
}

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

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

	int q = partition(A, 0, n-1);

	for(int i=0; i<n; i++){
		if(i==q){
			cout << '[' << A[i] << ']';
		}
		else{
			cout << A[i];
		}

		if(i<n-1){
			cout << ' ';
		}
		else{
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3372
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


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

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

LL N;

void solve()
{
    ++N;
    int x = __builtin_popcountll(N) - 1;
    int y = 63 - __builtin_clzll(N);

    vector<int> ans;

    for (int i = 1; i <= x + y; ++i) {
        ans.push_back(i);
    }
    int a = x, b = x;
    for (int i = y - 1; i >= 0; --i) {
        ans.push_back(++a);
        if (N >> i & 1)
            ans.push_back(b--);
    }

    printf("%d\n", SZ(ans));
    for (auto t : ans) {
        printf("%d ", t);
    }
    puts("");}


int main()
{
#ifdef __DEBUG
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
#endif

    read(N);
    solve();

    return 0;
}

// 不似秋光，只与离人照断肠。
//     -- 苏轼《减字木兰花·春月》


Measured memory_bytes: 256
ans=0
MOD=10**9+7
n,k=map(int,input().split())
min=0
max=n
num0=0
num1=n
for i in range(n+1):
  #print(min,max)
  i+=1
  if i>=k:
    ans+=max-min+1
    ans=ans%MOD
  min+=num0+1
  num0+=1
  max+=num1-1
  num1-=1
print(ans)

Measured memory_bytes: 9188
def solve(x, y, d, m):
    ret = ""
    for i in range(m):
        if x + y >= 0 and x - y >= 0:
            ret += "R"
            x -= d[i]
        elif x + y >= 0 and x - y < 0:
            ret += "U"
            y -= d[i];
        elif x + y < 0 and x - y >= 0:
            ret += "D"
            y += d[i];
        else:
            ret += "L"
            x += d[i]
    print (ret)


def main():
    m = 34
    X, Y, d = [], [], []

    for i in range(32, 0, -1):
        d += [2**i]
    d += [1]

    N = int(input())
    even, odd = 0, 0

    for i in range(N):
        x, y = map(int, input().split())
        X += [x]; Y += [y]
    
        if (abs(x) + abs(y)) % 2 == 0:
            even += 1
        else:
            odd += 1

    if even and odd:
        print(-1)
        return 0

    if odd:
        m -= 1
    else:
        d += [1]

    print(m)
    print(" ".join(map(str, d)))

    for i in range(N):
        solve(X[i], Y[i], d, m)

main()


Measured memory_bytes: 3188
fn main() {
    proconio::input! {
        x: i128,
        k: i128,
        d: i128,
    }
    if (k * d).abs() <= x.abs() {
        let ans = if x < 0 { x + k * d } else { x - k * d };
        println!("{}", ans.abs());
    } else {
        let div = x.abs() as i128 / d;
        let remaining = k - div;
        let ans = if x < 0 {
            let x = x + div * d;
            if remaining % 2 == 0 {
                x
            } else {
                x + d
            }
        } else {
            let x = x - div * d;
            if remaining % 2 == 0 {
                x
            } else {
                x - d
            }
        };
        println!("{}", ans.abs());
    }
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int tn;
  cin >> tn;
  vector<int> ts (tn+1,0);
  for ( int i=0; i<tn ;i++ ) {
    cin >> ts[i];
  }
  int tall = 0;
  for (int i = 0; i<tn ; i++ ) {
    if (tall < ts[i] ) {
      tall = ts[i];
    }
  }
  int ans =0;
  for (int i=0; i<tall ; i++ ) {
    for (int j = 0; j<tn; j++ ) {
      if ( ts[j] > i && ts[j+1] <= i ) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

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

    string s;
    cin >> s;
    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));
    if (y < 2019 || (y == 2019 && m < 4)
        || (y == 2019 && m == 4 && d <= 30)) cout << "Heisei\n";
    else cout << "TBD\n";

    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    int p[N]; REP(i,N) cin >> p[i];

    int ans = 0;
    REP(i,N-1){
        if(p[i] == i+1){swap(p[i], p[i+1]); ans++;}
    }
    if(p[N-1] == N) ans++;
    cout << ans << endl;
    return 0;
}

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int MOD = (int)1e9 + 7;
const int INV= 500000004;
const int MAX_N = 5000 + 5;
int dp[MAX_N][MAX_N];

int main(){
	int n,c;
	string s;
	cin >> n >> s;
	c = SZ(s);
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	rep(i,1,n+1) {
		dp[i][0] = (dp[i-1][0] + dp[i-1][1])%MOD;
		rep(j,1,i+1) {
			dp[i][j] = (dp[i-1][j-1]*2%MOD + dp[i-1][j+1])%MOD;
		}
	}
	rep(i,0,c) dp[n][c] = (ll)dp[n][c]*INV%MOD;
	cout<<dp[n][c]<<endl;
	return 0;
}

Measured memory_bytes: 98176
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	ll X;
	cin >> X;
	int i = 1;
	while (true)
	{
		ll sum = i * (i + 1) / 2;
		if (sum >= X)
		{
			break;
		}
		i++;
	}
	co(i);
	return 0;
}

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

using namespace std;

static const int MAX = 10000;
static const int INF = 1 << 30;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[MAX];


void dijkstra(){
    priority_queue<pair<int, int>> pq;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; ++i){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    pq.push(make_pair(0, 0));
    color[0] = GRAY;

    while (!pq.empty()){
        pair<int, int> f = pq.top();
        pq.pop();
        int u = f.second;
        color[u] = BLACK;
        if( d[u] < f.first*(-1 ))
            continue;

        for (int j = 0; j < adj[u].size(); ++j){
            int v = adj[u][j].first;
            if( color[v] == BLACK ) {
                continue;
            }
            if (d[v] > d[u] + adj[u][j].second )
            {
                d[v] = d[u] + adj[u][j].second;
                pq.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

int main()
{
    cin >> n;
    int k, c, u, v;
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();
    return 0;
}


Measured memory_bytes: 7976
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i,sum=0;
   cin>>n;
   int a[n],b[n],c[n-1];
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   for(i=0;i<n;i++)
   {
       cin>>b[i];
   }
   for(i=0;i<n-1;i++)
   {
       cin>>c[i];
   }
   for(i=0;i<n;i++)
   {
       //cout<<b[a[i]-1]<<" ";
       sum=sum+b[a[i]-1];
   }
   //cout<<sum;
   for(i=0;i+1<n;i++)
    {
       if(a[i]+1==a[i+1])
       {
           //cout<<i<<" "<<c[i]<<endl;
           //cout<<a[i+1]<<" == "<<a[i]+1;
           sum=sum+c[a[i]-1];
       }
   }
   cout<<sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
struct dsa
{
	int v,c;
}a[30];
int ans=0;
int s=0,s1=0;
bool cmp(dsa p,dsa q)
{
	return (p.v-p.c>q.v-q.c);
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i].v;
	for (int i=1;i<=n;i++) cin>>a[i].c;
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++)
	{
		s+=a[i].v;
		s1+=a[i].c;
		ans=max(s-s1,ans);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
print(700 + Counter(rs())['o'] * 100)

Measured memory_bytes: 63088
#include <iostream>
#include <vector>

using namespace std;
struct edge{int num,to;};
vector<int> G[100010],rG[100010],vs;
bool used[100010];
int comp[100010],n,m,ans = 0;
void add_edge(int from, int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v] = true;
	for(int x:G[v]){
		if(!used[x]) dfs(x);
	}
	vs.push_back(v);
}

void rdfs(int v,int k){
	used[v] = true;
	comp[v] = k;
	for(int x:rG[v]){
		if(!used[x]) rdfs(x,k);
	}
}

int scc(){
	int i,k = 0;
	for(i=0;i<n;i++) used[i] = false;
	for(i=0;i<n;i++){
		if(!used[i]) dfs(i);
	}
	for(i=0;i<n;i++) used[i] = false;
	for(i=vs.size()-1;i>=0;i--){
		if(!used[vs[i]]){
			rdfs(vs[i],k); k++;
		}
	}
	return k;
}

int main(){
	int i,j;
	cin >> n >> m;
	for(i=0;i<m;i++){
		int a,b; cin >> a >> b; a--; b--;
		add_edge(a,b);
	}
	int x = scc();
	for(i=0;i<n;i++){
		x = comp[i];
		bool flag = false;
		for(j=0;j<n;j++){
			if(comp[j]==x){
				if(flag) cout << " ";
				flag = true;
				cout << j + 1;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 8988
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18
double l(vector<ll> x,vector<ll> y){
	ll ans=0;
	REP(i,x.size()){
		ans+=(x[i]-y[i])*(x[i]-y[i]);
	}
	return sqrt((double)ans);
}
int main(){
	ll N,D;
	cin>>N>>D;
	vector<vector<ll>> x(N,vector<ll>(D));
	REP(i,N){
		REP(j,D){
			cin>>x[i][j];
		}
	}
	ll cnt=0;
	REP(i,N){
		FOR(j,i+1,N){
			double tmp=l(x[i],x[j]);
			if(tmp==(int)tmp)cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


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

int main(){
  int n,k,x;
  int i;
  int a = 0;

  scanf("%d %d", &n, &k);

  for(i = 0;i < n;i++){
    scanf("%d", &x);
    if(x >= k) a++;
  }

  printf("%d\n", a);

  return 0;
}


Measured memory_bytes: 128
S=sorted
n,k,*a=map(int,open(i:=0).read().split())
l=S([-a,i:=i+1]for a in a)
_,r=zip(*l)
while k:
 *_,b=r;k-=1
 for t in S(l):
  if t[1]-b:t[t[0]>-2<exit(print(-1))]+=1;r+=t[1],
print(len(r),*r)

Measured memory_bytes: 9400
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;	
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
 
template <typename T>
void cetak(T t){cout << t << ')' << endl;}
template <typename T, typename... V>
void cetak(T t, V... v) {cout << t; if (sizeof...(v)) cout << ", "; cetak(v...);}
 
#define debug(x...) cout << '(' << #x << ") = ("; cetak(x) 
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())


const int MOD = 1e9 + 7;

int add(int x, int y){
    int ret = x + y;
    if(ret >= MOD) ret -= MOD;
    return ret;
}
int sub(int x, int y){
    int ret = x - y;
    if(ret < 0) ret += MOD;
    return ret;
}
int mul(int x, int y){
    return (long long)x * y % MOD;
}


const int mx = 1e5 + 10;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> ac(n, 0), sub(n, 0);
    int AC = 0, submit = 0;
    for(int i = 0; i < m; i++){
        string ss;
        int x;
        cin >> x >> ss;
        x -= 1;
        if(ac[x]) continue;
        if(ss == "AC"){
            ac[x] = 1;
            AC += 1;
            submit += sub[x];
            continue;
        }
        sub[x] += 1;
    }
    cout << AC << ' ' << submit << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

    int n;
    cin >> n;

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

    int ans = INF;
    for (int p = 1; p <= 100; p++) {
        int cost = 0;
        for (int i = 0; i < n; i++) {
            cost += (a[i] - p) * (a[i] - p);
        }
        ans = min(ans, cost);
    }

    cout << ans << "\n";
}

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

int main(){
    int A,B,C,X;
    cin >> A >> B >> C>> X;
    int res=0;
    for (int a=0; a<=A; ++a){
        for(int b=0;b<=B;++b){
            for(int c=0;c<=C;++c){
                int total = 500*a+100*b+50*c;
                if(total == X) ++res;
            }
        }
    }
    cout << res << endl;
}

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

int main(){
  int n, a;
  cin >> n >> a;
  
  int ans = 1, h = a, b;
  for (int i = 0; i < n-1; i++) {
    cin >> b;
    if (h <= b) {
      ans ++;
      h = max(h, b);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] num = new int[N];
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(sc.next());
    }
    int ans = 0;
    
    for(int i = 1; i < N-1; i++){
      if((num[i-1] <= num[i] && num[i] <= num[i+1])
        	|| (num[i-1] >= num[i] && num[i] >= num[i+1])){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include <cstdio>
const int maxn = 105;
using namespace std;
char s[maxn]; int n;
int main(){
	scanf("%d%s", &n, s);
	if (n & 1){
		puts("No");
		return 0;
	}
	for (int i = 0; i < n / 2; i++)
		if (s[i] != s[i + n / 2]){
			puts("No"); return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128