akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>

using namespace std;

int main(void) {
	string s;
	int n;
	cin >> s >> n;
	vector<char> begin, end;
	bool inv = false;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			inv=!inv;
		}
		else {
			int f;
			char c;
			cin >> f >> c;

			if ((!inv&&f==1)||inv&&f==2) {
				begin.push_back(c);
			}
			else {
				end.push_back(c);
			}
		}
	}

	if(!inv){
		for (int i = begin.size() - 1; i >= 0; i--) {
			cout << begin[i];
		}for (int i = 0; i < s.length(); i++) {
			cout << s[i];
		}for (int i = 0; i < end.size(); i++) {
			cout << end[i];
		}
	}
	else {
		for (int i = end.size() - 1; i >= 0; i--) {
			cout << end[i];
		}for (int i = s.length() - 1; i >= 0; i--) {
			cout << s[i];
		}
		for (int i = 0; i < begin.size(); i++) {
			cout << begin[i];
		}
	}


	return 0;
}

Measured memory_bytes: 1024
require 'pp'
def update(id)
  update id*2+1 if id < $tree.size-$n
  update id*2+2 if id < $tree.size-$n
  $tree[id] = [$tree[id*2+1], $tree[id*2+2]].min if id < $tree.size-2**($num-1)
end

def query (a, b, k, l, r)
  return Float::INFINITY if r<= a || b <= l
  return $tree[k] if a <= l && r<= b
  vl = query(a, b, k*2+1, l, (l+r)/2)
  vr = query(a, b, k*2+2, (l+r)/2, r)
  #puts "vl:#{vl} vr:#{vr}"
  #puts
  return [vl,vr].min
end

$n,$l  = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
$num = 0
$tree = []
flag = false
while true
  if 2**$num < as.size
    (2**$num).times{|i|
      $tree << Float::INFINITY
    }
  else
    as.each{|a| $tree << a}
    (2**$num-$n).times{$tree << Float::INFINITY}
  end
  $num+=1
  break  if flag
  flag = true if 2**$num >= as.size
end
size2 = $tree.size - 2**($num-1)
update 0
min = []

m=1
while m<$n
  m*=2
end
#pp $tree
($n-$l+1).times{|i|
  #puts "l:#{size2+i} r::#{size2+i+$l-1}"
  min << query(i, i+$l,  0, 0, m)
}

puts min.join(" ")



Measured memory_bytes: 134524
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
  int n,i,x[1000],y[1000];
  double sum=0,max=0;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
      scanf("%d",&x[i]);
  }
  for(i=0;i<n;i++){
      scanf("%d",&y[i]);
  }
   
  for(i=0;i<n;i++){
      sum+=abs(x[i]-y[i]);
  }
  printf("%f\n",sum);
  sum=0;
   
  for(i=0;i<n;i++){
       sum+=abs(x[i]-y[i])*abs(x[i]-y[i]);
  }
  printf("%f\n",sqrt(sum));
  sum=0;
   
  for(i=0;i<n;i++){
       sum+=abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i]);
  }
  printf("%f\n",pow(sum,1.0/3.0));
   
  for(i=0;i<n;i++){
      if(max<abs(x[i]-y[i])) max=abs(x[i]-y[i]);
  }
  printf("%f\n",max);
   
  return 0;
}


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

using namespace std;

int pre[100010];
bool root[100010];

int find(int a) {
    if (pre[a] != a) {
        pre[a] = find(pre[a]);
    }
    return pre[a];
}

void join(int a, int b) {
    int find_a = find(a);
    int find_b = find(b);
    if (find_a != find_b) {
        pre[find_b] = find_a;
    }
}

