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

using namespace std;
typedef long long ll;

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

  string s;
  cin >> s;

  int count = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == '1') count++;
  }

  cout << count << "\n";
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <math.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int T, A;
  scanf("%d %d", &T, &A);

  int H[1000];
  int tmpI;
  double tmpT = 100000.0;
  for(int i = 0; i < N; i++) {
    scanf("%d", &H[i]);
    double Ti = T - (H[i] * 0.006);
    if(fabs(A - Ti) < tmpT) {
      tmpT = fabs(A - Ti);
      tmpI = i;
    }
  }
  printf("%d\n", tmpI + 1);
  
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  if(s.find("a") != s.rfind("a")||s.find("b") != s.rfind("b")||s.find("c") != s.rfind("c")) puts("No");
  else puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> A(N, 0);
  ll ans = 0;
  ll cur = 0;
  REP(i, N){
    cin >> A[i];
    if(i != 0){
      if(A[i-1] > A[i]){
        ans += A[i-1]-A[i];
        A[i] = A[i-1];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4784
#include<map>
#include<set>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
#define IT iterator
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

//math
ll mult(ll a,ll b,ll p) {
	a=(a%p+p)%p; b=(b%p+p)%p;
	ll c=(ld)a*b/p;
	return a*b-c*p;
}
ll gcd(ll a,ll b) {return !a?b:gcd(b%a,a);}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}
ll Power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=mult(c,a,mod);
		b /= 2; a=mult(a,a,mod);
	}
	return c;
}

int main() {
	int a,b,c,d,e;
	qr(a); qr(b); qr(c); qr(d); qr(e);
	pr2(c*60+d-(a*60+b)-e);
	return 0;
}




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

struct Point {
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }

    Point operator-(const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }

    double operator*(const Point &rhs) const {
        return x * rhs.x + y * rhs.y;
    }

    double operator%(const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }

    bool operator<(const Point &rhs) const {
        return x == rhs.x ? y < rhs.y : x < rhs.x;
    }
};

double diameter(const vector<Point> &p) {
    int n = (int)p.size();
    int j = -1;
    for (int i = 0; i < n; ++i) {
        if (j == -1 || (p[0] - p[j]) * (p[0] - p[j]) < (p[0] - p[i]) * (p[0] - p[i])) j = i;
    }
    double res = (p[0] - p[j]) * (p[0] - p[j]);
    for (int i = 1; i < n; ++i) {
        while ((p[i] - p[j]) * (p[i] - p[j]) <= (p[i] - p[(j + 1) % n]) * (p[i] - p[(j + 1) % n])) j = (j + 1) % n;
        res = max(res, (p[i] - p[j]) * (p[i] - p[j]));
    }
    return sqrt(res);
}

int main() {
    int n; scanf("%d", &n);
    vector<Point> p(n);
    for (int i = 0; i < n; ++i) scanf("%lf%lf", &p[i].x, &p[i].y);
    printf("%.20lf\n", diameter(p));
}



Measured memory_bytes: 4088
n=int(input())
a=[0]*n
a=input().split()
ans=1
for i in range(0,n):
    a[i]=int(a[i])
    if a[i]==0:
        ans=0
        break
if ans!=0:
  for i in range(0,n):
    ans=ans*a[i]
    if ans>1000000000000000000:
        ans=-1
        break
print(ans)


Measured memory_bytes: 89468
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) = {
    val n = readLine.map(_.toInt)
    val as = readLine.split(" ").map(_.toLong)
    if (as.count(x => x < 0) % 2 == 0) {
      println(as.map(Math.abs).sum)
    } else if (as.count(x => x <= 0) % 2 == 0) {
      println(as.map(Math.abs).sum)
    } else {
      val abs = as.map(Math.abs)
      println(abs.sum - abs.min * 2)
    }
  }
}


Measured memory_bytes: 53012
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int m = scanner.nextInt();
      if (m == 0) {
        break;
      }
      int n = scanner.nextInt();
      int cc = 0;
      for (int ii = m; ii <= n; ii++) {
        int c = ii;
        for (; ;) {
          if (c % 5 == 0) {
            c /= 5;
            continue;
          }
          if (c % 3 == 0) {
            c /= 3;
            continue;
          }
          if (c % 2 == 0) {
            c /= 2;
            continue;
          }
          if (c == 1) {
            cc++;
            break;
          }
          break;
        }
      }
      System.out.println(cc);
    }
  }
}

