akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n; 
 string t;
 cin>>n>>t;
 ll cnt=0;
 rep(i,0,n){
  if(t[i]=='(')cnt++;
  if(t[i]==')'&&cnt!=0)cnt--;
 }
 rep(i,0,cnt)t+=')';
 cnt=0;
 string s;
 rrp(i,n,0){
  if(t[i]==')')cnt++;
  if(t[i]=='('&&cnt!=0)cnt--;
  //cout<<i<<" "<<cnt<<endl;
 }
 rep(i,0,cnt)s+='(';
 t=s+t;
 pr(t);
return 0;}


Measured memory_bytes: 3600
#include <vector>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
typedef long long ll;
using namespace std;
typedef vector<ll> vll; typedef set<ll> sll; typedef map<ll,ll> mll;
int bitct(long long r) {int c=0; for(; r; r&=r-1) c++; return c;}
long long gcd(long long x, long long y) {return x ? gcd(y%x,x) : y;}
long long choose(long long n, long long q) { if(n==0 || q==0) return 1;
  if (q==1) return n; else return ( choose(n, q-1) * (n-q+1 ) /q); }
template<typename T> ostream& operator << (ostream &o,vector<T> v) {o<<"[";
  int i=0,s=v.size();for(;i+1<s;i++)o<<v[i]<<", ";if(s)o<<v[i];o<<"]";return o;}
template<typename K, typename V> ostream& operator << (ostream &o,
  unordered_map<K, V> m) {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second <<
  ", "; o<<"}";return o;}
