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

using namespace std;

int main(){
  int N;
  int H[111111];
  int i;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> H[N-i-1];
  int max = 0;
  int s = 0;
  for(i=1;i<=N-1;i++){
    if(H[i]>=H[i-1]) {
      s++;
      if(s > max) max = s;
      }
    else s = 0;
  }
  cout << max << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int a,b,c,temp;
    cin>>a>>b>>c;
    if (a < b){
        temp = b;
        b = a;
        a = temp;
    }
    if ( a < c){
         temp = c;
         c = a;
         a = temp;
    }
    if (c > b){
        temp = c;
        c = b;
        b = temp;
    }
    int result = 0;
    if ((b+c)%2==0){
        result += (abs(b-c))/2;
        result += a-b;
    }
    else{
        a+=1;
        b+=1;
        result += 1;
        result += (abs(b-c))/2;
        result += a-b;
    }
    cout<<result<<endl;
}


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

#define lli long long int

int main()
{
lli h,w;
cin>>h>>w;
vector<string> v(h);
for(int i=0;i<h;i++)
cin>>v[i];
lli m=1000000007;
lli dp[h+1][w+1];
//dp[1][1]=1;
for(int i=0;i<=h;i++)
{
for(int j=0;j<=w;j++)
{
if(i==0||j==0)
dp[i][j]=0;
else if(v[i-1][j-1]=='#')
dp[i][j]=0;
else if(i==1&&j==1)
dp[i][j]=1;
else
/*{
if(v[i][j-1]=='#'&&v[i-1][j]=='#')
dp[i][j]=0;
else if(v[i][j-1]=='#')
dp[i][j]=dp[i-1][j];
else if(v[i-1][j]=='#')
dp[i][j]=dp[i][j-1];
else
dp[i][j]=(dp[i-1][j]+dp[i][j-1])%m;
}*/
dp[i][j]=(dp[i-1][j]+dp[i][j-1])%m;
}
}
cout<<dp[h][w]<<endl;
return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define dl pair <ll, ll>
#define vi vector <int>
#define vl vector <ll>
#define vii vector <ii>
#define graph vector <vi>
#define REP(a, b) for (int i = a; i < b; i++)
#define REP2(a, b) for (int j = a; j < b; j++)
#define REPS(a, b, c) for (int i = a; i < b; i += c)
#define tam 1000001

using namespace std;

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

    int n;
    cin >> n;
    int cont = 0;
    bool band = 0;
    int in1, in2;
    REP(0, n) {
    	cin >> in1 >> in2;
  		if (in1 == in2) cont++;
  		else {
  			if (cont >= 3) band = true;
  			cont = 0;
  		}
    }
    if (cont >= 3) band = true;
    cout << (band ? "Yes" : "No") << "\n";
    return 0;
}


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