int main() {
    int N, num;
    cin >> N >> num;
    for (int i = 1; i <= N; i++) {
        pre[i] = i;
        root[i] = true;
    }
    for (int i = 0; i < num; i++) {
        int a, b;
        cin >> a >> b;
        join(a, b);
    }
    int output = 0;
    for (int i = 1; i <= N; i++) {
        if (pre[i] == i) {
            output++;
        }
    }
    output = output - 1;
    cout << output;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[n]; REP(i,n) cin >> a[i];
  int mini = INF;
  REP(i,n) mini = min(mini,a[i]);
  int ans = mini;

  while(1) {
    mini = ans;
    int ok = 1;
    REP(i,n) {
      if (a[i] == mini) continue;
      if (a[i] < mini) { a[i] = 0; break; }
      a[i]%=mini;
      if (a[i] > 0) {
        ok = 0;
        ans = min(ans, a[i]);
      }
    }
    if (ok) break;
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define nl           printf("\n")
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define tc           ll t; scn(t); while(t--)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define fi           first
#define se           second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.rbegin(),v.rend())
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         5000005
#define inf          LLONG_MAX
#define zer          LLONG_MIN
#define dbug(a)      cout<<"dbug : "<<a<<endl
#define debug(a,b)   cout<<a<<" "<<b<<endl
#define read(v)      vec v(n,0); rep(i,0,n) {cin>>v[i];}
#define write(a,n)   rep(i,0,n) {cout<<a[i]<<" ";}
#define All          rep(i,0,n) 
ll zero = 0;




int main()
{
	string s;
	cin>>s;
	
	int n =  int(s.length());
	int ans=0;
	
	for(int i=0;i<n;i++){
		ans+= (s[i]-'0');
	}
	
	if(ans%9==0) cout<<"Yes";
	else cout<<"No";
return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int Alice = 0, Bob = 0;
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        Alice += vec.at(i);
      } else {
        Bob += vec.at(i);
      }
    }
    cout << Alice - Bob << endl;
  
}

Measured memory_bytes: 3568
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int i = Integer.parseInt(s);

        int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
//        String[] array = s.split(' ');
        System.out.println(arr[i-1]);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//indexは
long long INF = 1LL<<60;

int n;
void gene(int i,int rest,string s){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    if(i>n||rest<0)return;
    i++;
    rest--;
    for(int j=0;j<i+1;j++){
        char tmp='a'+j;
        if(tmp!='a'){
            char fb=tmp-1;
            if(s.find(fb)==string::npos)continue;
        }
        gene(i,rest,s+tmp);
    }
}

int main( ){
    cin>>n;
    gene(0,n,"");
    return 0;
}




Measured memory_bytes: 1536
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var n = 0
  val b = new ArrayBuffer[Int]
  while( {n=readInt;n} != 0 ) {
    val a = new Array[Int](7)
    for(i<-0 until n) {
      val m = readInt
      if(m<10) a(0) += 1
      else if(m>=10 && m<20) a(1) += 1
      else if(m>=20 && m<30) a(2) += 1
      else if(m>=30 && m<40) a(3) += 1
      else if(m>=40 && m<50) a(4) += 1
      else if(m>=50 && m<60) a(5) += 1
      else if(m>=60) a(6) += 1
    }
    b ++= a
  }
  println(b.mkString("\n"))
}

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

