akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int dp[2][100001];
    rep(i,2)rep(j,100001)dp[i][j] = INF;
    
    dp[0][0] = 1;
    dp[1][0] = 1;
    
        for(int j=1;j<n;j++){
            rep(i,2){
            dp[i][j] = min(dp[i][j-1],dp[!i][j-1])+1;
            if(!i && v[j-1]>=v[j]) dp[i][j] = min(dp[i][j-1],dp[i][j]);
            if( i && v[j-1]<=v[j]) dp[i][j] = min(dp[i][j-1],dp[i][j]);
        }
    }
    
    cout<<min(dp[0][n-1],dp[1][n-1])<<endl;
}


Measured memory_bytes: 1408
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn with_stdout<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w)
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut b = vec![0; n];
    for i in (1..n + 1).rev() {
        let mut j = i;
        let mut cnt = 0;
        while j <= n {
            cnt += b[j - 1];
            j += i;
        }
        if cnt % 2 != a[i - 1] {
            b[i - 1] = 1;
        }
    }

    let m: i32 = b.iter().sum();
    with_stdout(|mut w| {
        writeln!(w, "{}", m).unwrap();
        for i in 0..n {
            if b[i] > 0 {
                writeln!(w, "{}", i + 1).unwrap();
            }
        }
    });
}


Measured memory_bytes: 7036
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int W = cin.nextint;
        var dp = new long[W + 1];
        for (int i = 0; i < N; i++)
        {
            int w = cin.nextint;
            int v = cin.nextint;
            for (int j = dp.Length - 1; j >= 0; j--)
            {
                if (j - w < 0)
                {
                    break;
                }
                chmax(ref dp[j], dp[j - w] + v);
            }
        }
        WriteLine(dp[W]);
    }

}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

Measured memory_bytes: 11744
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	vector<ll> d(87);
	d[0] = 2;
	d[1] = 1;
	cin>>n;
	for(int i = 2;i<=n;i++){
		d[i] = d[i-1] + d[i-2];
	}
	cout << d[n] << endl;
	return 0;
}


Measured memory_bytes: 256
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
using namespace std;

int main(void) {
	int n; cin >> n;
	int F[50];
	F[0] = F[1] = 1;
	for (int i = 2; i <= n; i++) F[i] = F[i - 2] + F[i - 1];
	cout << F[n] << endl;
	return 0;
}


Measured memory_bytes: 3104
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define endl "\n"
using namespace std;
int main()
{
   fast
	 ll n;
	 cin>>n;
	 vector <string> v;
	 vector <ll> store;
	 for(ll i=0;i<n;i++)
	 {
		 string s;
		 cin>>s;
		 sort(s.begin(),s.end());
		 v.pb(s);
	 }
	 sort(v.begin(),v.end());
	 ll count=1,ans=0;
	 for(ll i=0;i<(n-1);i++)
	 {
		 if(v[i]==v[i+1])
		 {
			 count++;
		 }
		 else
		 {
			 store.pb(count);
			 count=1;
		 }
	 }
	 if(count!=1)
	 {
		 store.pb(count);
	 }
	 for(ll i=0;i<store.size();i++)
	 {
		 ans+=(((store[i])*(store[i]-1))/2);
	 }
	 cout<<ans;
	 return 0;
}


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

