akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
//Factors of an num
/*
vector<ll> fact(ll n){
	vector<ll>v;
	for(int i=1;i*i<=n;i++){
		if(n%i ==0){
			v.push_back(i);
		
		if(i!=n/i)
			v.push_back(n/i);
	    }
	}

	return v;
}
*/


/*
Seive Of Eratos..
int N=1e5;
vector<bool> isprime(N+1,true);
void pri(int n){
	for(int i=2;i*i<=n;i++){
		if(isprime[i]){
			for(int j=i*i;j<=n;j+=i){
				isprime[j]=false;
			}
		}
	}
	return;
}
*/

/*
//Prime Factors
vector<bool> isprime(1e6+1,true);
 vector<int> primes;
 void sieve()
 {

    ll  i,j;
    isprime[0] = false;
    isprime[1] = false;

    for(i=2; i<=1e6 ;i++)
  {

    if(isprime[i])
    {

      primes.push_back(i);

      for(j=i*i; j<=1e6; j+=i)
      {
        isprime[j]=false;
      }

    }

  }
}

vector<int> primefactors(int  N)

 {

    vector<int> factors;
    ll pf_idx = 0, pf=primes[pf_idx];

    while(pf*pf<=N)
    {
        while(N % pf == 0)
        {
            N/=pf;
            factors.push_back(pf);
        }
        pf = primes[++pf_idx];
    }
    
    if(N != 1) factors.push_back(N);
    return factors;
}
 */   




int main(){
	 
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin.tie(NULL);

string s,t;
cin>>s>>t;
ll cnt=0;
for(int i=0;i<s.length();i++){
	if(s[i]!=t[i])
		cnt++;
}
cout<<cnt<<endl;
}

Measured memory_bytes: 3804
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// B - Maximum Difference
int main(){
    int N;
    cin >> N;
    int A[110];
    rep(i, 0, N){
        cin >> A[i];
    }
    int ans = 0;

    rep(i, 0, N){
        rep(j, 0, N){
            ans = max(ans, abs(A[i]-A[j]));
        }
    }

    cout << ans << endl;
    return 0;
}




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