int main()
{
    ll N;
    cin >> N;
    ll a=0,b=0;
    for(int i = 0; i < N; ++i)
    {
        ll ai,bi;
        cin >> ai >> bi;
        if(ai>a){
            a = ai;
            b = bi;
        }
    }
    
    cout << a + b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>
#include <map>
#include <typeinfo>

using namespace std;

int main()
{
	int a, b, t;

	cin >> a >> b >> t;

	cout << t / a * b << endl;

}

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

ll solve() {
    ll N;
    cin >> N;
    ll x = -1;
    for ( int i = 0; i <= 50000; i++ ) {
        int y = i * 108 / 100;
        if ( y == N ) {
            x = i;
            break;
        }
    }
    if ( x >= 0 ) return x;
    else return -1;
}

int main() {
    auto ans = solve();
    if ( ans < 0 ) cout << ":(\n";
    else cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>

using namespace std;


int main() {

	int a, b;

	cin >> a >> b;

	if (a + b >= 10) {
		cout << "error" << endl;
	} else {
		cout << a + b << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
int main(void){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    int ret=(m2-m1)+(h2-h1)*60-k;
    cout<<ret<<endl;
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3176
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

def koch(n, sx, sy, gx, gy):
    if n == 0:
        print gx, gy
        return
    vx = gx - sx
    vy = gy - sy
    x1 = sx + vx / 3
    y1 = sy + vy / 3
    x3 = gx - vx / 3
    y3 = gy - vy / 3
    vx60 = vx / 2 - math.sqrt(3) * vy / 2
    vy60 = math.sqrt(3) * vx / 2 + vy / 2
    x2 = x1 + vx60 / 3
    y2 = y1 + vy60 / 3
    koch(n - 1, sx, sy, x1, y1)
    koch(n - 1, x1, y1, x2, y2)
    koch(n - 1, x2, y2, x3, y3)
    koch(n - 1, x3, y3, gx, gy)

n = input()
print 0, 0
koch(n, 0.0, 0.0, 100.0, 0.0)



Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const ll siz = 1e5 + 7;
vector<ll>adj[siz];
ll dis[siz];
ll n, m;
bool vis[siz];
void dfs(int v) {
	vis[v] = true;
	for (auto k : adj[v]) {
		if (!vis[k]) {
			dfs(k);
		}
		dis[v] = max(dis[v], dis[k] + 1);
	}
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	vector<int>u(m);
	for (int i = 0; i < m; i++) {
		int v;
		cin >> u[i] >> v;
		adj[u[i]].pb(v);
	}
	for (int i = 0; i < m; i++) {
		if (!vis[u[i]])
			dfs(u[i]);
	}
	ll nax = 0;
	for (int i = 1; i <= n; i++)nax = max(nax, dis[i]);
	cout << nax << endl;
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

inline ll encode(vector<int> &tile) {
  ll now = 0, base = 1000;
  for (int c : tile) {
    now += c;
    now *= base;
  }
  return now;
}

inline void rot(vector<int> &tile) {
  rotate(tile.begin(), tile.begin() + 1, tile.end());
}

inline void rm_tile(vector<int> &tile, map<ll, int> &colors) {
  REP(i, 4) {
    colors[encode(tile)]--;
    rot(tile);
  }
}

inline void add_tile(vector<int> &tile, map<ll, int> &colors) {
  REP(i, 4) {
    colors[encode(tile)]++;
    rot(tile);
  }
}

ll calc_tiles(vector<int> &upper, vector<int> &lower, map<ll, int> &colors) {
  ll ret = 1;
  vector<vector<int>> side_tiles = {{upper[1], lower[0], lower[3], upper[2]},
                                    {upper[3], upper[2], lower[3], lower[2]},
                                    {lower[1], upper[0], upper[3], lower[2]},
                                    {lower[1], lower[0], upper[1], upper[0]}};
  vector<vector<int>> used;
  for (vector<int> &tile : side_tiles) {
    ret *= max(colors[encode(tile)], 0);
    if (ret == 0) break;
    rm_tile(tile, colors);
    used.emplace_back(tile);
  }

  for (vector<int> &tile : used) add_tile(tile, colors);
  return ret;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<vector<int>> tiles(N);
  map<ll, int> colors;
  REP(i, N) {
    int c0, c1, c2, c3; cin >> c0 >> c1 >> c2 >> c3;
    tiles[i] = {c0, c1, c2, c3};
    REP(j, 4) {
      colors[encode(tiles[i])]++;
      rot(tiles[i]);
    }
  }

  ll ans = 0;
  REP(up, N) {
    rm_tile(tiles[up], colors);
    FOR(low, up+1, N) {
      rm_tile(tiles[low], colors);
      REP(k, 4) {
        ans += calc_tiles(tiles[up], tiles[low], colors);
        rot(tiles[low]);
      }
      add_tile(tiles[low], colors);
    }
  }
  cout << ans << endl;

  return 0;
}


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



int main(){
	int h, w, k, ans = 0;
	cin >> h >> w >> k;
	char c[h][w];
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			cin >> c[i][j];
		}
	}
	for(int i=0; i< 1<<h; i++) {
		for(int j=0; j< 1<<w; j++) {
			int black = 0;
			for(int x=0; x<h; x++) {
				for(int z=0; z<w; z++) {
					if(!(i>>x&1) && !(j>>z&1) && c[x][z] == '#'){
						black ++;
					}
				}
			}
			if(black == k) {
				ans ++;
			}
		}
	}
	cout << ans;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int inf = 1e9;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );

struct Dinic {
  int n, s, t;
  struct Edge {
    int to, cf;
    Edge(int _to, int _cf) : to(_to), cf(_cf) {}
  };
  vector<Edge> edge;
  vector<vector<int> > gr;
  vector<int> d, iGr;

  Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t) {
    edge.clear();
    gr.assign(n, {} );
  }

  void addEdge(int u, int v, int c) {
    gr[u].emplace_back(sz(edge) ); edge.emplace_back(v, c);
    gr[v].emplace_back(sz(edge) ); edge.emplace_back(u, 0);
  }

  bool bfs() {
    d.assign(n, inf); d[s] = 0;
    iGr.assign(n, 0);
    queue<int> q; q.emplace(s);

    while (sz(q) ) {
      int u = q.front(); q.pop();
      for (int i : gr[u]) if (d[ edge[i].to ] == inf && edge[i].cf) {
        d[ edge[i].to ] = d[u] + 1;
        q.emplace(edge[i].to);
      }
    }

    return d[t] != inf;
  }

  int dfs(int u, int flow) {
    if (u == t || !flow) return flow;

    for (; iGr[u] < sz(gr[u]); ++iGr[u]) {
      int i = gr[u][ iGr[u] ];
      if (d[ edge[i].to ] != d[u] + 1 || !edge[i].cf) continue ;

      int nxt = dfs(edge[i].to, min(flow, edge[i].cf) );
      if (nxt) { edge[i].cf -= nxt; edge[i ^ 1].cf += nxt; return nxt; }
    }

    return 0;
  }

  int getMxFlow() {
    int ret = 0;

    while (bfs() ) {
      int tmp;
      while ( (tmp = dfs(s, inf) ) ) ret += tmp;
    }

    return ret;
  }
};

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafCLover

  int n, m; cin >> n >> m;
  pair<int, int> s, t;
  vector<vector<char> > grid(n, vector<char>(m) );
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == 'S') s = { i, j };
      else if (grid[i][j] == 'T') t = { i, j };
    }
  }

  auto to1D = [&](int x, int y) { return x * m + y; };
  auto in = [&](int x, int y) { return to1D(x, y) << 1; };
  auto out = [&](int x, int y) { return to1D(x, y) << 1 | 1; };

  Dinic dinic(n * m * 2, in(s.first, s.second), out(t.first, t.second) );
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) dinic.addEdge(in(i, j), out(i, j), make_pair(i, j) != s && make_pair(i, j) != t ? 1 : inf);
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) if (grid[i][j] != '.') {
      for (int x = i + 1, y = j; x < n; ++x) if (grid[x][y] != '.') dinic.addEdge(out(i, j), in(x, y), inf);
      for (int x = i - 1, y = j; ~x; --x) if (grid[x][y] != '.') dinic.addEdge(out(i, j), in(x, y), inf);
      for (int x = i, y = j + 1; y < m; ++y) if (grid[x][y] != '.') dinic.addEdge(out(i, j), in(x, y), inf);
      for (int x = i, y = j - 1; ~y; --y) if (grid[x][y] != '.') dinic.addEdge(out(i, j), in(x, y), inf);
    }
  }

  int ans = dinic.getMxFlow();
  cout << (ans < inf ? ans : -1) << '\n';

  return 0;
}