int main() {
  int K,S,X;
  int c=0;
  cin >> K >> S;
  for(X=0; X<K+1 && X<S+1; X++){
    if(S-X <= K) c += S-X+1;
    else if(S-X <= 2*K) c += 2*K-(S-X)+1;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,ans
    integer(int64), allocatable:: a(:), l_a(:), r_a(:)

    read*, n
    allocate(a(n),l_a(n), r_a(n))
    read*, a(:)

    l_a(1)=a(1)
    do i = 2, n
        l_a(i) = l_a(i-1)+a(i)
    end do

    r_a(n)=a(n)
    do i = n-1,1,-1
        r_a(i) = r_a(i+1)+a(i)
    end do

    ans = abs(l_a(1)-r_a(2))
    do i=2,n-1
        ans = min(ans, abs(l_a(i)-r_a(i+1)))
    end do
    print'(i0)', ans
end program name

Measured memory_bytes: 5504
from bisect import bisect
S = input()
T = input()

NS = len(S)
NT = len(T)
alp = {}
for i in range(26):
    alp[chr(97+i)] = i
D = [[] for i in range(26)]
for i in range(NS):
    D[alp[S[i]]].append(i)
inf = float("inf")
for i in range(26):D[i].append(inf)
k = 0
l = -1
ans = -1
for i in range(NT):
    index = alp[T[i]]
    if D[index] == [inf]:break
    b = bisect(D[index],l)
    if D[index][b]==inf:
        k += 1
        l = D[index][0]
    else:
        l = D[index][b]
    if i==NT-1:ans = k*NS+l+1
print(ans)

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  int h=1e9+10,l=1;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  while(h > l+1){
    int m = (h+l)/2;
    int ans = 0;
    for(int i=0; i<N; i++){
      ans += (A[i]+m-1)/m - 1;
    }
    if(ans > K) l = m;
    else h = m;
  }
  if(h == 2){
    int ans = 0;
    for(int i=0; i<N; i++){
      ans += (A[i]+h-1)/h - 1;
    }
    if(ans <= K) h = 1;
  }
  cout << h;
  return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

int main() {
	ll a, b, c; cin >> a >> b >> c;

	cout << max((ll)0,c - (a - b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;

ll n, a[int(2e5) + 100];

int main() {
    fast_io;

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    sort(a, a + n);
    reverse(a, a + n);

    ll ans = a[0], cnt = 0, cur = 1;

    for (int i = 2; i < n; ++i)
        if (cnt == 1) {
            cnt = 0;
            ans += a[cur++];
        } else ++cnt, ans += a[cur];

    cout << ans << "\n";
}


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

struct Edge{
    ll target;
    ll weight;
};

struct State{
    ll node;
    ll sum_of_weight;

    bool operator < (const State& s)  const {
        return sum_of_weight > s.sum_of_weight;
    }
};

typedef vector<vector<Edge> > graph;

void dijkstra(graph &g, vector<ll>&d, ll start){

    priority_queue<State> pq;
    pq.push(State{start,0});

    while( pq.size() ){

        State s = pq.top(); pq.pop();

        if( d[s.node] != -1 ) continue;
        d[s.node] = s.sum_of_weight;

        for(auto edge: g[s.node]) {
            if( d[edge.target] != -1 ) continue;
            pq.push(State{edge.target, s.sum_of_weight + edge.weight});

        }
    }

}


int main(){

    ll N;
    cin >> N;

    graph G(N);
    for (int i = 0; i < N; i++)
    {
        ll u,k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            ll v,c;
            cin >> v >> c;
            G[u].push_back(Edge{v,c});
        }
    }

    vector<ll> d(N,-1);

    ll count = 1;
    dijkstra(G,d,0);

    for (int i = 0; i < N; i++)
    {
        cout << i << " " << d[i] << endl;
    }
    
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int x;
  cin >> x;
  
  int res[5000];
  for(int i=0 ; i<5000; ++i) res[i] = 1;

  int a=0;
  for(int i=1; i<=x; ++i){
    for(int j=2; j<=x; ++j){
      int num = pow(i,j);
      if(num > x) break;
      res[a] = num;
      a++;
    }
  }
  int mx = 0;
  for(int i=0; i<5000; ++i){
    mx = max(res[i], mx);
  }
  cout << mx;
}

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	string s[102];
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	int m; cin >> m;
	string t[102];
	for(int i=0;i<m;i++){
		cin >> t[i];
	}
	map<int, int> p;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(s[i]==s[j]){
				p[i]++;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i]==t[j]){
				p[i]--;
			}
		}
	}
	int ans = 0;
	for(auto kv:p){
		if(kv.second>ans){
			ans = kv.second;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007
#define ll long long

int main() {
	ll x;
	cin >> x;
	int n = 0;
	ll a = 100;
	while (a < x) {
		a *= 1.01;
		n++;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 3620
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<lint> zyo,rz;
lint mo=1000000007;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint con(int a,int b){
	//cout<<a<<' '<<b<<endl;
	if(a<0 || b<0) return 0;
	lint out=zyo[a+b]*rz[a];out%=mo;
	return (out*rz[b])%mo;
}
int main()
{
	zyo.pb(1);rep(i,252521) zyo.pb((zyo[i]*(i+1))%mo);
	rep(i,252521) rz.pb(invMod(zyo[i],mo));
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	lint out=con(h-1,w-1);//cerr<<out<<endl;
	rep(i,b){
		if(i<b-1) out-=con(h-a,i)*con(a-2,w-i-1);
		else out-=con(h-a,i)*con(a-1,w-i-1);
		out%=mo;if(out<0) out+mo;
	}
	out%=mo;out+=mo;
	cout<<(out%mo)<<endl;
}


Measured memory_bytes: 5232
import java.util.*;

public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A  = new int[M];
        int[] B  = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = sc.nextInt()-1;
            B[i] = sc.nextInt()-1;
        }

        long[] res = new long[M];

        UnionFind uni = new UnionFind(N);
        res[M-1] = (long)N * (N-1)/2;
        for(int m= M-2; m >=0; m--){
            res[m] = res[m+1];
            if(uni.findLeader(A[m+1]) != uni.findLeader(B[m+1])){
                long sizeA = uni.getGroupSize(A[m+1]);
                long sizeB = uni.getGroupSize(B[m+1]);
                res[m] -= sizeA * sizeB;
                uni.connect(A[m+1],B[m+1]);
            }
        }
        for(long inconv: res)
            System.out.println(inconv);
    }

    static class UnionFind{
        int[] parent;

        UnionFind(int V){
            parent = new int[V];
            Arrays.fill(parent,-1);
        }

        int findLeader(int a){
            if(parent[a] <0) return a;
            return findLeader(parent[a]);
        }

        int getGroupSize(int a){
            int leader = findLeader(a);
            return parent[leader] *-1;
        }

        void connect(int a, int b){
            int leaderA= findLeader(a);
            int leaderB= findLeader(b);
            if(leaderA==leaderB) return;

            if(getGroupSize(leaderA) < getGroupSize(leaderB) ){
                int temp = leaderA;
                leaderA = leaderB;
                leaderB = temp;
            }
            parent[leaderA] += parent[leaderB];
            parent[leaderB] =leaderA;
        }


    }
}


Measured memory_bytes: 93560
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            int d = scan.nextInt();
            if(!list.contains(d)) list.add(d);
        }
        System.out.println(list.size());
        scan.close();
        
    }
}

