akhauriyash/Code-Regression huggingface dataset:
(n, m) = [int(s) for s in input().split()]

d = []

h_list = [int(s) for s in input().split()]

for (i, h) in enumerate(h_list):
    d.append({
        'h': h,
        'max': 0
    })

for i in range(0, m):
    (a, b) = [int(s) - 1 for s in input().split()]

    if d[a]['max'] < d[b]['h']:
        d[a]['max'] = d[b]['h']

    if d[b]['max'] < d[a]['h']:
        d[b]['max'] = d[a]['h']

ans = 0

for e in d:
    if e['max'] < e['h']:
        ans += 1

print(ans)



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

int main() {
  int64_t H,W;
  cin >> H >> W;
  if(H==1 || W==1){
    cout << 1 << endl;
    return 0;
  }
  
  if(H*W%2 == 0){
    cout << H*W/2 << endl;
  }
  else{
    cout << H*W/2 +1 << endl;
  }
  
      
 
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  int A, B, C; cin >> A >> B >> C;
  if ((A <= C && C <= B) || (B <= C && C <= A))cout << "Yes";
  else cout << "No";

  return 0;
}

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

int main()
{
  int x, y;
  cin >> x >> y;

  vector<int> a = {1, 3, 5, 7, 8, 10, 12};
  vector<int> b = {4, 6, 9, 11};
  vector<int> c = {2};


  rep(i,a.size()){
    if(a.at(i) == x){
      rep(j, a.size())
      {
        if (a.at(j) == y)
        {
          cout << "Yes";
          return 0;
        }
      }
    }
  }
  rep(i, b.size())
  {
    if (b.at(i) == x)
    {
      rep(j, b.size())
      {
        if (b.at(j) == y)
        {
          cout << "Yes";
          return 0;
        }
      }
    }
  }
  rep(i, c.size())
  {
    if (c.at(i) == x)
    {
      rep(j, c.size())
      {
        if (c.at(j) == y)
        {
          cout << "Yes";
          return 0;
        }
      }
    }
  }

  cout << "No";
}


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

bool map[20][20];
int w,h;


int Search(int x,int y, int sum){

  sum++;
  map[y][x]=false;

//  cout << "x,y=" << x << ',' << y << endl;

  if(x!=w-1){
    if(map[y][x+1]==true){
      sum = Search(x+1,y,sum);
    }
  }
  if(x!=0){
    if(map[y][x-1]==true){
      sum = Search(x-1,y,sum);
    }
  }
  if(y!=h-1){
    if(map[y+1][x]==true){
      sum = Search(x,y+1,sum);
    }
  }
  if(y!=0){
    if(map[y-1][x]==true){
      sum = Search(x,y-1,sum);
    }
  }

  return sum;

}


int main(){

  int x,y;
  char info;

  while(cin >> w >> h){
    if(w==0 && h==0){ break; }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
          cin >> info;
          if(info == '.'){ map[i][j]=true;}
          else if(info == '#'){ map[i][j]=false;}
          else{ x=j; y=i; map[i][j]=false;}
        }
    }

    cout << Search(x,y,0) << endl;
  }

  return 0;

}

Measured memory_bytes: 1176
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
  
Node root;
  
Node treeMinimum(Node x){
 
  /*my code beginning*/
  while ( x->left != NIL ){
    x = x->left;
  }
  return x;
  /*my code end*/
 
}
  
Node treeMaximum(Node x){
 
 
}
 
Node treeSearch(Node u, int k){ /*find*/
 
  /*my code beginning*/
  if ( u == NIL || k == u->key ){
    return u;
  }
  if ( k < u->key ){ 
    return treeSearch(u->left,k);
  } else { 
    return treeSearch(u->right,k);
  }
  /*my code end*/
 
}
  
