akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;
int main(int argc, char *argv[])
{
    
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    int a,b,x;
    cin >> a >> b >> x;
    double base = (double) pow(a, 2)*b/2;
    double denominator;
    double numerator;
    if(x > base) {
        denominator = (double) a;
        numerator = ((double) pow(a, 2)*b - x) * 2/ pow(a, 2);
    //cout << denominator << " " << numerator << " " << denominator/numerator << endl;
        cout << fixed << setprecision(10) << atan(numerator/denominator)*180.0/acos(-1) << endl;
    } else {
        denominator = (double) x * 2/(a * b);
        numerator = (double) b;
        cout << fixed << setprecision(10) << atan(numerator/denominator)*180.0/acos(-1) << endl;
    //cout << denominator << " " << numerator << " " << denominator/numerator << endl;
    }
    return 0;
    
}


Measured memory_bytes: 4048
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const students = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)))
    .slice(0, -1);

  const result = students.map(getGrade).join('\n');
  console.log(result);
});

const getGrade = ([mid, final, re]) => {
  if (mid === -1 || final === -1) {
    return 'F';
  }

  const midFinal = mid + final;
  if (midFinal >= 80) {
    return 'A';
  } else if (midFinal >= 65 && midFinal < 80) {
    return 'B';
  } else if (midFinal >= 50 && midFinal < 65) {
    return 'C';
  } else if (midFinal >= 30 && midFinal < 50) {
    return re >= 50 ? 'C' : 'D';
  } else {
    return 'F';
  }
};


Measured memory_bytes: 16160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long s = scanner.nextLong();
        long c = scanner.nextLong();
        long count;
        if (c > s * 2) {
            count = s;
            c -= s * 2;
            count += c / 4;
        } else {
            count = c / 2;
        }
        System.out.println(count);
    }
}


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

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

    int S=0, temp = N;   

    while(N>0){
        S += N%10;
        N/=10;
    }

    if (temp%S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  long long K, A, B;
  long long ans = 1;
  cin >> K >> A >> B;
  if ((B - A) / 2 > 1) {
    if (A >= K)
      ans = 1 + K;
    else {
      ans = A + (B - A) * ((K - (A - 1)) / 2);
      ans += (K - (A - 1)) % 2;
    }
  } else {
    ans = 1 + K;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
def main():
    A, B, C, X, Y = [int(i) for i in input().split()]
#    print(A, B, C, X, Y)
    if((A + B) < C*2):
        result = A*X + B*Y
    else:
        if(X < Y):
            result = X * C * 2
            rem = Y - X
            if(B < C*2):
                result += B * rem
            else:
                result += C * rem*2
        else:
            result = Y * C * 2
            rem = X - Y
            if(A < C*2):
                result += A * rem
            else:
                result += C * rem*2
    
    print(result)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) > sum(B):
    print('No')
    exit()
else:
    cnt = sum(B)-sum(A)
a_tmp = 0
b_tmp = 0
for i in range(N):
    if A[i] == B[i]:
        continue
    if cnt == 0:
        print('No')
        exit()
    if A[i] > B[i]:
        b_tmp += A[i]-B[i]
    else:
        if (B[i]-A[i]) % 2 == 0:
            a_tmp += (B[i]-A[i]) // 2
        else:
            a_tmp += ((B[i]-A[i]) // 2)+1
            b_tmp += 1
if a_tmp > cnt or b_tmp > cnt:
    print('No')
    exit()
if (cnt-a_tmp)*2 == cnt-b_tmp:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 74040
from collections import deque

def cat_go(x,y,nx,ny):
    if x == nx:
        return 1-wall[2*x][min(ny,y)]
    else:
        return 1-wall[2*min(x,nx)+1][y]

def bfs():
    global mapp
    mapp[0][0] = 1
    que = deque()
    que.append([0,0])
    while que:
        place = que.popleft()
        x = place[0];y = place[1]
        #end
        if x == h-1 and y == w-1:
            return mapp[x][y]
        for d in [[1,0],[0,1],[-1,0],[0,-1]]:
            nx = x + d[0];ny = y + d[1]
            #forbidden
            if not (0<=nx and nx<h and 0<=ny and ny<w):continue
            if not cat_go(x,y,nx,ny):continue
            #wont go
            if mapp[nx][ny] != 0:continue
            #go
            mapp[nx][ny] = mapp[x][y]+1
            que.append([nx,ny])
    return 0

while True:
    w,h = map(int,input().split())
    if w==0 and h==0:exit()
    mapp = [[0] * w for _ in range(h)]
    wall = []
    for i in range(2*h-1):
        wall.append(list(map(int,input().split())))
    print(bfs())



Measured memory_bytes: 6044
#include <stdio.h>

#define MAX 500001

void swap(int [],int,int);
int left(int);
int right(int);
int parent(int);
void maxHeapify(int [],int,int);
void buildMaxHeap(int [],int);

int main(){
  int A[MAX],n;
  int i;
  
  scanf("%d",&n);

  for (i = 1;i <= n;i++){
    scanf("%d",&A[i]);
  }
  
  buildMaxHeap(A,n);

  for (i = 1;i <= n;i++){
    printf(" %d",A[i]);
  }

  printf("\n");
  
  return 0;
}

void swap(int A[],int a,int b){
  int temp;

  temp = A[a];
  A[a] = A[b];
  A[b] = temp;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2 + 1;
}

int parent(int i){
  return i/2;
}

void maxHeapify(int A[],int i,int n){
  int l,r,largest;

  l = left(i);
  r = right(i);

  if (l <= n && A[l] > A[i])
    largest = l;

  else
    largest = i;

  if (r <= n && A[r] > A[largest])
    largest = r;

  if (largest != i){
    swap(A,i,largest);
    maxHeapify(A,largest,n);
  }
  
}

void buildMaxHeap(int A[],int n){
  int i;

  for (i = n/2;i >= 1;i--)
    maxHeapify(A,i,n);
}



Measured memory_bytes: 3744
#include <iostream>
using namespace std;
int main(){
	while(1){
		int h,w;
		cin >> h >> w;
		if(h==0&&w==0)
			break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++)
				cout << "#" ;
			cout << endl;
		}
		cout << endl;
	}	
	return 0;
}

