akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int sum = 0;
  rep(i, 3) {
    int a; cin >> a;
    sum += a;
  }

  if (sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int *p, *q;
	p = (int*)malloc(sizeof(int));
	q = (int*)malloc(sizeof(int));
	while( scanf("%d%d",p,q) != EOF){
		printf("%d\n",*p + *q);
	}
	free(p);
	free(q);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int x;
	 cin>>x;
	 cout<<1-x<<'\n';
	 return 0;
}


Measured memory_bytes: 3644
n, m, l = gets.split.map(&:to_i)

a = n.times.map { gets.split.map(&:to_i) }
b = m.times.map { gets.split.map(&:to_i) }

c = n.times.map { l.times.map { 0 } }

n.times.each do |i|
  l.times.each do |j|
    c[i][j] = (0..m - 1).map { |k| a[i][k] * b[k][j] }.sum
  end
end

c.each do |line|
  puts line.join(' ')
end



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

long f(vector<int>& A, int s) {
  long acc = 0, ans = 0;
  for (int i = 0; i < A.size(); i++) {
    acc += A[i];
    if (acc == 0 || s != ((acc < 0) ? -1 : 1)) {
      int d = abs(acc) + 1;
      acc += s * d;
      ans += d;
    }
    s *= (-1);
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  long ans1 = f(A, 1);
  long ans2 = f(A, -1);
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 640
n=int(input())
import fractions
a = list(map(int, input().split()))
lcm = a[0]
for i in a:
  lcm = lcm * i // fractions.gcd(lcm, i)
b=[]
for i in a:
  b.append(lcm//i)
ans=sum(b)%(10**9+7)
print(ans)

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

struct Card
{
    char suit;
    int value;
};
void bubbleSort(Card c[],int n)
{
    int flag=1;
    Card t;
    while(flag)
    {
        flag=0;
        for(int i=0; i<n-1; i++)
        {
            if(c[i].value>c[i+1].value)
            {
                t=c[i];
                c[i]=c[i+1];
                c[i+1]=t;
                flag=1;
            }
        }
    }
}

void selectionSort(Card c[],int n)
{

    int minX;
    Card t;
    for(int i=0; i<n-1; i++)
    {
        minX=i;
        for(int j=i+1; j<n; j++)
        {
            if(c[j].value<c[minX].value)
                minX=j;
        }
        if(minX!=i)
        {
            t=c[i];
            c[i]=c[minX];
            c[minX]=t;
        }

    }
}

void print(Card c[],int n)
{
    for(int i=0; i<n-1; i++)
        cout<<c[i].suit<<c[i].value<<" ";
    cout<<c[n-1].suit<<c[n-1].value<<endl;
}

bool ifStable(Card c1[],Card c2[],int n)
{
    for(int i=0; i<n; i++)
    {
        if(c1[i].suit!=c2[i].suit)
            return false;
    }
    return true;
}


int main()
{
    int n;
    cin>>n;
    Card  c1[36],c2[36];
    for(int i=0; i<n; i++)
        cin>>c1[i].suit>>c1[i].value;
    for(int i=0; i<n; i++)
    {
        c2[i].suit=c1[i].suit;
        c2[i].value=c1[i].value;
    }
    bubbleSort(c1,n);
    selectionSort(c2,n);
    print(c1,n);
    cout<<"Stable"<<endl;
    print(c2,n);
    if(ifStable(c1,c2,n))
    {
        cout<<"Stable"<<endl;
    }
    else
    {
        cout<<"Not stable"<<endl;
    }
    return 0;
}





Measured memory_bytes: 3108
import sys
import os

def file_input():
    f = open('ARC080/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    N=int(input())
    a_li=list(map(int, input().split()))

    # four=0
    odd=0
    for i in a_li:
        if i%4==0:
            odd-=1
        if i%2!=0:
            odd+=1
    else:
        if (N%2==0 and odd<=0) or (N%2!=0 and odd<=1):
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 14480
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p, int r){
int x,i,j,t;
x=A[r];
i=p-1;
for(j=p;j<r;j++){
    if(A[j]<=x){
        i++;
        t=A[i];A[i]=A[j]; A[j]=t;
    }
}
t=A[i+1];A[i+1]=A[r];A[r]=t;
return i+1;
}

int main(){
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    q=partition(0,n-1);
    for(i=0;i<n;i++){
        if(i)printf(" ");
        if(i==q) printf("[");
        printf("%d",A[i]);
        if(i==q) printf("]");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long
#define problem ""

template<typename A, typename B, typename C>
struct triple{
    A X;
    B Y;
    C Z;
    triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0){
    return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b){
    if (a.X != b.X)
        return a.X < b.X;
    if (a.Y != b.Y)
        return a.Y < b.Y;
    return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p){
    ofs << "( " << p.F << " , " << p.S << " )";
    return ofs;
}
template<typename T>
void print(T a){
    for (auto i : a)
        cout << i << ' ';
    cout << '\n';
}
template<typename T>
T max(T a, T b, T c){
    return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c){
    return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a){
    return *min_element(all(a));
}
template<typename T, typename D>
D max(T a){
    return *max_element(all(a));
}
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve(){
    int n; cin >> n;
    vi a(n); rngi(i, n) cin >> a[i];
    int ans = 0; for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) ans += a[i]*a[j]; cout << ans << '\n';
}

signed main()
{
    if(0){
        freopen(problem".in", "r", stdin);
        freopen(problem".out", "w", stdout);
    }
    srand(time(NULL));
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1; //cin >> t;
    rng(t) solve();
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  char a,b;cin>>a>>b;
  string s(a-'0',b),t(b-'0',a);
  cout<<min(s,t)<<endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!long;
    long s;
    foreach (i; 1..N+1) {
        if (i%3 != 0 && i%5 != 0) s += i;
    }
    writeln(s);
}

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

const int N = 1e5 + 5;

map<int,int> Map;

map<int,int> ::iterator it;

int n , MAX = 0;

int main(void) {
    scanf("%d" , &n);
    for(int i = 1;i <= n;++ i) {
	int x; scanf("%d" , &x);
	++ Map[x];
    }
    for(it = Map.begin();it != Map.end();++ it) {
	if(it -> second >= 2) MAX = max (MAX , it ->first);
    }
    long long ans = 0;
    for(it = Map.begin();it != Map.end();++ it) {
	if(it -> first == MAX) {
	    if(it -> second >= 4) {
		cout << MAX *1ll * MAX; return 0;
	    }
	    break;
	}
	if(it -> second < 2) continue;
	ans = max(ans , MAX *1ll *  it -> first);
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    int x;
    int i = 1;
    while(true){
        cin >> x;
        if(x == 0){
            break;
        }
        cout << "Case " << i << ": "<< x << endl;
            i=i + 1;
    }
    
}



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

int main()
{
  int a, ans;
  ll b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ans = floor(a * x * 1.0 / b) - a * floor(x * 1.0 / b);

  cout << ans << endl;

  return 0;
}


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

typedef long long LL;

LL n,a,b;

void into(){
  scanf("%lld%lld%lld",&n,&a,&b);
}

LL ans;

void Get_ans(){
  if (a>b) swap(a,b);
  if (b-a&1^1) {ans=b-a>>1;return;}
  ans=min(a,n-b+1)+(b-a-1>>1);
}

void work(){
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {

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

		int n=Integer.parseInt(sc.next());

		String str=sc.next();
		String x;
		int k=Integer.parseInt(sc.next());

		String[] str2=str.split(""); //一文字ずつ取り出す
		x=str2[k-1];
		for(int i=0;i<str2.length;i++){

			if(str2[i].equals(x)==false){
				str2[i]="*";
			}
		}

		for(int i=0;i<str2.length;i++){

			System.out.print(str2[i]);
		}
		sc.close();

	}

}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define fir first
#define sec second

using namespace std;
struct Union
{
  Union *par = this;
  int val = -1;
  int rank = 1;
};

Union *root(Union *t)
{
  if (t->par == t)
    return t;
  else
    return root(t->par);
}

void unite(Union *a, Union *b)
{
  if (a->rank > b->rank)
    root(b)->par = root(a);
  else
  {
    root(a)->par = root(b);
    if (a->rank == b->rank)
      b->rank++;
  }
}
bool same(Union *a, Union *b)
{
  return root(a) == root(b);
}

int main()
{
  int N, M, ans = 0;
  cin >> N >> M;
  pair<int, int> edge[M];
  for (int i = 0; i < M; i++)
  {
    cin >> edge[i].fir >> edge[i].sec;
    edge[i].fir--;
    edge[i].sec--;
  }
  for (int i = 0; i < M; i++)
  {
    Union u[N];
    for (int j = 0; j < M; j++)
    {
      if (j == i)
        continue;
      unite(&u[edge[j].fir], &u[edge[j].sec]);
    }
    bool isBridge = false;
    for (int j = 0; j < N; j++)
    {
      if (!same(&u[0], &u[j]))
      {
        isBridge = true;
        break;
      }
    }
    if (isBridge)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int ans = 0;
        for(int i = 1; i * i <= n; i++){ 
            if(n % i){
                continue;
            }
            if(n / i == i){
                continue;
            }
            if(n % (n / i - 1) == 0){
                continue;
            }
            ans += n / i - 1;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 31488
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;
#define int long long

int32_t main(){_
	vi a(3) ;
	inp(a) 
	sort(all(a)) ;
	cout << a[0]+a[1] << endl ;
	
}





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

using namespace std;

const int INF = 1 << 30;

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

    int h[N];
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    int cost[N + 1];
    cost[0] = 0, cost[1] = INF;
    for (int i = 0; i < N - 1; ++i) {
        cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]));
        cost[i + 2] = cost[i] + abs(h[i + 2] - h[i]);
    }

    cout << cost[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int main() {
    int n;
    while (cin >> n, n) {
        vector<vector<int>> stage_time(n, vector<int>(n + 1));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= n; j++) cin >> stage_time[i][j];
        }
        vector<int> dp((1 << n) + 1, INF);
        dp[0] = 0;
        for (int cur = 0; cur < (1 << n); cur++) {
            for (int t = 0; t < n; t++) {
                int next = cur | (1 << t);
                int best = stage_time[t][0];
                for (int s = 0; s < n; s++) if (cur & (1 << s)) {
                    best = min(best, stage_time[t][s + 1]);
                }
                dp[next] = min(dp[next], dp[cur] + best);
            }
        }
        cout << dp[(1 << n) - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3424
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

bool take[310][310];

signed main() {
    int n;
    while(cin >> n, n) {
        int w[310];
        rep(i,0,n) cin >> w[i];
        memset(take, false, sizeof(take));

        rep(i,0,n) {
            rep(j,0,n-i) {
                int len = i+1;
                int s = j, t = j+i;
                rep(k,s,t) {
                    if(take[s][k] && take[k+1][t]) take[s][t] = true;
                }
                if(len == 2) {
                    if(abs(w[s] - w[t]) < 2) {
                        take[s][t] = true;
                    }
                }
                if(take[s][t]) {
                    int x = s-1, y = t+1;
                    while(1) {
                        if(x < 0 || x >= n || y < 0 || y >= n) break;
                        if(abs(w[x] - w[y]) >= 2) break;
                        take[x][y] = true;
                        x--; y++;
                    }
                }
            }
        }

        int dp[310][310] = {};
        rep(i,0,n) rep(j,i+1,n) {
            if(take[i][j]) dp[i][j] = j-i+1;
        }

        rep(i,0,n) rep(j,i,n) rep(k,i,j) {
            dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j]);
        }
        cout << dp[0][n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3928
//
//  main.cpp
//  鎵撴€吔
//
//  Created by RMBP on 2019/10/13.
//  Copyright 漏 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int a[100000000],b[100000000];
int main() {
    long long n,i,c;
    c=0;
    cin>>n;
    for (i=0;i<n+1;i++){
        cin>>a[i];
    }
    for (i=0;i<n;i++){
        cin>>b[i];
    }
    for (i=0;i<n;i++){
        if (a[i]>=b[i]){
            c=c+b[i];
        }
        else{
            if (b[i]-a[i]>=a[i+1]){
                c=c+a[i]+a[i+1];
                a[i+1]=0;
            }
            else if (b[i]-a[i]<a[i+1]){
                c=c+b[i];
                a[i+1]=a[i+1]-b[i]+a[i];
            }
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 2688
N = int(input())
S = [list(map(int, list(input()))) for i in range(N)]

# 奇数長のループがあるかどうかをチェック
color = [-1] * N
def dfs(node, par):
  global color
  res = True
  for i, s in enumerate(S[node]):
    if s and i != par:
      if color[i] == -1:
        color[i] = (color[node] + 1) % 2
        res *= dfs(i, node)
      else:
        res *= (color[i] == (color[node] + 1) % 2)
  return res

color[0] = 0
if dfs(0, -1):
  from scipy.sparse.csgraph import floyd_warshall
  import numpy as np
  dist = floyd_warshall(S).astype(int)
  print(dist.max() + 1)
else:
  print(-1)

Measured memory_bytes: 19252
import java.util.*;

public class Main {

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

        int[] antennaArr = new int[5];
        for (int i = 0; i < antennaArr.length; i++) {
            antennaArr[i] = sc.nextInt();
        }

        int border = sc.nextInt();

        boolean canConnect = true;
        for (int i = 0; i < antennaArr.length; i++) {
            for (int j = 0; j < antennaArr.length; j++) {
                if (i >= j) {
                    continue;
                }

                if (antennaArr[j] - antennaArr[i] > border) {
                    canConnect = false;
                }
            }
        }

        if (canConnect) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<string.h>
#include<math.h>

using namespace std;



int main(){
    string in;
    int num=0;
    while(cin>>in){
        bool flag=false;
        int temp = 0;
        for(int i=0; i<=in.length(); i++){
            if('0'<=in[i]&&in[i]<='9'){
                temp=temp*10+(in[i]-'0');
                flag=true;
            }else if (flag==true){
                num+=temp;
                temp=0;
                flag=false;
            }
        }
    }
    cout<<num<<endl;
}

Measured memory_bytes: 1184
program main
  implicit none
  integer i, H, W, A, B
  character(1000) X1,X2
  read(*, *)H, W, A, B
  !allocate(X1(W))
  !allocate(X2(W))
  !read(*, *) (L(i), i = 1,N)
  do i = 1,A
    X1(i:i) = '1'
    X2(i:i) = '0'
  end do
  do i = A+1,W
    X1(i:i) = '0'
    X2(i:i) = '1'
  end do
  do i = 1,H
    if (i > B) then
      write(*, *) X2(1:W)
    else
      write(*, *) X1(1:W)
    end if
  end do
end program main


Measured memory_bytes: 1152
#include<cstdio>
using namespace std;
#define N 3005
#define mod 1000000007
#define inv 500000004
int n,dp[N][N],v[N],q,a,b;
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",&v[i]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)dp[i][j]=(v[i]<v[j]);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&a,&b);
		int tp=dp[a][b]+dp[b][a];
		for(int j=1;j<=n;j++)
		{
			dp[j][a]=dp[j][b]=1ll*(dp[j][a]+dp[j][b])*inv%mod;
			dp[a][j]=dp[b][j]=1ll*(dp[a][j]+dp[b][j])*inv%mod;
		}
		dp[a][b]=dp[b][a]=1ll*tp*inv%mod;
	}
	int as=0;
	for(int i=2;i<=n;i++)
	for(int j=1;j<i;j++)as=(as+dp[i][j])%mod;
	for(int i=1;i<=q;i++)as=as*2%mod;
	printf("%d\n",as);
}//orz

Measured memory_bytes: 35456
#include <iostream>
using namespace std;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	int p[n]={};
	for(int i=0; i<n; i++){
		cin >> p[i];
	}
	int cnt=0;
	for(int i=1; i<n-1; i++){
		if(p[i]<max(p[i+1],p[i-1]) && p[i]>min(p[i+1],p[i-1])){
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            int x = Integer.parseInt(in.next());

            if (k == 1) {
                out.println(x);
                return;
            }
            for (int i = x - k + 1; i < x + k; i++) {
                out.printf("%d", i);
                out.print(" ");
            }
            out.println();

        }

    }
}



Measured memory_bytes: 23892
from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[0]*4 for j in range(c)]
for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j]
for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp
print(max(dp[-1]))

Measured memory_bytes: 223708
n = int(input())
h = list(map(int, input().split()))

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

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

int main(void) {
  int64_t X, Y;
  cin >> X >> Y;

  int64_t Ans = 0;
  for (int64_t i = X; i <= Y; i *= 2) {
    Ans++;
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int f(int l,int r){//printf("%d %d\n",l,r);
	int a,b;
	if(l+1==r){
		scanf("%d",&a);
		return a;
	}
	a=f(l,(l+r)/2);
	b=f((l+r)/2,r);
	if(a==b)return a;
	return abs(a-b);
}
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",f(0,1<<n));
	return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

i64 power(i64 x, i64 n, i64 mod) {
  i64 ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

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

  map<int, int> mp;
  int n;
  cin >> n;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int x = !(n % 2);
  for(auto it : mp) {
    if((it.first == 0 && it.second == 1) || (it.first == x && it.second == 2)) {
      x += 2;
      continue;
    }
    cout << 0 << endl;
    return 0;
  }

  cout << power(2, n / 2, mod) << endl;
}


Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest20191025
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int p = int.Parse(s[1]);

            p = p + (a * 3);

            Console.WriteLine(p / 2);

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 10000000
main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(b/c)-((a-1)/c);
}

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

template<typename M, typename T>
struct lazy_segment_tree{
	typedef function<M(M, M)> F;
	typedef function<M(M, T)> EVAL;
	typedef function<T(T, T)> G;
	int size;//2冪
	vector<M> val;//1-indexed
	vector<T> lazy;//遅延情報を入れる
	F f;//結合関数
	EVAL eval;//モノイドに作用素を作用させる関数
	G g;//作用素の結合関数 A->Bの順に作用させるとg(A, B)
	M em;//モノイドの単位元
	T et;//作用素の単位元

	lazy_segment_tree(int N, vector<M> &data, F f, EVAL eval, G g, M em, T et) : f(f), eval(eval), g(g), em(em), et(et){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, em);
		lazy.assign(2 * size, et);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = em;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	void propagate(int k){
		if(lazy[k] != et && k < size){
			lazy[2 * k + 0] = g(lazy[2 * k + 0], lazy[k]);
			lazy[2 * k + 1] = g(lazy[2 * k + 1], lazy[k]);
		}
		val[k] = eval(val[k], lazy[k]);
		lazy[k] = et;
	}

	//[l, r)に対してAを作用させたときの[s, t)の値を求める
	M update(int l, int r, T A, int k, int s, int t){
		propagate(k);
		if(t <= l || r <= s){
			return val[k];
		}
		else if(l <= s && t <= r){
			lazy[k] = g(lazy[k], A);
			propagate(k);
			return val[k];
		}
		else{
			return val[k] = f(update(l, r, A, 2 * k, s, (s + t) / 2), update(l, r, A, 2 * k + 1, (s + t) / 2, t));
		}

	}

	//[l, r)に対してAを作用させる
	void update(int l, int r, T A){
		M res = update(l, r, A, 1, 0, size);
	}

	M query(int l, int r, int k, int s, int t){
		propagate(k);
		if(t <= l || r <= s){
			return em;
		}
		else if(l <= s && t <= r){
			return val[k];
		}
		else{
			return f(query(l, r, 2 * k, s, (s + t) / 2), query(l, r, 2 * k + 1, (s + t) / 2, t));
		}
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		return query(l, r, 1, 0, size);
	}
};

//query:sum
//update:substitution
//(pair<int, int>, int, sum, eval, g, em, et)
//x = (値, 区間の長さ)

const pair<int, int> em(0, 0);
const int et = (1 << 31);

pair<int, int> sum(pair<int, int> x, pair<int, int> y){
	return pair<int, int>(x.first + y.first, x.second + y.second);
}

pair<int, int> eval(pair<int, int> x, int a){
	if(a == et) return x;
	else return pair<int, int>(a * x.second, x.second);
}

int g(int a, int b){
	if(b == et) return a;
	else return b;
}

int main(){
	int N, Q, i;
	scanf("%d%d", &N, &Q);
	vector<pair<int, int> > data(N, pair<int, int>(0x7fffffff, 1));
	lazy_segment_tree<pair<int, int>, int> t(N, data, sum, eval, g, em, et);
	for(i = 0; i < Q; i++){
		int c;
		scanf("%d", &c);
		if(c == 0){
			int l, r, x;
			scanf("%d%d%d", &l, &r, &x);
			t.update(l, r + 1, x);
		}
		else{
			int k;
			scanf("%d", &k);
			printf("%d\n", t.query(k, k + 1));
		}
	}
	return 0;
}


Measured memory_bytes: 6820
#include<iostream>
#include<string>

using namespace std;

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

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	if (S[K - 1] == 'A') {
		S[K - 1] = 'a';
	}
	else if (S[K - 1] == 'B') {
		S[K - 1] = 'b';
	}
	else {
		S[K - 1] = 'c';
	}
	cout << S << endl;
	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 num = sc.nextInt();

		if(num < 1000) {
			System.out.println("ABC");
		}else {
			System.out.println("ABD");
		}


	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,a[15],p[15],ans;
int main(){
	p[0]=1;
	for (int i=1;i<=10;i++) p[i]=p[i-1]*3;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=0;i<p[n];i++){
		int t=i,cnt=0;
		bool e=false;
		for (int j=0;j<n;j++){
			cnt=a[j];
			if (t%3==0){
				cnt--;
			}else if (t%3==2){
				cnt++;
			}
			if (cnt%2==0) e=true;
			t/=3;
		}
		if (e) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())

pos=[]
for i in range(M):
    array=list(map(int,input().split()))
    pos.append(array)

flg=True
num=[-1 for i in range(N)]

for i in range(M):
    if num[pos[i][0]-1]==-1 or num[pos[i][0]-1]==pos[i][1]:
        if pos[i][0]-1!=0 or pos[i][1]!=0:
            num[pos[i][0]-1]=pos[i][1]
        else:
            if N==1:
                num[pos[i][0]-1]=pos[i][1]
            else:
                flg=False
    else:
        flg=False

for i in range(len(num)):
    if num[i]==-1:
        if i==0:
            if N==1:
                num[i]=0
            else:
                num[i]=1
        else:
            num[i]=0

ans=0
for i in range(N):
    ans+=num[i]*10**(N-i-1)

if flg:
    print(ans)
else:
    print("-1")

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

int main(){
  ll n,k;
  cin >> n >> k;
  ll cnt = 0;
  n -= 1;
  if( n%(k-1) == 0 ){
    cnt = n/(k-1);
  }else{
    cnt = n/(k-1) + 1;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

ans_ls = list(itertools.permutations(range(1,N+1)))
P_num = ans_ls.index(tuple(P))
Q_num = ans_ls.index(tuple(Q))
print(abs(P_num-Q_num))

Measured memory_bytes: 8052
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<int , long long > > sales;
    while(n--){
      int id,code,num;
      cin>>id>>code>>num;
      int i = 0 ;
      for(; i < sales.size();i++){
	if(sales.at(i).first==id){
	  sales.at(i).second += (long long) code * num;
	  break;
	}
      }
      if(i == sales.size()){
	pair<int , long long> worker;
	worker.first = id;
	worker.second = (long long)code * num;
	sales.push_back(worker);
      }
      
    }
    bool found = false;
    rep(i,sales.size()){
      if(sales.at(i).second >= 1000000){
	found = true;
	cout << sales.at(i).first << endl;
      }
    }
    if(!found)
      cout << "NA" << endl;
    
  }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int N,C; cin >> N >> C;
  
  vector<vector<int>> ch(C, vector<int>(100100,0));
  for(int i = 0; i < N; i++){ 
    int s,t,c; cin >> s >> t >> c; c--; s--;
    ch[c][s]++; ch[c][t]--;}
  
  for(int c = 0; c < C; c++){
    for(int j = 0;  j+1 < 100100; j++){
      ch[c][j+1] += ch[c][j];}}
  
  for(int i = 0; i < C; i++){
    for(int j = 0; j < 100100; j++){
      if(ch[i][j]){ ch[i][j] = 1;}}}
  
  ll ans = 0;
  
  for(int i = 0; i < 100100; i++){
    
      ll res = 0;
    
      for(int j = 0; j < C; j++){
        res+= ch[j][i];}
    
    ans = max(ans, res);}
  
  cout << ans << endl; return 0;}
 
                             
                             

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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007;

void main() {
    int x, a;
    scan(x, a);
    writeln(x < a ? 0 : 10);
}























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

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

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

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

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int main(){
    int n, d;
    cin >> n >> d;
    int ans = n / (2 * d + 1);
    if(n % (2 * d + 1) != 0)    ans++;
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main(void){
    long long s = 0;
    long long a = 0;
    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
        long long d, c;
        cin >> d >> c;
        s += d * c;
        a += c;
    }
    if(s % 9 == 0) s--;
    cout << a + s / 9 - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n, m;
	cin>>n>>m;
	ll h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	ll ans=0;
	ll op[n];
	for(int i=0;i<n;i++){
		op[i] = 0;
	}
	ll a[m], b[m];
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		if(h[a[i]-1] > h[b[i]-1]) op[b[i]-1] = 1;
		else if(h[a[i]-1] < h[b[i]-1]) op[a[i]-1] = 1;
		else {
			op[b[i]-1] = 1;
			op[a[i]-1] = 1;
		}
	}
	

	
	for(int i=0;i<n;i++){
		//cout<<op[i]<<" ";
		if(op[i]==0)ans++;
	}
	cout<<ans;
	return 0;
}


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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }
  int pre = -999;
  for (int i = 0; i < N; i++) {
    if (pre <= l[i] - 1) {
      pre = l[i] - 1;
    } else if (pre <= l[i]) {
      pre = l[i];
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

void solve() {
  int n; cin >> n;
  vector<int> k(n), l(n), r(n);
  vector<vector<int>> diff(n);
  ll ans = 0;
  REP(i, n) {
    cin >> k[i] >> l[i] >> r[i];
    ans += r[i];
    if (l[i] > r[i]) diff[k[i] - 1].emplace_back(i);
  }
  int pos = 0;
  vector used(n, false);
  priority_queue<pair<int, int>> que;
  for (int i = n - 1; i >= 0; --i) {
    for (int e : diff[i]) que.emplace(l[e] - r[e], e);
    if (!que.empty()) {
      ans += que.top().first;
      int idx = que.top().second; que.pop();
      ++pos;
      used[idx] = true;
    }
  }
  REP(i, n) {
    if (!used[i] && l[i] >= r[i]) {
      ++pos;
      used[i] = true;
    }
  }
  vector<vector<int>> era(n);
  REP(i, n) {
    if (!used[i]) {
      ans -= r[i];
      ans += l[i];
      if (k[i] < n) era[k[i]].emplace_back(r[i] - l[i]);
    }
  }
  priority_queue<int> que2;
  REP(i, pos) {
    for (int e : era[i]) que2.emplace(e);
  }
  for (; pos < n; ++pos) {
    for (int e : era[pos]) que2.emplace(e);
    if (!que2.empty()) {
      ans += que2.top(); que2.pop();
    }
  }
  cout << ans << '\n';
}

int main() {
  int t; cin >> t;
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 20088
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a
ans = 0
K = int(input())
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = gcd(i,j)
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            a = dp[i][j]
            gcd = dp[a][k]
            if i == j == k:
                ans += gcd
            elif i != j != k:
                ans += gcd * 6
            else:
                ans += gcd * 3  
print(ans)


Measured memory_bytes: 69204
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	int cnt=0;
	if(0<=x) cnt++;
	int pos=0;
	for(int i=0;i<n;i++){
		int tmp;
		scanf("%d",&tmp);
		pos+=tmp;
		if(pos<=x) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fs first
#define sn second
#define mp make_pair
typedef long long int ll;

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}  
template<typename T, typename U> static inline void amax(T &x, U y){if (x < y)x = y;} 

const ll mod = 1e9+7; 

//void precomp(){}

void solve(){
    
    int n,k;cin>>n>>k;ll h[n];for(auto& i: h)cin>>i;
    vector<ll> dp(n,LONG_MAX);
    dp[0]=0;
    for(int i=1;i<n;i++){
    	for(int j=1;j<=k;j++){if(j>i)break;amin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));}
    }
    cout<<dp[n-1]<<"\n";
}

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

    //precomp();
	
	//int tc;cin>>tc;while(tc--)
    solve();

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  map<string, int64_t> strs;
  for(int i = 0; i < N; i++){
  	string s;
    cin >> s;
    sort(s.begin(), s.end());
    strs[s]++;
  }
  
  int64_t count = 0;
  for(auto p : strs){
    string s;
    int64_t c;
    tie(s, c) = p;
    count += c * (c - 1) / 2;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 11136
n = int(input())
h = list(map(int,input().split()))
h.append(0)

ans = 0
flag = False

while True:
  if max(h) == 0:
    break
  for i in range(n+1):
    h[-1] = 0
    if h[i] != 0:
      flag = True
      h[i] -= 1
    else:
      if flag == True:
        ans += 1
      flag = False
    
print(ans)

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int X; cin >> X;

  string ans;
  vector<int> num = {400,600,800,1000,1200,1400,1600,1800};

  for(int i = 0; i < 8; i++){
    if(X >= num[i] && X <= num[i]+199){
      cout << 8 - i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 3620
s = input()
p = input()

tf = "False"

for i in range(len(s)):
    flg = "True"
    for j in range(len(p)):
        if s[(i+j)%len(s)] != p[j]:
            flg = "False"
            break
        
    if flg == "True":
        tf = "True"
        break
    
if tf == "True":
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5560