Measured memory_bytes: 54240
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC100(void);
void ABC101(void);
void ABC102(void);
void ABC103(void);
void ABC104(void);
void ABC105(void);
void ABC106(void);
void ABC107(void);
void ABC108(void);
void ABC109(void);

int main(void){
    ABC105();
}

void ABC105(){
    int n,i,j,ans=0;
    cin>>n;
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            if(n==4*i+7*j)ans=1;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;


ll n, m;
/*********************GoodLuck***********************/
int main () {
    IOS();
    cin >> n >> m;

    if (n > m) {
        swap(n, m);
    }

    if (n == 1) {
        if (m == 1) {
            cout << 1 << endl;
        } else {
            cout << m - 2 << endl;
        }
    } else {
        cout << (n-2) * (m-2) << endl;
    }
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


ll N,K;
ll a[1010];
ll sum[1010];
ll mx;
vector<ll> vt[50];
int main() {
    cin>>N>>K;
    REP(i,0,N){
        cin>>a[i];
        sum[i+1] = sum[i] + a[i];
    }
    REP(i,0,N+1) {
        REP(j, i + 1, N+1) {
            ll sums = sum[j] - sum[i];
            for(ll k=0;k<41;k++){
                if(sums & (1LL<<k)){
                    vt[k].push_back(sums);
                }
            }
        }
    }
    ll ans = 0;
    vector<ll> now;
    for(ll l=41; l>=0; l--) {
        if (vt[l].size() >= K) {
            now = vt[l];
            for(ll k=0;k<l;k++){
                vt[k].clear();
                for(ll n:now) {
                    if (n & (1LL << k)) {
                        vt[k].push_back(n);
                    }
                }
            }
            ans += (1LL << l);
        }
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 76304
class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
max_A = max(A)

st = SegmentTree([N] * (max_A + 1), min, N)
dp = [1] * N
for i, a in enumerate(reversed(A)):
    j = N - 1 - i
    p1 = st.get(a, min(max_A + 1, a + K + 1))
    if p1 < N:
        dp[j] = max(dp[p1] + 1, dp[j])
    p2 = st.get(max(0, a - K), a)
    if p2 < N:
        dp[j] = max(dp[p2] + 1, dp[j])
    st.update(a, j)

print(max(dp))


Measured memory_bytes: 138500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  if ((c - (a - b)) < 0){
    cout << 0 << endl;
  }
  else{
    cout << c - (a - b) << endl;
  }
  

  return 0;
}


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

typedef struct{
	int Top;
	int Bottom;
	int Right;
	int Left;
	int Face;
	int Back;
}DICE;

DICE InitDice(void){
	DICE dice;
	dice.Top=1;
	dice.Bottom=6;
	dice.Right=3;
	dice.Left=4;
	dice.Face=2;
	dice.Back=5;
	return dice;
}

int main(void){
	int i,j,n,answer,buf;
	char input[32];
	DICE dice;
	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		dice=InitDice();
		answer=dice.Top;
		fgets(input,sizeof(input),stdin);
		for(i=0;i<n;i++){
			fgets(input,sizeof(input),stdin);
			input[strlen(input)-1]='\0';
			if(strcmp(input,"North")==0){
				buf=dice.Top;
				dice.Top=dice.Face;
				dice.Face=dice.Bottom;
				dice.Bottom=dice.Back;
				dice.Back=buf;
			}else if(strcmp(input,"East")==0){
				buf=dice.Top;
				dice.Top=dice.Left;
				dice.Left=dice.Bottom;
				dice.Bottom=dice.Right;
				dice.Right=buf;
			}else if(strcmp(input,"West")==0){
				buf=dice.Top;
				dice.Top=dice.Right;
				dice.Right=dice.Bottom;
				dice.Bottom=dice.Left;
				dice.Left=buf;
			}else if(strcmp(input,"South")==0){
				buf=dice.Top;
				dice.Top=dice.Back;
				dice.Back=dice.Bottom;
				dice.Bottom=dice.Face;
				dice.Face=buf;
			}else if(strcmp(input,"Right")==0){
				buf=dice.Face;
				dice.Face=dice.Right;
				dice.Right=dice.Back;
				dice.Back=dice.Left;
				dice.Left=buf;
			}else if(strcmp(input,"Left")==0){
				buf=dice.Face;
				dice.Face=dice.Left;
				dice.Left=dice.Back;
				dice.Back=dice.Right;
				dice.Right=buf;
			}
			answer+=dice.Top;
		}
		printf("%d\n",answer);
	}

	return 0;
}

Measured memory_bytes: 608
#include <iostream>

using namespace std;

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    int a[m + 1];
    int leftGates = 0;
    int rightGates = 0;

    for(int i = 1; i <= m; i++)
    {
        cin >> a[i];
        if(a[i] < x)
        {
            leftGates++;
        }
        else
        {
            rightGates++;
        }
    }

    cout << min(leftGates, rightGates);

    return 0;
}


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

int main(){
    string S;cin>>S;
    if(S[0] == S[1] && S[1] == S[2] && S[0] == S[2])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    return x.first>y.first;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}
vector<int> g[200001];
int p[200001];
int ans[200001];

void dfs(int node,int par,int incr)
{
    ans[node]+=incr;
    for(int to: g[node]){
        if(to==par) continue;
        dfs(to,node,incr+p[to]);
    }
}
void solve()
{   
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<q;i++){
        int pj,xj;
        cin>>pj>>xj;
        p[pj]+=xj;
    }
    dfs(1,-1,p[1]);  
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<' ';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 24064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define in long long int
in dp[101][100001];
in knapsack(vector<in>&w,vector<in>&v,in n,in cap)
{
    if(n==0||cap==0)
        return 0;
    if(dp[n][cap]!=-1)
        return dp[n][cap];
    if(w[n-1]<=cap)
        dp[n][cap]=max(v[n-1]+knapsack(w,v,n-1,cap-w[n-1]),knapsack(w,v,n-1,cap));
    else
        dp[n][cap]= knapsack(w,v,n-1,cap);
    return dp[n][cap];
}
int main() {
    memset(dp,-1,sizeof(dp));
	in n,cap;
	cin>>n>>cap;
	vector<in>w(n),v(n);
	for(in i=0;i<n;i++)
	{
	    cin>>w[i];
	    cin>>v[i];
	}
	cout<<knapsack(w,v,n,cap);
	return 0;
}

Measured memory_bytes: 82440
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double pi = 3.141592653589793;


int main()
{
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double hh = h+(m/60);

    double hx,hy,mx,my,hrad,mrad;
    hrad = (hh*2*pi/12);
    mrad = (m*2*pi/60);
    hy = a*sin(hrad);
    hx = a*cos(hrad);
    my = b*sin(mrad);
    mx = b*cos(mrad);

    double ans = sqrt((hy-my)*(hy-my)+(hx-mx)*(hx-mx));
    cout << fixed << setprecision(11) << ans << endl;
}

Measured memory_bytes: 4152
#include <stdio.h>
#include <math.h>

int isPrime(int);

int main()
{
        int N;
        int A[10000];
        int cnt = 0;
        float q;

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

        for (int i = 0; i < N; i++) {
                if (isPrime(A[i])) {
                        cnt++;
                }
        }

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

        return 0;
}

int isPrime(int a)
{
        if (a == 2) {
                return 1;
        }

        if (a < 2 || a % 2 == 0) {
                return 0;
        }

        float q;
        q = sqrt(a);

        for (int i = 3; i <= (int)q+1; i+=2) {
                if (a % i == 0) {
                        return 0;
                }
        }

        return 1;
}


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

int main() {
   double A, B, H, M;
   cin >> A >> B >> H >>M;
   double la = 0, lb = 0;
   la = (H / 12.0 + M / 720.0);
   lb = (M / 60.0);
   double div = abs(la - lb);
   if(div > 0.5) {
      div = 1.0 - (div);
   }

   double abcos = cos(abs(la-lb) * M_PI * 2);
   double ans = sqrt((A*A + B*B - 2*A*B*abcos));
   cout << fixed << setprecision(12) << ans << endl;

}


Measured memory_bytes: 4172
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
using namespace std;
int min (int a, int b){
  if(a<b) return a;
  else return b;
}
int max (int a, int b){
  if(a>b) return a;
  else return b;
}
int main(){
  int n; cin >>n;
  int t[110];
  for(int i=0;i<n ; i++)
  cin >>t[i];
  int sum=0;
  for(int i=0;i<n;i++)
  sum += t[i];

  int m; cin >>m;

  for(int i=0;i<m;i++){
   int p; cin >>p;
   int x; cin >>x;
   cout<< sum-t[p-1]+x<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

template<typename T>
struct LazySegmentTree{
private:
    int n;
    vector<T> node,lazy;
public:
    T SUP=0; /* 初期値　*/
    T merge(T x,T y){
        return x+y;
    }
    LazySegmentTree(vector<T> v){
        int sz=(int)v.size();
        n=1; while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--) node[i]=merge(node[2*i+1],node[2*i+2]);
    }
    void eval(int idx,int l,int r){
        if(lazy[idx]!=0){
            node[idx]+=lazy[idx];
            if(r-l>1){
                /* node[idx]からの伝播  */
                lazy[2*idx+1]+=lazy[idx]/2;
                lazy[2*idx+2]+=lazy[idx]/2;
            }
            lazy[idx]=0;
        }
    }
    void update(int a,int b,T x,int idx=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(idx,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            lazy[idx]+=x*(r-l);
            eval(idx,l,r);
        }else{
            update(a,b,x,2*idx+1,l,(l+r)/2);
            update(a,b,x,2*idx+2,(l+r)/2,r);
            node[idx]=merge(node[2*idx+1],node[2*idx+2]);
        }
    }
    T query(int a,int b,int idx=0,int l=0,int r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return 0;
        eval(idx,l,r);
        if(a<=l && r<=b) return node[idx];
        T vl = query(a,b,2*idx+1,l,(l+r)/2);
        T vr = query(a,b,2*idx+2,(l+r)/2,r);
        return merge(vl,vr);
    };
};



signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,q; cin >> n >> q;
    vector<ll> v(n,0);
    LazySegmentTree<ll> lsg(v);
    rep(i,q){
        int x; cin >> x;
        if(x==0){
            int s,t,y; cin >> s >> t >> y;
            s--;
            lsg.update(s,t,y);
        }else{
            int s,t; cin >> s >> t;
            s--;
            cout << lsg.query(s,t) << "\n";
        }
    }

}



Measured memory_bytes: 8712
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    int n,a[300000];
    ll b=0;
    cin>>n;
    for(int i=0;i<n*3;i++){
        cin>>a[i];
    }
    sort(a, a+n*3, greater<int>());
    for(int i=0;i<n;i++){
        b+=a[i*2+1];
    }
    cout<<b<<endl;
}


