akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace ABC138
{
    class E
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            Dictionary<char, List<long>> dict = new Dictionary<char, List<long>>();

            for (int i = 0; i < s.Length; i++)
            {
                if (!dict.ContainsKey(s[i]))
                {
                    dict.Add(s[i], new List<long>());
                    dict[s[i]].Add(i);
                }
                else if (dict.ContainsKey(s[i]))
                {
                    dict[s[i]].Add(i);
                }
            }

            // NGの時
            for (int i = 0; i < t.Length; i++)
            {
                if (!dict.ContainsKey(t[i])) { Console.WriteLine(-1); return; }
            }

            long current = -1;
            int index = 0;
            long turn = 0;

            foreach (var c in t)
            {
                var list = dict[c];

                index = list.BinarySearch(current + 1);
                if (index < 0) { index = ~index; }
                if (list.Count <= index) { index = 0; turn++; }

                current = list[index];
            }

            Console.WriteLine((long)s.Length * turn + current + 1);
        }
    }
}

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

vector<int> use;
vector<int> ans;
vector<vector<int> > graph;
vector<vector<int> > graph2;

int solve(int s, int k){
    int sum = 1;
    use[s] = k;
    for(int i = 0; i < graph[s].size(); i++){
        if(use[graph[s][i]] == k){
            continue;
        }
        sum += solve(graph[s][i], k);
    }
    return sum;
}

int main(){
    ll n, m, k; cin >> n >> m >> k;
    graph = vector<vector<int> >(n);
    graph2 = vector<vector<int> >(n);
    use = vector<int>(n, -1);
    ans = vector<int>(n, 0);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(int i = 0; i < k; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        graph2[a].push_back(b);
        graph2[b].push_back(a);
    }
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        if(use[i] != -1){
            continue;
        }
        int size = solve(i, i);
        mp[i] = size;
    }
    for(int i = 0; i < n; i++){
        int k = use[i];
        int ans = mp[k] - 1;
        ans -= graph[i].size();
        for(int l = 0; l< graph2[i].size(); l++){
            if(use[graph2[i][l]] == k){
                ans--;
            }
        }
        cout << max(ans, 0) << " ";
    }
}

Measured memory_bytes: 13824
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print $ solve n s

solve :: Int -> String -> Int
solve n s = minimum $ zipWith (+) (init ws) (tail es) where
  ws = scanl (\w c -> if c == 'W' then w + 1 else w) 0 s
  es = scanr (\c e -> if c == 'E' then e + 1 else e) 0 s


Measured memory_bytes: 61692
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
char b[7];
bool yymm,mmyy;
int main(){
  scanf("%s",b);
  if(b[0] == '0' && b[1] != '0' || b[0] == '1' && b[1] <= '2') mmyy = 1;
  if(b[2] == '0' && b[3] != '0' || b[2] == '1' && b[3] <= '2') yymm = 1;
  if(yymm){
    if(mmyy) puts("AMBIGUOUS");
    else puts("YYMM");
  }else{
    if(mmyy) puts("MMYY");
    else puts("NA");
  }
  return 0;
}


Measured memory_bytes: 256
# rubyで簡単にアルファベットの配列を作れる
alphabet = ('a'..'z').to_a # [*'a'..'z']だけでもいけるらしい
s = gets.chomp.chars.uniq.sort

ans = ''
alphabet.each do |a|
    if s.include?(a) == false then
        ans=a
        break
    end
end

puts ans=='' ? 'None' : ans

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

void solve()
{
    ll x, k, d, left = 0;
    cin >> x >> k >> d;

    ll moves = abs(x)/d;
    if(moves<k)
    {
        k-=moves;
        x = min(abs(x-moves*d), abs(x+moves*d));
    }
    else
    {
        cout << min(abs(x-k*d), abs(x+k*d));
        return ;
    }
    if(k%2==1)
    {
        ll a = x-d, b = x+d;
        if(abs(a)<abs(b))
        {
            x = abs(a);
        }
        else
        {
            x = abs(b);
        }
    }
    cout << abs(x);
}


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


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int main()
{
	int x=gi(),y=gi();
	if (x%y) cout<<x<<endl;
	else puts("-1");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)