ll dis[2020][2020],yan[2020][2020];
ll cnt[2020];
int main() {
	ll n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
		dis[i][j]=j-i;
		dis[j][i]=j-i;
		yan[i][j]=yan[j][i]=j-i;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			dis[i][j]=min(dis[i][j],yan[i][x]+yan[y][j]+1);
			dis[i][j]=min(dis[i][j],yan[i][y]+yan[x][j]+1);
			dis[j][i]=dis[i][j];
		}
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)cnt[dis[i][j]]++;
	for(int i=1;i<n;i++)cout<<cnt[i]<<endl;
	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> X, L;
  vector<lpair> perm;

  cin >> N;
  X.resize(N);
  L.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i] >> L[i];
    perm.push_back(lpair(X[i] + L[i], i));
  }
  sort(ALL(perm));

  llong ans = 0, right = -inf<llong>;
  for (int i = 0; i < N; ++i) {
    if (right <= X[perm[i].second] - L[perm[i].second]) {
      ++ans;
      right = perm[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 h,w,m;
    cin >> h >>w >>m;

    unordered_map<i64,unordered_set<i64>> hw;
    unordered_map<i64, i64> h_map, w_map;
    for (int i=0; i<m; ++i) {
        i64 h1,w1;
        cin >> h1 >> w1;
        auto it = h_map.find(h1);
        if (it==h_map.end()) {
            h_map[h1] = 1;
            hw[h1] = unordered_set<i64>();
        } else {
            ++h_map[h1];
        }

        auto it2 = w_map.find(w1);
        if (it2==w_map.end()) {
            w_map[w1] = 1;
        } else {
            ++w_map[w1];
        }
        hw[h1].insert(w1);
    }
    i64 w_max{0}, h_max{0};
    vector<i64> w_max_v, h_max_v;
    for (auto kv : h_map) {
        if (kv.second > h_max) {
            h_max = kv.second;
            h_max_v.clear();
            h_max_v.push_back(kv.first);
        } else if (kv.second == h_max) {
            h_max_v.push_back(kv.first);
        }
    }
    for (auto kv : w_map) {
        if (kv.second > w_max) {
            w_max = kv.second;
            w_max_v.clear();
            w_max_v.push_back(kv.first);
        } else if (kv.second == w_max) {
            w_max_v.push_back(kv.first);
        }
    }
    bool br{false};
    for (i64 hm : h_max_v) {
        for (i64 wm: w_max_v) {
            if (hw.find(hm) == hw.end() ||
                    hw[hm].find(wm) == hw[hm].end()) {
                br = true;
                break;
            }
        }
        if (br) break;
    }
    i64 ans = w_max + h_max - (br?0:1);

    cout << ans << endl;

    return 0;
}

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,k,cnt = 0,h;
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    h = 0;
    cin >> h;
    if (h >= k){
      cnt += 1;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

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

long long lcm(long long a, long long b) {
    return a / gcd(a,b) * b;
}


int main () {

    ll N,X;
    cin >> N >> X;
    vector < ll > x(N);
    REP(i,N) cin >> x[i];

    ll g = abs(X - x[0]);
    REP(i,N) {
        ll diff = abs(X - x[i]);
        g = gcd(g, diff);
    }

    cout << g << endl;

    return 0;
}


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

int main(){
    
    int a, b;
    int i_surface, i_length;
    
    cin >> a >> b;
    
    if(a < 1 || a > 100 || b < 1 || b > 100){
        return 1;
    }
    
    /*calc*/
    i_surface = a * b;
    i_length = 2 * (a + b);
    
    /*output*/
    cout << i_surface << " " << i_length << endl;
    
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> H(N), ans(N);
	for(int i=0;i<N;i++){
		cin>>H.at(i);
	}
	ans.at(0) = 0;
	for(int i=1;i<N;i++){
		if(H.at(i)<=H.at(i-1)) ans.at(i)=ans.at(i-1)+1;
		else ans.at(i) = 0;
	}
	
	int mx=0;
	for(int i=0; i<N; i++) {
		if(mx<ans.at(i)) mx=ans.at(i);
	}
	
	cout<<mx<<endl;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
count = [[0, False] for _ in range(n+2)]
for _ in range(m):
    a = int(input())
    count[a][1] = True
count[n][0] = 1

for i in range(n)[::-1]:
    if count[i][1] and count[i+1][1]:
        print(0)
        exit(0)
    if count[i][1]:
        continue
    count[i][0] = (count[i+1][0] + count[i+2][0])
print(count[0][0] % 1000000007)


Measured memory_bytes: 469492
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main(){
    cs;
    int n,ans=1e9;
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    repp(i,1,100){
        int t=0;
        rep(j,n) t+=(i-v[j])*(i-v[j]);
        ans=min(ans,t);
    }
    cout<<ans;
}

Measured memory_bytes: 256
def gcd_of_two(a, b)
  small, large = [a, b].sort
  if small == 0
    return large
  else
    gcd_of_two(small, large % small)
  end
end

def gcd_of_many(array)
  current = array.shift
  until array.empty?
    following = array.shift
    current = gcd_of_two(current, following)
  end
  return current
end

def lcm_of_two(a, b)
  gcd = gcd_of_two(a, b)
  return a * b / gcd
end

def lcm_of_many(array)
  current = array.shift
  until array.empty?
    following = array.shift
    current = lcm_of_two(current, following)
  end
  return current
end

n = gets
as = gets.split.map(&:to_i)
lcm = lcm_of_many(as.dup)
puts as.map { |e| (lcm-1)%e }.inject(:+)


Measured memory_bytes: 21628
//tree walk
//https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/7/ALDS1_7_C

#include <iostream>
#define NIL -1
using namespace std;

int ipre = 0;
int iin = 0;
int ipost = 0;

struct Node{
    int parent;
    int left;
    int right;
};

void preParse(Node T[], int pre[], int i);
void inParse(Node T[], int in[], int i);
void postParse(Node T[], int post[], int i);
void print(int v[], int n);

int main(){
    int n;
    cin >> n;
    int id, l, r;
    Node T[n];
    for (int i = 0; i < n; i++){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
    for (int i = 0; i < n; i++){
        cin >> id >> l >> r;
        T[id].left = l;
        T[id].right = r;
        T[l].parent = id;
        T[r].parent = id;
    }
    int pre[n];
    int in[n];
    int post[n];
    int root;
    for (int i = 0; i < n; i++){
        if (T[i].parent == NIL)
            root = i;
    }
    preParse(T, pre, root);
    inParse(T, in, root);
    postParse(T, post, root);
    cout << "Preorder" << endl;
    print(pre, n);
    cout << "Inorder" << endl;
    print(in, n);
    cout << "Postorder" << endl;
    print(post, n);
    return 0;
}

void preParse(Node T[], int pre[], int i){
    if (i == NIL)
        return;
    pre[ipre] = i;
    ipre++;
    preParse(T, pre, T[i].left);
    preParse(T, pre, T[i].right);
}

void inParse(Node T[], int in[], int i){
    if (i == NIL)
        return;
    inParse(T, in, T[i].left);
    in[iin] = i;
    iin++;
    inParse(T, in, T[i].right);
}

void postParse(Node T[], int post[], int i){
    if (i == NIL)
        return;
    postParse(T, post, T[i].left);
    postParse(T, post, T[i].right);
    post[ipost] = i;
    ipost++;
}

void print(int v[], int n){
    cout << ' ';
    for (int i = 0; i < n; i++){
        if (i == n - 1)
            cout << v[i] << endl;
        else
            cout << v[i] << ' ';
    }
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)


def main():
    n, u, v = map(int, input().split())
    u -= 1
    v -= 1
    connect = [[] for _ in range(n)]

    for _ in range(n-1):
        a, b = map(int, input().split())
        connect[a-1].append(b-1)
        connect[b-1].append(a-1)

    # 頂点xから見た全頂点の深度リストを取りたい
    def dfs(list, now, prev=-1, depth=0):
        list[now] = depth
        kids = connect[now]
        for kid in kids:
            if kid == prev:
                continue
            dfs(list, kid, now, depth+1)

    list_v, list_u = [None]*n, [None]*n

    dfs(list_v, v)
    dfs(list_u, u)

    tmp_list = [(depth, index) for index, depth in enumerate(list_v)]
    sorted_v = sorted(tmp_list, reverse=True)
    ans = -1

    for depth, index in sorted_v:
        if list_u[index] < depth:
            ans = depth-1
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 117808
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g[1001],h,i,j;
	scanf("%d",&a);
	scanf("%d",&s);
	for(i=0;i<s;i++){
		scanf("%d %d",&d,&f);
		if(a-d<(a+1)/2){
			d=a-d+1;
		}
		if(a-f<(a+1)/2){
			f=a-f+1;
		}
		//printf("d = %d && f = %d\n",d,f);
		if(d<=f){
			g[i]=d%3;
			//printf("1 - %d\n",i);
		}
		else{
			g[i]=f%3;
			//printf("2 - %d\n",i);
		}
		if(g[i]==0){
			g[i]=3;
		}
	}
	for(i=0;i<s;i++){
		printf("%d\n",g[i]);
	}
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e2 + 5;

int a[N];
int n;

int32_t main()
{
	IOS;
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
	}
	int t=1;
	int best = INT_MAX;
	while(t<=n)
	{
		int s1= 0;
		int s2=0;
		rep(i,1,n)
		{
			if(i<=t)
			{
				s1 += a[i];	
			}
			else if(i>t)
			{
				s2 += a[i];
			}
		}
		best = min(best,abs(s1-s2));
		t++;
	}
	cout << best << endl;
}


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

vector<ll> p = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<bool> ok(10);
  REP(i, 0, M) {
    ll A;
    cin >> A;
    ok[A] = true;
  }

  vector<ll> dp(N + 1, -(1LL << 60));
  dp[0] = 0;

  REP(i, 1, N + 1) {
    REP(k, 1, 10) if (ok[k]) {
      if (i - p[k] >= 0) {
        dp[i] = max(dp[i], dp[i - p[k]] + 1);
      }
    }
  }

  string ans;
  for (ll i = N; i > 0;) {
    for (ll k = 9; k >= 1; k--) if (ok[k]) {
      if (i - p[k] >= 0 && dp[i] == dp[i - p[k]] + 1) {
        ans += to_string(k);
        i -= p[k];
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
A =[list(map(int, input().split())) for i in range(n)]
for i in range(n):
    A[i].pop(0)
C = set([i for i in range(1,31)])
if n==1:
    print(len(A[0]))
else:
    for i in range(n):
        C = C & set(A[i])
    print(len(list(C)))

Measured memory_bytes: 3064
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <math.h>
using namespace std;


int main() {

   double a;

  
   cin >> a;
  

   printf("%.10f %.10f",a*a*3.141592653589793,2*a*3.141592653589793);
  

  return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 10000

typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m, p, a, b;
int ti[8];

typedef pair<Edge, int> P;

Weight dist[1<<8][30];
bool visited[1<<8][30];
  
Weight dijkstra(const Graph &g, int s, int t) {
  REP(i,1<<n) REP(j,g.size()) {
    dist[i][j] = INF;
    visited[i][j] = 0;
  }
  dist[0][s] = 0;
  int ma = 0;
  priority_queue<P> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(P(Edge(-2, s, 0),0)); !Q.empty(); ) {
    Edge e = Q.top().first;
    int S = Q.top().second;
    Q.pop();
    if (t == e.dst) return dist[S][e.dst];
    if (dist[S][e.dst] < e.weight) continue;
    if (visited[S][e.dst]) continue;
    visited[S][e.dst] = 1;
    FOR(f,g[e.dst]) {
      REP(i,n) {
        if ((S>>i)&1) continue;
        if (visited[S|1<<i][f->dst]) continue;
        double cost = e.weight+f->weight/ti[i];
        if (dist[S|(1<<i)][f->dst] > cost) {
          dist[S|(1<<i)][f->dst] = cost;
          Q.push(P(Edge(f->src, f->dst, cost), S|(1<<i)));
        }
      }
    }
    ma = max(ma,(int)Q.size());
  }
  // cout << ma << endl;
  return INF;
}


int main() {
  while(cin>>n>>m>>p>>a>>b,n) {
//    cout << n <<m<<p<< endl;
    a--;b--;
    REP(i,n) cin >> ti[i];
    Graph g(m);
    REP(i,p) {
      int x,y,z;
      cin >> x >> y >> z;
      x--;y--;
      g[x].push_back(Edge(x,y,z));
      g[y].push_back(Edge(y,x,z));
    }
    double res = dijkstra(g, a, b);
    if (res == INF)
      cout << "Impossible" << endl;
    else
      printf("%.8lf\n",res);
  }
}

Measured memory_bytes: 9664
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int input1,input2,input3;
  cin >> input1 >> input2 >> input3;
  cout << input3 << " " << input1 << " "<< input2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(i=a;i<=n;i++)
#define ll long long
int main(){
  ll i,j;
  ll N,K;
  ll countMod[200001];
  ll sum = 0;
    
  cin >> N >> K ;
  rep(i,0,K-1)
   countMod[i] = 0;
  
  rep(i,1,N){
    if(2*i%K == 0)
      countMod[i%K] += 1;
  }
  rep(i,0,K-1)
    sum += pow(countMod[i],3);
 
  cout << sum << endl; 
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  	char S[3];
  	char T[3];
  	int res= 0;
  	 
  	for(int i = 0; i < 3; i++){
    	cin >> S[i];
    }
  	for(int i = 0; i < 3; i++){
    	cin >> T[i];
    }
  
  	for(int i = 0; i < 3; i++){
    	if(S[i] == T[i]){
        	res++;
        }
    }
  
  	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

template<typename T>
struct bit {
  vector<T> data;
  bit(int sz) {
    data.assign(++sz, 0);
  }
  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }
  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> pos(N);
  REP(i, N) pos[A[i]-1] = i+1;

  set<int> s;
  s.insert(0); s.insert(N+1);

  int ans = 0;
  REP(i, N){
    auto it = s.lower_bound(pos[i]);
    int r = *it--;
    int l = *it;
    ans += (i+1)*(r-pos[i])*(pos[i]-l);
    s.insert(pos[i]);
  }
  cout << ans << endl;

  return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k); 

}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key< y->key) y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u!=NIL) {
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }


}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);

    } 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 

    
   
  }

  return 0;
}

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