Measured memory_bytes: 3076
while True:
	try:
		a, b = [int(x) for x in input().split()]
		road = [[0 if i == 0 or j == 0 else 1 for j in range(a+1)] for i in range(b+1)]
		closed = [[int(p) for p in input().split()] for _ in range(int(input()))]

		for x, y in closed:
			road[y][x] = 0

		road[0][1] = 0.5
		road[1][0] = 0.5

		for i in range(1, b+1):
			for j in range(1, a+1):
				road[i][j] = (road[i-1][j] + road[i][j-1]) * road[i][j]

		print(int(road[-1][-1]))
	except:
		break


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;

int n, m;
vector<int> a[N];

vector<int> ans;

bool c[N];
int p[N];
void bfs(int xx)
{
    memset(c, false, sizeof c);
    queue<int> q;
    q.push(xx);
    c[xx] = true;
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        for (int i = 0; i < a[x].size(); ++i)
        {
            int h = a[x][i];
            if (!c[h])
            {
                c[h] = true;
                p[h] = x;
                q.push(h);
            }
            if (h == xx)
            {
                vector<int> v;
                for (int y = x; y != h; y = p[y])
                    v.push_back(y);
                v.push_back(h);
                if (ans.empty() || v.size() < ans.size())
                    ans = v;
                return;
            }
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    while (m--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x].push_back(y);
    }
    for (int i = 1; i <= n; ++i)
    {
        bfs(i);
    }
    if (ans.empty())
        cout << -1 << endl;
    else
    {
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); ++i)
            cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N, M = inm()
A = inl()
assert len(A) == N


def solve():
    uf = UnionFind(N)
    for _ in range(M):
        x, y = inm()
        uf.union(x, y, pay=False)
    rs = uf.roots()
    rs.sort(key=lambda x: uf.size(x), reverse=True)
    s = rs[0]
    for i in range(1, len(rs)):
        if not uf.union(s, rs[i], pay=True):
            return "Impossible"
    return uf.paid_cost()


class UnionFind:
    def __init__(self, n):
        # total number of nodes.
        self.n = n
        # node id -> root node id
        self._root_table = list(range(n))
        # root node id -> group size
        self._size_table = [1] * n
        self._cost_table = [[A[i]] for i in range(n)]  # heaps
        self._paid_cost = 0

    def paid_cost(self):
        return self._paid_cost

    def find(self, x):
        """Returns x's root node id."""
        r = self._root_table[x]
        if r != x:
            # Update the cache on query.
            r = self._root_table[x] = self.find(r)
        return r

    def union(self, x, y, pay):
        """Merges two groups."""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # Ensure that x is the larger (or equal) group.
        if self._size_table[x] < self._size_table[y]:
            x, y = y, x

        self._size_table[x] += self._size_table[y]
        self._root_table[y] = x

        if pay:
            if not self._cost_table[x]:
                return False
            ax = heapq.heappop(self._cost_table[x])
            if not self._cost_table[y]:
                return False
            ay = heapq.heappop(self._cost_table[y])
            self._paid_cost += ax + ay

        for z in self._cost_table[y]:
            heapq.heappush(self._cost_table[x], z)
        self._cost_table[y] = []
        return True

    def size(self, x):
        return self._size_table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self._root_table) if x == i]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


print(solve())


Measured memory_bytes: 27216
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

string pop(vstring &v) {
  string s = v.back();
  v.pop_back();
  return s;
}

int main() {
  ll n;
  while (cin >> n) {
    ll result = 0;
    for (ll q = 1; ; ++q) {
      ll m = (n - q) / q;
      if (m <= q) break;
      if ((n - q) % q == 0) {
        // cout << "qm " << q << ' ' << m << endl;
        result += m;
      }
    }
    cout << result << endl;
  }
}


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