Node treeSuccessor(Node x){
 
  /*my code beginning*/
  Node y;
  if ( x->right != NIL ){ 
    return treeMinimum(x->right);
  }
  y = x->parent;
  while ( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
  /*my code end*/
 
}
  
Node treeDelete(Node z){ /*delete*/
  Node y; // node to be deleted
  Node x; // child of y
 
  /*my code beginning*/
  if ( z->left == NIL || z->right == NIL ){ 
    y = z;
  } else {
    y = treeSuccessor(z);
  }
  if ( y->left != NIL ){ 
    x = y->left;
  } else {
    x = y->right;
  }
  if ( x != NIL ){ 
    x->parent = y->parent;
  }
  if ( y->parent == NIL ){ 
    root = x;
  } else if ( y == y->parent->left ){ 
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }
  if (y != z){
    z->key = y->key;
  }
  return y;
  /*my code end*/
 
}
  
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  /*my code beginning*/
  while (x!=NIL){
    y=x;
    if (z->key < x->key){ 
      x=x->left;
    } else{
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL){ 
    root = z;
  } else if (z->key < y->key){
    y->left=z;
  } else {
    y->right=z;
  }
  /*my code end*/
 
}
  
void inorder(Node u){
 
  /*my code beginning*/
  if (u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  /*my code end*/
 
}
void preorder(Node u){
 
  /*my code beginning*/
  if (u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
  /*my code end*/
 
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  /*my code beginning*/
  root=NIL;
  /*my code end*/
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
typedef long long ll;
typedef pair<int, int> P;
vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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;
}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank;

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r; // 辺の縮約（一度根をたどったら辺を直接根に向かって貼り直す）
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x; // xよりyのほうが高さが小さい木
        return true;
    }
};

// 最大公約数
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// 最小公倍数
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y)
{
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

int main()
{
    int N;
    cin >> N;
    set<ll> A;
    rep(i, N)
    {
        ll a;
        cin >> a;
        if (A.count(a)) {
            cout << "NO" << endl;
            return 0;
        }
        A.insert(a);
    }

    cout << "YES" << endl;
}

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

int main() {
    long N;
    string S;
    long Q;
    cin >> N;
    cin >> S;
    cin >> Q;
    long kA[Q];
    for(long i=0; i<Q; i++){
        cin >> kA[i];
    }

    for (long q=0; q<Q; q++) {
        long k = kA[q];
        long Dcnt = 0;
        long Mcnt = 0;
        long DMcnt = 0;
        long DMCcnt = 0;
        for (long i=0; i<S.length(); i++) {
            if (i-k >= 0 && S[i-k] == 'D') {
                Dcnt--;
                DMcnt -= Mcnt;
            } else if (i-k >= 0 && S[i-k] == 'M') {
                Mcnt--;
            }

            if (S[i] == 'D') {
                Dcnt++;
            } else if (S[i] == 'M') {
                Mcnt++;
                DMcnt += Dcnt;
            } else if (S[i] == 'C') {
                DMCcnt += DMcnt;
            }
        }
        cout << DMCcnt << endl;
    }
}


Measured memory_bytes: 1412
n = int(input())
import sys
input = sys.stdin.readline
l = list(map(int,input().split()))
x = min(l)
flag = True
while flag:
  flag = False
  for i in l:
    p = i%x
    if  p != 0 and p < x:
      x = p
      flag = True
print(x)

Measured memory_bytes: 58864
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 3003
using namespace std;
const int Mod = 998244353;

int n, X, f[N][N << 1], fac[N << 1], inv[N << 1];

inline int C(int x, int y) {
    return x < y ? 0 : 1LL * fac[x] * inv[y] % Mod * inv[x - y] % Mod;
}

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

    inv[0] = inv[1] = fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; ++i)
        fac[i] = 1LL * fac[i - 1] * i % Mod,
        inv[i] = 1LL * inv[Mod % i] * (Mod - Mod / i) % Mod;

    for (int i = 1; i <= n; ++i)
        inv[i] = 1LL * inv[i - 1] * inv[i] % Mod;

    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < 6000; ++j)
            (f[i + 1][j + 1] += f[i][j]) %= Mod,
            (f[i + 1][j + 2] += f[i][j]) %= Mod;

    long long ans = 1;
    for (int i = 1; i <= n; ++i) {
        long long tmp = 0;
        for (int j = 0; j < X; ++j)
            (tmp += f[i][j]) %= Mod;
        for (int j = X + 1; j <= 2 * i; j += 2) {
            if (j < i) continue;
            int p = i - (j - X + 1), q = X - 1 - (j - X + 1);
            //if (j < 2 * X && p >= 0 && q >= 0) (tmp += f[p][q]) %= Mod;
            if (j >= X * 2) (tmp += (j == (i << 1) ? (X & 1) : 0)) %= Mod;
            else (tmp += (p >= 0 && q >= 0 ? f[p][q] : 0)) %= Mod;
        }
//        if (i >= X && (X & 1))
//            ++tmp;
        (ans += 1LL * tmp * C(n, i) % Mod) %= Mod;
    }
    cout << ans % Mod;
    return 0;
}