Measured memory_bytes: 19032
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int i = 1;
	while((i*2)<=n){
		//if(i>=n) break;
		i = i*2;
	}
	cout << i << endl;
	return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,p,flag=0;
    cin >> n >> p;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2) flag = 1;
    }
    if(flag) cout << long(pow(2,n-1)) << endl;
    else{
        if(p==0) cout << long(pow(2,n)) << endl;
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int nxt[100000][26];



long long solve() {
	string s, t;
	cin >> s >> t;

	int nx[26];
	memset(nx, -1, sizeof(nx));


	rep(_,2) {
		for (int i = s.size() - 1; i >= 0; i--) {
			rep(j, 26)nxt[i][j] = nx[j];
			nx[s[i] - 'a'] = i;
		}
	}


	int p = s.size() - 1;
	long long ret = 0;

	rep(i, t.size()) {
		int ch = t[i] - 'a';
		if (nxt[p][ch] == -1)return -1;

		if (p < nxt[p][ch]) {
			ret += nxt[p][ch] - p;
		}
		else {
			ret += s.size() - p + nxt[p][ch];
		}
		p = nxt[p][ch];
	}

	return ret;
}


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

	cout << solve() << endl;



	return 0;
}

Measured memory_bytes: 10704
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int f = 0;
		for (int i = 0; i < n; i++) {
			long a = scanner.nextLong();
			if(a % 2 != 0){
				f++;
			}
		}
		if(f % 2 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 32744
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(float,input().split()))

dp=[[0]*(N+1) for i in range(N+1)]

dp[0][0]=1
for n in range(N):
    for i in range(n+1):
        j=n-i
        dp[j][i+1]+=dp[j][i]*P[n]
        dp[j+1][i]+=dp[j][i]*(1-P[n])

ans=0
for i in range((N+1)//2):
    ans+=dp[i][-i-1]

print(ans)


Measured memory_bytes: 290824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況


int main() {
    // // input
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) {
        cin >> h[i];
    }
    // solve
    int cnt = 0;
    // rep(i, n) {
    //     if (h[i] == 0) continue;
    //     while (h[i] != 0) {
    //         for (int l = i; l < n; l++) {
    //             if (h[l] == 0) break;
    //             h[l]--;
    //         }
    //         cnt++;
    //     }
    // }
    rep(i, n) {
        if (i == 0) {
            cnt += h[i];
        } else if (h[i] > h[i-1]) {
            cnt += h[i] - h[i-1];
        }
    }
    // output
    cout << cnt << "\n";
}

Measured memory_bytes: 3620
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A =[list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
    flag_AC = 0
    for j in range(M):
        flag_AC += A[i][j]*B[j]
    ans+= int(flag_AC+C>0)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;

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

  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
    
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }

    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }

    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }

  return 0;
}



  

Measured memory_bytes: 576
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = collections.Counter(["".join(sorted(str(input().rstrip('\n')))) for _ in range(n)])
    t = 0
    for k, v in s.items():
        for i in range(1, v):
            t += i
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 64092
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100005];
int Abs(int x){
	return x<0 ? (-x) : x;
}
int calc(int x){
	return min(Abs(x-a[n]/2),Abs(x-(a[n]/2+1)));
}
int cal2(int x){
	return Abs(x-a[n]/2);
}
int main(){
	//freopen("d.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	int ans=-1;
	if(a[n]%2){
		for(int i=1;i<n;++i){
			if(calc(a[i])<calc(ans)){
				ans=a[i];
			}
		}
	}
	else{
		for(int i=1;i<n;++i){
			if(cal2(a[i])<cal2(ans)){
				ans=a[i];
			}
		}
	}
	printf("%d %d\n",a[n],ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
const int MAX_N = 1e5+10;

struct Edge { int to, id; };
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if(u == p) continue;
    if(k == c) ++k;
    ans[ei] = k; ++k;
    dfs(u, ans[ei], v);
  }
}