int main(){
	string s;
  	cin >> s;
  	int c=0,max = 0;
  	int flag=0;
  	
  	for(int i; i <= s.size();i++){
	  	if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G'){

	          if(flag == 0){
	    	      	flag = 1;
        	  }
    	      	c++;
          if(c == s.size()){
          	max = c;
            break;
          }
        }else{
           if(flag == 1){
          		flag = 0;
             	if(max < c){
                	max = c;
                }
             	c=0;
             	
          	}
        }

    }
  	cout << max << endl;

}

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

constexpr int h = 17;
constexpr int MaxN = 1 << h;

ll dat[MaxN*2], laz[MaxN*2];
int n, q, c, s, t; ll x;

int apply(int p, ll x, int i) {
  dat[p] += x << i;
  laz[p] += x;
}

int flush(int p) {
  repr(i, h) {
    int q = p >> i+1;
    if (laz[q]) {
      apply(q<<1, laz[q], i);
      apply(q<<1|1, laz[q], i);
      laz[q] = 0;
    }
  }
}

int build(int p) {
  rep(i, h) {
    int q = p >> i+1;
    dat[q] = dat[q<<1] + dat[q<<1|1] + (laz[q] << i+1);
  }
}

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

  cin >> n >> q;
  rep(_, q) {
    cin >> c >> s >> t;
    s--; t--;
    if (c == 0) {
      cin >> x;
      flush(s += MaxN); flush(t += MaxN);
      int s0 = s, t0 = t; t++;
      for (int i = 0; s < t; s >>= 1, t >>= 1, i++) {
        if (s & 1) apply(s++, x, i);
        if (t & 1) apply(--t, x, i);
      }
      build(s0); build(t0);
    } else {
      flush(s += MaxN); flush(t += MaxN);
      t++;
      ll res = 0;
      for (; s < t; s >>= 1, t >>= 1) {
        if (s & 1) res += dat[s++];
        if (t & 1) res += dat[--t];
      }
      cout << res << "\n";
    }
  }
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    rep1(i,n){
        ans+=(1+(n/i))*(n/i)/2*i;
       
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define faster ios::sync_with_stdio(false)
#define ll long long int
#define sz 200005
#define mp(x,y) make_pair(x,y) 
#define pii pair<long long int,long long int>
#define tor ::iterator
#define letsgo long long  int i,j,k,q=0,t,tmp,n,flg=0,cntr=0,maxxer = 0
#define fi first
#define se second
#define be begin()
#define en end()
#define mod 1000000007
#define debug(x) cout<<" "<<x<<endl

bool comparator(pair<ll,ll> p1,pair<ll,ll> p2){
	if(p1.fi< p2.fi)
		return true;
	else if(p1.fi == p2.fi){
		return p1.se > p2.se;
	}
	else
		return false;
}

ll dp[100005][3];
int val[100005][3];
int main(){
	faster;
	letsgo; 
	cin>>n;
	vector <ll> v;

	for(i=0;i<n;i++){
		cin>>val[i][0]>>val[i][1]>>val[i][2];
	}
	dp[0][0] = val[0][0];
	dp[0][1] = val[0][1];
	dp[0][2] = val[0][2];
	for(i=1;i<n;i++){
		for(j=0;j<3;j++){
			dp[i][(j)%3] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+val[i][(j)%3];
		}
	}
	// for(i=1;i<n;i++){
	// 	for(j=0;j<3;j++){
	// 		cout<<dp[i][j]<<" ";		
	// 	}
	// 	cout<<endl;
	// }
	
	for(i=0;i<3;i++){
		maxxer = max(maxxer,dp[n-1][i]);
	}
	cout<<maxxer;

}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

// modeは余り
int main()
{
    ll N;
    std::cin >> N;

    ll sum = 0;
    ll mod = 1000000007;

    std::vector<ll> A(N);
    for(ll i=0; i < N; i++) {
        ll x;
        std::cin >> x;
        A[i] = x;
    }

    int tmp = A[N-1];
    for(ll i=N-2; i >= 0; i--) {
        ll tmp2 = A[i] * tmp % mod;
        sum = (sum + tmp2) % mod;
        tmp = (tmp + A[i]) % mod;
    }

    std::cout << sum << std::endl;
}

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

int main( void )
{
  int N;
  cin >> N;
  bool can = false;

  for( int i = 0; i <=  N  / 4; i++ )
    for( int j = 0; j <=  N  / 7; j++ )
      if( 4 * i + 7 * j == N )
	can = true;

  if( can )
  cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MAX_V = 200000;


using P = pair<int, int>;
struct Edge {
    Edge(int _to, int _cost): to(_to), cost(_cost) {}
    int to;
    int cost;
};
int V;
vector<vector<Edge>> G(MAX_V, vector<Edge>());
vector<int> d(MAX_V, INF);

void dijkstra(int s) {
    priority_queue<P> q;
    d[s] = 0;
    q.emplace(0, s);

    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i, G[v].size()) {
            auto e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.emplace(d[e.to], e.to);
            }
        }
    }
};


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

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b, 1);
    }
    dijkstra(0);

    cout << ((d[n - 1] == 2) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

void bubble_sort(double v[], int n)
{
    for (int i = 0; i < n-1; i++){
        for (int j = n-1; j > i; j--){
            if(v[j] > v[j-1]) {
                int tmp = v[j];
                v[j] = v[j-1];
                v[j-1] = tmp;
            }
        }
    }
}

int main ()
{
    int n;
    scanf("%d", &n);
    double v[n];
    for (int i = 0; i < n; i++){
        scanf("%lf", &v[i]);
    }
    bubble_sort(v, n);
    double prdct = 1;
    for (int i = 0; i < n-1; i++){
        prdct *= 2;
        v[i] /= prdct;
    }
    v[n-1] /= prdct;
    double ans = 0;
    for (int i = 0; i< n; i++){
        ans += v[i];
    }
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 128
#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=="Sunny") cout << "Cloudy" << endl;
	else if(s=="Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){int a[4]={0};
int b[4]={0};
int t1=0,t2=0;
int k;

scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);


for( k=0;k<4;k++){
t1+=a[k];
t2+=b[k];
}

if(t1>=t2) printf("%d\n",t1);

else printf("%d\n",t2);

return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int n,m;
//queue <vector<int>> kyu;
vector< vector<int>> S;
void dfs(vector<int> a,int size){
    if(size==n){
        //kyu.push(a);
        S.push_back(a);
        //出来た配列をキューにぶち込む（配列の保存方法がこれしか思いつかん)
        //参考：パナソニックコンテストDS
        return ;
    }
    for(int i=a[size-1];i<=m;i++){
        a.push_back(i);
        dfs(a,size+1);
        a.erase(a.end()-1);
    }
}
int main(){
    int q;
    cin>>n>>m>>q;
    vector<int> a(q),b(q),c(q),d(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--,b[i]--;
    }
    vector<int> A;
    for(int i=1;i<=m;i++){
        A.push_back(i);
        dfs(A,1);
        A.erase(A.end()-1);
    }
    //A.push_back(1);
    //dfs(A,1);
    int ans=0;
    int size = S.size();
    rep(j,size){
    //while(!kyu.empty()){
        //cout<<q.front()<<endl;
        //vector<int> k = kyu.front();
        int score=0;
        rep(i,q){
            if(S[j][b[i]]-S[j][a[i]]==c[i]){
                score += d[i];
            }
        }
        if(score >= ans){
            ans = score;
        }
        /*
        rep(i,n){
            cout<<k[i]<<" ";
        }
        cout<<endl;
        */
        //kyu.pop();
    }
    cout<<ans<<endl;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a > b && a > c){
    cout << b * c / 2 << endl;
  }else if(b > a && b > c){
    cout << a * c / 2 << endl;
  }else if(c > a && c > b){
    cout << a * b / 2 << endl;
  }
  return 0;
}

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

int main(void){
    char c[3][3];;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	int l,i;
	char s[25];
	gets(s);
	l=strlen(s);
	for(i=0;i<l;i++)
	{
		if(s[i]==',') s[i]=' ';
	}
	printf("%s\n",s);
	
}

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

#define N 200123
#define mod 1000000007

int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int a, b; cin >> a >> b;
    // a--; b--;
    // cout << (b+a-1)/a <<"\n";
    int i;
    int c = a;
    i = (b==1? 0:1);
    while(a < b){
    	a = (a-1) + c;
    	i++;
    }
    cout << i << "\n";
 return 0;
}

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