Measured memory_bytes: 21844
// k - stones
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
ll arr[100005];
ll n, k;


int main() {


	cin >> n >> k;

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

	for (int i  = 1 ; i <= k; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (arr[j] <= i && dp[i - arr[j]] == 0)
				dp[i] = 1;
		}
	}


	if (dp[k] == 1)
		cout << "First" << endl;
	else
		cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 1024
import sys

input=sys.stdin.readline

N=int(input())
ans=0
val=2
for i in range(N):
    a=int(input())
    if i==0:
        ans+=a-1
        val=2
    else:
        if a!=val:
            ans+=(a-1)//val
        else:
            val+=1

print(ans)


Measured memory_bytes: 40684
#include<bits/stdc++.h>
#include<stdio.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb                  push_back
#define arr                 vector<ll>
#define mem(x,val)          memset(x,val,sizeof(x))
#define vp                 vector<pair<ll,ll>>
#define matrix              vector<vector<ll> >
#define digit(x)            floor(log10(x))+1
#define debug(x)            cerr << #x << " is " << x << endl;
#define all(a)              a.begin(),a.end()
#define fixed               setprecision(15)
// ll dx[]={-1,1,0,0},dy[]={0,0,-1,1}; 4 Sides
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};    8 Sides
using namespace std;
vector<ll>a[200002];
ll vis[200002];
set<pair<ll, ll>>z;
ll minx = INT_MAX;
ll maxx = INT_MIN;
ll ans;
void dfs(ll node){
    ans++;
    maxx = max(maxx, ans);
    vis[node] = 1;
    for (auto child: a[node]){
        if (!vis[child]){
            
            dfs(child);
        }
    }
}
arr read(ll n){
     arr a;
    for (ll i=0;i<n;i++){
        ll x;
        cin>>x;
        a.pb(x);
      }
     return a;
 }
 int main(){
     ll n, m;
     cin>>n>>m;
     for (ll i=0;i<m;i++){
         ll x,y;
         cin>>x>>y;
         if (x > y){
             swap(x, y);
         }
         z.insert({x,y});
     }
     for (auto x:z){
         a[x.first].pb(x.second);
         a[x.second].pb(x.first);
     }
     ll cnt=0;
     for (ll i=1;i<=n;i++){
         if (!vis[i]){
             cnt++;
             ans=0;
             dfs(i);
         }
     }
     cout<<maxx<<endl;
    return 0;
    }


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

int main(){
    int N,Y;
    cin >> N >> Y;
    int x,y,z;
    for(x=0;x<=N;++x){
        for(y=0;y<=N;++y){
            z = Y-10000*x-5000*y;
            if(x+y+z/1000==N && z>=0){
                cout << x << ' ' << y << ' ' << z/1000 << endl;
                break;
            }
        }
        if(x+y+z/1000==N && z>=0) break;
    }
    if(x==N+1){
        cout << -1 << ' ' << -1 << ' ' << -1 << endl;
    }
    return 0;
}

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