int main() {
  
  int H, W, K; cin >> H >> W >> K;
  
  char table[H][W]; int ans = 0;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table[i][j];
    }
  }
  
  for (int i = 0; i < (1 << H); i++) {
    
    bitset<6> row(i);
    
    for (int j = 0; j < (1 << W); j++) {
      
      bitset<6> column(j);
      
      int count = 0;
      
      for (int k = 0; k < H; k++) {
        
        if (row.test(k)) continue;
        
        for (int l = 0; l < W; l++) {
          
          if (column.test(l)) continue;
          
          if (table[k][l] == '#') count++;
          
        }
        
      }
      
      if (count == K) ans++;
      
    }
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3620
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::map<int,int> map;
	rep(i,n) map[a[i]]++;
	int sum=0;
	for(auto x:map) {
		sum+=x.second*(x.second-1)/2;
	}
	rep(i,n) {
		print(sum-(map[a[i]]-1));
	}
	return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x>>y;
	if(x<=9 && y<=9) cout<<x*y<<endl;
	else cout<<-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

void check(int64_t n, int64_t k){
    if(k == 1) return;
    if(n % k == 0){
        check(n / k, k);
    }else{
        if(n % k == 1){
            st.insert(k);
            return;
        }
    }
}

int main() {
    int64_t n, ans = 0;
    cin >> n, n--;
    for(int64_t i = 1; i * i <= n; i++){
        if(n % i == 0) ans += (2 - (i * i == n));
    }
    ans--;
    n++;
    for(int64_t i = 1; i * i <= n; i++){
        if(n % i == 0){
            check(n, i);
            check(n, n / i);
        }
    }
    cout << st.size() + ans << endl;
    return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto C = new ulong[](M);
    auto A = new long[](M);
    foreach (i; 0 .. M)
    {
        long a, b;
        scan(a, b);
        auto cs = aryread();
        A[i] = a;
        foreach (c; cs)
        {
            C[i] = C[i] | (1 << (c - 1));
        }
    }
    auto dp = new long[][](M + 1, 1 << N);
    foreach (i; 0 .. M + 1)
        dp[i][] = long.max / 4;
    dp[0][0] = 0;
    foreach (i; 0 .. M)
        foreach (ulong s; 0UL .. 1UL << N)
        {
            dp[i + 1][s] = dp[i + 1][s].min(dp[i][s]);
            dp[i + 1][s | C[i]] = dp[i + 1][s | C[i]].min(dp[i][s] + A[i]);
        }
    writeln(dp[M][$ - 1] == long.max / 4 ? -1 : dp[M][$ - 1]);
}


Measured memory_bytes: 40180
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	int a[100];
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = INF;
	for(int i = -100; i <= 100;i++) {
		int c = 0;
		rep(j, n)c += (i - a[j])*(i - a[j]);
		ans = min(ans, c);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

bool check(int a, int b) {
	return a > b;

}

int main() {
	int a, b, c;
	int k;
	cin >> a >> b >> c >> k;
	if (a > b)swap(a, b);
	if (b > c)swap(b, c);
	rep(i, k){
		c *= 2;
	}
	cout << a + b + c << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, M, Q;
	scanf("%d%d%d", &N, &M, &Q);
	vector<int> L(M), R(M);
	vector<vector<int>> sum(N + 1,vector<int>(N + 1, 0)); // sum[i][j]:二次元累積和
	REP(i, M) {
		scanf("%d%d", &L[i], &R[i]);
		sum[L[i]][R[i]]++;
	}
	REP(i, N)REP(j, N) {
		sum[i + 1][j + 1] += sum[i + 1][j];
	}
	REP(i, N)REP(j, N) {
		sum[i + 1][j + 1] += sum[i][j + 1];
	}
	vector<int> p(Q), q(Q);
	REP(i, Q) {
		scanf("%d%d", &p[i], &q[i]);
		int res = (sum[q[i]][q[i]] - sum[q[i]][p[i] - 1]) - (sum[p[i] - 1][q[i]] - sum[p[i] - 1][p[i] - 1]);
		printf("%d\n", res);
	}


	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    string s;
    cin >> s;

    int a = stoi(s);
    int x = a / 100;
    int y = a % 100;

    string res;

    if (x == 0 && y == 0) res = "NA";
    else if ((x > 12 && y <= 12 && y > 0) || (x == 0 && y <= 12)) res = "YYMM";
    else if ((x <= 12 && y > 12 && x > 0) || (x <= 12 && y == 0)) res = "MMYY";
    else if (x <= 12 && y <= 12) res = "AMBIGUOUS";
    else res = "NA";

    cout << res << endl;
}

Measured memory_bytes: 256
sd = input()
t = input()
sdl = len(sd)
tl = len(t)
for i in range(tl, sdl+1)[::-1]:
    f = False
    for j in range(tl):
        if sd[i-tl+j] != t[j] and sd[i-tl+j] != "?":
            f = True
    if not f:
        res = sd[:i-tl] + t + sd[i-tl+j+1:]
        res = res.replace("?", "a")
        print(res)
        exit()
print("UNRESTORABLE")


Measured memory_bytes: 3060
object Main extends App {
  import scala.io.StdIn._

  solve(readInt)
  def solve(n: Int): Unit = {
    if (n == 0) return
    val mode = readLine.trim
    if (mode == "") readInt()
    val modes = readLine.trim.split(' ').map(_.toDouble)
    val maxMode = modes.max
    val memo = Array.tabulate(201){x ⇒ Array.tabulate(101){v ⇒ if (x == 0 && v == 0) Some(Some(0d)) else None: Option[Option[Double]]}}
    for (_ ← 0 until readInt){
      val Array(x, v) = readLine.trim.split(' ').map(_.toInt)
      if (v * v > 2 * x * maxMode) println("crash")
      else {
        sub(x, v) match {
          case Some(0d) ⇒ println("perfect")
          case Some(d) ⇒ println(s"good ${d.toInt}.${((d * 1000).toInt%1000+1000).toString.tail}")
          case None ⇒ println("try again")
        }
      }
    }
    def sub(x: Double, v: Double): Option[Double] = {
      if (x < 0 || v < 0) None
      else memo((x * 2).toInt)(v.toInt) match {
        case Some(r: Option[Double]) ⇒ r
        case None if v == 0 ⇒ Some(x).also(r ⇒ memo((x * 2).toInt)(v.toInt) = Some(r))
        case None ⇒ modes.flatMap(a ⇒ sub(x - v + a / 2, v - a)) match {
          case l if l.nonEmpty ⇒ Some(l.min).also(r ⇒ memo((x * 2).toInt)(v.toInt) = Some(r))
          case _ ⇒ None.also(r ⇒ memo((x * 2).toInt)(v.toInt) = Some(r))
        }
        case _ ⇒ ???
      }
    }
    if (n != 1) println()
    solve(n - 1)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


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

int main()
{
    string s;
    cin >> s;
    bool ok = true;
    if (s[0] != 'A')
        ok = false;
    int cnt = 0;
    for (int i = 2; i <= s.size() - 2; i++)
    {
        if (s[i] == 'C')
            cnt++;
    }
    if (cnt >= 2 || cnt == 0)
        ok = false;
    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == 'C')
            continue;
        if ('A' <= s[i] && s[i] <= 'Z')
            ok = false;
    }
    if (ok)
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<assert.h>

typedef long long ll;

int main()
{
    int a, b, c;
    
    scanf("%d%d%d", &a, &b, &c);
    if (a+b+c>=22)
    {
        printf("bust");
    }
    else
    {
        printf("win");
    }

    return 0;
}



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

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int n;
	vector<ll> a, b;
	ll push = 0;
	cin >> n;
	REP(i, n){
		ll x, y;
		cin >> x >> y;
		a.push_back(x);
		b.push_back(y);
	}
	reverse(all(a));
	reverse(all(b));
	REP(i, n){
		if((a[i]+push)%b[i] == 0) continue;
		push += b[i]-((a[i]+push)%b[i]);
	}
	cout << push << endl;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 5;
ll N, A[MAX];
vector<ll> vt;

bool check(ll x){
    unordered_map<ll, ll> mp;
    ll piv = 0, sum = 1, ret = 0;
    mp[0] = 1;
    for(int i = 0; i < N; i++){
        if(A[i] >= x){
            piv++;
            sum += mp[piv];
        }
        else{
            sum -= mp[piv];
            piv--;
        }
        ret += sum;
        mp[piv]++;  sum++;
    }
    return (2LL * ret < N * (N + 1) / 2);
}

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; i++){
        scanf("%lld", A + i);
        vt.push_back(A[i]);
    }
    sort(vt.begin(), vt.end());
    vt.erase(unique(vt.begin(), vt.end()), vt.end());
    ll l = 0, r = vt.size() - 1;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(check(vt[mid]))  r = mid - 1;
        else l = mid;
    }
    cout << vt[l] << endl;
}