// Template START
#define endl "\n"
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
const int mod = (int)1e9 + 7 ;
template<class T>
auto matrix( int r, int c, T v ){
    return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
template<class T>
auto matrix( int o1, int o2, int o3, T v ){ 
    return vector<vector<vector<T>>>( o1, vector<vector<T>>( o2, vector<T>( o3, v ) ) ) ;
}
#define v vector
int power( int x, int n ){
    if( n == 0 ) return 1 ;
    else if( n & 1 ) return ( x * power( (x*x) % mod, n / 2 ) ) % mod ;
    return power( (x*x) % mod, n / 2 ) % mod ;
}
template<class T> void __print( v<T> &arr ){
    int n = arr.size() ;
    cerr << "[ " ;
    for( int i = 0 ; i < n ; i++ ) {
        cerr << arr[i] ;
        if( i != n - 1 ) cerr << ", " ;
    }
    cerr << " ]" << endl ;
}
template<class T> void __print( T arr[], int n ){ 
    cerr << "[ " ;
    for( int i = 0 ; i < n ; i++ ) {
        cerr << arr[i] ;
        if( i != n - 1 ) cerr << ", " ;
    }
    cerr << " ]" << endl ;
}
#define print(x) cerr << "{ " << #x << " : " << x << " } " ;
#define println(x) cerr << "{ " << #x << " : " << x << " }" << endl ;
// Template END
const int mx = (int)2e5 + 1 ;
class compare {
    // multiset<dataType, compare>
    // priority_queue<dataType, vector<dataType>, compare>
    public :
    // first - ratings, second - number
    bool operator()( const pair<int,int> &a, const pair<int,int> &b ){
        return a.first > b.first ;
    }
} ;

signed main(){
    int a ;
    float b ;
    cin >> a >> b ;
    int x = round(b * 100) ;
    cout << (int)(( a * x ) / 100) ;
    return 0 ;   
}          

Measured memory_bytes: 3752
# -*- coding: utf-8 -*-
import sys
from collections import deque

N=input()

al=[ [] for i in range(N+1) ]
Q=[]    #クエリー
for _ in range(N-1):
    a,b=map(int, sys.stdin.readline().split())
    al[a].append(b)
    al[b].append(a)
    Q.append((a,b))

K=0
start=None
for i,t in enumerate(al):
    K=max(K,len(t))
    if start is None and len(t)==1:
        start=i

edge={} #辺集合 (fro,to):色

#BFS
Visit=[ 0 for _ in range(N+1) ] #訪問した頂点
q=deque()
q.append(start)
Visit[start]=1
used=[ None for _ in range(N+1) ] #前の頂点との間で使用済みのカラー

while q:
    fro=q.popleft()
    for color in range(1,K+1):
        if used[fro]!=color:
            break

    for to in al[fro]:
        if Visit[to]==0:
            Visit[to]=1	#ここで訪問済みVisitに1をセットする。4行上のpopleftの直後でVisitをセットすると同じ頂点がqに入り、TLEする
            q.append(to)
            edge[(fro,to)]=color
            edge[(to,fro)]=color
            used[to]=color
            color+=1
            if used[fro]==color:
                color+=1

print K
for a,b in Q:
    print edge[(a,b)]


Measured memory_bytes: 90584
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

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

solve str = go [] str
  where
    go [] (s:ss) = go [s] ss
    go ts [] = length str - length ts
    go (t:ts) (s:ss) = if t == s 
                       then go (s:t:ts) ss
                       else go ts ss

Measured memory_bytes: 8700
sa = [i for i in input()]
sb = [i for i in input()]
sc = [i for i in input()]

turn = 0
while True:
    if turn == 0:
        if sa:
            card = sa.pop(0)
        else:
            break
    elif turn == 1:
        if sb:
            card = sb.pop(0)
        else:
            break
    else:
        if sc:
            card = sc.pop(0)
        else:
            break
    turn = 'abc'.index(card)

print('ABC'[turn])


Measured memory_bytes: 3060
// ~/Wiley/Atypon/RedLink/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>
#include <complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100005, M = 62;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1.0);

int n, m, clr[N];
vector<vector<pair<int,int> > > g;

void dfs(int u,int p, int last) {
    int c = 1;
    for(int i=0; i<g[u].size(); i++) {
        if(g[u][i].first != p) {
            while(c == last) c++;
            clr[g[u][i].second] = c;
            dfs(g[u][i].first, u, c);
            m = max(m, c);
            c++;
        }
    }
}

int main() {
    cin>>n;
    g.resize(n);
    for(int i=0, a,b; i<n-1; i++) {
        cin>>a>>b;
        a--,b--;
        g[a].push_back(make_pair(b, i));
        g[b].push_back(make_pair(a, i));
    }
    dfs(0,-1,-1);
    cout<<m<<endl;
    for(int i=0; i<n-1; i++)
        cout<<clr[i]<<endl;
    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector <ll> v(n);
  ll flag;
  rep(i, n) {
    cin >> v.at(i);
    if (v.at(i) == 1) flag = i;
  }
  ll res = INF;
  for (ll i = flag-k+1; i <= flag; i++) {
    ll tmp = 1;
    if (i >= 0) {
      if (i%(k-1)) {
        tmp += i/(k-1) + 1;
      } else {
        tmp += i/(k-1);
      }
    }
    if (i+k-1 < n) {
      if (((n-1)-(i+k-1))%(k-1)) {
        tmp += ((n-1)-(i+k-1))/(k-1) + 1;
      } else {
        tmp += ((n-1)-(i+k-1))/(k-1);
      }
    }
    chmin(res, tmp);
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int x;
  vector<int> p(n);
  int pi = 0;
  for(int i=0;i<n;i++){
     cin>>x;
     if(p[pi-1]!=x){
        p[pi]=x;
        pi++;
     }
  }

  for(int i=0;i<pi;i++){
   // cout<<p[i]<<"out"<<endl;
    if(i>0&&p[i]<=p[i-1])
     {
        p[i-1]--;
      //  cout<<p[i-1]<<endl;
     }
  }
  int cnt=0;
  for(int i=0;i<pi-1;i++){
       // cout<<p[i]<<endl;
    if(p[i]>p[i+1]){
        cout<<"No"<<endl;
        return 0;
    }
  }
   cout<<"Yes"<<endl;


  return 0;
}


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

int n, q;

struct Node {
  int min = 0x7fffffff, lazy = -1;
} seg[400005];

void update(int u, int l, int r, int ql, int qr, int v) {
  if (l == ql && r == qr) {
    seg[u].lazy = v;
    return;
  }

  if (seg[u].lazy != -1) {
    seg[u << 1].lazy =
      seg[u << 1 | 1].lazy =
      seg[u].lazy;
    seg[u].lazy = -1;
  }

  int m = (l + r) >> 1;

  if (qr <= m)
    update(u << 1, l, m, ql, qr, v);
  else if (ql > m)
    update(u << 1 | 1, m + 1, r, ql, qr, v);
  else
    update(u << 1, l, m, ql, m, v), update(u << 1 | 1, m + 1, r, m + 1, qr, v);
  
  int lm = seg[u << 1].lazy != -1 ? seg[u << 1].lazy : seg[u << 1].min;
  int rm = seg[u << 1 | 1].lazy != -1 ? seg[u << 1 | 1].lazy : seg[u << 1 | 1].min;

  seg[u].min = min(lm, rm);
}

int query(int u, int l, int r, int ql, int qr) {
  if (seg[u].lazy != -1)
    return seg[u].lazy;

  if (l == ql && r == qr)
    return seg[u].min;  

  int m = (l + r) >> 1;
  if (qr <= m)
    return query(u << 1, l, m, ql, qr);
  else if (ql > m)
    return query(u << 1 | 1, m + 1, r, ql, qr);
  else
    return min(query(u << 1, l, m, ql, m),
        query(u << 1 | 1, m + 1, r, m + 1, qr));
}

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

  for (int i = 0; i < q; i++) {
    int o; cin >> o;
    if (o == 0) {
      // update
      int l, r, v; cin >> l >> r >> v;
      update(1, 0, n - 1, l, r, v);
    } else {
      int l, r; cin >> l >> r;
      cout << query(1, 0, n - 1, l, r) << endl;
    }
  }
}



Measured memory_bytes: 5152
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

#define long long long int

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    vector<int> num(26);

    long res = 1;

    for (int i = 0; i < s.size(); i++) {
        res += i - num[s[i] - 'a'];
        num[s[i] - 'a']++;
    }

    cout << res;

    return 0;
}

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

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

    string s;
    cin >> s;
    rep(qi, s.size()) cout << "x";
    cout << endl;
}

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