int main() {

    int W,H,N;
    cin >> W >> H >> N;

    vector<vector<int>> fie(W,vector<int>(H,0));
    rep(i,1,N){
        int x,y,a;
        cin >> x >> y >> a;
        rep(j,0,W - 1){
            rep(k,0,H - 1){
                bool ans = false;
                ans |= (a == 1 && j < x);
                ans |= (a == 2 && j >= x);
                ans |= (a == 3 && k < y);
                ans |= (a == 4 && k >= y);

                if(ans){
                    fie[j][k] = 1;
                }
            }
        }
    }

    int res = 0;

    rep(i,0,W - 1){
        rep(j,0,H - 1){
            if(fie[i][j] == 0) res++;;
        }
    }

    cout  << res  << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] num = new int[3];
		for(int i = 0; i < 3; i++) num[i] = sc.nextInt();
		Arrays.sort(num);
		int ans = num[2] - num[1];
		num[1] += ans; num[0] += ans;
		if((num[2] - num[0]) % 2 == 0) ans += (num[2] - num[0]) / 2;
		else ans += (num[2] + 1 - num[0]) / 2 + 1;
		System.out.println(ans);
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    int L=lcm(X,360);
    cout << L/X << '\n';
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;

ll N, A, B, X[101010];


int main() {
	cin >> N >> A >> B;
	rep(i, 0, N) {
		cin >> X[i];
	}

	ll ans = 0;
	rep(i, 1, N) {
		ll walk = X[i] - X[i - 1];
		if (walk*A > B) {
			ans += B;
		}
		else {
			ans += walk * A;
		}
	}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ull            unsigned long long int
#define ll             long long int
#define pb(x)          push_back(x)
#define mp(a,b)        make_pair(a,b)
#define li(ini)        for(ull i=ini;;i++)
#define lfi(i,ini,r)   for(ull i=ini;i<r;i++)
#define lfd(i,ini,r)   for(ull i=ini;i>=r;i--)
#define lit(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define l(v)           for(ull b:v)
#define sorta(v)       sort(v.begin(),v.end())
#define sortd(v)       sort(v.begin(),v.end(),greater<>())
#define vf(i)          v[i].first
#define vs(i)          v[i].second
#define fast_io        ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define en             "\n"
#define sr(s)          reverse(s.begin(),s.end())


using namespace std;

vector<ll>v;
vector<ll>s;

int main()
{
    fast_io

    ll x=0,res=0,t=0,i=0,j=0,m=0,n=0,a=0,b=0,c=0,d=0,sum=0,flag=0,flag1=1,cont=0,k=0;

    string s,l,r;
    cin>>s;
   ll le=s.size();
   ll  q=le/2;
   lfi(i,0,q)
   {
       l+=s[i];
   }
   lfi(i,q+1,le)
   {
       r+=s[i];
   }

   string l1=l;
   string r1=r;
   string s1=s;
   sr(l);
   sr(r);
   sr(s);
   //cout<<l<<" "<<r<<" "<<s<<en;
   if(s==s1 && l==l1 && r==r1)
   {
       cout<<"Yes\n";
   }
   else
   {
       cout<<"No\n";
   }



    return 0;
}



Measured memory_bytes: 256
time = [0,0,0,0,0]
def suc(time):
  point = 5-1
  while point >= 0:
    if time[point] == 0:
      time[point] = 1
      return time
      break
    else:
      time[point] = 0
      point -= 1
  else:
    return 'over'
n = int(input())
s = [0 for _ in range(5)]
for i in range(n):
  now = input()[0]
  if now == 'M':
    s[0] += 1
  elif now == 'A':
    s[1] += 1
  elif now == 'R':
    s[2] += 1
  elif now == 'C':
    s[3] += 1
  elif now == 'H':
    s[4] += 1
ans = 0
while time != 'over':
  if sum(time) != 3:
    pass
  else:
    tmp = 1
    for j in range(5):
      if time[j] == 1:
        tmp *= s[j]
    ans += tmp
    #print(tmp,time)
  time = suc(time)
#print(s)
print(ans)

Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        h: [usize; n],
    }
    let mut s = vec![0; n];
    for i in (0..n - 1).rev() {
        if h[i] >= h[i + 1] {
            s[i] = s[i + 1] + 1;
        }
    }

    println!("{}", s.iter().max().unwrap());
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <map>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
  cout << setprecision(6);
  cout << setiosflags(ios::scientific);
  cout.flags(ios::fixed);

  int n=0;
  cin >> n;

  int t=0,h=0;

  for(int i=0; i<n; i++){
    string taro, hanako;
    cin >> taro;
    cin >> hanako;

    if(taro > hanako)
      t+=3;
    else if(taro == hanako)
      {
	t++;
	h++;
      }
    else
      h+=3;
  }

  cout << t << " " << h << endl;
}

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

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 100010;