Measured memory_bytes: 70656
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	int p;
	for(int i=0; i<n; i++){
		cin >> a.at(i);
		if(a.at(i) == 1){
			p=i;
		}
	}	
	if(n<=k){
		cout << "1" << endl;
	}else{
		cout << (n-2)/(k-1) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 640
import math
n = int(input())
st = [list(map(int, input().split())) for i in range(n-1)]
for j in range(n-1):
    t = st[j][1]+st[j][0]
    for i in range(j+1,n-1):
        if t<st[i][1]:
            t = st[i][1]
        elif (t-st[i][1])%st[i][2]!=0:
            t += st[i][2]-(t-st[i][1])%st[i][2]
        t += st[i][0]
    print(t)
print(0)

Measured memory_bytes: 3188
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
inf = 10**9 +7
ans = inf
for j in range(min(A), max(A) + 1):
    res = 0
    for a in A:
        res += (a-j)**2
    ans = min(ans, res)
print(ans)

Measured memory_bytes: 38512
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
  print(0)
  quit()
  
x.sort()
y = [x[i]-x[i-1] for i in range(1, m)]
y.sort(reverse = True)
ans = sum(y)

for i in range(n-1):
  ans -= y[i]
  
print(ans)

Measured memory_bytes: 13968
/*** Author: Dhruv Rastogi ***/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll,ll>
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mint map<int,int> 
#define int long long
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>

const int sz=1e5+5;
int a[sz],b[sz],c[sz];
void solve(){  
  int n;
  cin>>n;
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);

	int j=0;
	for(int i=2;i<n;i+=2)
		b[i]=a[j++];
	int last=n-1;
	for(int i=1;i<n;i+=2)
		b[i]=a[last--];
	b[0]=a[j++];
	j=0;
	for(int i=1;i<n;i+=2)
		c[i]=a[j++];
	last=n-1;
	for(int i=2;i<n;i+=2)
		c[i]=a[last--];
	c[0]=a[last--];
	int ans2=0;
	int ans=0;
	rep(i,1,n){
		ans+=abs(b[i]-b[i-1]);
		ans2+=abs(c[i]-c[i-1]);
	}
	cout<<max(ans2,ans)<<endl;

}

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

Measured memory_bytes: 2560
N = int(input())
H = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
  dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
print(dp[N-1])

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

int main() {
    int N, ans = 0, num = 0;
    cin >> N;
    vector<int> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < N - 1; i++) {
        if (S.at(i) >= S.at(i + 1)) {
            num++;
            if (i == N - 2 && ans < num) {
                ans = num;
            }
        }
        else {
            if (ans < num) {
                ans = num;
            }
            num = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

const int INF = 1<<29;

int n, m;
int dist[51][51];
int a, b, c, d;

int main() {
    while (cin >> n >> m) {
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dist[i][j] = INF;
        for (int i = 0; i < n; ++i) dist[i][i] = 0;
        for (int i = 0; i < m; ++i) {
            scanf("%d,%d,%d,%d\n",&a,&b,&c,&d);
            a--;b--;
            dist[a][b] = c;
            dist[b][a] = d;
        }
        for (int k = 0; k < n; ++k)
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
        
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        a--;b--;
        cout << c - d - dist[a][b] - dist[b][a] << endl;
    }
    return 0;
}


Measured memory_bytes: 1248
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a%3 == 0|b%3 == 0|(a+b)%3 == 0){
      System.out.println("Possible");
    }else{
      System.out.println("Impossible");
    }
  }
}