Measured memory_bytes: 5272
n,k = map(int, input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
roop = []
while visit[pos] !=2:
    if visit[pos]==0:
        move.append(pos)
    else:
        roop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1

if len(move)>k:
    print(move[k]+1)
else:
    print(roop[(k-(len(move)-len(roop)))%len(roop)]+1)



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

int main()
{
    int n, a = 0;
    char s_array[51];

    scanf("%d", &n);
    scanf("%s", s_array);

    for (int i = 0; i<(n-2); i++)
    {
        if (s_array[i] == 'A')
        {
            if (s_array[i + 1] == 'B')
            {
                if (s_array[i + 2] == 'C')
                {
                    a ++;
                }
            }
        }
    }

    printf("%d", a);

    return 0;
}

Measured memory_bytes: 1708
// inputに入力データ全体が入る
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split("/");

	//文字列から10進数に変換するときはparseIntを使います
	var X = tmp[2];
	



	//出力
	console.log("2018/01/"+X);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9676
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 5e5 + 5;

ll fact[maxn];

ll C(ll n, ll k) {
    return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    string s, t; cin >> s >> t;
    ll ans = 0;
    for (ll i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

/*

*/

Measured memory_bytes: 3792
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int ans = 1;
  
  for(int i=1;i<n;i++){
    if(s[i] != s[i-1]) ans ++;
  }
  
  cout << ans << endl;
  
  return 0;
}

  

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

struct edge{
    int from, to;
    ll cost;
};

int main(){
    int N, M;
    cin >> N >> M;
    edge es[M];
    rep(i, M){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].from--, es[i].to--;
    }
    ll d[N];
    fill(d, d+N, -INF);
    d[0] = 0;
    rep(i, N){
        rep(j, M){
            edge e = es[j];
            if(d[e.from] != -INF && d[e.to] < d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    ll ans = d[N-1];
    rep(i, N){
        rep(j, M){
            edge e = es[j];
            if(d[e.from] != -INF && d[e.to] < d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    if(ans == d[N-1]) cout << ans << endl;
    else cout << "inf" << endl;
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x - r < 0 || y - r < 0 || y + r > H || x + r > W)cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3112
n = gets.to_i
a = gets.split.map(&:to_i)

strong_cards = a.sort.reverse

alice = strong_cards.select.each_with_index{|_, i| i.even?}.inject(:+)
bob = strong_cards.select.each_with_index{|_, i| i.odd?}.inject(:+)

puts alice - bob

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

using std::cout;
using std::cin;
using std::endl;
using std::vector;

int main()
{
    size_t in_num;
    cin >> in_num;

    vector<int> in(in_num);
    for (auto i = 0; i < in_num; i++) {
        cin >> in.at(i);
    }

    for (auto i = 0; i < in_num; i++) {
        if (i != 0) {
            cout << " ";
        }
        cout << in.back();
        in.pop_back();
    }
    cout << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    char s;
    vector<int> W(N+2), E(N+2);
    for (int i = 1; i <= N; i++){
        W[i] = W[i-1];
        E[i] = E[i-1];
        cin >> s;
        if (s == 'W'){
            W[i] = W[i] + 1;
        }
        else{
            E[i] = E[i] + 1;
        }
    }
    W[N+1] = W[N];
    E[N+1] = E[N];
    int ans = 300000;
    for (int i = 1; i <= N; i++){
        if (E[i] - E[i-1] > 0){
            ans = min(ans, W[i] - W[0] + E[N] - E[i+1]);
        }
        else{
            ans = min(ans, W[i-1] - W[0] + E[N+1] - E[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> pt;
	char locate = s[0];
	pt.push_back(1);
	rep(i,1,n){
		if(locate == s[i]) pt[pt.size()-1]++;
		else{
			pt.push_back(1);
			locate = s[i];
		}
	}
	if(pt.size()/2<=k){
		cout << n-1 << endl;
		return 0;
	}
	int ans=0;
	rep(i,0,pt.size()){
		ans += pt[i]-1;
	}
	cout << ans+k*2 << endl;
	/*
	int ans_max = ans;
	rep(i,k*2+1,pt.size()){
		ans -= pt[i-(k*2+1)];
		ans += pt[i];
		ans_max = max(ans,ans_max);
	}
	*/
	//cout << ans_max << endl;
}


Measured memory_bytes: 972
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val arr = readLine()!!.split(" ").map(String::toInt)

    if (n==1) {
        print("0")
        return
    }

    var max = 0
    var cnt = 0
    for (i in n-1 downTo 0) {
        if (i-1 < 0) {
            break
        }

        if (arr[i-1] >= arr[i]) {
            cnt++
            continue
        } else {
            if (max < cnt) {
                max = cnt
            }
            cnt = 0
        }
    }

    if (max < cnt) {
        max = cnt
    }

    print(max)
}

Measured memory_bytes: 59392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		int[] inputNum = new int[100];
		int max=0;
		String line = "NA";
		
		for(int i=0;i<100;i++){
			inputNum[i] = 0;
		}
		
		while(true){
			line = br.readLine();
			if(line==null || line.isEmpty()){
				break;
			}
			if(!line.equals("")){
				inputNum[Integer.parseInt(line)-1]++;
			}
		}
		
		for(int i=1;i<100;i++){
			if(max < inputNum[i]){
				max = inputNum[i];
			}
		}
		
		for(int i=0;i<100;i++){
			if(inputNum[i] == max){
				System.out.println(i+1);
			}
		}
	}
}

Measured memory_bytes: 16868
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=1e5+1e2;
int n;
int Ans;
int a[maxn],b[maxn],c[maxn],d[maxn];
int fa[maxn];
map<int,int>e;

inline void file() {
	freopen("AGC016D.in","r",stdin);
	freopen("AGC016D.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int find(int x) {
	if (x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}

int main() {
//	file();

	n=read();
	For (i,1,n) a[i]=read(),a[n+1]^=a[i];
	For (i,1,n) b[i]=read(),b[n+1]^=b[i];
	int flag=1;
	For (i,1,n) if (a[i]!=b[i]) flag=0;
	if (flag) {
		puts("0"); return 0;
	}

	++n;
	For (i,1,n) c[i]=a[i],d[i]=b[i];
	sort(c+1,c+n+1); sort(d+1,d+n+1);
	For (i,1,n) if (c[i]!=d[i]) {
		puts("-1"); return 0;
	}
	int N=unique(c+1,c+n+1)-(c+1);
	For (i,1,N) e[c[i]]=i; Set(d,0);
	For (i,1,N) fa[i]=i;
	
	For (i,1,n-1)
		if (a[i]!=b[i]) {
			int x=e[a[i]],y=e[b[i]]; d[e[a[i]]]=d[e[b[i]]]=1;
			x=find(x); y=find(y); ++Ans;
			if (x!=y) fa[x]=y;
		}
	d[e[a[n]]]=1;
	
	For (i,1,N) if (d[i] && find(i)==i) ++Ans;
	printf("%d\n",Ans-1);
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	
	VI x(m), b(m-1);
	rep(i, m) cin >>x[i];
	if(n>=m){ puts("0"); return 0;}
	sort(all(x));
	rep(i, m-1) b[i] = x[i+1] - x[i];
	sort(all(b));
	ll ans = 0;
	cout << accumulate(b.begin(), b.begin()+m-n, 0LL) <<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string s;
	long long int k;
	cin >> s >> k;
	for (long long int i = 0; i < s.length(); i++) {
		if (i == k - 1 || s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}

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

using namespace std;

int main() {

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	m1 = h1 * 60 + m1;
	m2 = h2 * 60 + m2;

	cout << m2 - m1 - k << endl;
	
	return 0;

}

Measured memory_bytes: 3636