int top;
ll a[MAXN];
ll c[MAXN];
ll tim[MAXN];

inline void solve(int p, ll x, ll t) {
	tim[p] += t * (x / a[p]), x %= a[p];
	p = upper_bound(a + 1, a + 1 + p, x) - a;
	if(p == 1) c[1] += t, c[x + 1] -= t;
	else solve(p - 1, x, t);
}

int main() {
#ifdef LOCAL
	FILE("");
#endif

	int n = ri, q = ri;

	a[++top] = n;
	for(int i = 1; i <= q; i++) {
		ll x = rl;
		while(a[top] >= x && top) --top;
		a[++top] = x;
	}

	tim[top] = 1;
	for(int i = top; i > 1; i--)
		solve(i - 1, a[i], tim[i]);

	for(int i = 1; i <= a[1]; i++)
		c[i] += c[i - 1];

	for(int i = 1; i <= a[1]; i++)
		printf("%lld\n", c[i] + tim[1]);
	n -= a[1];
	while(n--) puts("0");
	return 0;
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int w, h, xs, ys, xg, yg, n, c, d, x, y, b[101][101];
int dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};

bool dfs(int x, int y){

  int nx, ny;
  b[x][y] = 0;
  if(x == xg && y == yg) return true;
  bool r = 0;
  rep(i, 4){
    nx = x + dx[i]; ny = y + dy[i];
    if(nx > 0 && nx <= h && ny > 0 && ny <= w && b[nx][ny]==c)r=r||dfs(nx, ny);
  }
  return r;
}

int main(){
  while(scanf("%d %d", &w, &h) && w && h){
    memset(b, 0, sizeof(b));
    scanf("%d%d%d%d", &ys, &xs, &yg, &xg);
    scanf("%d", &n);
    rep(i, n){
      scanf("%d%d%d%d", &c, &d, &y, &x);
      rep(j, (d?4:2)) rep(k, (d?2:4)) b[x + j][y + k] = c;
    }
    /*    rep(i, h){
      rep(j, w) printf("%d ", b[i][j]);
      puts("");
      }*/
    c = b[xs][ys];
    //    printf("%d\n", c);
    //    fprintf(stderr, "error\n");
    if(c > 0 && dfs(xs, ys)) puts("OK");
    else puts("NG");
  }
  return 0;
}

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