Measured memory_bytes: 20820
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
vector<llong>A, B;
llong N, SUM = 0;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		llong a;
		cin >> a;
		a--;
		A.push_back(a);
		B.push_back(0);
	}
	for (int i = 0; i < A.size(); i++) {
		B[A[i]]++;
	}

	for (int i = 0; i < B.size(); i++) {
		llong tmp = B[i] * (B[i] - 1);
		tmp /= 2;
		SUM += tmp;
	}
	for (int i = 0; i < A.size(); i++) {
		cout << SUM - B[A[i]] + 1 << endl;
	}
	return 0;





}

Measured memory_bytes: 5988
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(void){
  long int n, sum=0;
  cin >> n;
  long int a[n];
  for(int j=0;j<n;j++){
    cin >> a[j];
  } 
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i-1]>a[i] && i>=1){
      sum+=(a[i-1]-a[i]);
      a[i]+=(a[i-1]-a[i]);
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 5172
N, M = map(int, input().split())
countlis = [0] * (N+1)
penalty = 0
clear = 0
checkset = set()
for i in range(1,M+1):
    p,s = input().split()
    p = int(p)
    if p in checkset:
        continue
    if s == "WA":
        countlis[p] += 1
    elif s == "AC":
        penalty += countlis[p]
        clear += 1
        checkset.add(p)

print("{0} {1}".format(clear, penalty))

Measured memory_bytes: 17988
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
using namespace std;

typedef long long ll;
typedef long double ld;

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

int myGcd(int a, int b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}


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

	int A, B, H, M;
	ld choushin, tanshin; //時針、短針の角度
	ld rad; //角度
	ld ans;

	cin >> A >> B >> H >> M;

	choushin = 6.0 * M;
	tanshin = 30.0 * H + 0.5 * M;
	rad = abs(choushin - tanshin);

	if (rad > 180)
	{
		rad = 360 - rad;
	}

	rad = rad * PI / 180;

	ans = (pow(A, 2.0) + pow(B, 2.0)) - 2 * A * B * cos(rad);

	cout << fixed << setprecision(20) << sqrt(ans) << endl;

	return 0;
}

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


#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
ll mod = 1e9 + 7;
ld eps = 1e-6;




int main() {
	fastIO;
	int n;
	cin >> n;
	int dp[n+1], arr[n+1];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		if (i > 1) {
			dp[i] = min(abs(arr[i-1]-arr[i]) + dp[i-1], abs(arr[i-2]-arr[i]) + dp[i-2]);
		}
		else {
			dp[i] = abs(arr[i-1]-arr[i]) + dp[i-1];
		}
	}

	cout << dp[n-1];

}


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

long long Pow(long long x, long long a)
{
    long long res = 1;
    while(a > 0)
    {
        if(a&1) res *= x;
        x *= x;
        a >>= 1;
    }
    return res;
}