int main () {
  long long N;
  cin >> N;
  long long ans10 = 1;
  long long ans9 = 1;
  long long ans8 = 1;
  long long mod = 1000000007;
 
  for (int k = 0; k < N; k++) {
    ans10 *= 10;
    ans10 %= mod;
    ans9 *= 9;
    ans9 %= mod;
    ans8 *= 8;
    ans8 %= mod;
  }
  
  if (ans10 + ans8 - ans9*2 >= 0){
    cout << ans10 + ans8 - ans9*2 << endl;
  }
  else if (ans10 + ans8 - ans9*2 + mod >= 0){
    cout << ans10 + ans8 - ans9*2 + mod << endl;
  }
  else {
    cout << ans10 + ans8 - ans9*2 + mod*2 << endl;
  }
}

Measured memory_bytes: 3632
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            if (line.Last().Equals('s'))
            {
                Console.WriteLine(line + "es");
            } else
            {
                Console.WriteLine(line + "s");
            }
        }
    }
}


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


int main(){
  int n,i;
  cin >> n;
  vector<int> d(n);
  set<int> s;
  for(i=0;i<n;++i){
    cin >> d[i];
    s.insert(d[i]);
  }
  cout << s.size() << endl;
  return 0;
}


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

using namespace std;

int getModNumber(int number)
{
    int n = 0;
    
    while (number % 2 == 0)
    {
        number /= 2;
        n++;
//        printf("number=%d\n", number);
    }

    return n;
}