int main(){
    double a;
    double n, k, i;
    cin >> n >> k;
    if(n < k){
        for(i = 1; i <= n; i++){
            double t = i;
            double c = 0;
            while(t < k){
                c++;
                t *= 2.0;
            }
            a += 1.0 / pow(2.0, c);
        }
        a /= n;
    }
    else{
        for(i = 1; i <= k-1; i++){
            double t = i;
            double c = 0;
            while(t < k){
                c++;
                t *= 2.0;
            }
            a += 1.0 / pow(2.0, c);
        }
        a /= n;
        a += (n - k + 1.0) / n;
    }
    printf("%.15f\n", a);
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         vector<ll>v;
          // 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
         for(int i=0;i<3;i++) v.pb(1);
         v.pb(2);
         v.pb(1);
         v.pb(2);
         v.pb(1);
         v.pb(5);
         v.pb(2);
         v.pb(2);
         v.pb(1);
         v.pb(5);
         v.pb(1);
         v.pb(2);
         v.pb(1);
         v.pb(14);
         v.pb(1);
         v.pb(5);
         v.pb(1);
         v.pb(5);
         v.pb(2);
         v.pb(2);
         v.pb(1);
         v.pb(15);
         v.pb(2);
         v.pb(2);
         v.pb(5);
         v.pb(4);
         v.pb(1);
         v.pb(4);
         v.pb(1);
         v.pb(51);
         // cout<<v.size();
         ll k;
         cin>>k;
         cout<<v[k-1]<<endl;

      }
      






}



























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