Measured memory_bytes: 1408
/**
 * @author torith
 * @date 2018-10-15
 */

#include <bits/stdc++.h>

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<int> A;
    int tmp;
    for (int i = 0; i < 3; ++i) {
        cin >> tmp;
        A.push_back(tmp);
    }

    sort(A.begin(),A.end());
    int first = A[2];
    int second = A[1];
    int third = A[0];

    int ans = 0;

    ans += (first - second) / 2;
    second += int ((first - second) / 2) * 2;
    ans += (first - third) / 2;
    third += int ((first - third) / 2) * 2;
    if ((first - second) == 1 && (first - third) == 1) {
        ans += 1;
    }else if (!( first - second == 0 && first - third == 0)) {
        ans += 2;
    }else{

    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,t,e,x,set=-1;
	cin>>n>>t>>e;
	for(int i=0;i<n;i++){
		cin>>x;
		if((t/x)*x>=t-e&&(t/x)*x<=t+e)
			set=i+1;
		if((t/x)*x+x>=t-e&&(t/x)*x+x<=t+e)
			set=i+1;
	}
	cout<<set<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll H, W, h, w;

    cin >> H >> W >> h >> w;

    cout << (H - h) * (W - w) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;
typedef long long ll;

int main(){
  int n, s, r;
  
  cin >> n;

  ll dp[101][21];
  memset(dp, 0, sizeof(dp));

  cin >> s;
  dp[0][s] = 1;

  for(int i = 1; i < n-1; i++){
    cin >> s;
    
    for(int j = 0; j <= 20; j++){
      if(dp[i-1][j] != 0){
        if( j + s <= 20 ) dp[i][j+s] += dp[i-1][j];
        if( j - s >= 0 ) dp[i][j-s] += dp[i-1][j];
      }
    }
  }

  cin >> r;

  cout << dp[n-2][r] << endl;

  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 18;
int dp[N + 1][1 << N][2];

void add(int a[2], int b[2]) {
	for (int i = 0; i < 2; i++) {
		if (b[i] > a[0]) {
			a[1] = a[0];
			a[0] = b[i];
		}
		else if (b[i] > a[1]) {
			a[1] = b[i];
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

   	memset(dp, -1, sizeof(dp));

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

    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < (1 << n); j++) {
    		dp[i + 1][j][0] = dp[i][j][0];
    		dp[i + 1][j][1] = dp[i][j][1];
    		if ((j >> i) & 1)
    			add(dp[i + 1][j], dp[i][j ^ (1 << i)]);
    	}
    }

    int mx = 0;
    for (int i = 1; i < (1 << n); i++) {
    	mx = max(mx, dp[n][i][0] + dp[n][i][1]);
    	cout << mx << "\n";
    }

    return 0;   
}   

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

vector<pii> vp[15];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      vp[i].eb(mp(x - 1, y));
    }
  }

  int ans = 0;
  rep(i, (1 << n)) {
    bool flg = true;
    rep(j, n) {
      if ((i >> j) & 1) {
        rep(k, vp[j].size()) {
          if (((i >> vp[j][k].F) & 1) != vp[j][k].S) flg = false;
        }
      }
    }
    if (flg) ans = max(ans, popcount(i));
  }

  cout << ans << endl;
}


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