using namespace std;

long long n,k,ans,ans1;

long long calc(long long val){
    return 1ll*val*val*val;
}

int main(){
    cin >> n >> k;
    if(k&1){
        ans=n/k;
        cout << calc(ans);
    }
    else{
        ans1=(n+k/2)/k;
        ans=n/k;
        cout << calc(ans)+calc(ans1);
    }

    return 0;
}


Measured memory_bytes: 256
/*	ex4_1
	suzuto	*/

#include <stdio.h>

int min_num_func(int n, int width); /*プロトタイプ宣言*/

int main(void) {
  int n, d, width, min_num; /*変数の宣言*/
  scanf("%d %d", &n, &d); /*木の本数N、及び監視の幅を表すDの入力*/
  width = 2 * d + 1; /*監視員が見られる最大の木の本数widthを算出*/

  /*監視員を番号d+1からwidthずつずらしていくと効率的この時一人を除き(あるいは全員)width本の木を見れる*/
  min_num = min_num_func(n, width); /*width * i >= n となる最小のi = resをmin_numに代入*/
  printf("%d\n", min_num); /*最小限の監視員数を出力*/
  return 0;
}

/*width * i >= n となる最小のi = res(この時 width * (i - 1) <= n - 1)を算出する関数*/
/*条件式を変形すると res <= (n + width - 1) / width < res + 1となるため中式の商 = resとなる*/
int min_num_func(int n, int width){
  int res;/*変数の宣言*/
  res = (n + width - 1) / width; /*resの算出*/
  return res;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include "atcoder/fenwicktree.hpp"
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
	int n, q;
	cin >> n >>q;
	fenwick_tree<ll> ft(n);
	rep(i, n) {
		ll s;
		cin >> s;
		ft.add(i, s);
	}
	rep(i, q) {
		bool t;
		cin >> t;
		if (!t) {
			int p;
			ll x;
			cin >> p >> x;
			ft.add(p, x);
		}
		else {
			int p, x;
			cin >> p >> x;
			cout << ft.sum(p, x) << endl;;
		}
	}
	return 0;
}