int main() {
    long long X;
    cin >> X;
    for(long long A = -1000; A <= 1000; ++A) {
        for(long long B = -1000; B <= 1000; ++B) {
            if(Pow(A,5) - Pow(B,5) == X) {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int n;
vector<int> v[100000];

int dfs(int x) {
    if (v[x].size() == 0) return 0;
    vector<int> d;
    for (auto i : v[x]) {
        d.push_back(dfs(i) + 1);
    }
    sort(d.begin(), d.end());
    int m = 0;
    for (int i = d.size(); i > 0; i--) {
        d[i-1] += d.size() - i;
        m = max(m, d[i-1]);
    }

    return m;
}

int main() {
    cin >> n;
    for (int i = 1, c; i < n; i++) {
        cin >> c;
        v[c-1].push_back(i);
    }
    cout << dfs(0) << endl;

    return 0;
}


Measured memory_bytes: 13568
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Pair = Tuple!(string, "red", string, "blue");

void main() {
    int n;
    scan(n);
    auto s = readln.chomp;
    auto mae = s[0 .. n];
    auto ato = s[n .. $].retro.to!string;
    debug {
        writeln(mae);
        writeln(ato);
    }
    long[Pair] asc;

    foreach (i ; 0 .. (1<<n)) {
        string r, b;
        foreach (j ; 0 .. n) {
            if (i & (1 << j)) {
                r ~= mae[j];
            }
            else {
                b ~= mae[j];
            }
        }
        auto pr = Pair(r, b);
        if (pr in asc) {
            asc[pr]++;
        }
        else {
            asc[pr] = 1;
        }
    }

    long ans;

    foreach (i ; 0 .. (1<<n)) {
        string r, b;

        foreach (j ; 0 .. n) {
            if (i & (1 << j)) {
                r ~= ato[j];
            }
            else {
                b ~= ato[j];
            }
        }

        auto pr = Pair(r, b);

        if (pr in asc) {
            ans += asc[pr];
        }
    }

    writeln(ans);
}










































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 50044
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e9 + 7)
#define eps 0.000001
typedef long long LL;
using namespace std;
const LL mod = (1e9 + 7);

char ch[200005];
LL num[27], ans = 1, sum = 0;

int main()
{
    scanf("%s", ch);
    int len = strlen(ch);
    for(int i = 0;i < len;i++)
    {
        int a = ch[i] - 'a';
        num[a]++;
        sum++;
        ans += sum - num[a];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
x, y = gets.chomp.split(" ")
(0..51).each do |i|
    (0..26).each do |j|
        ans = 2 * i + 4 * j
        k = i + j
        ans = ans.to_s
        k = k.to_s
        # p ans
        # p x
        if ans == y && k == x
            puts "Yes"
            exit
        end
    end
end
puts "No"

Measured memory_bytes: 14220
// at_abc164a.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	string k;
	cin >> k;
	if (!k.compare("SAT")){
		cout << "1\n"; return 0;
	}
	if (!k.compare("MON")) {
		cout << "6\n"; return 0;
	}
	if (!k.compare("TUE")) {
		cout << "5\n"; return 0;
	}
	if (!k.compare("WED")) {
		cout << "4\n"; return 0;
	}
	if (!k.compare("THU")) {
		cout << "3\n"; return 0;
	}
	if (!k.compare("FRI")) {
		cout << "2\n"; return 0;
	}
	if (!k.compare("SUN")) {
		cout << "7\n"; return 0;
	}
}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <unordered_map>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll N;
    scanf("%lld", &N);

    printf("%lld\n", N + N * N + N * N * N);
}


Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	cin>>n;
	vector<int> p(n), q(n);
	rep(i,n)cin>>p[i];
	rep(i,n)cin>>q[i];
	int perm[8] = {1,2,3,4,5,6,7,8};
	int cnt = 0;
	int p_pos, q_pos;
	do{
		++cnt;
		bool p_ok = true, q_ok = true;
		rep(i,n){
			if(perm[i] != p[i])p_ok = false;
			if(perm[i] != q[i])q_ok = false;
		}
		if(p_ok)p_pos = cnt;
		if(q_ok)q_pos = cnt;
	}while(next_permutation(perm, perm+n));
	cout<<abs(p_pos-q_pos)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;++i)
#define Sort(a) sort(a.begin(),a.end())
const int INF = 1e9+7;

int main(){
  string S;
  cin >> S;
  int cnt0=0,cnt1=0;
  rep(i,S.size()){
    if(S.at(i)=='0')
      ++cnt0;
    else
      ++cnt1;
  }
  if(cnt0<cnt1)
    cout << cnt0*2 << endl;
  else
    cout << cnt1*2 << endl;
}


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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b) {
        if(b==c) cout << "No";
        else cout << "Yes";
    } else {
        if(b==c) cout << "Yes";
        else {
            if(a==c) cout << "Yes";
            else cout << "No";
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int m[50],f[50],r[50],i;

    for(i=0;i<50;i++){
        scanf("%d %d %d", &m[i], &f[i], &r[i] );
        if( m[i]==-1 && f[i]==-1 && r[i]==-1){
            break;
        }
    }

    for(i=0;i<50;i++){
        if( m[i]==-1 && f[i]==-1 && r[i]==-1 ){
            break;
        }else if( m[i]==-1 || f[i]==-1 || m[i]+f[i]<30 ){
            printf("F\n");
        }else if( 80<=m[i]+f[i] ){
            printf("A\n");
        }else if( 65<=m[i]+f[i] && m[i]+f[i]<80 ){
            printf("B\n");
        }else if( 50<=m[i]+f[i] && m[i]+f[i]<65 ){
            printf("C\n");
        }else if( 30<=m[i]+f[i] && m[i]+f[i]<50 ){
            if( 50<=r[i] ){
                printf("C\n");
            }else{
             printf("D\n");   
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n;cin>>n;
	map<string,ll>mp;
	rep(i,0,n){
		string s;cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	ll ans=0;
	for(auto i:mp){ll p=i.second;ans+=(p*(p-1)/2);}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 11264
#include <iostream>

int main()
{
	int sequenceLength;
	std::cin >> sequenceLength;
	int current;
	std::cin >> current;
	
	int min = current, max = current;
	long sum = current;
	for (int i = 2; i <= sequenceLength; i++) {
		std::cin >> current;
		if (current < min)
			min = current;
		if (current > max)
			max = current;
		sum += current;
	}
	std::cout << min << " " << max << " " << sum << "\n";
    return 0;
}




Measured memory_bytes: 3132
n,m = map(int,input().split())
ans = [0]*(m+1)
count = 0
for i in range(n):
  l = list(map(int,input().split()))
  for j in range(1,l[0]+1):
    ans[l[j]] += 1
        
for i in ans:
  if i == n:
    count += 1
print(count)
        
    


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	dsu ds(n);
	rep(i,q){
		int t, u, v;
		cin >> t >> u >> v;
		if(t == 0) ds.merge(u, v);
		else cout << ds.same(u, v) << endl;
	}
	return 0;
}


Measured memory_bytes: 3900
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break

    ans = max(len(S)//2,ans)

print(ans)


Measured memory_bytes: 39280
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string[] str1 = Console.ReadLine().Split(' ');

        int Row = int.Parse(str1[0]);
        int Colum = int.Parse(str1[1]);

       

        int[,] matrix = new int[Row, Colum];
        int[,] vector = new int[Colum,1];

        for (int i=0;i < Row;i++)
        {
            string[] str2 = Console.ReadLine().Split(' ');

            for(int j = 0;j < Colum;j++)
            {
                matrix[i, j] = int.Parse(str2[j]);              
            }
      
        }

        for (int i = 0; i < Colum;i++)
        {
            int x = int.Parse(Console.ReadLine());
            vector[i, 0] = x;
        }


        int[,] Out = new int[Row, 1];
        

        for (int i = 0; i< Row;i++)
        {
            int Sum = 0;
            for (int j =0;j < Colum;j++)
            {
                Sum += matrix[i, j] * vector[j, 0];
                Out[i, 0] = Sum;
            }
        }

        for (int i = 0; i< Row;i++)
        {
            Console.WriteLine("{0}", Out[i, 0]);
        }

    }
}

Measured memory_bytes: 9244
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
ll Ai, Ao, At, Aj, Al, As, Az;

int main(){
    ios_base::sync_with_stdio(false);

    cin >> Ai >> Ao >> At >> Aj >> Al >> As >> Az;

    ll ans = 0;
    ans += Ao;
    if(Ai > 0 && Aj > 0 && Al > 0 && Ai%2 + Aj%2 + Al%2 >= 2){
        ans += 3;
        Ai--;
        Aj--;
        Al--;
    }
    ans += (Ai/2)*2;
    ans += (Aj/2)*2;
    ans += (Al/2)*2;

    cout << fixed << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        string s = Console.ReadLine();
        
        if(s[a] != '-'){
            Console.WriteLine("No");
            return;
        }
        
        for(var i = 0;i < a + b + 1;i++){
            if(i == a){
                continue;
            }
            if('0' <= s[i] && s[i] <= '9'){
                
            }else{
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N;
	std::cin >> N;

	ll ans = 0;
	repeq(i, 1, N) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}

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


Measured memory_bytes: 3672
from collections import deque
def BFS_grid(grid,visited,start,goal):
    y,x = start
    visited[y][x] = 1
    q = deque([start])
    delta = [[-1,0],[0,-1],[1,0],[0,1]]
    h = len(grid)
    w = len(grid[0])
    flag = False
    while q:
        y,x = q.popleft()
        for dy,dx in delta:
            if (0<= x+dx < w) and (0<= y+dy<h) :
                if visited[y+dy][x+dx] == 0 and grid[y+dy][x+dx]==".":
                    visited[y+dy][x+dx] = visited[y][x] +1
                    q.append([y+dy,x+dx])
                    if [y+dy,x+dx] == goal:
                        flag = True
    return flag


h,w = map(int,input().split())
mz = []
white = 0

for i in range(h):
    mz.append(list(input()))
    white += mz[-1].count(".")

visited = [[0]*w for i in range(h)]
if BFS_grid(mz,visited,[0,0],[h-1,w-1]):
    print(white - (visited[h-1][w-1]-visited[0][0]+1))
else:
    print(-1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    vector<ll> ans(3);
    cin >> ans[0];
    cin >> ans[1];
    cin >> ans[2];
    sort(all(ans));
    if(ans[0] == 5 && ans[1] == 5 && ans[2] == 7) YES();
    else NO();
}

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

const int MAX_N = (int)(100 + 5);

int h, w;
char field[MAX_N][MAX_N];

set<int> row;
set<int> col;

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; ++i) {
    scanf("%s", &field[i]);
  }

  for (int i = 0; i < h; ++i) {
    bool thisrow = true;
    for (int j = 0; j < w; ++j) {
      thisrow &= (field[i][j] != '#');
    }
    if (thisrow) {
      row.insert(i);
    }
  }

  for (int j = 0; j < w; ++j) {
    bool thiscol = true;
    for (int i = 0; i < h; ++i) {
      thiscol &= (field[i][j] != '#');
    }
    if (thiscol) {
      col.insert(j);
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (row.find(i) == row.end() && col.find(j) == col.end()) {
        printf("%c", field[i][j]);
      }
    }
    if (row.find(i) == row.end()) printf("\n");
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 998244353
#define MAX 10010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COM_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  ll N;
  cin>>N;
  COM_init();
  
  ll POW2[MAX],POW3[MAX];
  POW2[0]=1,POW3[0]=1;
  RREP(i,MAX-1){
    POW2[i]=POW2[i-1]*2%MOD;
    POW3[i]=POW3[i-1]*3%MOD;
  }
  
  ll ans=POW3[N],cnt=0;
  for(ll i=N/2+1; i<=N; ++i){
    cnt+=COM(N,i)*POW2[N-i]%MOD;
    cnt%=MOD;
  }
  
  ans=ans-cnt*2;
  ans%=MOD;
  if(ans<0) ans+=MOD;
  co(ans);
  return 0;
}

Measured memory_bytes: 394640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    bool sign = true;
    string s;
    do{
        if(n % 2 != 0){
            s += '1';
            if(sign)
                -- n;
            else
                ++ n;
        }
        else{
            s += '0';
        }
        n /= 2;
        sign = !sign;
    }while(n != 0);

    reverse(s.begin(), s.end());
    cout << s << endl;

    return 0;
}


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

public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int W = Integer.parseInt(s[1]);
    long[] val = new long[n];
    long[] wt = new long[n];
    long maxVal = 0;
    for(long i=0;i<n;i++){
      String[] str = br.readLine().split(" ");
      wt[(int)i] = Long.parseLong(str[0]);
      val[(int)i] = Long.parseLong(str[1]);
      maxVal += val[(int)i];
    }
    long[][] dp = new long[(int)n+1][(int)maxVal+1];
    long max = 0;
    for(long i=0;i<=n;i++){
      for(long j=0;j<=maxVal;j++){
        if(i==0 || j==0) {
 
                    if(j==0)
                        dp[(int)i][(int)j]=0;
                    else
                    dp[(int)i][(int)j] = Long.MAX_VALUE;
 
                    continue;
                }
        else if(j>=val[(int)(i)-1] && dp[(int)(i)-1][(int)j-(int)val[(int)(i)-1]]!=Long.MAX_VALUE)
          dp[(int)i][(int)j] = Math.min(dp[(int)(i)-1][(int)j], wt[(int)(i)-1] + dp[(int)(i)-1][(int)j-(int)val[(int)(i)-1]]);
        else
          dp[(int)i][(int)j] = dp[(int)(i)-1][(int)j];
        
        if(dp[(int)i][(int)j]<=W)
          max = Math.max(max,j);
      }
    }
    
    
    System.out.println(max);
  }
}


Measured memory_bytes: 137476
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int a, b, c = 0;
    std::cin >> a >> b >> c;
    
    int answer = c - (a - b);
    
    if(answer <= 0) answer = 0;
    
    std::cout << answer;
    
    return 0;
}


Measured memory_bytes: 256
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
using namespace std;

signed main() {
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			if (i*n + j*m - i*j*2 == k) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,i,j,m,f;
	char a[256],b[256],x;
	while(1){
	scanf("%d ",&n);
	if(n==0){
		break;
        }

	for(i=0;i<n;i++){
		scanf("%c %c ",&a[i],&b[i]);
	}
	
	scanf("%d ",&m);
	for(i=0;i<m;i++){
		scanf("%c ",&x);
		f=0;
		for(j=0;j<n;j++){
		 if(x==a[j]){
			printf("%c",b[j]);
			f=1;
			break;
		 }
	    }
	 if(f==0){
	    printf("%c",x);
	 }
	}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1004
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	long long int N,M;
	cin>>N>>M;
	long long int R[N];
	long long int S[N];
	long long int E[M][2];
	long long int C[M+1];
	for (long long int i = 0; i < N; ++i)
	{
		R[i]=i;
		S[i]=1;
	}
	for (long long int i = 0; i < M; ++i)
	{
		long long int x,y;
		cin>>x>>y;
		x--;
		y--;
		C[i]=-1;
		E[i][0]=x;
		E[i][1]=y;
	}
	C[M]=(N*(N-1))/2;
	for (long long int i = M-1; i >= 0; --i)
	{
		long long int x=E[i][0];
		long long int y=E[i][1];
		while(x!=R[x])
		{
			x=R[x];
		}
		while(y!=R[y])
		{
			y=R[y];
		}
		if(x==y)
		{
			C[i]=C[i+1];
		}
		else
		{
			C[i]=C[i+1]-S[x]*S[y];
			if(S[x]>S[y])
			{
				R[y]=x;
				S[x]=S[x]+S[y];
				S[y]=0;
			}
			else
			{
				R[x]=y;
				S[y]=S[x]+S[y];
				S[x]=0;
			}
		}
	}
	for (long long int i = 1; i <= M; ++i)
	{
		cout<<C[i]<<endl;
	}
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

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

int main(void){
  int n;
  int mn,mx;
  cin >> n;
  mx = 0; mn = 2000;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    if (t>mx) mx = t;
    if (t<mn) mn = t;
  }
  cout << (mx-mn+1)/2 << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int p;
void cou(int,int);
int main(){
  int n;
  while(1){
    p=0;
    cin >> n;
    if(n==0)break;
    for(int i=1;i<n;i++){
      cou(n,i);
    }
    cout << p << endl;
  }
  return 0;
}
void cou(int n,int r){
  int t=0;
  for(int i=r;i<n;i++){
    t+=i;
    if(t==n){
      p++;
      return;
    }
    if(t>n)return;
  }
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define N 100010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],ans;
vector<pair<int,int> > op;
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	sort(a+1,a+n+1);
	if(a[1]>=0){
		ans=a[1];
		for(int i=2;i<n;++i){
			op.emplace_back(ans,a[i]);
			ans-=a[i];
		}
		op.emplace_back(a[n],ans);
		ans=a[n]-ans;
	}
	else if(a[n]<=0){
		ans=a[n];
		for(int i=n-1;i>=1;--i){
			op.emplace_back(ans,a[i]);
			ans-=a[i];
		}
	}
	else{
		ans=a[1];
		int i;
		for(i=n;a[i-1]>=0;--i){
			op.emplace_back(ans,a[i]);
			ans-=a[i];
		}
		op.emplace_back(a[i],ans);
		ans=a[i]-ans;
		for(--i;i>1;--i){
			op.emplace_back(ans,a[i]);
			ans-=a[i];
		}
	} 
	printf("%d\n",ans);
	for(auto x:op){
		printf("%d %d\n",x.first,x.second);
	}
	return 0;
}



Measured memory_bytes: 4584