long long N, K, Q;
long long A[2050];
//   val     , pos
map<long long, vector<long long> >posmap;
vector<long long> pos;
set<long long> vals;

int main(){
	cin >> N >> K >> Q;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
		posmap[A[i]].push_back(i);
		vals.insert(A[i]);
	}
	pos.push_back(-1);
	pos.push_back(N);
	vals.insert(0);

	long long ans = INT_MAX;
	for(set<long long>::iterator it = vals.begin(); it != vals.end(); it++){
		long long val = *it;
		for(auto p: posmap[val]){
			pos.push_back(p);
		}
		sort(pos.begin(), pos.end());
		//posの間がOKな区間, まずQ回取れるか確認
		//そのあととれる数のリストでしたからQ個の差でansを更新

		//cout << "val = " << val << endl;
		long long removenum = 0;
		vector<long long> remove;
		for(long long i = 0; i < (long long)pos.size() - 1; i++){
			long long start = pos[i] + 1;
			long long tail = pos[i+1] - 1;
			long long num = tail - start + 1;
			//cout << "start = " << start << " tail =" << tail << endl;
			if(num < K){
				continue;
			}
			long long tmpremovenum = num - K + 1;
			vector<long long> tmp;
			for(long long j = start; j<=tail; j++){
				tmp.push_back(A[j]);
			}
			sort(tmp.begin(), tmp.end());
			for(long long j = 0; j < tmpremovenum; j++){
				remove.push_back(tmp[j]);
			}
			removenum += num - K + 1;
		}
		if(removenum < Q){
			continue;
		}
		sort(remove.begin(), remove.end());
		ans = min(ans, remove[Q-1] - remove[0]);
	}
	cout << ans << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, X;
    cin >> N >> X;

    ll sum = N;
    ll a = std::min(X, N - X);
    ll b = std::max(X, N - X);
    while (a > 0)
    {
        ll c = b / a;
        sum += 2 * a * c;
        ll d = b % a;
        b = a;
        a = d;
    }
    sum -= b;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	ll count = 0;
	int tmp = N;

	do
	{
		count++;
	} while ((tmp /= K) > 0);

	cout << count << endl;

	return 0;
}

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