int main()
{
    int t,n,i,j,k,x,y,z,p,q,r,count=0,flag=0;
    cin>>n;
    while(n>0){
    	r=n%10;
    	if(r==7){
    		flag=1;
    		break;
		}
		n=n/10;
	}
	if(flag==1)
		cout<<"Yes";
	else
		cout<<"No";
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	int a[200010] = {};
	for (int i = 0; i < n; i++) {
		int p; cin >> p; a[p]++;
	}
	sort(a, a + 200001);
	int ans = 0;
	for (int i = 200000 - k; a[i] > 0; i--)ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 1656
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

float kion(int T, int x){
    return T - x * 0.006;
}

int main(){
    int n, t, a;
    float min = 6000;
    int ans = 0;
    cin >> n >> t >> a;
    int h[n];
    for(int i=0;i<n;i++)
        cin >> h[i];

    for(int i=0;i<n;i++) {
        if(abs(kion(t, h[i])-a) < abs(min)) {
            min = abs(kion(t, h[i]) - a);
            ans = i;
        }
    }

    cout << ans + 1 << endl;

    return 0;
}


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

const int N = 605;
typedef long long ll;

char a[N][N];
bool f[N][N][N];
int ans, n;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++) {
			cin>>a[i][j];
			a[i + n][j + n] = a[i + n][j] = a[i][j + n] = a[i][j];
			f[i][j][0] = f[i + n][j + n][0] = f[i + n][j][0] = f[i][j + n][0] = 1;
		}
	for(int k = 1; k < n; k++)
		for(int i = 1; i <= 2*n && i + k <= 2*n; i++)
			for(int j = 1; j <= 2*n && j + k <= 2*n; j++) 
				if(a[i][j + k] == a[i + k][j]) f[i][j][k] = f[i][j][k - 1];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			bool ok = 1;
			for(int k = 0; k < n; k++)
				if(!f[i + k][j + k][n - k - 1]) {
					ok = 0;
					break;
				}
			if(ok) ans++;
		}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> k(M),p(M);
  vector<vector<ll>> s(M,vector<ll>());
  for(ll i=0;i<M;++i){
    cin >> k[i];
    for(ll j=0;j<k[i];++j){
      ll tmp;
      cin >> tmp;
      s[i].push_back(tmp);
    }
  }
  for(ll i=0;i<M;++i) cin >> p[i];
  //bit全探索
  int ans=0;
  for(int bit=0;bit<(1<<N);++bit){
    bool flag = true;
    bitset<10> bs(bit);
    for(ll i=0;i<M;++i){
      int tmp=0;
      for(ll j=0;j<k[i];++j){
        tmp += bs[s[i][j]-1];
      }
      if(tmp%2==p[i]) continue;
      else {
        flag = false;
        break;
      }
    }
    if(flag) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for(int i = 0; i < (int)(n) ; i++)

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

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


map<string, int> memo;

int dfs(string s, int depth) {
    if (s.size() == 1)return 0;
    if (memo.count(s)) return memo[s];
    int ans = 1e9;
    for (int i = 0; i < s.size() - 1; i++) {
        int x = s[i] + s[i + 1] - 2 * '0';
        string t = s.substr(0, i);
        if (x >= 10) t += '1';
        t += x % 10 + '0';
        t += s.substr(i + 2);
        ans = min(ans, dfs(t, depth + 1) + 1);
    }

    return memo[s] = ans;
}


map<string, int> memo2;

int dfs2(string s, int depth) {
    if (s.size() == 1)return 0;
    if (memo2.count(s)) return memo2[s];
    int ans = -1e9;
    for (int i = 0; i < s.size() - 1; i++) {
        int x = s[i] + s[i + 1] - 2 * '0';
        string t = s.substr(0, i);
        if (x >= 10) t += '1';
        t += x % 10 + '0';
        t += s.substr(i + 2);
        ans = max(ans, dfs2(t, depth + 1) + 1);
    }

    return memo2[s] = ans;
}



pair<ll,vector<int>> compress(int dig, ll count) {
    if( count == 0 ) return {0,{}};
    
    if( dig + dig >= 10 ){
        auto r = compress(dig + dig - 9, count / 2);
        r.first += count / 2 * 2;
        if(count%2){
            r.second.push_back(dig);
        }
        return {r.first, r.second};
    }else{
        auto r = compress(dig + dig, count / 2);
        r.first += count / 2;
        if(count%2){
            r.second.push_back(dig);
        }
        return {r.first, r.second};
    }    
}

ll naive(vector<int> d){
    ll ans = 0;
    while( d.size() > 1 ){
        int x = d[d.size()-1] + d[d.size()-2];
        if( x < 10){
            d.pop_back();
            d[d.size()-1] = x;
        }else{
            d[d.size()-2] = 1;
            d[d.size()-1] = x % 10;
        }
        ans++;
    }
    return ans;
}


long long calc(string s) {

    int sum = 0;
    for (int i = 0; i < s.size(); i++) sum += s[i] - '0';

    return s.size() + 1 + sum / 10;
}

vector<int> cnv(string s){
    vector<int> res;
    for( auto x : s ){
        res.push_back(x-'0');
    }
    return res;
}
void solve(long long M, std::vector<long long> d, std::vector<long long> c) {
   
    long long tot = 0;
    vector<int> seq;
    for (int i = 0; i < c.size(); i++) {
        auto r = compress(d[i], c[i]);
        tot += r.first;
        seq.insert(seq.end(), r.second.begin(), r.second.end());
    }
 
    cout << tot + naive(seq) << endl;
}
 
 

int main() {
    long long M;
    scanf("%lld", &M);
    std::vector<long long> d(M);
    std::vector<long long> c(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &d[i]);
        scanf("%lld", &c[i]);
    }
    solve(M, std::move(d), std::move(c));
    return 0;
}