Measured memory_bytes: 8204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    string s;cin>>s;
    ll ans=0;
    for(auto x:s)if(x=='x')ans++;
    if(ans>7)out("NO");
    else out("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

int main() {
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> S(a+2, 0), T(b+2, 0);
    for (ll i = 0; i < a; ++i) {
        cin >> S[i+1];
    }
    S[0] = -1e18;
    S[a+1] = 1e18;
    for (ll i = 0; i < b; ++i) {
        cin >> T[i+1];
    }
    T[0] = -1e18;
    T[b+1] = 1e18;

    for (ll i = 0; i < q; ++i) {
        ll p;
        cin >> p;
        auto s1 = upper_bound(S.begin(), S.end(), p);
        auto s2 = s1-1;
        auto t1 = upper_bound(T.begin(), T.end(), p);
        auto t2 = t1-1;

        auto res = min({
            abs(*s1-*t1)+abs(*t1-p),
            abs(*s1-*t1)+abs(*s1-p),
            abs(*s2-*t2)+abs(*t2-p),
            abs(*s2-*t2)+abs(*s2-p),
            abs(*s2-*t1)+abs(*t1-p),
            abs(*s2-*t1)+abs(*s2-p),
            abs(*s1-*t2)+abs(*t2-p),
            abs(*s1-*t2)+abs(*s1-p)
        });
        cout << res << endl;
    }
}


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

int main(void){
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    
    cout << double(W)*double(H)/2 << " ";
    if ((2*x == W) && (2*y == H)){
        cout << 1;
    }
    else{
        cout << 0;
    }
    return 0;
}

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


int main(){
 int n ;
 
  cin >> n ;
  vector<int> a(n);
  
  vector<int> x(n);
  
  for (int i = 0;i<n;i++){
    
   cin >> a.at(i); 
  }
  
  for (int i = 0;i<n;i++){
    x.at(a.at(i) - 1) = i + 1;
    
  }
  
  
  
  
  for (int i = 0; i < n-1 ; i++){
    
   cout << x.at(i) << ' ' ;
  }
  
  cout << x.at(n-1) << endl;
    
}

Measured memory_bytes: 1664
from functools import reduce


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


n = int(input())
a = list(map(int, input().split()))

l = [0 for i in range(n)]
for i in range(0, n - 1, 1):
    l[i + 1] = gcd(l[i], a[i])

r = [0 for i in range(n)]
for i in range(n - 2, -1, -1):
    r[i] = gcd(r[i + 1], a[i + 1])

m = [gcd(l[i], r[i]) for i in range(n)]

print(reduce(max, m))


Measured memory_bytes: 14576
n = int(input())

if n <= 111:
    print("111")
elif n <= 222:
    print("222")
elif n <= 333:
    print("333")
elif n <= 444:
    print("444")
elif n <= 555:
    print("555")
elif n <= 666:
    print("666")
elif n <= 777:
    print("777")
elif n <= 888:
    print("888")
elif n <= 999:
    print("999")


Measured memory_bytes: 3316
def ttt (x,y,z,i,m,p,q,r):
  if i==n and (p==0 or q==0 or r==0):
    return 10000000
  if i==n:
    m+=abs(x-a)+abs(y-b)+abs(z-c)
    return m
  else:
    return min(ttt(x,y,z,i+1,m,p,q,r), ttt(x+l[i],y,z,i+1,m+10,p+1,q,r), 
               ttt(x,y+l[i],z,i+1,m+10,p,q+1,r), ttt(x,y,z+l[i],i+1,m+10,p,q,r+1))
n,a,b,c=map(int, input().split())
l=[int(input()) for i in range(n)]
print(ttt(0,0,0,0,0,0,0,0)-30)


Measured memory_bytes: 3064
n=int(input())
a=sorted(list(map(int,input().split())))
m=a[-1]
cnt=[0]*(m+1)
ans=0
for i in range(n):
    if cnt[a[i]]>=1:
        cnt[a[i]]+=1
        continue
    for j in range(a[i]*2,m+1,a[i]):
        cnt[j]+=1
    cnt[a[i]]=1
for i in range(n):
    if cnt[a[i]]==1:
        ans+=1
print(ans)

Measured memory_bytes: 32300
function toInt(str)
       parse(Int64,str)
end
function bothPushTime(A_push,A_release,B_push,B_release)
    if(A_push < B_push)
    #AがBより先に押した場合
        if(A_release < B_push)
        #Aが離すのがBが押すより先の場合
            return 0
        else
        #Aが離すのがBが押すより後の場合
            return ifelse(A_release < B_release,A_release-B_push,B_release-B_push)
            #Aが先に離した場合とBが先に離した場合で分ける
        end
    else
    #AがBより後に押した場合
        if(B_release < A_push)
        #Bが離すのがAが押すより先の場合
            return 0
        else
        #Bが離すのがAが押すより後の場合
            return ifelse(B_release < A_release,B_release-A_push,A_release-A_push)
        end
    end
end
alice_push,alice_release,bob_push,bob_release = map(toInt,split(readline(STDIN)))
#Aliceが押、離、Bobが押、離の順
println(bothPushTime(alice_push,alice_release,bob_push,bob_release))

        

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

bool check( string name, int yy, int mm, int dd, int y, int m, int d )
{
	if ( y <= yy-1 )
	{
		cout << name;
		return true;
	}
	if ( y == yy )
	{
		if ( m <= mm-1 )
		{
			cout << name;
			return true;
		}
		else if ( m == mm )
		{
			if ( d <= dd )
			{
				cout << name;
				return true;
			}
		}
	}
	return false;
}

int main( void )
{
	int y, m, d;
	while ( cin >> y >> m >> d )
	{
		if ( check( "pre-meiji", 1868, 9, 7, y, m, d ) )
		{
			cout << endl;
			continue;
		}
		else if ( check( "meiji", 1912, 7, 29, y, m, d ) )
		{
			cout << " " << y - 1868 + 1 << " " << m << " " << d << endl;
			continue;
		}
		else if ( check( "taisho", 1926, 12, 24, y, m, d ) )
		{
			cout << " " << y - 1912 + 1 << " " << m << " " << d << endl;
		}
		else if ( check( "showa", 1989, 1, 7, y, m, d ) )
		{
			cout << " " << y - 1926 + 1 << " " << m << " " << d << endl;
			continue;
		}
		else
		{
			cout << "heisei " << y - 1989 + 1 << " " << m << " " << d << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
a = [0]
a += map(int, input().split())
a += [0]

x = 0
for i in range(N+1):
    x += abs(a[i]-a[i+1])

for i in range(1,N+1):
    print(x - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))


Measured memory_bytes: 14048
n, x = input().split(" ")
n = int(n)
x = int(x)

m_list = []

for i in range(n):
	m_list.append(int(input()))

m_list.sort()

donuts = 0

for i in m_list:
	x -= i
	donuts += 1

while x >= m_list[0]:
	x -= m_list[0]
	donuts += 1

print(donuts)

Measured memory_bytes: 3064
// AOJ 1319 Driving an Icosahedral Rover
// 2018.2.8 bal4u

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define INF   100
#define XBASE 100
#define XMAX  200
#define YBASE 50
#define YMAX  100
#define QMAX  910000

typedef struct { unsigned char x, y, k; } Q;
Q q[QMAX+2]; int top, end;

int tr[60][3] = {
{ 5, 13, 15},{14, 16,  3},{17,  4, 12},
{20,  8,  1},{ 6,  2, 18},{ 0, 19,  7},
{ 4, 22, 11},{23,  9,  5},{10,  3, 21},
{12,  7, 24},{ 8, 25, 13},{26, 14,  6},
{ 9, 28,  2},{29,  0, 10},{ 1, 11, 27},
{32, 34,  0},{35,  1, 30},{ 2, 31, 33},
{34, 37,  4},{38,  5, 35},{ 3, 33, 36},
{37, 40,  8},{41,  6, 38},{ 7, 36, 39},
{40, 43,  9},{44, 10, 41},{11, 39, 42},
{43, 32, 14},{30, 12, 44},{13, 42, 31},
{28, 46, 16},{47, 17, 29},{15, 27, 45},
{50, 20, 17},{18, 15, 48},{16, 49, 19},
{53, 23, 20},{21, 18, 51},{19, 52, 22},
{56, 26, 23},{24, 21, 54},{22, 55, 25},
{59, 29, 26},{27, 24, 57},{25, 58, 28},
{58, 50, 32},{48, 30, 59},{31, 57, 49},
{46, 53, 34},{51, 35, 47},{33, 45, 52},
{49, 56, 37},{54, 38, 50},{36, 48, 55},
{52, 59, 40},{57, 41, 53},{39, 51, 58},
{55, 47, 43},{45, 44, 56},{42, 54, 46}};

char d[XMAX+1][YMAX+1][60];
int dx[2][3] = {{-1,1,0},{-1,1, 0}};
int dy[2][3] = {{ 0,0,1},{ 0,0,-1}};
int dk[2][3] = {{ 1,0,2},{ 0,1, 2}};

int main()
{
	int x, y, k, i, f, t, nx, ny, nk, ans;

	memset(d, INF, sizeof(d));
	d[XBASE][YBASE][0] = 0;
	q[0].x = XBASE, q[0].y = YBASE, q[0].k = 0, top = 0, end = 1;
	while (top != end) {
		x = q[top].x, y = q[top].y, k = q[top++].k;

		f = (x+y) & 1, t = d[x][y][k]+1;
		for (i = 0; i < 3; i++) {
			nx = x + dx[f][i], ny = y + dy[f][i], nk = tr[k][dk[f][i]];
			if (nx >= 0 && nx <= XMAX && ny >= 0 && ny <= YMAX && d[nx][ny][nk] > t) {
				d[nx][ny][nk] = t;
				q[end].x = nx, q[end].y = ny, q[end++].k = nk;
			}
		}
	}

	while (1) {
		x = in(), y = in(), k = in();
		if ((x|y|k) == 0) break;
		x += XBASE, y += YBASE, k *= 3;
		ans = INF;
		for (i = 0; i < 3; i++) if (ans > d[x][y][k+i]) ans = d[x][y][k+i];
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 5524
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int l, r, d;
    cin >> l >> r >> d;
    int res = 0;
    fore(i, l, r+1) {
    	res += ( (i%d) == 0 );
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 3050;
const int mod = (int) 1e9 + 7;

int n;
string s;
long long dp[MAXN][MAXN];
long long sum[MAXN][MAXN];

int main() { 

  scanf("%d\n", &n);
  getline(cin, s);

  dp[1][1] = 1; sum[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    bool less = (s[i - 2] == '<');
    for (int j = 1; j <= i; j++) {
      if (less) {
        dp[i][j] = sum[i - 1][j - 1];
      } else {
        dp[i][j] = sum[i - 1][i - 1] - sum[i - 1][j - 1];
        if (dp[i][j] < 0) {
          dp[i][j] += mod;
        }
      }
    }
    sum[i][1] = dp[i][1];
    for (int j = 2; j <= i; j++) {
      sum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;
    }
  }

  cout << sum[n][n] << endl;

  return 0;
}


Measured memory_bytes: 142848
#include <stdio.h>

int main(void)
{
	int cars[10];
	int num = 0, cars_top = 0;
	
	while(scanf("%d", &num) != EOF){
		
		if(num != 0){					//push
			cars[cars_top] = num;
			cars_top++;
		}
		else if(num == 0){				//pop
			cars_top--;
			num = cars[cars_top];
			printf("%d\n", num);
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100
#define MAXK 100000
#define MOD 1000000007

int N, K, t, a[MAXN + 3], dp[2][MAXK + 3], prefix[2][MAXK + 3]; 

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
        cin >> a[i];

    t = 0;

    for (int j = 0; j <= K; j++) {
        dp[t][j] = (j == 0 ? 1 : 0);
        prefix[t][j] = (j > 0 ? prefix[t][j - 1] : 0) + dp[t][j];
    }

    dp[1][0] = 1;
    prefix[1][0] = 1;

    for (int i = 1; i <= N; i++) {
        t = 1 - t;
        for (int j = 1; j <= K; j++) {
            int all = prefix[1 - t][j];
            int exclude = (j - a[i] <= 0 ? 0 : prefix[1 - t][j - a[i] - 1]);
            dp[t][j] = (all - exclude + MOD)%MOD;
        }
        
        prefix[t][0] = dp[t][0];
        for (int j = 1; j <= K; j++)
            prefix[t][j] = (prefix[t][j - 1] + dp[t][j])%MOD;
    }

    cout << dp[t][K] << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#define mp make_pair
using namespace std;

map<string,vector<string> > recipe;
map<string,int>items;

int price(string item){
  if(recipe.find(item) != recipe.end()){
    int p=0;
    for(int i=0;i<recipe[item].size();i++)
      p+= price(recipe[item][i]);
    return min(p,items[item]);
  }
  else return items[item];
}

int main(){
  int n,m,k;
  while(true){
    cin>>n;
    if(!n)break;
    string name;
    int pr;
    items.clear();
    recipe.clear();
    for(int i=0;i<n;i++){
      cin>>name>>pr;
      items.insert(mp(name,pr));
    }
    cin>>m;
    for(int j=0;j<m;j++){
      cin>>name>>k;
      vector<string> material;
      string mat_name;
      for(int i=0;i<k;i++){
	cin>>mat_name;
	material.push_back(mat_name);
      }
      recipe.insert(mp(name,material));
    }
    cin>>name;
    cout<<price(name)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
int N;
int  h[100001];
int  dp[100001];
int  INF = INT_MAX;

int 
chmin(int  *a, int b) 
{
	 if (*a > b){
		 *a = b; //	printf("%ld\n",*a);
		 return 1; 
	 }
	 return 0;
}


int 
main(){
	int i;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&h[i]);
		dp[i]=INF;
	}
	
	dp[0]=0;
	
	#if 0
	for(i=0;i<N;++i){
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    #endif
    for (i = 1; i < N; i++) {
        chmin(&dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(&dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
	
	//for(i=0;i<N;i++){
		printf("%d\n",dp[N-1]);
	
	//}
	
 return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main() {
	llong ans=0;
    llong n,d;cin >> n>>d;
    vector<vector<double>> V(n,vector<double>(d));
    REP(i,n){
        REP(j,d){
            cin >> V[i][j];
        }
    }

    REP(i,n-1){
        FOR(j,i+1,n){
            double dd =0;
            REP(k,d){
                dd +=pow((V[i][k] - V[j][k]),2);
            }
            dd = sqrt(dd);
            if(dd== (int(dd))) {ans++;}
        }
    }




    cout << ans << endl;



    return 0;
    




}


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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    int n,a,b;
    cin>>n>>a>>b;

    int all=0,B=0;

    rep(i,n){
        char s;
        cin>>s;

        if(s=='c')cout<<"No"<<endl;
        else if(s=='a'){
            if(all<a+b){
                cout<<"Yes"<<endl;
                all++;
            }
            else cout<<"No"<<endl;
        }
        else {
            if(all<a+b&&B<b){
                cout<<"Yes"<<endl;
                B++;
                all++;
            }
            else cout<<"No"<<endl;
        }
    }

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n;
	cin>>n;
	ll arr[n];
	unordered_map<ll,ll> um;
	ll sum = 0;
	REP(i,0,n){
		cin>>arr[i];
		um[arr[i]]++;
		sum += arr[i];
	}
	ll q;
	cin>>q;
	while(q--){
		ll b,c;
		cin>>b>>c;
		if(um.count(b) && um[b] > 0){
			ll v = um[b];
			um[c] += um[b];
			um[b] = 0;
			sum = sum + (c-b)*v;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 7516
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      ll n;
      cin >> n;
      ll even[n/2];
      ll odd[n/2];
      ll ans=0;
      for(ll i=0;i<n/2;i++){
       cin >> even[i] >> odd[i]; 
      }
      sort(odd,odd+n/2);
       sort(even,even+n/2); 
      ll oddcnt=0,suboddcnt=0;
      ll evencnt=0,subevencnt=0;
      ll od=odd[0],eve=even[0];
      ll i=0;
      while(i<n/2){
        ll num=1;
        ll O=odd[0];
        while(odd[i]==odd[i+1]){
          num++;
          O=odd[i];
          i++;
        }
        if(oddcnt<=num){
          od=O;
          suboddcnt=oddcnt;
          oddcnt=num;
        }else{
         suboddcnt=max(suboddcnt,num); 
        }
        i++;
      }
      
      i=0;
       while(i<n/2){
        ll num=1;
        ll E=even[0];
        while(even[i]==even[i+1]){
          E=even[i];
          num++;
          i++;
        }
        if(evencnt<=num){
          eve=E;
          subevencnt=evencnt;
          evencnt=num;
        }else{
         subevencnt=max(subevencnt,num); 
        }
              i++;
      }
     if(even[0]==odd[0] && n==2){cout << 1 << endl;}
      else{
      if(od!=eve){
       cout << n-oddcnt-evencnt << endl;
      }else{
       cout << min(n-oddcnt-subevencnt,n-suboddcnt-evencnt) << endl;; 
      }
     }
      return 0;}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)

int input() {
  int cell;
  cin >> cell;
  return cell;
}

vector<vector<char>> inputs(int H, int W) {
  vector<vector<char>> table(H, vector<char>(W));
  rep(i, H){
    rep(j, W){
      cin >> table.at(i).at(j);
    }
  }
  return table;
}

vector<int> row_check(vector<vector<char>> table){
  int H = table.size();
  int W = table.at(0).size();
  vector<char> check_line(W, '.');
  vector<int> indexs(0);
  rep(i, H){
    if(table.at(i) == check_line)
      indexs.push_back(i);
  }
  return indexs;
}

vector<vector<char>> tenchi(vector<vector<char>> table){
  int H = table.size();
  int W = table.at(0).size();
  vector<vector<char>> tenchied(W, vector<char>(H));
  rep(i, H){
    rep(j, W){
      tenchied.at(j).at(i) = table.at(i).at(j);
    }
  }
  return tenchied;
}

vector<vector<char>> mark_white_line(vector<vector<char>> table, vector<int> row_indexs, vector<int> column_indexs){
  int H = table.size();
  int W = table.at(0).size();
  //消すlineを'%'で埋める
  rep(i, W){
    for(int row_index : row_indexs){
      table.at(row_index).at(i) = '%';
    }
  }
  rep(i, H){
    for(int column_index : column_indexs){
      table.at(i).at(column_index) = '%';
    }
  }
  return table;
}

vector<char> delete_white_line(vector<vector<char>> table){
  vector<char> line_table(0);
  for(vector<char> row : table){
    for(char cell : row){
      if(cell == '%')
        continue;
      line_table.push_back(cell);
    }
  }
  return line_table;
}

void output(vector<char>, int, int);

int main() {
  int H, W;
  H = input();
  W = input();
  vector<vector<char>> table = inputs(H, W);
  vector<int> row_indexs = row_check(table);
  vector<int> column_indexs = row_check(tenchi(table));
  vector<char> line_table = delete_white_line(mark_white_line(table, row_indexs, column_indexs));
  output(line_table, H-row_indexs.size(), W-column_indexs.size());
}

void output(vector<char> line_table, int H, int W){
  rep(i, H){
    rep(j, W){
      cout << line_table.at(W*i+j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256