int main(void) {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		if(to_string(i).length() % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;


string s;
int ans;

int main(void) {
    cin >> s;
    int r = 0, p = 0;
    for(int i=0; i<(int)s.size(); i++) {
      if (p<r) {
        if (s[i]=='g')  ans++;
        p++;
      } else {
        if (s[i]=='p') ans--;
        r++;
      }
    }
    cout << ans << endl;

	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;
ll  n;
int c;
void dfs(ll t){
    if(t>n)return;
    string s=to_string(t);
    bool c1=false;
    bool c2=false;
    bool c3=false;
    rep(i,0,s.size()){
        if(s.at(i)=='7')c1=true;
        if(s.at(i)=='5')c2=true;
        if(s.at(i)=='3')c3=true;
    }
    if(c1 and c2 and c3){
        c++;
    }
    dfs(10*t+7);
    dfs(10*t+5);
    dfs(10*t+3);
}

int main(){
    cin>>n;
    c=0;
    dfs(0);
    cout<<c<<endl;
return 0;
}

Measured memory_bytes: 256
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

for a in adj:
  print(" ".join(map(str, a)))


Measured memory_bytes: 5680
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	int value = 0;
	int cnt = 0;
	while (1){
		
		cin >> value;
		if (value == 0) break;
		if (cnt != 0) cout << endl;
		cnt++;
		int Coin[4] = { 10, 50, 100, 500 };
		int hasCoin[4] = {};
		int hasMoney = 0;
		for (int i = 0; i < 4; i++){
			cin >> hasCoin[i];
			hasMoney += hasCoin[i] * Coin[i];
		}
		int useCoin[4];
		int gap = hasMoney - value;
		int willHaveMoney[4] = {};
		for (int i = 3; i >= 0; i--){
			willHaveMoney[i] = gap / Coin[i];
			gap = gap % Coin[i];

			if (willHaveMoney[i] < hasCoin[i]){
				useCoin[i] = hasCoin[i] - willHaveMoney[i];
			}
			else{
				useCoin[i] = 0;
			}
		}
		for (int i = 0; i < 4; i++){
			if (useCoin[i] != 0){
				cout << Coin[i] << " " << useCoin[i] << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

int main() {
	int N; cin >> N;
	string S; cin >> S;
	int Q; cin >> Q;
	rep(q, Q) {
		int K;
		cin >> K;

		ll C, M, cnt;
		C = M = cnt = 0;
		rep(i, K) {
			if(S[i] == 'M')
				M++;
			else if(S[i] == 'C') {
				cnt += M;
				C++;
			}
		}

		ll res = 0;
		rep(i, N) {
			if(S[i] == 'D') {
				res += cnt;
			}

			if(S[i] == 'M') {
				cnt -= C;
				M--;
			}
			else if(S[i] == 'C')
				C--;

			if(i+K < N) {
				if(S[i+K] == 'M')
					M++;
				else if(S[i+K] == 'C') {
					cnt += M;
					C++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}


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

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

    long long ans = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                ans += __gcd(__gcd(a, b), c);
            }
        }
    }

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

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <algorithm>
#include <math.h>
#include<string>
#include<vector>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " <<  b << " " << endl;
    return 0; 
}

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

int n, q[N];
ll c, h[N], f[N];

inline long double slope(int x, int y) {
    return 1.0 * ((f[x] + h[x] * h[x]) - (f[y] + h[y] * h[y])) / (long double) (h[x] - h[y]);
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> c;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", h + i);
    int l = 1, r = 1;
    q[1] = 1, f[1] = 0;
    for (int i = 2, j; i <= n; ++i) {
        while (l < r && slope(q[l], q[l + 1]) < 2.0 * h[i]) ++l;
        j = q[l];
        f[i] = f[j] + (h[i] - h[j]) * (h[i] - h[j]) + c;
        while (l < r && slope(q[r], q[r - 1]) > slope(q[r], i)) --r;
        q[++r] = i;
    }
    cout << f[n] << endl;
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
ll fact[N], invFact[N];

ll nCr(int n, int r){
	return fact[n] * invFact[r] % mod * invFact[n - r] % mod;
}
void solve()
{	
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n){
		cin >> b[i];
		c[i] = i + 1;
	}
	int f = 0, s = 0, cnt = 0;
	do{
		if(c == a) f = cnt;
		if(c == b) s = cnt;
		cnt++;
	}while(next_permutation(all(c)));
	cout << abs(f - s);
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    while (a > 0 && c > 0) {
      c -= b;
      a -= d;
    }

    if (c <= 0) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 27080
#include <bits/stdc++.h>
#include<vector>
#include<math.h>
using namespace std;
 
int main() {
  int a;
  double e=0,f=0,g=0;
  double c=0.0;
  cin>>a;
  double b[2][a];
  vector<int> d(a);
  for(int i=0;i<a;i++){
    cin>>b[0][i]>>b[1][i];
    d.at(i)=i;
  }
  do{
  for(int i=0;i<a-1;i++){
    f=b[1][d.at(i)]-b[1][d.at(i+1)];
    //cout<<f<<endl;
    e=b[0][d.at(i)]-b[0][d.at(i+1)];
    //cout<<e<<endl;
    c+=sqrt(f*f+e*e);
    //cout<<fixed<<setprecision(12)<<c<<endl;
  }
    g++;
  }while(next_permutation(d.begin(),d.end()));
  cout<<fixed<<setprecision(12)<<c/g;
}

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

int main(){
    ll k;
    string s;
    cin >> s >> k;

    int i = 0;
    int n;
    while((n = s[i] - '0') == 1){
        if(k == i + 1){
            cout << 1 << endl;
            return 0;
        }
        i++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int K = sc.nextInt();
    int S = sc.nextInt();
    int count = 0;

    for (int x = 0; x <= K; x++) {
      for (int y = 0; y <= K; y++) {
        int rest = S - x - y;
        if (rest>=0 && rest<=K){
          count++;
        }
      }
    }

    out.println(count);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) scanf("%d",&c[i][j]);
    }

    int a[3]={0,c[1][0]-c[0][0],c[2][0]-c[0][0]};
    int b[3]={c[0][0],c[0][1],c[0][2]};

    if(c[1][1]!=a[1]+b[1]){
        printf("No\n");
        return 0;
    }
    if(c[1][2]!=a[1]+b[2]){
        printf("No\n");
        return 0;
    }
    if(c[2][1]!=a[2]+b[1]){
        printf("No\n");
        return 0;
    }
    if(c[2][2]!=a[2]+b[2]){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;


/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;

vector<array<u64, 3>> memo;

constexpr u64 dp(const vector<array<u32, 3>>& day_happiness, u16 prev_task,
                 u32 days, u32 curr_day) noexcept {
    if (curr_day == days) {
        return 0;
    }

    if (prev_task < 3 && memo[curr_day][prev_task] > 0) {
        return memo[curr_day][prev_task];
    }

    u64 res = 0;
    for (u16 task = 0; task < 3; task++) {
        if (task == prev_task) {
            continue;
        }
        res = max(res, day_happiness[curr_day][task] +
                           dp(day_happiness, task, days, curr_day + 1));
    }

    if (prev_task < 3) {
        memo[curr_day][prev_task] = res;
    }
    return res;
}

i32 main() {
    u32 num_vacations = 0;
    cin >> num_vacations;

    vector<array<u32, 3>> day_happiness(num_vacations);
    for (u32 day = 0; day < num_vacations; day++) {
        for (u16 task = 0; task < 3; task++) {
            cin >> day_happiness[day][task];
        }
    }

    memo = vector<array<u64, 3>>(num_vacations, array<u64, 3>{ 0, 0, 0 });
    cout << dp(day_happiness, 3, num_vacations, 0) << '\n';
}

Measured memory_bytes: 14192
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
S=[list(map(int,input().split())) for i in range(Q)]

l=[0]*10**6
total=0

for i in range(N) :
    l[A[i]]+=1   #各数字の個数
    total+=A[i]  #初期総和

for i in range(Q) :
    s0=S[i][0]  #Bの値、交換した値
    s1=S[i][1]  #Cの値、交換する値
    total+=s1*l[s0]-s0*l[s0]
    l[s1]+=l[s0]
    l[s0]=0
    print(total)

Measured memory_bytes: 39380
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();

		long min = 0,max = 0,sum=0;
		for(int i=0;i<n;i++) {
			int q=scan.nextInt();
			if(i==0) {
				min=q;
				max=q;
			}
			if(min>q)min=q;
			if(max<q)max=q;
			sum+=q;
		}
		System.out.println(min+" "+max+" "+sum);
		scan.close();
	}

}


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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using mii = map<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

bool query(int a, vi &dlist) {
  while (a > 0) {
    for (auto d : dlist) {
      if (a%10 == d) return false;
    }
    a /= 10;
  }
  return true;
}

signed main() {
  int n,m;cin>>n>>m;
  vi d(m);cin>>d;
  while (!query(n,d)) n++;
  cout << n << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int X,Y;
    cin >> X >> Y;

    cout << X + Y/2 << endl;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;

    int ans = 0;
    reps(i, n) {
      int w = i;
      while (w > 0 && w % 5 == 0) ans++, w /= 5;
    }
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    cout << "a";
    cout << " ";
    if (a<b){
        cout << "<";
    }
    else if (a>b){
        cout << ">";
    }
    else{
        cout << "==";
    }
    cout << " ";
    cout << "b";
    cout << endl;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int n, a[202020],c[202020],sum=0, l[202020], r[202020];
ll ans= 0;
set<int> s;

int main(){

cin >> n ;
rep(i, 1, n){
cin >> a[i];
c[a[i]] = i;
}

s.insert(0);
s.insert(n+1);

rep(i, 1, n){
int t = c[i];
s.insert(t);
auto k = s.find(t);
int l = *(--k);
k++;
int r = *(++k);

ans+= 1LL*(t-l)*(r-t)*i;

}

cout << ans << endl;

return 0;}


Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>
 
int main(void){
  int i,j,to,sum;
  char x[10010];
  char cmp[2][4]={"JOI","IOI"};
 
  while(scanf("%s",x) != EOF){
    to = strlen(x)-2;
    for(i=0;i<2;i++){
      for(j=sum=0;j<to;j++){
    if(!strncmp(&x[j],cmp[i],3)) sum++;
      }
      printf("%d\n",sum);
    }
  }
 
  return 0;
}


Measured memory_bytes: 1916
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c;
	while(cin>>a>>b>>c) {
		cout<<a*b/2<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
//RMQ問題：次の２つのクエリがたくさん与えられる,高速に答えよ。
//1.区間[i,j]内の要素ai〜ajの最大値をこたえる。2.要素aiにxを追加する。
//ただし、0 <= i,j <= Nとする。最初はa0〜ajは全てINF(= -1e+8)である。

//単純に配列でシュミレーションすると、常にO(NQ),累積和を使うと、クエリ1はO(1),クエリ2はO(N)かかるので、最悪O(NQ)
//領域を2分割,2分割していって、塊で答えを覚えておけばクエリ1は木の深さ分でできる。
//葉ノードの区間長が1ならば、葉ノードを変える→根まで木の深さ分更新(O(logN))でできる。
//ということで、セグメントツリー(初実装)で解く.(蛇足 : 大きい区間の答えを持つ,ノードが便利なのはもちろん、葉ノードは1要素になってるから、区間長1の変更も簡単。

//RMQのペア(番号,数)バージョン。2この変数でソートされた平衡２分木でもできると思う。

#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i,n) for(i = 0;i < n;i++)

using namespace std;

typedef pair<int,int> P;

//完全２分木にしよう。(要素数によっては右側の要素を使わないかも…)
class segtree{
	P *a;		//配列で表現。根 = 0,左の子のノード番号 = 親ノード番号*2 + 1。なので、区間長についてはあまり意識しなくてよい。
	int dep;	//根から葉までの距離

public:
	segtree(int depth,int x)
	{
		int i;
		dep = depth;
		a = new P[1 << (dep+1)];
		rep(i,1 << (dep+1) )
			a[i] = P(1,x);
	}
	~segtree()
	{
		delete[] a;
	}
	void insert(int i,int x)	//根の左からi(>=0)番目にxを加算する
	{	
		int num = i + (1 << dep);
		int E;	//左のノード(ノード番号が奇数)なら1,右のノードなら-1

		//値の追加
		a[num] = P(i,a[num].second + x);

		//ツリーの更新
		while(num > 0){
			E = (num%2)?1:-1;
			if(a[num].second > a[num + E].second || (a[num].second == a[num + E].second && a[num].first < a[num + E].first) )
				a[(num-1) >> 1] = a[num];
			else
				a[(num-1) >> 1] = a[num + E];
			num = (num-1) >> 1;
		}
	}
	P getmax(int i,int j)
	{
		P ans = a[i + (1 << dep)];

		if(i == j)
			return ans;
		if(i > j)
			swap(i,j);
		//遅延処理.
		//葉から見ていく方法でやろう。a[num_i]とa[num_j]を見ている。num_i < num_j.みたいな
		//閉区間
		int num_i = i + (1 << dep);	//左の子ならその親、右の子ならその親+1に移動
		int num_j = j + (1 << dep);	//左の子ならその親-1、右の子ならその親に移動

		while( num_i <= num_j )
		{
			if( (ans.second < a[num_i].second) || (ans.second == a[num_i].second && ans.first > a[num_i].first) )
				ans = a[num_i];
			if( (ans.second < a[num_j].second) || (ans.second == a[num_j].second && ans.first > a[num_j].first) )
				ans = a[num_j];
			num_i = (num_i)%2 ? ((num_i-1) >> 1) : ( ((num_i-1) >> 1) + 1 );
			num_j = (num_j)%2 ? ( ((num_j-1) >> 1) -1 ) : ((num_j-1) >> 1);
		}
		return ans;
	}
	void print_a(int n){
		for(int i = 0;i < n;i++)
			cout << "a[i + (1 << dep)] = " << a[i + (1 << dep)].first << " " << a[i + (1 << dep)].second << endl;
	}
};

int main(){
	int i;
	int n,q;
	int a,b;
	P ans[100000];
	segtree seg(21,0);

	cin >> n >> q;
	for(i = 0;i < q;i++){
		cin >> a >> b;
		seg.insert(a,b);
		//seg.print_a(n+1);
		ans[i] = seg.getmax(1,n);
	}
	for(i = 0;i < q;i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 34576