Measured memory_bytes: 30112
N,M = map(int,input().split())
if N == 1 and M == 1:
    print(1)
elif N == 2 or M == 2:
    print(0)
elif N == 1:
    print(M-2)
elif M == 1:
    print(N-2)
else:
    print((N-2) * (M-2))

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

typedef std::string::const_iterator State;
class ParseError {};

using namespace std;

int expression(State&);
int term(State&);
int number(State&);
int factor(State&);
void consume(State&);

// begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
            << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

int expression(State &begin) {
	int ret = term(begin);
	//cout << "e:" << *begin << endl;
	while(1) {
		if(*begin == '+') {
			begin++;
			ret += term(begin);
		} else if(*begin == '-') {
			begin++;
			ret -= term(begin);
		} else {
			break;
		}
	}
	
	return ret;
}

int term(State &begin) {
	int ret = factor(begin);
	//cout << "t:" << *begin << endl;
	while(1) {
		if(*begin == '*') {
			begin++;
			ret *= factor(begin);
		} else if(*begin == '/') {
			begin++;
			ret /= factor(begin);
		} else {
			break;
		}
	}
	
	return ret;
}

int number(State &begin) {
	int ret = 0;
	//cout << "n:" << *begin << endl;
	while(isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	
	return ret;
}

int factor(State &begin) {
	//cout << "f:" << *begin << endl;
	if(*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
	} else {
		return number(begin);
	}
}

int main() {
	int n;
	cin >> n;
	cin.ignore();
	for(int i=0; i<n; ++i) {
		string s;
		getline(cin, s);
		
		State begin = s.begin();
		int ans = expression(begin);
		consume(begin, '=');
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3204
import static java.lang.Math.*;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		int[] dp = new int[N];
		dp[N - 2] = abs(h[N - 2] - h[N - 1]);
		for (int i = N - 3; i >= 0; i--) {
			dp[i] = min(dp[i + 1] + abs(h[i + 1] - h[i]), dp[i + 2] + abs(h[i + 2] - h[i]));
		}

		out.println(dp[0]);
		sc.close();

	}

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

}


Measured memory_bytes: 48948
#include <bits/stdc++.h>
#define N 301
using namespace std;
typedef complex <double> P;
const double EPS = 1e-8;
P p[N];
int n;

int cnt(P c){
  int res=0;
  for(int i=0;i<n;i++)if(abs(c-p[i])<1+EPS) res++;
  return res;
}

P get_C(P a,P b){
  double x=abs(b-a);
  if(x>2||a==b) return a;
  return P(x/2,sqrt(1-x*x/4))*(b-a)/abs(b-a)+a;  
}


int main(){
  while(1){
  cin>>n;
  if(!n)break;
  double a,b;
  for(int i=0;i<n;i++)cin>>a>>b,p[i]=P(a,b);
  
  int ans=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      ans=max(ans,cnt(get_C(p[i],p[j])));
  cout <<ans<<endl;  
  }
  return 0;
}

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

int grcdiv(int a, int b) {
    return b == 0 ? a : grcdiv(b, a % b);
}

int main() {
    int n1, n2;
    cin >> n1;
    cin >> n2;

    cout  << grcdiv(abs(n1), abs(n2)) << endl;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=1000000007;
const int N=75;
int C[N*5][N*5];
int n,k,ans,used[N];
int q1[N],q2[N],suf[N];
int f[N][N];
char s[N];
void init(){
	For(i,0,N*5-1) C[i][0]=1;
	For(i,1,N*5-1) For(j,1,i)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
}
void solve(int S1,int S2){
	if (!S1&&!S2) return ++ans,void(0);
	if ((S1+S2)*2>n+1||S1+2*S2>k) return; 
	memset(used,0,sizeof(used));
	int h=0,t=*q2=0;
	For(i,1,k)
		if (s[i]=='r') q1[++t]=i;
		else if (s[i]=='b'&&h!=t&&*q2!=S2)
			used[q1[++h]]=used[i]=1,q2[++*q2]=i;
	if (*q2!=S2) return;
	For(i,1,S1)
		if (h==t) return;
		else used[q1[++h]]=1;
	Rep(i,k,1) suf[i]=suf[i+1]+(!used[i]);
	For(i,1,S2) q2[i]=suf[q2[i]];
	memset(f,0,sizeof(f));
	f[0][0]=1;
	int upp=max(2,n)+1;
	For(i,2,upp) Rep(j,S2-1,0) For(k,2*j,upp-i*(S2-j)){
		int psum=k-2*j;
		For(l,1,min(S2-j,(upp-k)/i)){
			if ((psum+=i-2)>q2[S2-j-l+1]) break;
			f[j+l][k+i*l]=(f[j+l][k+i*l]+1ll*C[j+l][l]*f[j][k])%mo;
		}
	}
	For(k,0,upp){
		int sum=2*S1+2*k-2*S2-1;
		int par=2*S1+2*k+1;
		if (sum&&sum<=n&&f[S2][k])
			ans=(ans+1ll*f[S2][k]*C[n-sum+par-1][par-1]%mo*C[S2+S1][S2])%mo;
	}
}
int main(){
	init();
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	For(S1,0,n) For(S2,0,n) solve(S1,S2);
	printf("%d\n",ans);
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
//ll a[SZ];
//ll b[SZ];
vector <ll> adj[SZ];
bool vis[SZ];

void dfs(ll u) {
    if(vis[u]) return;
    vis[u] = 1;

    for(auto v: adj[u]) {
        dfs(v);
    }
}

int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin2(n, q);

    while(q--) {
        cin3(x, y, z);
        adj[x].pb(y);
        adj[y].pb(x);
    }

    for1(i, n) {
        if(!vis[i]) {
            c++;
            dfs(i);
        }
    }

    cot1(c);

    return 0;
}



Measured memory_bytes: 19256
N,M = map(int, input().split())
A = [int(input()) for _ in range(M)]

mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
a = -1
if len(A):
    a = A.pop(0)
    if a == 1:
        dp[1] = 0

        
for i in range(1, N):
    if a == -1 and len(A):
        a = A.pop(0)
    if i == a:
        dp[i] = 0
        dp[i+1] = dp[i-1]
        a = -1
    else:
        dp[i+1] = dp[i] + dp[i-1]
        
print(dp[N]%mod)

Measured memory_bytes: 460020
function main(input) {
    const splitInput = input.split(' ');
    if((splitInput[0] * splitInput[1]) % 2 === 0) {
        //偶数
        console.log('Even');
    } else {
        //奇数
        console.log('Odd');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU 

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi Height(10);
	REP(i, 10) {
		cin >> Height[i];
	}
	so(Height); rev(Height);
	REP(i, 3) {
		cout << Height[i] << endl;
	}
	PAU;
	return 0;
}



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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

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

    int n;
    cin >> n;

    cout << n * n * n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define rep(i,n,b) for(int i=0;i<n;i=i+b)
#define ld long double 
using namespace std;
int main()
{ 
    int n,x,y;
    cin >> n >> x >> y;
    cout << y * (int)ceil((double)n/(double)x);
}


Measured memory_bytes: 3620
#import sys
import numpy as np

#input = sys.stdin.readline
MOD = 1000000007


N = int(input())

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

M = {}
res = 0
for i in range(len(A)):
    if (A[i]+i) not in M:
        M[A[i]+i] = 1
    else:
        M[A[i]+i] +=1
    
    if (i - A[i]) in M:
        res+=M[i-A[i]]

print(res)


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

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

    bool a = false, b = false;

    string s;   cin >> s;

    for(auto &c : s) {
        if(c == 'A') {
            a = true;
        } else {
            b = true;
        }
    }

    if(!a || !b) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOREACH(element, vec_name) for (auto &(element) : (vec_name))

#define VECCIN(vec_name) for (auto &element : (vec_name)) cin >> element

typedef long long ll;

const int INF = 1e9;

int main()
{
    int i = 0;
    int n,l;
    cin >> n;
    vector<int> p(n);
    VECCIN(p);
    int num = INF;
    int ans = 0;
    FOREACH(e,p){
        if(e<=num){
            num = e;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main()
{
	for(int n;cin>>n && n;){
		vector<string> ss(n);
		for(int i=0;i<n;i++) cin>>ss[i];
		
		for(int i=0;i<n;i++){
			for(int j=ss[i].size();j--;)
				if(ss[i][j]=='.'){
					ss[i][j]='+';
					break;
				}
			replace(begin(ss[i]),end(ss[i]),'.',' ');
		}
		for(int i=0;i<n;i++) for(int j=0;j<ss[i].size();j++){
			if(ss[i][j]!='+') continue;
			for(int k=i+1;k<n;k++){
				if(j>=ss[k].size() || islower(ss[k][j])) break;
				if(ss[k][j]=='+'){
					for(int l=i+1;l<k;l++)
						ss[l][j]='|';
					break;
				}
			}
		}
		for(int i=0;i<n;i++) cout<<ss[i]<<endl;
	}
}

Measured memory_bytes: 1852
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 

using namespace std;

int n;
char s[200010];
int a, b, c, d;
int posA, posB;

bool moveIn(int &pos, char ch)
{
	if (s[pos + 1] == '.') {
		s[pos] = '.';
		s[pos + 1] = ch;
		pos++;
	} else if (s[pos + 2] == '.') {
		s[pos] = '.';
		s[pos + 2] = ch;
		pos += 2;
	} else {
		return false;
	}
	return true;
}

bool move(int src, int target, char ch)
{
	int p = src;
	while (p < target) {
		if (false == moveIn(p, ch))
			return false;
	}
	
	if (p == target)
		return true;
	else
		return false;
}

int main()
{
	scanf("%d%d%d%d%d\n", &n, &a, &b, &c, &d);
	scanf("%s", s);
	int len = strlen(s);
	for (int i = len ; i >= 1 ; i--)
		s[i] = s[i - 1];
	s[0] = ' ';
	
	posA = a;
	posB = b;
	s[a] = 'A';
	s[b] = 'B';
	
//	if (c < d)
//	{
//		int temp;
//		temp = c;
//		c = d;
//		d = temp;
//		
//		temp = a;
//		a = b;
//		b = temp;
//	}	
	
	if (c < d)
	{
		//先移动b
		if (move(b, d, 'B')) {
			if (move(a, c, 'A')) {
				printf("Yes\n");
				return 0;
			} else {
				printf("No\n");
				return 0;				
			}
		} else {
			printf("No\n");
			return 0;
		}
	}
	else
	{
		//先移动a，设法让a跳过b去
		posA = a;
		posB = b;
		while ((posA < c) && (posB < d))
		{
			if (moveIn(posA, 'A')) {
				continue;
			} else {
				if (posA > posB) {
					printf("No\n");
					return 0;
				}
				
				if (moveIn(posB, 'B')) {
					continue;
				} else {
					printf("No\n");
					return 0;
				}
			}
		}
		
		if ((posA > c) || (posB > d)) {
			printf("No\n");
			return 0;
		}
		
		if (posA == c)
		{
			if (posB <= d) {
				if (move(posB, d, 'B')) {
					printf("Yes\n");
					return 0;
				} else {
					printf("No\n");
					return 0;
				}
			} else {
				printf("No\n");
				return 0;
			}
		} else {
			if (move(posA, c, 'A')) {
				printf("Yes\n");
				return 0;
			} else {
				printf("No\n");
				return 0;
			}
		}
	}
	
	printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 

    int N,M;
    cin>>N>>M;
    vector<int> V(N);
    for(int i=0;i<N;i++) cin>>V[i];

    int same[110000]={},num[110000]={};

    sort(V.begin(),V.end());
    for(int i=0;i<N-1;i++){
        if(V[i]==V[i+1]){
            same[V[i]%M]++;
            i++;
        }
    }
    for(int i=0;i<N;i++){
        num[V[i]%M]++;
    }
    int ans=0;
    for(int i=0;i<=M/2;i++){
        if(i*2%M==0){
            ans+=num[i]/2;
        }else{
            int x=M-i;
            int n=min(num[i],num[x]);
            num[i]-=n; num[x]-=n;
            ans+=n;
            ans+=min(num[i]/2,same[i]);
            ans+=min(num[x]/2,same[x]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long  a,x,n;
    cin >> x;
    a = 100;
    n = 0;
    while ( a < x){
        a += a/100;
        n++;
    }
    cout << n;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define int ll
using ll = long long;
using pii = pair<int,int>;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> a(n),b(n);
   set<pii> sa,sb;
   f(i,0,n){
      cin >> a[i];
      sa.insert({a[i],i});
   }
   f(i,0,n){
      cin >> b[i];
      sb.insert({b[i],i});
   }
   vector<int> val1(n,0),val2(n,0);
   while(!sa.empty()){
      auto k = sa.end();
      k--;
      sa.erase(k);
      int in = (*k).S;
      int sm = a[(in-1+n)%n]+a[(in+1)%n];
      if(!sm) continue;
      int kk = a[in]/sm;
      if(kk){
         a[in] -= kk*sm;
         val1[in] += kk;
         sa.insert({a[in],in});
      }
   }
   while(!sb.empty()){
      auto k = sb.end();
      k--;
      sb.erase(k);
      int in = (*k).S;
      int sm = b[(in-1+n)%n]+b[(in+1)%n];
      if(!sm) continue;
      int kk = b[in]/sm;
      if(kk){
         b[in] -= kk*sm;
         val2[in]+=kk;
         sb.insert({b[in],in});
      }
   }


   int ans = 0;
   f(i,0,n){
      if(a[i]!=b[i]){
         cout << "-1\n";
         return 0;
      }
      ans += val2[i];
      ans -= val1[i];
   }
   cout<< ans << '\n';
   return 0;
}

Measured memory_bytes: 33536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')yes;
    else no;
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int M = 1e9 + 7;
const int MAXN = 2e5+100;
int N;
ll a[MAXN];

void read(){
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
}

void solve(){
    read();
    vector<ll> prefix(N+1, 0);
    for(int i = 1; i <= N; i++){
        prefix[i] = (prefix[i-1] + a[i]) % M;
    }
    ll ans = 0;
    for(int i = N; i > 0; i--){
        ans = (ans + ((prefix[i-1] * a[i]) % M))%M;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k, h[100010];
ll dp[100010];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> h[i];
    rep(i, 100010) dp[i] = LLINF;
    dp[0] = 0;

    rep(i, n) {
        for (int j = 1; j <= k; j++) {
            if (i + j < n) chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll N,K;
  cin>>N>>K;
  ll ans = min(N%K,(K-N%K));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    int h[101]{};
    while (n != 0) {
        for (int i = 0; i <= n; i++) {
            cin >> h[i];
        }
        for (int i = 0; i <= n; i++) {
            vector<int> a;
            for (int j = 0; j <= n; j++) {
                if (i != j) {
                    a.push_back(h[j]);
                }
            }
            bool flag = true;
            for (int i = 0; i < n - 1; i++) {
                if (a[1] - a[0] != a[i + 1] - a[i]) {
                    flag = false;
                }
            }
            if (flag) {
                cout << h[i] << "\n";
                goto loop;
            }
        }
        loop:
        cin >> n;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    if((A==5 && B==5 && C==7) ||(A==5 && B==7 && C==5)||(A==7 && B==5 && C==5) ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
        
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#if 0
void debug(vector<int>& v) {
  cout << __LINE__ << ":vector<int>(" << v.size() << ") ";
  rep(i, (int)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
#else
void debug(vector<int>& v) {
}
#endif

int main(int argc, const char * argv[]) {
  int n = inputValue();
  vector<int> arr;
  inputVector(&arr, n);
  vector<int> nonsorted;
  debug(arr);
  rep(i, n-1) {
    if (arr[i] < arr[i+1]) {
    } else {
      nonsorted.push_back(i);
    }
  }
  debug(nonsorted);
  if (nonsorted.size() == 0) {
    cout << "YES" << endl;
    return 0;
  }
  if (nonsorted.size() > 2) {
    cout << "NO" << endl;
    return 0;
  }
  int t = arr[nonsorted[0]];
  arr[nonsorted[0]] = arr[nonsorted[1]+1];
  arr[nonsorted[1]+1] = t;
  debug(arr);
  rep(i, n-1) {
    if (arr[i] < arr[i+1]) {
    } else {
      cout << "NO" << endl;
      return 0;
    }
  } 
    
    cout << "YES" << endl;
    // source code
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = sorted(int(a) for a in input().split())

# エラトステネスの篩
max_A = A[-1]
search_list = [True for _ in range(max_A)]

count = 0
for i, a in enumerate(A):
    if not search_list[a - 1]:
        continue
    for j in range(a, max_A + 1, a):
        search_list[j - 1] = False
    if i < N - 1 and A[i + 1] == a:
        continue
    count += 1

print(count)


Measured memory_bytes: 32292
#include<iostream>
#include <algorithm>
  
using namespace std;
  
void triangleCal()
{
    int n;
    int side[3];
   
    cin >>n;
     
    while(n--)  //instead of "for"
    {
        cin >>side[0]>>side[1]>>side[2]; 
         
        sort(side, side+3); // sort data by ascending order
         
       if(side[2] * side[2] == side[1] * side[1] + side[0] * side[0]) 
       {
           cout <<"YES"<<endl;
       }
       else
       {
           cout <<"NO"<<endl;
       }
    }
     
    return;
}
    
int main(){
    
    triangleCal();
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()
{       
    IOS;
   	ll n;
   	cin>>n;
   	vector<ll> v(n+1);
   	map<ll,ll> mp;
   	for(ll i=1;i<=n;i++)
   	{
   		cin>>v[i];
   		mp[v[i]]=i;
   	}
   	ll ans=0;
   	ll left=mp[1];
   	ll right=n-mp[1]+1;
   	ans=left*right;
   	set<ll> s;
   	s.insert(mp[1]);
   	for(ll i=2;i<=n;i++)
   	{
   		ll left=0;
   		ll right=0;
   		s.insert(mp[i]);
   		auto it=s.find(mp[i]);
   		auto it1=s.find(mp[i]);
   		it1--;
   		if(it==s.begin())
   			left=mp[i];
   		else
   			left=(mp[i]-*it1);
   		it++;
   		if(it==s.end())
   			right=(n-mp[i]+1);
   		else
   			right=(*it-mp[i]);
   		ans+=left*right*i;
   	}
   	cout<<ans;
}    

Measured memory_bytes: 23680