int main()
{
    // 100 まで計算してみて調べてみる
#if 0
    int n[100];
    for (int i = 0; i < 100; i++)
    {
        n[i] = getModNumber(i + 1);
    }
    
    for (int i = 0; i < 100; i++)
    {
        if (i != 0 && i % 16 == 0)
        {
            printf("\n");
        }
        printf("%02d, ", n[i]);
    }
    
    // 1 - 16  : 16
    // 1 - 32  : 32
    // 1 - 48  : 32
    // 1 - 64  : 64
    // 1 - 80  : 64
    // 1 - 100 : 64
#else
    int N;
    
    cin >> N;
    int n[] = {1, 2, 4, 8, 16, 32, 64};
    
    for (int i = sizeof(n) / sizeof(int) - 1; i >= 0; i--)
    {
        if (N & n[i])
        {
            printf("%d\n", n[i]);
            break;
        }
    }
#endif
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<set>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
ll CaseN=1;

ll tst()
{
   ll ans=0;  
        
    
       
   return ans;
}


void solve()
{
ll d;
cin>>d;
vector<ll> c(27,0);
vector<ll> l(27,0);
for(ll i=1;i<=26;i++)
{
cin>>c[i];	
}
vector<vector<ll> > p(d+1,vector<ll>(27,0) );
for(ll i=1;i<=d;i++)
{
for(ll j=1;j<=26;j++)
{
	cin>>p[i][j];
}		
}
vector<ll> t(d+1) ;
for(ll i=1;i<=d;i++)
{
cin>>t[i];	
}
vector<ll> sat(d+1,0);
// t[i];
ll s=0; // satis
for(ll i=1;i<=d;i++)
{
	// t[i] help
	l[t[i]]=i;
	// p // satis
	ll m =0;
	for(ll j=1;j<=26;j++)
	{
		m+= (c[j]*(i-l[j]));
	}
	
	s += (p[i][t[i]] - m);
	//cout<<m<<" "<<p[i][t[i]]<<" "<<s<<endl;
	sat[i]= s;	
	
}


for(ll i=1;i<=d;i++)
{
cout<<sat[i]<<endl;	
}

//cerr<<"Case #"<<CaseN<<": ";
    CaseN++;
	
return ;
}



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


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <list>
#include <sstream>

#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;
const ll inf = 9223372036854775803;
const int maxN = 300005;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<bool> sn(n, false);
    int ans = 0;
    while(k--) {
        int t;
        cin >> t;
        while (t--) {
            int x;
            cin >> x;
            sn[x-1] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        if (!sn[i]) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

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

  string op;
  cin >> op;

  int B;
  cin >> B;
  
  if (op == "+") {
    cout << A + B << endl;
  } else {
    cout << A - B << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[10000],b[10000],c[100000];
	int e,f,g;
	scanf("%s %s %s",a,b,c);
	e=strlen(a);
	f=strlen(b);
	g=strlen(c);
	if(a[e-1]==b[0] && b[f-1]==c[0])
	printf("YES\n");
	else 
	printf("NO\n");
	return 0;
}


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

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    long[][] s = new long[4][N];
    for (int i = 0; i < N; i++) {
      long x = scanner.nextLong();
      long y = scanner.nextLong();
      long z = scanner.nextLong();
      s[0][i] =  x + y + z;
      s[1][i] = -x + y + z;
      s[2][i] =  x - y + z;
      s[3][i] =  x + y - z;
    }

    for (int i = 0; i < 4; i++) {
      Arrays.sort(s[i]);
    }
    
    long max = 0;
    for (int i = 0; i < 4; i++) {
      long a = 0;
      for (int j = 0; j < M; j++) {
        a += s[i][j];
      }
      if (-a > max) max = -a;
      
      a = 0;
      for (int j = 0; j < M; j++) {
        a += s[i][N - j - 1];
      }
      if (a > max) max = a;
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 28304
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string t;
  cin >> t;
  for(int i=0;i<t.size();i++){
    if(t.at(i)=='?') t.at(i)='D';
  }
  cout << t << endl; 
}

Measured memory_bytes: 3756
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int l;
  cin>>l;
  double length=(double)l/3;
  cout<<pow(length,3)<<endl;


  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int a, b; cin >> a >> b;
  vector<string> v(a+3);
  for(int i = 1; i < a+1; i++)cin >> v[i];
  for(int i = 0; i < a+2; i++){
    if(i == 0 || i == a+1){
      for(int j = 0; j < b+2; j++)cout << "#";
      cout << endl;
    }
    else{
      cout << "#" << v[i] << "#" << endl;
    }
  }
  system("pause");
}

Measured memory_bytes: 504
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 5100000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


//UF木
struct UnionFind {
private:
	vector<int> par, ran, sz;
public:
	UnionFind(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		sz.resize(n, 1);
		rep(i, n) {
			par[i] = i;
		}
	}
	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 (ran[x] < ran[y]) {
			par[x] = y; sz[y] += sz[x];
		}
		else {
			par[y] = x; sz[x] += sz[y];
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int num(int x) { return sz[find(x)]; }
};

ll n, m;
ll ans[100005];
int a[100005], b[100005];

int main() {

	cin >> n >> m;

	UnionFind uf(n);

	for (int i = m - 1; i >= 0; i--) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	ans[m - 1] = n * (n - 1) / 2;

	rep(i, m - 1) {
		ll cnt = 0;
		if (!uf.same(a[i], b[i])) {
			cnt += (ll)uf.num(a[i]) * (ll)uf.num(b[i]);
			uf.unite(a[i], b[i]);
		}
		ans[m - i - 2] = ans[m - i - 1] - cnt;
	}

	rep(i, m) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

int main() {
  unsigned long n, m;
  std::cin >> n >> m;

  // std::map<unsigned long long, unsigned long long> ab_map;
  // for (size_t i = 0; i < n; ++i) {
  //   unsigned long long a, b;
  //   std::cin >> a >> b;
  //   ab_map.insert(std::make_pair(a, b));
  // }
  std::vector<std::pair<unsigned long long, unsigned long long>> ab_map;
  for (size_t i = 0; i < n; ++i) {
    unsigned long long a, b;
    std::cin >> a >> b;
    ab_map.push_back(std::make_pair(a, b));
  }
  std::sort(ab_map.begin(), ab_map.end());

  unsigned long long ans = 0;
  unsigned long long current = 0;
  for (auto ab : ab_map) {
    const unsigned long long a = ab.first;
    const unsigned long long b = ab.second;
    if (current + b < m) {
      ans += a * b;
      current += b;
      continue;
    } else {
      const unsigned long long num = m - current;
      ans += a * num;
      current += num;
      break;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  ll N, ans;
  cin >> N;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));

  ans = 0;
  for (ll i=1; i<=N; i++){
    ll tmp;
    cin >> tmp;
    if( i % 2 == 1 && tmp %2 ==1){
      ans ++;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int n,m,tot,id,head[N],dfn[N],low[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
int top,s[N];
bool vv[N],vis[N];
bool tarjan(int u)
{
    dfn[u]=low[u]=++id;
    s[++top]=u;vis[u]=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(vv[v]) continue;
        if(!dfn[v])
        {
            if(tarjan(v)) return true;
            low[u]=min(low[u],low[v]);
        }
        else if(vis[v])
            low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u])
    {
        if(s[top]!=u) return true;
        top--;vis[u]=false;
    }
    return false;
}
int main()
{
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int u,v;scanf("%d%d",&u,&v);add(u,v);
    }
    bool ff=true;
    for(int i=1;i<=n;i++)
        if(!dfn[i])
    {
        if(tarjan(i)){ff=false;break;}
    }
    for(int i=1;i<=n;i++)
    {
        vv[i]=true;
        id=0;top=0;
        memset(dfn,0,sizeof(dfn));
        memset(vis,false,sizeof(vis));
        memset(low,0,sizeof(low));
        bool flag=false;
        for(int j=1;j<=n;j++)
            if(!dfn[j]&&!vv[j])
        {
            if(tarjan(j)) {flag=true;break;}
        }
        if(!flag) vv[i]=false;
    }
    int ans=0,p[N];
    for(int i=1;i<=n;i++)
        if(!vv[i]) p[++ans]=i;
    if(ff) printf("-1\n");
    else
    {
        printf("%d\n",ans);
        for(int i=1;i<=ans;i++)
            printf("%d\n",p[i]);
    }
}


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

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

    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'R')
            cnt++;
        else
            cnt = 0;
        ans = max(ans,cnt);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
/******************
*  Writer: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;

string s,t;
set<char> s_faq[256],t_faq[256];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		s_faq[s[i]].insert(t[i]);
		t_faq[t[i]].insert(s[i]);
		if(s_faq[s[i]].size()>1 || t_faq[t[i]].size()>1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
}
//FaQ for I failed so many times online and more times offline
//FaQ
//FaQ

Measured memory_bytes: 916
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String S = sc.next();
	for ( int i = 0; i < S.length()-1; i++ ) {
	    if ( S.charAt(i) == 'A' && S.charAt(i+1) == 'C' ) {
		System.out.println("Yes");
		return ;
	    }
	}
	System.out.println("No");
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, k, ret;
vector<vector<int>> G;

bool used[100009];

int dfs(int v) {
    used[v] = true;
    int res = 0;
    for(int u : G[v]) {
        if(!used[u]) {
            int x = dfs(u);
            if(x < k)
                chmax(res, x);
            else if(v)
                ret++;
        }
    }
    return res + 1;
}

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

    cin >> n >> k;
    G.resize(n);

    rep(i, n) {
        int a;
        cin >> a;
        a--;
        if(i == 0)
            ret += (a ? 1 : 0);
        else
            G[a].push_back(i);
    }

    dfs(0);

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 10496
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 {
     static boolean isPrime(int n)  
      {
        if (n <= 1) return false;  
        if (n <= 3) return true;  
        if (n % 2 == 0 || n % 3 == 0) return false;  
        for (int i = 5; i * i <= n; i = i + 6)  
            if (n % i == 0 || n % (i + 2) == 0)  
            return false;  
          
        return true;}  
    
    static int nextPrime(int N)  
      {  
        if (N <= 1)  
            return 2;  
        int prime = N-1;  
        boolean found = false;  
        while (!found)  
        {  
            prime++;  
      
            if (isPrime(prime))  
                found = true;  
        }  
      
        return prime;  
    }  
	public static void main (String[] args)
	 {
	 Scanner s=new Scanner(System.in);
	 int a=s.nextInt();
	 System.out.println(nextPrime(a));}}
	 

Measured memory_bytes: 23892
import itertools

def is_triangle(list_L):
    
    if (list_L[0] + list_L[1] > list_L[2]) and (list_L[1] + list_L[2] > list_L[0]) and (list_L[2] + list_L[0] > list_L[1]) :
        return True
    else :
        return False

def is_uniqueL(list_L):

    return len(list_L) == len(set(list_L))

N = int(input())
L = map(int,input().split())

comb_L = list(itertools.combinations(L, 3))

sum = 0

for a_comb_L in comb_L :

    if is_uniqueL(a_comb_L) == True and is_triangle(a_comb_L) == True:
        sum += 1

print(sum)

Measured memory_bytes: 20476
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	rep(i, s.length()) {
		if ((i % 2 == 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) || (i % 2 == 1 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')))continue;
		else return cout << "No" << endl,0;
	}
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

typedef pair<int, int> pii;

map<pii, int> mp;

int main()
{
	int n, t;
	scanf("%d %d", &n, &t);

	// 입력이 1개뿐이면 그냥 m - n
	if (n == 1)
	{
		int val;
		scanf("%d", &val);
		cout << t;
		return 0;
	}

	// map에 n, m값을 모두 넣어준다.
	// n기준으로 오름차순 정렬
	int tmp = n;
	while (tmp--)
	{
		int val;
		scanf("%d", &val);

		mp[{val, val + t}] = 1;
	}

	// 첫 시작값과 끝 값을 넣어준다.
	auto it = mp.begin();
	int start = it->first.first;
	int end = it->first.second;
	it++;

	long long sum = 0;
	for (it; it != mp.end(); it++)
	{
		int sTmp = it->first.first;
		int eTmp = it->first.second;

		// 새로 들어온 시작 값이 start와 end 사이 있을 경우
		if (start <= sTmp && sTmp <= end)
		{
			// 새로 들어온 끝 값이 end보다 크면
			// end를 갱신
			if (eTmp > end)
				end = eTmp;
		}

		// 새로 들어온 start가 end보다 클 때
		else if (sTmp > end)
		{
			// 기존에 존재하던 start와 end를 sum에 계산해준다.
			sum += end - start;
			// 갱신
			start = sTmp;
			end = eTmp;
		}

		// map의 마지막 부분에 왔는지 확인하고
		// 마지막 부분이라면 값을 계산해주고 종료
		if (++it == mp.end())
		{
			sum += end - start;
			break;
		}
		it--;
	}

	cout << sum;
	return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=abs(a-c),y=abs(b-d);
  if(x*y==0){
    cout<<0<<endl;
    return 0;
  }
  int k=__gcd(x,y);
  int p=((x+y)/k-1)*k;
  cout<<p<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int l;
int main() {
	cin>>s;
	l = s.length();
	if (s[0] == s[l - 1]) {
		if (l % 2 == 0) cout<<"First"; else cout<<"Second";
	} else {
		if (l % 2 == 0) cout<<"Second"; else cout<<"First";
	}
}

Measured memory_bytes: 512
def insert_sort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt

def shellSort(A, n):
    cnt = 0
    G = []; h = 0
    while h <= n:
        if 3 * h + 1 <= n:
            h = 3 * h + 1
            G.append(h)
        else: break
    G = sorted(G, reverse=True)
    m = len(G)
    for i in range(m):
        cnt = insert_sort(A, n, G[i], cnt)
    return m, cnt, G

A = []
n = int(input())
for i in range(n):
    A.append(int(input()))

m, cnt, G = shellSort(A, n)
print(m)
for i in range(m):
    if i == m - 1:
        print(G[i])
    else:
        print(G[i], end=" ")
print(cnt)
for i in A:
    print(i)



Measured memory_bytes: 45516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 2e09

vector<int> h(100010), dp(100010, INF);
int rec(int i){
    if (dp.at(i) < INF) return dp.at(i);
    if (i == 0) return 0;

    int res = INF;
    res = min(res, rec(i-1)+abs(h.at(i)-h.at(i-1)));
    if (i > 1) res = min(res, rec(i-2)+abs(h.at(i)-h.at(i-2)));

    return dp.at(i) = res;

}

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> h.at(i);
    dp.at(0) = 0;

    cout << rec(n-1) << endl;
    return 0;
}

Measured memory_bytes: 5760
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj = null;
var inputFile = [];
reader.on('line', function(input){inputFile.push(input);});
reader.on('close', function(){
  obj = init(inputFile);
  Main();
});
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    "list" : input, "index" : 0, "max" : input.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  var output = 0;
  if(B == 1){
    myout(output);
    return;
  }
  var tap = 1;
  for(var i = 0; i < 100; i++){
    tap += (A - 1);
    output++;
    if(tap >= B){
      break;
    }
  }
  myout(output);
}


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

typedef pair<int,int> P;

const int H_MAX=51,W_MAX=51;
const int INF=10000000;
int H,W;
char s[W_MAX][H_MAX];
int d[W_MAX][H_MAX]; //最短経路の記録
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(int sx,int sy,int gx,int gy){
    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            d[i][j]=INF;
        }
    }
    queue<P> que;
    que.push(P(sx,sy));
    d[sx][sy]=0;

    while(que.size()){
        P p=que.front(); que.pop();
        if(p.first==gx&&p.second==gy) break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx&&0<=ny&&nx<W&&ny<H&&s[nx][ny]=='.'&&d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }

    return d[gx][gy];
}


int main(){
    cin >> H >> W;
    int cnt=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[j][i];
            if(s[j][i]=='#') cnt++;
        }
    }
    if(bfs(0,0,W-1,H-1)==INF) cout << -1 << endl;
    else cout << H*W-cnt-bfs(0,0,W-1,H-1)-1 << endl;
}

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

#define ll int64_t
using namespace std;
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll our=1e18l;
int main(){
    IOS
    ll n;
    cin>>n;
    ll tmp=1;
    ll aa;
    bool fl=false;
    bool haszero=false;

    ll a[n];
    fo(i,n){
    	 cin>>a[i];
    	 if(a[i]==0) haszero=true;
    }
    if(haszero) {
    	cout<<0<<endl;
    	return 0;
    }
    fo(i,n){
    	if(tmp>our/a[i]) {
    		tmp=-1;
    		fl=true;
    	}
    	if(!fl) tmp=tmp*a[i];
    }

    cout<<tmp<<endl;
}

Measured memory_bytes: 4392
// https://atcoder.jp/contests/abc174/tasks/abc174_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  string cs;
  cin >> N >> cs;

  set<ll> r_indices;
  set<ll> w_indices;

  rep(i, N) {
    if (cs[i] == 'R') r_indices.insert(i);
    if (cs[i] == 'W') w_indices.insert(i);
  }

  if (r_indices.size() == 0 || w_indices.size() == 0) drop(0);

  ll res = 0;

  while (1) {
    ll w_i = *w_indices.begin();
    ll r_i = *r_indices.rbegin();

    if (r_i < w_i) break;

    w_indices.erase(w_i);
    r_indices.erase(r_i);

    w_indices.insert(r_i);
    r_indices.insert(w_i);

    ++res;
  }

  cout << res << "\n";
}


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

using ll = long long;

void solve(long long N, std::vector<long long> A){
    ll ans = 0;
    ll uku = 2;
    ans += A[0] - 1;
    for(int i = 1;i < N;i++){
        //cout<<A[i]<<" "<<uku<<endl;
        ans += (A[i] - 1) / uku;
        if(A[i] == uku)uku++;
        //cout<<ans<<endl;
    }
    /*
    for(int i = 0;i < N;i++){
        cout<<A[i]<<" ";
    }
    
    cout<<endl;
    */
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

const int MAX_SIZE = 100;

pair<int, int> calc(int n, int h[]) {
  pair<int, int> a;
  for (int i = 0; i < n - 1; ++i) {
    int d = h[i + 1] - h[i];
    if (d > 0) {
      if (d > a.first) a.first = d;
    } else {
      if (-d > a.second) a.second = -d;
    }
  }
  return a;
}

int main() {
  int t, n, h[MAX_SIZE];
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> n;
    for (int j = 0; j < n; ++j) {
      cin >> h[j];
    }
    pair<int, int> a = calc(n, h);
    cout << a.first << ' ' << a.second << endl;
  }
}

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

int main(int argc, char const *argv[])
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n", (b / a < c) ? (b / a) : c );
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=3005;const db pie=acos(-1);
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,a[MAXN],L;db ansx,ansy;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),L=read();Rep(i,1,n)a[i]=read();
	Rep(i,1,n)Rep(j,i+1,n)ansx+=cos(pie*(a[i]+a[j])/L)*(n-2*(j-i)),ansy+=sin(pie*(a[i]+a[j])/L)*(n-2*(j-i));
	ansx/=1ll*n*(n-1)*(n-2)/6,ansy/=1ll*n*(n-1)*(n-2)/6,printf("%.10lf %.10lf",ansx,ansy);
	return 0;
}




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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

//8:08~

void solve()
{
  int n, a_input;
  cin >> n;
  deque<int> a;
  for(int i = 0; i < n; ++i)
  {
    cin >> a_input;
    a.push_back(a_input);
  }
  sort(a.begin(), a.end());

  ll ans = 0;
  deque<int> b;
  b.push_back(a.back());
  a.pop_back();
  while(!a.empty())
  {
    ll af = a.front();
    ll ab = a.back();
    ll bf = b.front();
    ll bb = b.back();

    ll dff = abs(af - bf);
    ll dfb = abs(af - bb);
    ll dbf = abs(ab - bf);
    ll dbb = abs(ab - bb);
    ll dmax = max({dff, dfb, dbf, dbb});

    if (dmax == dff)
    {
      b.push_front(af);
      a.pop_front();
    }
    else if (dmax == dfb)
    {
      b.push_back(af);
      a.pop_front();
    }
    else if (dmax == dbf)
    {
      b.push_front(ab);
      a.pop_back();
    }
    else if (dmax == dbb)
    {
      b.push_back(ab);
      a.pop_back();
    }
    ans += dmax;
  }

  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4056