template<typename K, typename V> ostream& operator << (ostream &o, map<K, V> m)
  {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second << ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, unordered_set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename T> ostream& printv(vector<T> v) {int i=0,s=v.size();
  for(;i+1<s;i++)cout<<v[i]<<" ";if(s)cout<<v[i];return cout;}

int main() {
  ios_base::sync_with_stdio(false);
  ll N ;
  cin >> N ;

  ll factor=1;
  ll tot=1;
  for(int i=0;i<N;i++) {
    tot*=3;
    ll x;
    cin >> x;

    if(x%2==0) {
      factor*=2;
    }

  }

  cout << tot-factor << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;//vertex, cnt
int main(int argc, char *argv[]){
  int n, m;
  while(cin >> n >> m){
    if(n == 0 && m == 0)break;
    vector<vector<int> > g(n, vector<int>());
    bool used[n];
    memset(used, 0, sizeof(used));
    for (int i = 0; i < m; i++) {
      int to, from;
      cin >> to >> from;
      to--;from--;
      g[to].push_back(from);
      g[from].push_back(to);
    }
    queue<pii> que;
    que.push(pii(0, 0));
    int ans = -1;
    used[0] = true;
    while(!que.empty()){
      int v = que.front().first;
      int cnt = que.front().second;
      que.pop();
      if(cnt > 2)break;
      ans++;
      for (int i = 0; i < g[v].size(); i++) {
        int next = g[v][i];
        if(used[next] == false){
          used[next] = true;
          que.push(pii(next, cnt + 1));
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
  	cin.tie(NULL);cout.tie(NULL); cerr.tie(NULL); 
  	#ifdef LOCAL
  		freopen("in.txt", "r", stdin);
  		freopen("out.txt", "w", stdout);
  	#endif
  	
  	long long a,b,c;
  	cin >> a >> b >> c;
  	swap(a,b);
  	swap(a,c);
  	cout << a << " " <<  b << " " << c;


}

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

int main(){
    int n;
    cin >> n;
    int finnal=0,last=1;
    for(int i=1;i<=n;i++){
        int m=i;
        int ans=0;
        while(m%2==0&&i!=0){
            ans ++;
            m /= 2;
        }
        if(ans>finnal)last = i;
        finnal=max(ans,finnal);
    }
    cout << last << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

bool judge(vector<int> A, int K) {
	int N = A.size();
	for(int t = 0; t < 2; ++t) {
		vector<int> B = A;
		int c = 0;
		for(int i = 0; i < K; ++i) {
			if (i + K <= N && (B[i] + c) % 2 != 0) {
				++c;
			}
			B[i] = (B[i] + c) % 2;
		}
		bool f = true;
		for(int i = 0; i < K; ++i)
			f = f && B[i] == 0;
		/*
		cerr << K << ":";
		for(int i = 0; i < N; ++i) {
			cerr << B[i];
		}
		cerr << endl;
		*/
		if(f) return true;
		reverse(ALL(A));
	}
	return false;
}

signed main(){
	string S;
	cin >> S;
	int N = S.size();
	vector<int> A(N);
	for(int i = 0; i < N; ++i) A[i] = S[i] - '0';
	int l = 1, u = N + 1;
	while (u - l > 1) {
		int c = (l + u) / 2;
		if (judge(A, c)) {
			l = c;
		} else {
			u = c;
		}
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 2876
import java.util.Scanner;

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

		int n = sc.nextInt();
		int y = sc.nextInt();

		int a = -1, b = -1, c = -1;

		loop: for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n - i; j++) {
				int mny = i * 10000 + j * 5000 + (n - i - j) * 1000;
				if (mny == y) {
					a = i;
					b = j;
					c = n - i - j;
					break loop;
				}
			}
		}

		System.out.println(a + " " + b + " " + c);

		sc.close();
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265

// read statement carefully.

const int N = 1e5+5;
ll n,m;
map<ll,ll>can;
ll cnt[N];

void solve()
{
      cin>>n>>m;
      can[1]=1;
      rep(i,1,n+1) cnt[i]=1;
      rep(i,0,m)
      {
             ll x, y;
             cin>>x>>y;
            // cout<<can[x]<<" "<<cnt[x]<<" "<<can[y]<<" "<<cnt[y]<<endl;
             if(can[x])
             {
                    can[y]=1;
                    cnt[x]--;
                    if(cnt[x]<=0) can[x]=0;
                    cnt[y]++;
             }
             else
             {
                    cnt[x]--;
                    cnt[y]++;
             }
             //cout<<can[x]<<" "<<cnt[x]<<" "<<can[y]<<" "<<cnt[y]<<endl;
      }
      ll ans=0;
      for(auto x:can) if(x.S==1) ans++;
      cout<<ans;
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

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

using namespace std;

typedef long long ll;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cnt(200000 + 1, 0);
  rep(i, n) {
    int a;
    cin >> a;
    cnt[a]++;
  }

  vector<int> vp;
  rep(i, cnt.size()) if (cnt[i]) vp.eb(cnt[i]);

  sort(rall(cnt));

  int ans = 0;
  REP(i, k, cnt.size()) ans += cnt[i];

  cout << ans << endl;
}


Measured memory_bytes: 2168
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int c=a-b;
	int d=a*b;
	int e=a+b;
	if(c<d)
	swap(c,d);
	if(c<e)
	swap(c,e);
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n;
		int d;
		n = sc.nextInt();
		d = sc.nextInt();
		int range = d * 2 + 1;
		int ans = 0;
		if(n % range != 0) {
			ans = n / range + 1;
		} else {
			ans = n / range;
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21972
#!/usr/bin/env python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


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


def solve():
    S = input()
    if S[2] == S[3] and S[4] == S[5]:
        return "Yes"
    return "No"


def main():
    print(solve())


if __name__ == '__main__':
    main()


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

using namespace std;

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back

// rep
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,n) REP(i,0,n)

int check(char grid[2][2]) {
  if(grid[0][0] == '#'
     && grid[0][1] == '.'
     && grid[1][0] == '.'
     && grid[1][1] == '.') {
    return +1;
  }
   
  if(grid[0][0] == '.'
     && grid[0][1] == '#'
     && grid[1][0] == '#'
     && grid[1][1] == '#'
  ) {
    return +1;
  }
   
  if(grid[0][0] == '#'
     && grid[0][1] == '#'
     && grid[1][0] == '#'
     && grid[1][1] == '.'
  ) {
    return -1;
  }
 
  if(grid[0][0] == '.'
     && grid[0][1] == '.'
     && grid[1][0] == '.'
     && grid[1][1] == '#'
  ) {
    return -1;
  }
   
  return 0;
}
 
int main() {
   
  int H, W;
  while(cin >> H >> W) {
    H+=2, W+=2;
    vector<vector<char>> G(H, vector<char>(W, '.'));
    REP(i, 1, H-1) {
      REP(j, 1, W-1) {
        cin >> G[i][j];
      }
    }
     
    vector<pair<double, int>> event;
     
    rep(i, H-1) {
      rep(j, W-1) {
         
        char grid[2][2];
        grid[0][0] = G[i][j];
        grid[0][1] = G[i][j+1];
        grid[1][0] = G[i+1][j];
        grid[1][1] = G[i+1][j+1];
         
        int num = check(grid);
        if(num!=0) {
          double ang = atan2((H-2)-i, j);
          event.PB(MP(atan2((H-2)-i, j), num));
        }
         
      }
    }
     
    sort(ALL(event));
     
    int mx = 2;
    int cnt = 1;
    for(auto e : event) {
      cnt += e.second;
      mx = max(mx, cnt);
    }
    cout << mx << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3580
import collections

N = int(input())
A = list(map(int, input().split()))

P = [i+A[i] for i in range(N)]
Q = [j-A[j] for j in range(N)]

Q_dict = collections.Counter(Q)

cnt = 0
for i in range(N-1):
    Q_dict[Q[i]] -= 1
    cnt += Q_dict[P[i]]

print(cnt)

Measured memory_bytes: 50748
N = int(input())

ans = 1
if N < 10:
    ans = N
elif 10 <= N and N < 100:
    ans = 9
elif 100 <= N and N < 1000:
    ans = 9 + (N - 99)
elif 1000 <= N and N < 10000:
    ans = 909
elif 10000 <= N and N < 100000:
    ans = 909 + (N-9999)
elif 100000 <= N and N < 1000000:
    ans = 90909
elif 1000000 <= N:
    ans = 90909 + (N-999999)

print(ans)


Measured memory_bytes: 3060
N =int(input())
lis = [[i for i in input().split()]+[j+1]for j in range(N)]
for i in range(N):
    lis[i][1] = int(lis[i][1])
lis = sorted(lis,key =lambda x:-x[1])
lis = sorted(lis,key =lambda x:x[0])
for i in range(N):
    print(lis[i][2])


Measured memory_bytes: 3060
def calc(N, A, B):
    before = sum(A)
    for i in range(N - 1, -1, -1):
        if (B[i] >= A[i + 1]):
            B[i] -= A[i + 1]
            A[i] -= min(A[i], B[i])
            A[i + 1] = 0
        else:
            A[i + 1] -= B[i]
            B[i] = 0
    after = sum(A)
    return before - after


N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s) for s in input().split(' ')]
print(calc(N, A, B))

Measured memory_bytes: 18624
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Measured memory_bytes: 40540
#include <iostream>

int value(int a[], int size, int p){
	int w = 0, k = 1;
	for (int i = 0; i < size; i++){
		if (w + a[i] <= p){
			w += a[i];
		}else{
			w = a[i];
			k++;
		}
	}
	return k;
}
int main(){
	int n, k;
	std::cin >> n >> k;
	int w[n];
	int max = 0; int sum = 0;
	for (int i = 0; i < n; i++){
		std::cin >> w[i];
		if (max < w[i]){
			max = w[i];
		}
		sum += w[i];
	}
	while (max != sum){
		int mid = (max + sum) / 2;
		if (value(w, n, mid) > k){
			max = mid + 1;
		}else{
			sum = mid;
		}
	}
	std::cout << max << std::endl;
	return 0;
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int h,w,d;
  cin >> h >> w >> d;
  map<int,pii> mp;
  rep(i,h){
    rep(j,w){
      int a;
      cin >> a;
      a--;
      mp[a] = pii(i,j);
    }
  }
  vector<long> data(h*w);
  rep(i,d){
    data.at(i) = 0;
    for(int j=1;d*j+i<h*w;j++){
      pii P = mp.at(d*j+i-d);
      pii nP = mp.at(d*j+i);
      long cost = abs(P.first - nP.first) + abs(P.second - nP.second);
      data.at(d*j+i) = data.at(d*j+i-d) + cost;
    }
  }
  int q;
  cin >> q;
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;r--;
    cout << data.at(r) - data.at(l) << endl;
  }
}


Measured memory_bytes: 7424
import heapq
V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    nodes[s].append(t)
    cost[s].append(d)

dist = [float('inf')] * V
dist[root] = 0

h = [(0, root)]
while h:
    c, v = heapq.heappop(h)
    if visited[v]:
        continue
    visited[v] = True
    for i in range(len(nodes[v])):
        t = nodes[v][i]
        nc = c + cost[v][i]
        if dist[t] > nc:
            dist[t] = nc
            heapq.heappush(h, (nc, t))

for i in range(V):
    if dist[i] == float('inf'):
        print('INF')
    else:
        print(dist[i])

Measured memory_bytes: 75872
#include<stdio.h>
int main()
{
    int n,m,j,k,l,i;

    while(1)
    {
        scanf("%d %d",&n,&m);
        if(n==0&&m==0) break;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                printf("#");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 1996
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//内積
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//外積
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//直行？
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//平行？
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int main()
{
	int n, l; cin >> n >> l;
	vector<string> st;
	for (int i = 0; i < n; i++)
	{
		string s; cin >> s;
		st.push_back(s);
	}
	sort(all(st));
	for (int i = 0; i < n; i++)cout << st[i];
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a >= k) cout << k << endl;
	else if(a + b >= k) cout << a << endl;
	else cout << a - (k - a - b) << endl;
}

Measured memory_bytes: 3624
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def comb(n):
    return int(n*(n-1)/2)

def main():
    N = I()
    A_list = LI()
    A_ctr = collections.Counter(A_list)
    base = 0
    for i in range(1,N+1):
        base += comb(A_ctr[i])
    for i in range(1,N+1):
        i_val = A_ctr[A_list[i-1]]
        before = comb(i_val)
        after = comb(i_val-1)
        print(int(base - before + after))
main()


Measured memory_bytes: 34176
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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



int main(){fastio
    ll n,m;cin>>n>>m;
    vector<ll>v[n+1];
    rep(i,1,m){
        ll a,b;cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll ans[n+1];memset(ans,-1,sizeof(ans));
    ans[1]=0;
    queue<ll>q;q.push(1);
    while(!q.empty()){
        ll t=q.front();q.pop();
        for(auto x:v[t]){
            if(ans[x]==-1){
                ans[x]=t;
                q.push(x);
            }
        }
    }
    cout<<"Yes"<<endl;
    rep(i,2,n)cout<<ans[i]<<endl;
    return 0;
}


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

int main () {
  int w, a, b;
  cin >> w >> a >> b;
  int ans = 0, c = a+w, d = b+w;
  if (c < b) {
    ans = b-c;
  }
  if (d < a) {
    ans = a-d;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
if K % N == 0 or K % M == 0:
    print('Yes')
    exit()
candidates = set()
for i in range(1, N):
    curr = i * M
    for j in range(1, M):
        curr += N - 2 * i
        candidates.add(curr)
for j in range(1, M):
    curr = j * N
    for i in range(1, N):
        curr += M - 2 * j
        candidates.add(curr)
print('Yes') if K in candidates else print('No')


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

using namespace std;

int main() {
  string A;
  string B;

  cin >> A >> B;

  sort(A.begin(), A.end());
  sort(B.begin(), B.end(), greater<char>());

  int N = A.size();
  int M = B.size();

  if (N < M) {
    int i = 0;
    while (i < N && A[i] == B[i]) {
      ++i;
    }
    if (i == N) {
      printf("Yes\n");
      return 0;
    }
  }
  int i = 0;
  N = min(N, M);
  while (i < N && A[i] == B[i]) {
    ++i;
  }
  if (i < N && A[i] < B[i]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, b; cin >> a >> b;
    cout << (a+b+1)/2 << endl;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
P=list(map(int, input().split()))
class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]
uni=UnionFind(N)

for i in range(M):
    x,y=map(int, input().split())
    uni.Unite(x-1,y-1)
ans=0    
for i,p in enumerate(P):
  if uni.isSameGroup(i,p-1):
    ans+=1
print(ans)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int main() {
    int n;
    cin >> n;
    vector<string> words(n);
    set<string> counts;

    for (int i = 0; i < n; i++) {
        cin >> words[i];
        counts.insert(words[i]);
    }
    if (counts.size() != n) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < n - 1; i++) {
        string prev = words[i];
        string next = words[i + 1];
        char pc = prev.back();
        char nf = next[0];
        if(pc != nf) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Bi = Sarray();
            var ans = Bi[0] + Bi[N - 2];
            for (var i = 1; i < N - 1; ++i)
            {
                ans += Min(Bi[i], Bi[i - 1]);
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  vector<vector<int>> g(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  rep(i,n){
    bool ok = true;
    for(int j:g[i]){
      if(h[i]<=h[j]){
        ok = false;
        break;
      }
    }
    if(ok) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8736
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans = Integer.MAX_VALUE;
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt();
		for(int c = 0; c <= Math.max(X, Y); c++) {
			ans = Math.min(A * Math.max(0, X - c) + B * Math.max(0, Y - c) + 2 * C * c, ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d == 7:
	print('{0}+{1}+{2}+{3}=7'.format(a,b,c,d))
elif a-b+c+d == 7:
	print('{0}-{1}+{2}+{3}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
	print('{0}+{1}-{2}+{3}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
	print('{0}+{1}+{2}-{3}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
	print('{0}-{1}-{2}+{3}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
	print('{0}+{1}-{2}-{3}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
	print('{0}-{1}+{2}-{3}=7'.format(a,b,c,d))
else:
	print('{0}-{1}-{2}-{3}=7'.format(a,b,c,d))

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n, k;
	cin >> n >> k;

	ll h[n];
	rep(i, n) cin >> h[i];

	ll INF = 1e13;
	ll c[n];
	rep(i, n) c[i] = INF;
	c[0] = 0;

	for(int i = 1; i < n; i++){
		for(int j = max(i-k, 0); j < i; j++){
			c[i] = min(c[i], c[j] + abs(h[j] - h[i]));
		}
	}

	cout << c[n-1] << endl;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%d %d", $n, $m);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$queue = new SplPriorityQueue();
for($i=0; $i<$n; $i++) {
    $queue->insert($a[$i], $a[$i]);
}
while($m) {
    $max = $queue->extract();
    $max = $max/2;
    $queue->insert($max, $max);
    $m--;
}
$count = $queue->count();
$ans = 0;
for($i=0; $i<$count; $i++) {
    $ans += (int)floor($queue->extract());
}
echo $ans;


Measured memory_bytes: 53748
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for(int i=0; i<N; ++i) {
    cin >> A[i];
  }
  for(int i=0; i<N; ++i) {
    cin >> B[i];
  }
  for(int i=0; i<N-1; ++i) {
    cin >> C[i];
  }

  int prev_idx = A[0]-1;
  int ret = B[prev_idx];
  for(int i=1; i<N; ++i) {
    int cur_idx = A[i]-1;
    ret += B[cur_idx];
    if (cur_idx - prev_idx == 1) {
      ret += C[prev_idx];
    }
    prev_idx = cur_idx;
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int w[10],k[10];
	while(cin>>w[0]){
	for(int i=1;i<10;i++)
		cin>>w[i];
	for(int i=0;i<10;i++)
		cin>>k[i];
	for(int i=0;i<9;i++){
        for(int j=9;j>i;j--){
	        if(w[j]>w[j-1]){
	            int t=w[j];
	            w[j]=w[j-1];
	            w[j-1]=t;
	        }
        }
    }
	for(int i=0;i<9;i++){
        for(int j=9;j>i;j--){
	        if(k[j]>k[j-1]){
	            int t=k[j];
	            k[j]=k[j-1];
	            k[j-1]=t;
	        }
        }
    }
	cout<<w[0]+w[1]+w[2]<<" "<<k[0]+k[1]+k[2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		long a = Long.parseLong(strArr[0]);
		long b = Long.parseLong(strArr[1]);
		long k = Long.parseLong(strArr[2]);
		if (a > k) {
			a -= k;
			k = 0;
		} else {
			k -= a;
			a = 0;
		}
		if (b > k) {
			b -= k;
		} else {
			b = 0;
		}
		System.out.println(a + " " + b);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

int main()
{
    int n;
    cin >> n;
    int a[51];
    int b[51];
    int c[51];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
    }
    for (int i = 1; i < n; i++)
    {
        cin >> c[i];
    }
    int satisfaction = 0;
    int lastDish = -100;
    for (int i = 1; i <= n; i++)
    {
        satisfaction += b[a[i]];
        if (lastDish == a[i] - 1)
        {
            satisfaction += c[lastDish];
        }
        lastDish = a[i];
    }
    cout << satisfaction;
    return 0;
}


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

#define N 1200

int func(char s){
	int d = (s);

	if((d >= 65) && (d <= 90)){
		return (d+32);
	}else if((d >=97) && (d <= 122)){
		return (d-32);
	}

	return d;
}

void calc(char s[N]){
	int count=0;
	
	for(int i=0;i<N;i++){
		s[i] = (func(s[i]));
	}

}

int main(void){
	char s[N];

	scanf("%[^\n]s",s);

	calc(s);


	printf("%s\n",s);
	//getchar();
}


Measured memory_bytes: 2112
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll tenth[10][200001];
int main(){
	string S;
	scan(S);
	int N=S.size();
	int simo[2019]={};
	simo[0]=1;
	rep1(i,9){
		tenth[i][0]=1;
		rep(j,N){
			tenth[i][j+1]=tenth[i][j]*10%2019;
		}
	}
	ll now=0;
	ll ans=0;
	brep(i,N){
		now=(now+(S[i]-'0')*tenth[S[i]-'0'][N-i-1])%2019;
		ans+=simo[now];
		simo[now]++;
	}
	prin(ans);
	return 0;
}


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

using namespace std;
//long long mod = 1000000000+7;

  long long  pow(long long  a, long long  b, long long mod)
 {
        stack<int>k;
        int j = 2048;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }
long long an = 0;



 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
         //freopen("task.in","r",stdin);
     //freopen("palindrome.out","w",stdout);
      int n;
      cin>>n;
      int x[n];
      int dp[n];
      cin>>x[0]>>x[1];
      dp[1] = abs(x[0]-x[1]);
      dp[0] = 0;
        for(int i = 2;i<n;++i){
            cin>>x[i];
            dp[i] = min(abs(x[i]-x[i-1])+dp[i-1],abs(x[i]-x[i-2])+dp[i-2]);

        }
        cout<<dp[n-1]<<endl;

    return 0;
 }


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <algorithm>
#include <cstring>

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;

inline i32 diff(i32 x, i32 y) {
	return x > y ? x - y : y - x;
}

const int MaxN = 100001;

i32 A[MaxN], dp[MaxN];

signed main(signed argc, char **argv) {
	i32 n;
	scanf("%" SCNdFAST32, &n);

	for (int i = 0; i < n; ++ i) {
		scanf("%" SCNdFAST32, A + i);
	}

	memset(dp, 0x3f, sizeof dp);

	dp[0] = 0;
	dp[1] = diff(A[0], A[1]);
	for (int i = 2; i < n; ++ i) {
		dp[i] = std::min(dp[i - 1] + diff(A[i], A[i - 1]), dp[i - 2] + diff(A[i], A[i - 2]));
	}

	printf("%" SCNdFAST32, dp[n - 1]);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int a,b;
scanf("%d %d",&a,&b);
if(a>=13){b=b;}
else if(a>=6&&a<=12){b=b/2;}
else {b=0;}
printf("%d",b);
return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
n,e = [int(i) for i in input().split()]

"""隣接行列の初期化"""
INF = float("inf")
dist = [[float("inf")]*n for _ in [0]*n]
for i in range(n):
    dist[i][i] = 0

for _ in range(e):
    s,t,d = [int(i) for i in input().split()]
    dist[s][t] = d

def Floyd_Warshall(dist): # 
    """
    Floyd_Warshall 
    dist: 隣接行列（破壊される)
    #隣接行列のつながっていない辺はfloat("inf")で埋める（負辺を気にせずによい）
    #実行時間が気になるときは INF = 10**18 などで埋める（負辺に注意）
    #dist[i[i] < 0なる i があればnegative cycle
    """
    num_of_vertices = len(dist)
    for k in range(num_of_vertices):
        for i, c2 in enumerate(dj[k] for dj in dist):
            for j, (c1, c3) in enumerate(zip(dist[i], dist[k])):
                if c1 > c2+c3:
                    dist[i][j] = c2+c3

Floyd_Warshall(dist)

def has_negative_cycle(dist) -> bool:
    return any(row[i] < 0 for i, row in enumerate(dist))
 
if has_negative_cycle(dist):
    print("NEGATIVE CYCLE")
    exit()
else:
    for row in dist:
        print(" ".join(map(lambda n: str(n) if n!=INF else "INF", row)))


Measured memory_bytes: 6208
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <stack>
#include <list>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, P> P2;
typedef pair<int, pair<P, P> > PPP;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.14159;

int main(){
	double d;
	double px, py, vx, vy;
	while(cin >> d && d != 0.0){
		cin >> px >> py >> vx >> vy;
		if(py * vx - px * vy < EPS && py * vx - px * vy > -EPS){
			double dis = sqrt(py * py + px * px);
			if(px * vx + py * vy < EPS){
				if(dis < d) cout << fixed << setprecision(9) << dis << endl;
				else cout << "impossible" << endl;
			}else{
				if(dis < 1.0 && 2.0 - dis < d){
					cout << fixed << setprecision(9) << 2.0 - dis << endl;
				}else{
					cout << "impossible" << endl;
				}
			}
		}else{
			cout << "impossible" << endl;
		}
	}
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/27  Problem: ABC 113 C / Link: http://abc113.contest.atcoder.jp/tasks/abc113_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

	LL N, M; cin >> N >> M;
	vector<pair<int, string>> ans;
	vector<vector<PII>> P(N + 1);
	FOR(_, 0, M) {
		int p, y; cin >> p >> y;
		P[p].push_back(PII(y, _));
	}
	FOR(i, 0, N + 1) {
		SORT(P[i]);
		FOR(k, 0, SZ(P[i])) {
			stringstream ss;
			ss << setw(6) << setfill('0') << i;
			ss << setw(6) << setfill('0') << k + 1;
			string s;
			ss >> s;
			ans.emplace_back(make_pair(P[i][k].second,s ));
		}
	}

	SORT(ans);
	for (auto it : ans) {
		cout << it.second << endl;
	}

	return 0;
}


Measured memory_bytes: 13168
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        char[] S = sc.next().toCharArray();

        int ranked = 0;
        int ranked2 = 0;
        for (int i = 0; i < N; i++) {
            int rank = i + 1;
            boolean ok = false;

            if (S[i] == 'a') {
                if (ranked < A + B) {
                    ok = true;
                }
            } else if (S[i] == 'b') {
                if (ranked < A + B && ranked2 < B) {
                    ok = true;
                    ranked2++;
                }
            }

            if (ok) { 
                ranked++;
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }

        return;
    }

}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		double s = 0;
		
		for(int i = 0; i < n ; i ++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < n; j ++) {
			s += Math.sqrt( (a[i] - a[j])*(a[i] - a[j]) +(b[i] - b[j])*(b[i] - b[j]) );
				
			}
		}
		System.out.println(s/n);
		
		// TODO 自動生成されたメソッド・スタブ

	}

}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll K,N;
    cin >> N >> K;
    ll A[N];
    ll B[N + 1];
    for(ll i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        A[i] = tmp;
        if(i == 0){
            B[i] = 0;
        }else{
            B[i] = B[i-1] + A[i - 1];
        }
    }
    B[N] = B[N - 1] + A[N - 1];
    for(int i = 0; i < N + 1; i++){
        //cout << B[i] << ",";
    }
    ll M = 0;
    for(int i = 0; i < N - K + 1; i++){
        M =  max(M,B[i + K] - B[i]);
    }
    cout << fixed;
    cout << std::setprecision(10) << (float)(M + K) / (float)2;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int X,A,B;
	cin>>X>>A>>B;
	int c=X-A;
	int d=c/B;
	int e=c-d*B;
	cout<<e<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
char n[5];
int main(){
    scanf("%s", &n);
    ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) ? printf("Yes\n") : printf("No\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>

using namespace std;



int main() 
{
	string a, b;
	cin >> a >> b;
	int size = a.size();
	a += a;
	for (int i = 0; i < size; i++)
	{
		string temp = a.substr(i, size);
		if (temp == b)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;







}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  for(;;){
    int n;scanf("%d",&n);
    if(!n){break;}
    int min=0, max=0x80000000, sum=0;
    REP(i,n){
      int a;scanf("%d",&a);
      min=std::min(min,sum);
      max=std::max(std::max(max,sum+a-min),a);
      sum+=a;
    }
    printf("%d\n",max);
  }
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int k = 0;
    if((S == "hi")||(S == "hihi")||(S == "hihihi")||(S == "hihihihi")||(S == "hihihihihi")){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
}


Measured memory_bytes: 256