int main() {
  int N; cin >> N;
  g.resize(N);
  ans = vector<int>(N-1);
  rep(i, N-1) {
    int a, b; cin >> a >> b; a--, b--;
    g[a].push_back((Edge){b, i});
    g[b].push_back((Edge){a, i});
  }

  int mx = 0;
  rep(i, N) {
    mx = max(mx, int(g[i].size()));
  }
  cout << mx << endl;

  dfs(0);

  rep(i, N-1) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int h[10];
    for (int i=0; i<10; ++i) cin>>h[i];
    partial_sort(h, h+3, h+10, greater<int>());
    cout<<h[0]<<endl<<h[1]<<endl<<h[2]<<endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e4+7;
int a[N]={2,10,3,9,4,8,6,12};
int b[N]={6,2,10,3,9,4,8,12};
int main(){
	int n;
	cin>>n;
	if(n==3){
		puts("2 5 63");
		return 0;
	}
	else if(!(n&1)){
		for(int i = 8;i<n;i++) a[i]=a[i-8]+12;
		for(int i = 0;i<n;i++) printf("%d ",a[i]);
	}
	else {
		for(int i = 8;i<n;i++) b[i]=b[i-8]+12;
		for(int i = 0;i<n;i++) printf("%d ",b[i]);
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll W,n;
vector<ll>wt,val;
vector<vector<ll> >k(0,vector<ll>(0,0));
ll knapsack(){
        k.assign(n+1,vector<ll>(W+1,0));
        for(ll i=1;i<=n;i++)
            for(ll w=1;w<=W;w++)
                if(wt[i-1]<=w)
                    k[i][w]=max(val[i-1]+k[i-1][w-wt[i-1]],k[i-1][w]);
                else
                    k[i][w]=k[i-1][w];
        return k[n][W];

}
int main(){
    while(cin>>n>>W){
        val.resize(n);
        wt.resize(n);
        for(ll i=0;i<n;i++)
            cin>>wt[i]>>val[i];
        ll res=knapsack();
        cout<<res<<endl;
    }

    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

ll choose(ll n, ll r) {
  if (r < 0 || r > n) return 0;
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for (ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main(){
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  rep(i, N) a[i]--;

  vector<ll> que(N + 1, 0);
  rep(i, N) que[a[i]]++;
  ll ans = 0;
  rep(i, N) ans += choose(que[i], 2);
  rep(i, N){
    cout << ans - choose(que[a[i]], 2) + choose(que[a[i]] - 1, 2) << endl;
  }
}


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

int main() {
  vector<ll> ABC(3);
  rep(i,0,3) cin >>ABC[i];
  sort(ABC.begin(),ABC.end());
  ll temp=ABC[2]/2;
  ll ans=ABC[0]*ABC[1]*(ABC[2]-temp)-ABC[0]*ABC[1]*temp;
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3604
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=3e3+1;
const ll INF=1e9;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n,a[N],dp[N][N][2];

ll F(ll i,ll j,ll turn)
{
	if(i>j){return 0;}
	if(dp[i][j][turn]!=-1){return dp[i][j][turn];}
	if(turn){return dp[i][j][turn]=max(a[i]+F(i+1,j,turn^1),a[j]+F(i,j-1,turn^1));}
	else{return dp[i][j][turn]=min(-a[i]+F(i+1,j,turn^1),-a[j]+F(i,j-1,turn^1));}
}

int main()
{
	cin>>n;
	ms(dp,-1);
	for(ll i=1;i<=n;i++){cin>>a[i];}
	cout<<F(1,n,1)<<endl;
}


Measured memory_bytes: 141184
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	for(i=1;i<=10;i++){
	scanf("%d",&a);
		s+=a;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

void Cont(){
    int32_t N;
    cin >> N;
    vector<int> vec(N-1);
    int temp;
    for(auto& v : vec){
        cin >> temp;
        vec.at(temp-1)++;
    }
    for(auto& v : vec){
        cout << v <<"\n";
    }
        cout << "0" <<"\n";
}


int main()
{
	std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Cont();
}





Measured memory_bytes: 4004
#include<stdio.h>
int main()
{
    int m,f,r,sum=0,i;
    for(;scanf("%d%d%d",&m,&f,&r);)

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



Measured memory_bytes: 2088
module ABC131

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_A

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A (order)

    ! arguments for this <subroutine>
    integer(INT32), intent(in) :: order

    ! variables for this <subroutine>
    integer(INT32) :: given_integer

    ! arrays for this <subroutine>
    integer(INT32), dimension(0:order) :: data_digit

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! read out the given integer
    read(unit=INPUT_UNIT, fmt=*) given_integer

    ! STEP.02
    ! get the value of each digit
    do itr = 0_INT32, order, 1_INT32
      data_digit(itr) =                   mod(given_integer, 10_INT32 ** (itr + 1_INT32))
      data_digit(itr) = data_digit(itr) - mod(given_integer, 10_INT32 ** itr            )
      data_digit(itr) = data_digit(itr) / 10_INT32 ** itr
    end do

    ! STEP.03
    ! judge the digits
    if (data_digit(0) .eq. data_digit(1) .or. data_digit(1) .eq. data_digit(2) .or. data_digit(2) .eq. data_digit(3)) then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Bad'
    else
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Good'
    end if

    ! STEP.END
    return

  end subroutine task_A

end module ABC131


program main

  ! <module>s to import
  use, non_intrinsic :: ABC131

  ! require all variables to be explicitly declared
  implicit none

  call task_A (3)

end program main

Measured memory_bytes: 512
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ll modularExponentiation(ll x,ll n,ll M);
ll binpow(ll x,ll n);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
void solve()
{
   ll a,b,c;cin>>a>>b>>c;
   cout<<c<<" "<<a<<" "<<b<<"\n"; 
}
int main()
{

   fastio
   //Test_cases
   solve();
  return 0;
}
ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
          
} 
ll lcm(ll a,ll b)  
{  
    return (a*b)/gcd(a, b);  
}  
ll modularExponentiation(ll x,ll n,ll M)
{   
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
ll binpow(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)res=res*x;
         x=x*x;
         n>>=1;
    }
    return res;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;
    
    if(n==0)
        return 1.00;
    
    while(i<=n)
    {
        res*=i;
        i++;
    }
    
    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>

Measured memory_bytes: 256
using System;

namespace Array
{
    class Finding_Missing_Cards
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var exist = new bool[52];
            for (int i = 0; i < n; i++)
            {
                var array = Console.ReadLine().Split(' ');
                switch (array[0])
                {
                    case "S": exist[int.Parse(array[1]) - 1] = true; break;
                    case "H": exist[int.Parse(array[1]) + 12] = true; break;
                    case "C": exist[int.Parse(array[1]) + 25] = true; break;
                    case "D": exist[int.Parse(array[1]) + 38] = true; break;
                }
            }

            for (var i = 0; i < 52; i++)
            {
                string s = "";
                switch (i / 13)
                {
                    case 0: s = "S"; break;
                    case 1: s = "H"; break;
                    case 2: s = "C"; break;
                    case 3: s = "D"; break;
                }
                if (!exist[i])
                {
                    Console.WriteLine(s + " " + ((i % 13) + 1));
                }
            }
        }
    }
}

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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		Integer x = Integer.parseInt(s.next());
		Integer y = Integer.parseInt(s.next());
		s.close();
		if(x > y){
			Integer remain = x % y;
			Integer new_remain = y % remain;
			Integer bkp = 0;
			while(new_remain > 0){
				bkp = new_remain;
				new_remain = remain % new_remain;
			}
			System.out.println(bkp);
		}
		else if(y > x){
			Integer remain = y % x;
			Integer new_remain = x % remain;
			Integer bkp = 0;
			while(new_remain > 0){
				bkp = new_remain;
				new_remain = remain % new_remain;
			}
			System.out.println(bkp);
		}
		else{
			System.out.println(y);
		}
	}
}

Measured memory_bytes: 17336
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    G = [[] for _ in range(N+1)]
    st = 0
    st_w = 0
    for i in range(N-1):
        u, v, w = (int(i) for i in input().split())
        G[u].append((v, w))
        G[v].append((u, w))
        if i == 0:
            st = u
            st_w = w
    color = [-1] * (N+1)  # 0: white, 1: black, -1: undefined
    from collections import deque

    def coloring(v, w):
        """
        breadth-first search
        a simplified version
        """
        que = deque()
        color[v] = 0
        que.append((v, w))
        while que:
            u, w = que.popleft()
            for v, d in G[u]:
                if color[v] != -1:
                    continue
                if d % 2 != 0:
                    n_col = (color[u] + 1) % 2
                else:
                    n_col = color[u]
                color[v] = n_col
                que.append((v, d))

    coloring(st, st_w)
    for c in color[1:]:
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    string s; cin>>s;
    int ans=0;
    rep(i,3){
        if(s[i]=='1') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<deque>
using namespace std;

int main(){
	int N, L;//input the number of elements and size of sub-arrays
	cin >> N >> L;
	
	vector<int> ele(N);//define a vector to store all elements
	deque<int> deq(L);//define deque
	
	for(int i = 0; i < N; i++) {//initialize ele(N)
	    cin >> ele[i];
	}
	
	for(int i = 0; i < N; i++){
	    
		while(!deq.empty() && ele[deq.back()] >= ele[i]) {
		    //if the new ele is smaller than the ele whose index is the back of deq
		    deq.pop_back();
		}
		deq.push_back(i);
		
		if(i >= L - 1){
		    //print the minimum of last window
			cout << ele[deq.front()] ;
			if(i ==N - 1){
			    cout<<'\n';
			}else{
			    cout << ' ';
			}
			//delete the ele which is not in the current window
			if(deq.front() == i - L + 1) deq.pop_front();
		}
	}
	return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    string s; cin >> s;
    string t = "AKIHABARA";
    int itr_s = 0, itr_t = 0;
    while(true) {
        if(itr_s > s.size() || itr_t > t.size()) break;
        if(s[itr_s] == t[itr_t]) {
            itr_s++;
            itr_t++;
            continue;
        }
        if(t[itr_t] == 'A') itr_t++;
        else {
            cout << "NO" << '\n';
            return 0;
        }
    }
    cout << "YES" << '\n';
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
rn = [0]
wn = [0]
for i in range(n):
  if s[i] == "R":
    rn.append(rn[-1]+1)
    wn.append(wn[-1])
  else:
    rn.append(rn[-1])
    wn.append(wn[-1]+1)
ans = 10**10
for i in range(n+1):
  ans = min(ans,max(wn[i],rn[-1]-rn[i]))
print(ans)

Measured memory_bytes: 95564
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int, int>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	FOR0(i, n) cin >> a[i];
	sort(a, a + n);
	int ans= 0;
	FOR0(i, k) ans += a[i];
	cout << ans;
	


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 1;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t; cin>>s;
    t = s; reverse(ALL(t));
    int n = S(s);
    int k; cin>>k;
    V<V<V<int>>> lcs(n+1, V<V<int>>(n+1, V<int>(k+1, 0)));
    F(i,n+1) F(j,n+1) F(kk,k+1) {
        if (j < n) MA(lcs[i][j+1][kk], lcs[i][j][kk]);
        if (i < n) MA(lcs[i+1][j][kk], lcs[i][j][kk]);
        if (kk < k) MA(lcs[i][j][kk+1], lcs[i][j][kk]);
        if (i < n && j < n) {
            if (s[i] == t[j])
                MA(lcs[i+1][j+1][kk], lcs[i][j][kk] + 1);
            else if (kk < k)
                MA(lcs[i+1][j+1][kk+1], lcs[i][j][kk] + 1);
        }
    }
    int ma=0;
    F(i,n+1) {
        // without center
        MA(ma, 2*lcs[i][n-i][k]);
        if (i<n) {
            MA(ma, 2*lcs[i][n-1-i][k] + 1);
        }
    }
    cout << ma << "\n";
}

Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int N , K , R , S , P;
    string T;
    cin >> N >>K >>R >>S >>P;
    cin >> T;
    int res =0;
    rep(i,N){
        if(i>K-1){
            if(T[i]==T[i-K]){
                T[i]='a';
            }
        }
    }
    rep(i,N){
            if(T[i]=='r')
                res += P;
            if(T[i]=='s')
                res += R;
            if(T[i]=='p')
                res += S;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
from functools import reduce

def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(x, y):
    return int(x*y // gcd(x, y))

n = int(input())
t = [int(input()) for i in range(n)]

def lcm_ans(LIST):
    return reduce(lambda a, b: (a*b)//gcd(a, b), t)

print(lcm_ans(t))

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

int main() {
		int i, h, m, s;

		cin >> i;

		h = i / 3600;
		m = (i - (h * 3600)) / 60 ;
		s = i - (h * 3600) - (m * 60);

		cout << h << ":"
				<< m << ":"
				<< s << "\n";
		
		return 0;

}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define pll pair<ll,ll>
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"
const ll mod=1e9+7;
inline ll mul(ll a, ll b){ return (a * 1ll * 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 max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){return (a%b==0)?(a/b):(a/b+1);}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    for(auto v : V) os << v <<"  ";
    return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";
    return os<<"}";
}
struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        return p1.first<p2.first;
    }
};


int main(){
	fio;	
	string s;cin>>s;
	if(s.back()=='s'){
		s.append("es");
	}else{
		s.append("s");
	}
	cout<<s<<endl;
}

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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            var R = GetInt();
            var G = GetInt();
            var ans = 2 * G - R;

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<string>

using namespace std;

const int MOD = 1e9 + 7;

int main(){
int N; cin >> N;
  string S1,S2; cin >> S1 >> S2;
  
  int i = 0;
  
  vector<char> vec;
    
  while( i < N){
    if( S1[i] == S2[i]){ vec.push_back('a'); i++;}
    else{ vec.push_back('b'); i += 2;}}
  
  long long cnt = 1;
  
  if( vec[0] == 'a'){ cnt *= 3;}
  else{ cnt *= 6;}
  
  for(int i = 1; i < vec.size(); i++){
    //vec[i-1]とvec[i]の比較を行いたい
    if(vec[i-1] == 'a' && vec[i] == 'a' ){ cnt *= 2;}
    else if( vec[i-1] == 'a' && vec[i] == 'b'){ cnt *= 2;}
    else if( vec[i-1] == 'b' && vec[i] == 'a' ){ cnt *= 1;}
    else if( vec[i-1] == 'b' && vec[i] == 'b' ){ cnt *= 3;}
    cnt = cnt % MOD;}
  
  cout << cnt << endl; return 0;}
  


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    int sum=0;
    cin >> n;
    while(n>0){
        int l,r;
        cin >> l >> r;
        sum += r-l+1;
        n =n-1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
	var arr = input[1].split(" ").map(Number);
	var n=0;
	var m=0;
	for(var i=0;i<arr.length;i++){
		if(arr[i]%2==0) n++;
		else m++;
	}
	console.log(m%2==0?"YES":"NO")
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 17484
// Try diverta 2019 Programming Contest 2
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let k = get!();
    
    if k == 1 {
    	println!("0");
    } else {
    	println!("{}", n - k);
    }
}

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

int main() {
  int n=0,k=0,ans=1;
  cin >> n >> k;
  
  for (int i=0; i < n; i++) {
    if (ans < k) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int l[105];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  sort(l, l+n);
  int ret = 0;
  for(int i = 0; i < n; i++) {
    ret += (2*(i%2) - 1) * l[i];
  }
  printf("%d\n", abs(ret));
}


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

#define PrintLn(X) cout << X << endl
int main(void)
{
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if(N < K){
		PrintLn(N * X);
	}else{
		PrintLn(K * X + (N - K) * Y);
	}
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

ll _MOD = 1000000009;
double EPS = 1e-10;
ll INF = LLONG_MAX / 2;

int main() {
	for (;;) {
		int n; cin >> n;
		if (!n) break;
		vector<int> a(n), b(n);
		rep(u, n) scanf("%d%d", &a[u], &b[u]);
		if (n == 2) {
			cout << abs(a[0] - a[1]) << endl;
			continue;
		}
		vector<i_i> ab;
		vector<int> c;
		rep(u, n)
			if (b[u] == 1) c.pb(a[u]);
			else ab.pb(i_i(a[u], b[u] - 2));
		int N = ab.size(), M = c.size();
		if (!N) {
			cout << -1 << endl;
			continue;
		}
		sort(ab.begin(), ab.end());
		ab.front().second++;
		ab.back().second++;
		sort(c.begin(), c.end());
		vector<ll> dp(M + 1, INF);
		dp[0] = 0;
		rep(i, N) {
			int a = ab[i].first, b = ab[i].second;
			vector<ll> _dp(M + 1, INF);
			deque<i_ll> d;
			ll sum = 0;
			rep(j, M + 1) {
				if (!d.empty() && j - d.front().first > b) d.pop_front();
				while (!d.empty() && d.back().second >= dp[j] - sum) d.pop_back();
				d.push_back(i_ll(j, dp[j] - sum));
				if (!d.empty()) _dp[j] = d.front().second + sum;
				if (j < M) sum += abs(c[j] - a);
			}
			dp = _dp;
		}
		ll ans = dp[M] + ab.back().first - ab.front().first;
		if (ans >= INF) ans = -1;
		cout << ans << endl;
	}
}

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

int main(){
  int k;
  string s;
  cin>>k>>s;
  if(s.length()<=k) cout<<s;
  else {
    for(int i=0;i<k;i++) cout<<s[i];
    cout<<"...";
  }
  return 0;
}


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

vector<int> solve(int n, int m, vector<vector<int> > const & g, vector<vector<int> > const & g_rev) {
    queue<int> que;
    vector<int> outdegree(n);
    REP (i, n) {
        outdegree[i] = g[i].size();
        if (outdegree[i] == 0) {
            que.push(i);
        }
    }
    vector<int> parent(n, -1);
    while (not que.empty()) {
        int i = que.front();
        que.pop();
        for (int j : g[i]) {
            if (parent[j] == -1) {
                parent[j] = i;
            }
        }
        for (int j : g_rev[i]) {
            -- outdegree[j];
            if (outdegree[j] == 0) {
                que.push(j);
            }
        }
    }
    return parent;
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > g(n), g_rev(n);
    REP (i, n - 1 + m) {
        int a, b; cin >> a >> b;
        -- a;
        -- b;
        g[a].push_back(b);
        g_rev[b].push_back(a);
    }
    auto parent = solve(n, m, g, g_rev);
    REP (i, n) {
        cout << parent[i] + 1 << endl;
    }
    return 0;
}


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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int p[N];

bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    auto ans = 0;
    auto sorted = [](vector<int>&& v) { return sort(v.begin(), v.end()), v; };

    for (int i = 1; i < n - 1; ++i)
        if (sorted({ p[i - 1], p[i], p[i + 1] })[1] == p[i])
            ++ans;

    cout << ans << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	set<int> s ;
	s.insert(0) ; s.insert(-1) ;
	s.insert(n+1) ; s.insert(n+2) ;
	vll pos(n+1,-1) ;
	for(int i=0;i<n;i++) pos.at(a.at(i)) = i+1 ;
	ll ans = 0 ;
	for(int i=n;i>=1;i--){
		int w,x,y,z ;
		auto itr = s.lower_bound(pos.at(i)) ; itr++ ;
		z = *itr ; itr-- ;
		y = *itr ; itr-- ;
		x = *itr ; itr-- ;
		w = *itr ;
		if(w==-1) w = 0 ;
		if(z==n+2) z = n+1 ;
		ans += (x-w)*(y-pos.at(i))*i+(pos.at(i)-x)*(z-y)*i ;
		s.insert(pos.at(i)) ;
//		cout << ans << endl ;
//		cout << w << " " << x << " " << y << " " << z << endl ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 9576
#include <stdio.h>
int main(void){
	int n,i,soma=0;
	scanf("%d", &n);
	int custos[n], valor[n], lucro[n];
	for(i=0;i<n;i++)scanf("%d", &valor[i]);
	for(i=0;i<n;i++)scanf("%d", &custos[i]);
	for(i=0;i<n;i++)lucro[i]=valor[i]-custos[i];
	for(i=0;i<n;i++){
		if(lucro[i]>0)soma+=lucro[i];
	}
	printf("%d\n", soma);
	return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def calc(lst):
    ret = 0
    for a, b, c, d in abcd:
        if lst[b-1] - lst[a-1] == c:
            ret += d
    return ret

def dfs(lst):
    if len(lst) == n:
        return calc(lst)
    
    x = lst[-1]
    ret = 0
    for i in range(x, m+1):
        ret = max(ret, dfs(lst + [i]))
    return ret

n, m, q = LI()
abcd = [LI() for _ in range(q)]
ans = dfs([1])
print(ans)

Measured memory_bytes: 77600
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define all(a) a.begin(),a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pp , null_type,less< pp >, rb_tree_tag,tree_order_statistics_node_update>

ll power(ll b, ll exp){
    ll res = 1;
    while(exp > 0){
        if(exp % 2){
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost
    ll T,D,S;
    cin >> D >> T >> S;
    double t=(1.0*D)/(S*1.0);
    if( t>T )   {
        cout << "No";
    }
    else    {
        cout << "Yes";
    }
    return 0;
}


Measured memory_bytes: 3584
//11-2 ??????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N;
    cin >> N;

    int ans = 0;
    for(int i=0; i<N; i++){
        string tmp;
        cin >> tmp;
        tmp = tmp + tmp;
        bool ari = false;
        for(int l=0; l<20-S.length(); l++){
            if(tmp.substr(l,S.length()) == S) ari = true;
        }
        if(ari) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3156