int n, m;
int memo[100010];

vector<int> graph[100010];

int dp(int i){
  if(memo[i] != -1) return memo[i];
  int ans = 0;
  for(int j = 0;j < graph[i].size();j++){
    ans = max(ans, dp(graph[i][j])+1);
  }

  return memo[i] = ans;
}

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

  int a, b;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    graph[a-1].push_back(b-1);
  }

  memset(memo, -1, sizeof(memo));
  int ans = 0;
  for(int i = 0;i < n;i++){
    ans = max(ans, dp(i));
  }

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


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

using namespace std;

#define B

#ifdef B
int main(void)
{
	int n, x;
	vector<int> ans;
	while (true)
	{

		cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		int cnt = 0;
		for (size_t i = 1; i < n-1; i++)
		{
			for (size_t j = i + 1; j < n; j++)
			{
				for (size_t k = j+1; k <= n; k++)
				{
					if (i + j + k == x)
						cnt++;
				}
			}
		}
		ans.push_back(cnt);
	}
	for (auto a : ans)
	{
		cout << a << endl;
	}
	return 0;
}
#endif // B

Measured memory_bytes: 3128
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
mx = array.count(max(s, key = array.count))
for a in sorted(s):
    if array.count(a) == mx:
        print(a)

Measured memory_bytes: 7572
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define sl(c) (('a')<=(c)&&(c)<=('z'))
#define ll(c) (('A')<=(c)&&(c)<=('Z'))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define makeupper(t) (transform(all(t),t.begin(),::toupper))
#define makelower(t) (transform(all(t),t.begin(),::tolower))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define NEXT_LINE string junk; getline(cin, junk);
#define output(v) do{rep(i,v.size())cout<<(i?" ":"")<<v[i];cout<<"\n";}while(0)
#define output2(v) rep(i,v.size()){rep(j,v[i].size()){cout<<(j?" ":"")<<v[i][j];}cout<<"\n";}
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vec a(6),b(6);
    set<vec>list;
    stack<vec>s;
    rep(i,6)cin>>a[i];
    rep(i,6)cin>>b[i];
    list.insert(a);
    s.push(a);
    while(!s.empty()){
        auto d=s.top();
        s.pop();
        vec c={d[4],d[0],d[2],d[3],d[5],d[1]};
        if(!list.count(c)){
            list.insert(c);
            s.push(c);
        }
        c={d[1],d[5],d[2],d[3],d[0],d[4]};
        if(!list.count(c)){
            list.insert(c);
            s.push(c);
        }
        c={d[0],d[3],d[1],d[4],d[2],d[5]};
        if(!list.count(c)){
            list.insert(c);
            s.push(c);
        }
        c={d[0],d[2],d[4],d[1],d[3],d[5]};
        if(!list.count(c)){
            list.insert(c);
            s.push(c);
        }
    }
    if(list.find(b)!=list.end())cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 3224
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque
import pprint

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod
# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n,m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
    sys.exit()
if n%2 == m%2:
    print(kaijo(n,1,mod)*kaijo(m,1,mod)*2%mod)
else:
    print(kaijo(n, 1, mod) * kaijo(m, 1, mod)%mod)

Measured memory_bytes: 64364
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

int main() {
	int n;
	cin >> n;
	vector<string> s(n+1);
	vector<vector<int>> cnt(n, vector<int>(26, 0));
	REP(i, n) {
		cin >> s[i];
		sort(all(s[i]));
		/*REP(j, s[i].size()) {
			int c = s[i][j] - 'a';
			cnt[i][c]++;
		}*/
	}
	s[n] = "zzzzzzzzzzz";
	sort(all(s));
	ll con = 0;
	ll res = 0;
	REP(i, n) {
		if (s[i] == s[i + 1]) {
			con++;
		}
		else {
			res += con * (con + 1) / 2;
			con = 0;
		}
	}
	put(res);
	return 0;
}

Measured memory_bytes: 20608