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

#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}

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

    int N, W;
    cin >> N >> W;

    vector<int> v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];

    vector<vector<int>> dp(N+1, vector<int>(W+1, 0));    

    rep(i, N) {
        rep(j, W + 1) {
            chmax(dp[i + 1][j], dp[i][j]);
            if (j + w[i] <= W) {
                chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;
}



Measured memory_bytes: 6776
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, d := readInt(), readInt(), readInt(), readInt()

	for a > 0 || c > 0 {
		c -= b
		if c <= 0 {
			fmt.Println("Yes")
			return
		}
		a -= d
		if a <= 0 {
			fmt.Println("No")
			return
		}
	}
}


Measured memory_bytes: 1756
dict = {}

n = int(input())

for i in range(n):
	s = input()
	try:
		dict[s] += 1
	except:
		dict[s] = 1

m = int(input())

for i in range(m):
	s = input()
	try:
		dict[s] -= 1
	except:
		dict[s] = -1

ans = sorted(dict.items(), key=lambda x: -x[1])

if ans[0][1] < 0:
	print(0)
else:
	print(ans[0][1])

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007
typedef long long ll;

int
main(int argc, char *argv[])
{
  int n, d;
  scanf("%d %d", &n, &d);
  printf("%d\n", (n - 1)/(2 * d + 1) + 1);
  return 0;
}


Measured memory_bytes: 128
N,x=map(int,input().split())
A=list(map(int,input().split()))
total=0
for i in range(N-1):
    if A[i]+A[i+1]>x:
        total+=A[i]+A[i+1]-x
        if A[i+1]<=A[i]+A[i+1]-x:
            A[i+1]=0
        else:
            A[i+1]-=A[i]+A[i+1]-x
print(total)

Measured memory_bytes: 14540
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		List<Integer> temp = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			ary[i] = x;
			temp.add(x);
		}
		Collections.sort(temp);
		Integer min = temp.get(n / 2 - 1);
		Integer max = temp.get(n / 2);
		for (int i = 0; i < n; i++) {
			if (ary[i] <= min) {
				System.out.println(max);
			} else {
				System.out.println(min);
			}
		}
	}
}


Measured memory_bytes: 105652
#include <stdio.h>
int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a < b){
        if(b < c)printf("%d %d %d\n", a, b, c);
        else if(a < c)printf("%d %d %d\n", a, c, b);
        else printf("%d %d %d\n", c, a, b);
    } else {
        if(c < b)printf("%d %d %d\n", c, b, a);
        else if(c < a)printf("%d %d %d\n", b, c, a);
        else printf("%d %d %d\n", b, a, c);
    }
}



Measured memory_bytes: 2068
#include<stdio.h>

int main(void){
	int x,y,p,q;
	scanf("%d%d",&x,&y);
	p=x;q=y;
	if(p < 0){p*=-1;}
	if(q < 0){q*=-1;}
	if(x >= 0 && y >= 0){
		if(y >= x){printf("%d\n",y-x);}
		else if (y == 0){printf("%d\n",x-y+1);}
		else{printf("%d\n",x-y+2);}
	}
	else if(x < 0 && y < 0){
		if(p >= q){printf("%d\n",p-q);}
		else{printf("%d\n",q-p+2);}
	}
	else{
		if(y == 0){printf("%d\n",p-q);}
		else if(p >= q){printf("%d\n",p-q+1);}
		else{printf("%d\n",q-p+1);}
	}
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class AFrog1 {
public:
    int N;
    int h[100001];
    int dp[100001]{0};

    // dp: 残りiでの最小コスト
    void solve(std::istream& in, std::ostream& out) {
        in >> N; REP(i, N) in >> h[i];
        dp[0] = 0; dp[1] = abs(h[N-1] - h[N-2]);
        FOR(i, 2, N) dp[i] = min(dp[i-1] + abs(h[N-i-1] - h[N-i]), dp[i-2] + abs(h[N-i-1] - h[N-i+1]));
        COUT(dp[N-1]);
    }
};


int main() {
    AFrog1 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace::std;
#define INF 1000000
struct point{
    int x,y;
};
int h,w,n,ans=0,i,j,x,y;
char map[1000][1000];
point cheese[10];
int move(int p){
    int count[1000][1000],i,j;
    for (i=0; i<w; i++) {
        for (j=0; j<h; j++) {
            count[i][j]=INF;
        }
    }
    count[cheese[p].x][cheese[p].y]=0;
    queue<point> q;
    q.push(cheese[p]);
    while (!q.empty()) {
        point position=q.front();
        q.pop();
        int a[]={0,1,0,-1},b[]={1,0,-1,0};
        for (i=0; i<4; i++) {
            if (position.x+a[i]>=0&&position.x+a[i]<w&&position.y+b[i]>=0&&position.y+b[i]<h&&map[position.x+a[i]][position.y+b[i]]!='X'&&count[position.x+a[i]][position.y+b[i]]==INF) {
                count[position.x+a[i]][position.y+b[i]]=count[position.x][position.y]+1;
                point t;
                t.x=position.x+a[i];
                t.y=position.y+b[i];
                q.push(t);
            }
        }
    }
    return count[cheese[p+1].x][cheese[p+1].y];
}
int main(){
    scanf("%d%d%d",&h,&w,&n);
    for (i=0; i<h; i++) {
        for (j=0; j<w; j++) {
            scanf(" %c",&map[j][i]);
            if (map[j][i]=='S') {
                cheese[0].x=j;
                cheese[0].y=i;
            }else if (map[j][i]>=49&&map[j][i]<=57){
                cheese[map[j][i]-48].x=j;
                cheese[map[j][i]-48].y=i;
            }
        }
    }
    for (i=0; i<n; i++) {
        ans+=move(i);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5928
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
using namespace std;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


int main()
{
	string s;
	map<int,bool> m;
	map<int,bool> m2;
	map<int,int> count;

	while(getline(cin,s) && s.size())
	{
		vector<string> _s = split(s,',');
		int a = atoi(_s[0].c_str());
		m[a] = true;
		count[a]++;
	}

	while(getline(cin,s))
	{
		vector<string> _s = split(s,',');
		int a = atoi(_s[0].c_str());
		m2[a] = true;
		count[a]++;
	}

	for(int i=0;i<1001;i++)
	{
		if(m2.find(i) != m2.end() && m.find(i) != m.end())
		{
			cout << i << " " << count[i] << endl; 
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
 
int main()
{
  int A[100];
  int N;
  int key;
  int i, j, k;
 
  //Read N and keys
  scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d", &A[i]);
 
  //Sort
  for(i=0; i<N; i++)
    {
      key=A[i];
      j=i-1;
 
      //if A[j]>key, change A[j] to A[j+1]
      while(j>=0 && A[j]>key)
    {
      A[j+1]=A[j];
      j=j-1;
    }
      A[j+1]=key;
 
      //print
      for(k=0; k<N; k++)
    {
      printf("%d", A[k]);
      if(k!=N-1)printf(" ");
    }
      printf("\n");
    }
 
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n";
#define ll long long

const ll MOD = 1e9 + 7;

int main() {
    int n,a,b,c,d;
    string s;
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    s = '#' + s + '#';
    int tmp = 0, rockmax = 0;
    // 岩が連続してなければ移動可能
    for(int i=a; i<=c; i++) {
        if (s[i] == '#') {
            tmp++;
        } else {
            rockmax = max(tmp, rockmax);
            tmp = 0;
        }
    }
    tmp = 0;
    for(int i=b; i<=d; i++) {
        if (s[i] == '#') {
            tmp++;
        } else {
            rockmax = max(tmp, rockmax);
            tmp = 0;
        }
    }
    if (c < d) {
        // 追い抜かない場合
        if (rockmax <= 1) printf("Yes\n");
        else printf("No\n");
    } else {
        // 追い抜く場合（...が必要）
        tmp = 0;
        bool ok = false;
        for(int i=b; i<=d; i++) {
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
                ok = true;
            }
        }
        if (ok) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int i=0;
  while(b<=a){
    b *= 2;
    i++;
  }
  while(c<=b){
    c *= 2;
    i++;
  }
  if(i<=k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
void solve()
{

 int row,col,mod=1e9+7;
 cin>>row>>col;
 string arr[row];
 for(int i=0;i<row;i++)
 {
    cin>>arr[i];
 }
 vector<vector<long long int>>dp(row,vector<long long int>(col,0));
dp[0][0]=1;
 for(int i=1;i<col;i++)
    if(arr[0][i]!='#')
    dp[0][i]=dp[0][i-1];


 for(int i=1;i<row;i++)
    if(arr[i][0]!='#')
    dp[i][0]=dp[i-1][0];


 for(int i=1;i<row;i++)
 {
     for(int j=1;j<arr[i].size();j++)
     {
        if(arr[i][j]!='#')
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
     }
 }

 /*for(int i=0;i<row;i++)
 {
     for(int j=0;j<col;j++)
     {
       cout<<dp[i][j]<<" ";
     }
     cout<<"\n";
 }*/
 cout<<dp[row-1][col-1];
}

int main()
{
    int test;
  //  cin>>test;
  test=1;
  while(test--)
  {
    solve();
  }


    return 0;
}


Measured memory_bytes: 13000
// MISCELLANEOUS
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

typedef unsigned int ui;

// --------------------------------------------------------------------------------------

using namespace std;

int main(void)
{
    size_t n;
    cin >> n;
    int a, prev, stat = 0;
    ui count = 0;
    cin >> a;
    REPST(i,n-1) {
        prev = a;
        cin >> a;
        switch (stat) {
            case 0: {
                if (a > prev) { stat = 1; }
                else if (a < prev) { stat = -1; }
                break;
            }
            case 1: {
                if (a < prev) { ++count; stat = 0; }
                break;
            }
            case -1: {
                if (a > prev) { ++count; stat = 0; }
                break;
            }
            default: { break; }
        }
    }
    cout << (++count) << '\n';

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_s = sorted(a, reverse=True)
hantei = a_s[:2]
del a_s
for i in range(n):
    if a[i] == hantei[0]:
        print(hantei[1])
    else:
        print(hantei[0])

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


int main() {
  
  int n;
  while (cin >> n && n > 0) {
    int y_max, z_max, m, x;
    int smallest=n;
    for (int i=0; i*i*i <= n; i++) {
      for (int j=0; j*j + i*i*i <= n; j++) {
        x = n-j*j-i*i*i;
        if (x<0) {
          break;
        }
        if (i+j>smallest) {
          break;
        }
        if (x+i+j < smallest && x>= 0) {
          smallest = x + i + j;
        }
      }
    }
    cout << smallest << endl;
  }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

class RollingHash{
  public:
  vector<vector<ull>> hash1,hash2;
  vector<ull> pows;
  vector<string> s;
  const int n;
  const ull base = 1162261467;
  const ull modu = (1ll << 61)-1;
  const ull msk = (1ll << 31)-1;
  RollingHash(int N,vector<string> k): hash1(2*N+1,vector<ull>(2*N+1,0)),hash2(2*N+1,vector<ull>(2*N+1,0)),pows(2*N+1,1),n(N),s(k) {
    rep(j,2*n)rep(i,2*n)hash1[j][i+1] = mod(mul(hash1[j][i],base)+s[j][i]);
    rep(j,2*n)rep(i,2*n)hash2[j][i+1] = mod(mul(hash2[j][i],base)+s[i][j]);
    rep(i,2*n)pows[i+1] = mod(mul(pows[i],base));
  }
  vector<ull> get(ll uy,ll ux,bool is){
    vector<ull> res(n);
    if(is){
      rep(i,n)res[i] = mod(modu*3+hash1[uy+i][ux+n]-mul(hash1[uy+i][ux],pows[n]));
    }else{
      rep(i,n)res[i] = mod(modu*3+hash2[ux+i][uy+n]-mul(hash2[ux+i][uy],pows[n]));
    }
    return res;
  }
  ull mul(ll l,ll r){
    ull ul = l >> 31,dl = l & msk;
    ull ur = r >> 31,dr = r & msk;
    ull um = (ul*dr+dl*ur) >> 31,dm = (ul*dr+dl*ur) & msk;
    return ul*ur*2 + dl*dr + (um << 1) + (dm << 31);
  }
  ull mod(ll val){
    ull u = val >> 61,d = val & modu;
    return u+d >= modu ? u+d-modu  : u+d;
  }
};

int main(){
  
  int n;
  cin >> n;
  vector<string> s(2*n);
  rep(i,n)cin >> s[i];
  rep(i,n)s[i] += s[i];
  rep(i,n)s[n+i] = s[i];
  RollingHash rh(n,s);
  ll res = 0;
  rep(i,n)rep(j,n){
    if(rh.get(i,j,true) == rh.get(i,j,false))res++;
    //vector<ull> g = rh.get(i,j,true),gg = rh.get(i,j,false);
    //rep(k,n)cout << g[k] << " ";cout << endl;
    //rep(k,n)cout << gg[k] << " ";cout << endl;
    //cout << endl;
  }

  cout << res << endl;
  /*
  rep(i,2*n)rep(j,2*n)cout << rh.hash1[i][j] << (j == 2*n-1 ? "\n" : " ");
  cout << endl;
  rep(i,2*n)rep(j,2*n)cout << rh.hash2[i][j] << (j == 2*n-1 ? "\n" : " ");
  
  cout << rh.mod((rh.modu*4+rh.hash1[2][3+n]-rh.mul(rh.hash1[2][3],rh.pows[n]))) << endl;
  cout << rh.mod((rh.modu*4+rh.hash2[3][2+n]-rh.mul(rh.hash2[3][2],rh.pows[n]))) << endl;*/


  return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = a[0];
    rep(i,n) ans = __gcd(ans,a[i]);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

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

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

  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (a >= b) {
    cout << 1 << endl;
    return 0;
  }

  int ans = (b - a + (a - 2)) / (a - 1) + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1001001001
#define LINF (1LL << 62)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solv() {
    string str;
    cin >> str;
    char num[3];
    if (str.size() == 2 && str[0] == str[1]) {
        cout << " 1 2\n";
        return;
    }
    rep(i, str.size() - 2) {
        set<char> st;
        st.insert(str[i]);
        st.insert(str[i + 1]);
        st.insert(str[i + 2]);
        if (st.size() < 3) {
            cout << i + 1 << ' ' << i + 3 << endl;
            return;
        }
    }
    cout << "-1 -1" << endl;
}

int main() {
    solv();
    return 0;
}

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

int main(){
    string a;
    int price = 700;
    cin >> a;
    for(auto i = 0; i < a.size(); i++) {
        if (a.at(i) == 'o') price += 100;
    }
    cout << price << endl;

    return 0;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);


  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);

  for (int i = 0; i < n - 1; ++i) {
    cin >> a[i];
    b[a[i] - 1]++;
  }

  for (int i = 0; i < n; ++i) {
    cout << b[i] << endl;
  }



  return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	ll A,B,C,K,ans;
	cin >> A >> B >> C >> K;
	if(K%2==0){
		ans = A - B;
	}else{
		ans = B - A;
	}
	if(abs(ans) > 1e18){
		cout << "unfair" << endl;
	}else{
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?GCD(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/GCD(a,b);}

int main(){
    string s; cin >> s;
    int e0 = 0,e1 = 0,o0=0,o1=0;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i] == '0') ++e0;
            else ++e1;
        }
        else{
            if(s[i] == '0') ++o0;
            else ++o1;
        }
    }

    cout << min(o0+e1,o1+e0) << endl;
    

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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


int temoto[55];

int main(){
	while(1){
		int n,p;
		scanf("%d %d",&n,&p);
		for(int i = 0;i < n;i++) temoto[i] = 0;
		int wan = p;
		int ans = 0;
		if(n + p == 0) break;
		for(int i = 0; ;i++){
			if(i == n) i = 0;
			if(wan == 1 && temoto[i] == p-1){
				ans = i;
				break;
			}else if(wan > 0){
				wan--;
				temoto[i]++;
			}else{
				wan = temoto[i];
				temoto[i] = 0;
			}
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3212
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(s: String) -> bool {
    let mut chars = s.chars();
    let a = chars.next();
    let b = chars.next();
    let c = chars.next();
    let d = chars.next();
    a == Some('Y') && b == Some('A') && c == Some('K') && d == Some('I')
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    print_yesno(solve(sc.next()), "Yes", "No")
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

vector<int> to[200005];

mint dfs(int v) {
  mint res = 1;
  for (int u : to[v]) {
    res *= dfs(u);
  }
  return res + 1;
}

int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  set<P> s;
  for (int i = n-1; i >= 0; --i) {
    int x = p[i].first, d = p[i].second;
    while (s.size() && s.begin()->first < x+d) {
      to[i].push_back(s.begin()->second);
      s.erase(s.begin());
    }
    s.emplace(x, i);
  }

  mint ans = 1;
  for (auto x : s) {
    int v = x.second;
    ans *= dfs(v);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 22144
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
int main(){
  long long Q,H,S,D,N,X;
  cin>>Q>>H>>S>>D>>N;
  S=min(min(min(4*Q,2*Q+H),2*H),S);
  
  if(2*S>D) X=(N/2)*D+(N%2)*S;
  else X=S*N;
  cout<<X<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double ans = 0;
		for (int i = 0; i < n; i++) {
			ans += (double)1 / sc.nextInt();
		}
		System.out.println(1/ans);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while( true ) {
        int n;
        cin >> n;
        if( n == 0 ) break;
        int mx = 0, num;
        for( int i  = 0; i < n; ++i ) {
            int a, b, c;
            cin >> a >> b >> c;
            if( mx < b + c ) {
                mx = b + c;
                num = a;
            }
        }
        cout << num << " " <<  mx << endl;
    }
    return 0;
}





Measured memory_bytes: 3160
#include<iostream>
#include<vector>
using namespace std;
vector<int>G[1<<17];
int n,K,a[1<<17];
vector<int>dk[1<<17];
int pk[1<<17];
void dfs(int u,int k)
{
	pk[k]=u;
	if(k>=K)
	{
		dk[pk[k-K]].push_back(u);
	}
	for(int i=0;i<G[u].size();i++)dfs(G[u][i],k+1);
}
int dp[1<<17];
int get(int,int);
int bfs(int u)
{
	dp[u]=1e9;
	int s=0;
	for(int i=0;i<G[u].size();i++)
	{
		s+=bfs(G[u][i]);
	}
	//dp[u]=min(dp[u],s+(int)G[u].size());
	s=0;
	for(int i=0;i<dk[u].size();i++)s+=dp[dk[u][i]];
	dp[u]=min(dp[u],s+(int)dk[u].size());
	if(1L*n*K<1e8)dp[u]=get(u,K-1);
	return dp[u];
}
int get(int u,int k)
{
	if(k<0)return dp[u]+1;
	int ans=dp[u]+1;
	int sum=0;
	for(int i=0;i<G[u].size();i++)
	{
		sum+=get(G[u][i],k-1);
	}
	return min(ans,sum);
}
main()
{
	cin>>n>>K;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]--;
		if(i)G[a[i]].push_back(i);
	}
	dfs(0,0);
	bfs(0);
	cout<<get(0,K)+!!a[0]<<endl;
}

Measured memory_bytes: 18560
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk; 
    string s;
    cin>>n;
    cin>>s;
    a=0; b=0;
    for(i=0;i<s.size();i++) if(s[i]=='R') a++;
    for(i=0;i<a;i++) if(s[i]=='W') b++;
    cout<<b<<endl;
	
} 

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1000111;

const ll MOD = 1000000007LL;

void solve() {

}

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n*a, b);






    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N, a[10005], c, i;
    scanf("%d", &N);
    c=0;
    for (i=1; i<=N; i++) {
        scanf("%d", &a[i]);
        while (a[i]%2 == 0) {
            a[i]/=2;
            c++;
        }
    }
    printf("%d", c);
    return 0;
}

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

int main(){
	int A, B;
	cin >> A >> B;
	
	if(A==B) cout << "Draw" << endl;
	else if(A!=1 && B!=1){
		if(A<B) cout << "Bob" << endl;
		else cout << "Alice" << endl;
	}
	else{
		if(A==1) cout << "Alice" << endl;
		else cout << "Bob" << endl;
	}
	return 0;
}

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

int main(){
  
  string a,b;
  cin>>a>>b;
 
  if(a[0]!=b[0] and a[1]!=b[1] and a[2]!=b[2]) cout<<0<<endl;
 else if(a==b) cout<<3<<endl;
  else if( (a[0] == b[0] and a[1]!=b[1] and a[2]!=b[2]) || 
          (a[1] == b[1] and a[0]!=b[0] and a[2]!=b[2]) ||
           (a[2] == b[2] and a[1]!=b[1] and a[0]!=b[0])) cout<<1<<endl;
  else cout<<2<<endl;
}
  

Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const H = Number(stdin.shift());
    const A = stdin.shift().split(' ').map(Number);

    for (let i = 0; i < H; i++) {
        const id = i + 1;
        const parent = id !== 1 ? Math.floor(id / 2 - 1) : null;
        const left = id * 2 <= H ? id * 2 - 1 : null;
        const right = id * 2 + 1 <= H ? id * 2 : null;

        let out = `node ${id}: `;
        out += `key = ${A[i]}, `;
        out += parent !== null ? `parent key = ${A[parent]}, ` : '';
        out += left !== null ? `left key = ${A[left]}, ` : '';
        out += right !== null ? `right key = ${A[right]}, ` : '';
        console.log(out);
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cerr << #x << " = " << x << endl;

template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}

template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}

template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}

template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}

void solve(); signed main() {
#ifdef LOCAL
    freopen("C:\\Users\\artma\\CLionProjects\\problems\\input.txt", "r", stdin);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}

const int MOD = 1e9 + 7, MAXN = 1e5 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
    int n, k;
    cin >> n >> k;
    vec<int> a(n);
    cin >> a;

    int l = 0, r = 1e9 + 7;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        int sum = 0;
        for (auto it : a) {
            sum += (((it + mid - 1) / mid) - 1);
        }
        if (sum <= k) {
            r = mid;
        }
        else {
            l = mid;
        }
    }

    cout << r << endl;
}

Measured memory_bytes: 4776
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = B = 0
for i,v in enumerate(list(itertools.permutations(range(1,N+1))), 1):
    if list(v) == P:
        A = i
    elif list(v) == Q:
        B = i
        continue
    else:
        pass

print(abs(A-B) if A != 0 and B != 0 else 0)

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

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int main(){
    string s;
    cin>>s;
    string ans = "AC";
    //A = 65 Z = 90
    if(s[0] != 'A') ans = "WA";
    int count = 0;

    FOR(i,1,s.size()){
        if(i >= 2 && i <= s.size()-2){
            if(s[i] == 'C') ++count;
            if(count > 1) ans = "WA";

        } 
        if((int)s[i] >= 65 && (int)s[i] <= 90 && s[i] != 'C') ans = "WA";
    }
    if(!count) ans = "WA";  
    
  
    put(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,sum=0,maxi,*pt;
    cin>>n>>m;
    int arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    //int refer=sum/(4*m);
    int cnt=0;
    for(i=0; i<n; i++)
    {
        int u=arr[i]*4*m;
        if(u>=sum)
        {
            cnt++;
        }
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
string S;
bool check[100002];

int main(){
    cin>>S;
    REP(i,100001){
       check[i]=false;
    }
    check[0]=true;
    string d="dream";
    string d2="dreamer";
    string e="erase";
    string e2="eraser";
    REP(i,S.size()){
        if(check[i]==false)continue;
        if(i+5<S.size()+1){
           bool c=true;
           REP(j,5){
              if(S[i+j]!=d[j])c=false;
           }
           if(c){
              check[i+5]=true;
           }
        }
        if(i+7<S.size()+1){
           bool c=true;
           REP(j,7){
              if(S[i+j]!=d2[j])c=false;
           }
           if(c){
              check[i+7]=true;
           }
        }
        if(i+5<S.size()+1){
           bool c=true;
           REP(j,5){
              if(S[i+j]!=e[j])c=false;
           }
           if(c){
              check[i+5]=true;
           }
        }
        if(i+6<S.size()+1){
           bool c=true;
           REP(j,6){
              if(S[i+j]!=e2[j])c=false;
           }
           if(c){
              check[i+6]=true;
           }
        }
    }
    /*REP(i,S.size()+1){
        cout<<check[i]<<endl;
    }*/
    
    
    if(check[S.size()]){
       cout<<"YES"<<endl;
    }else{
       cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
n=int(input())
h=[int(x) for x in input().split()]

flag=0
for i in range(n-1):
  if h[i+1]-h[i]<=-2:
    print("No")
    exit()
  elif h[i+1]-h[i]==-1:
    if flag==0:
      flag=-1
    elif flag==1:
      flag=0

    if flag<=-1:
      print("No")
      exit()
  elif h[i+1]-h[i]>=1:
    flag=1
  #print(flag)
print("Yes")    

Measured memory_bytes: 63984
#include<iostream>
#include <algorithm>
using namespace std;
main(){
long a,b;
cin>>a>>b;
long  ans=(a/b)*(a/b)*(a/b);
if(b%2==0){
long cnt=0;
for(int i=1;i<=a;i++)if(i%b==b/2)cnt++;
ans+=cnt*cnt*cnt;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

n, m, x = map(int, input().split())

C = []
A = []
for _ in range(n):
    a = list(map(int, input().split()))
    C.append(a[0])
    A.append(a[1:])

ans = []
for i in range(n):
    for combination in list(itertools.combinations(range(n), i+1)):
        # print(combination)
        total = 0
        li = [0] * m
        for j in combination:
            total += C[j]
            for k in range(m):
                li[k] += A[j][k]
        flag = True
        for l in range(m):
            if li[l] < x:
                flag = False
        if flag:
            ans.append(total)
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 68596
def main():
    N, K = map(int, input().split())
    N = N % K
    if N == 0:
        print(0)
    elif N * 2 <= K:
        print(N)
    else:
        while N > 0:
            N = N - K
        print(abs(N))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    char ch;
    int i, num, counter[1200] = {0};

    
    while(scanf("%c", &ch) != EOF){

        if('A' <= ch && ch <= 'Z'){
            num = ch - 'A';
            counter[num]++;
        }
        else if('a' <= ch && ch <= 'z'){
            num = ch - 'a';
            counter[num]++;
        }
    }

    for(i = 0, ch = 'a'; i < 26; i++, ch++){
        printf("%c : %d\n", ch, counter[i]);
    }
    
    return 0;
}


Measured memory_bytes: 3172
import Data.List
--import Data.Array
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
--import Data.Vector as V
import Control.Monad
import Control.Monad.ST

-- Knapsack DP
-- 1<=maxw<=10^9
-- 1<= v  <=10^3
-- 1<= n  <=100
type Item  = (Int,Int)
type Items = [Item]
type DP s = STUArray s (Int,Int) Int

dp_i :: DP s -> Item -> Int -> Int -> Int -> ST s ()
dp_i dparr (w,v) _ _ 1 = forM_ [1..v] $ \j -> writeArray dparr (1,j) w
dp_i dparr (w,v) maxw maxv i = do
  forM_ [1..v] $ \j -> do
     w0 <- readArray dparr (i-1,j)
     writeArray dparr (i,j) $ min w0 w
  forM_ [v+1..maxv] $ \j -> do
    w0 <- readArray dparr (i-1,j)
    w1 <- readArray dparr (i-1,j-v)
    if w0 <= w1+w then writeArray dparr (i,j) w0
        else writeArray dparr (i,j) (w1+w)

solve :: [(Int,Item)] -> Int -> Int -> Int -> ST s Int
solve ls n maxw maxv = do
  dparr <- newArray ((1,0),(n,maxv)) (maxw+1)
  forM_ ls $ \(i,item) -> dp_i dparr item maxw maxv i --dp
  let find :: DP s -> Int -> ST s Int
      find dparr' j = do
        w0 <- readArray dparr' (n,j)
        if w0 > maxw then find dparr' (j-1) else return j
  ans <- find dparr maxv
  return ans

main :: IO ()
main = do
  [n,maxw] <- map read.words <$> getLine
  let forM' [] = return (0,[])
      forM' (n:ns) =  do
      (w:v:emp) <- map read.words <$> getLine :: IO [Int]
      (v1,ls) <- forM' ns
      return (v+v1,(n,(w,v)):ls)
  (maxv,ls) <- forM' [1..n]
  putStrLn $ show $ runST $ solve ls n maxw maxv


Measured memory_bytes: 79228
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
//09062355704
int f(int a,int b,int c){
    int out=b*60+c;
    a-=b/12;
    if(a<0)a+=60;
    if(a%5)return -1;
    out+=a/5*3600;
    return out;
}
signed main(){
    int n;
    while(cin>>n,n){
        vvi in(n,vi(3));
        rep(i,n)rep(j,3)cin>>in[i][j];
        vi dp(43200,-inf);
        rep(i,n){
            vi t;
            rep(j,60){
                sort(all(in[i]));
                do{
                    int a=f(in[i][0],in[i][1],in[i][2]);
                    if(a+1)t.pb(a);
                }while(next_permutation(all(in[i])));
                rep(k,3)(in[i][k]+=1)%=60;
            }
          //show1d(t);
            vi ndp(43200,-inf);
            rep(j,43200)rep(k,t.size())if(i==0||dp[j]+inf){
                if(i==0){
                    ndp[t[k]]=t[k];
                    continue;
                }
                int mi=dp[j],ma=j;
                cmin(mi,t[k]);
                cmax(ma,t[k]);
                cmax(ndp[ma],mi);
            }
            dp=ndp;
        }
        int mi=inf,it;
        rep(i,43200)if(mi>i-dp[i]){
            mi=i-dp[i];
            it=i;
        }
//      cout<<it<<" "<<dp[it]<<endl;
        printf("%02d:%02d:%02d %02d:%02d:%02d\n",dp[it]/3600,dp[it]%3600/60,dp[it]%60,it/3600,it%3600/60,it%60);
    }
}



Measured memory_bytes: 3808
#include <stdio.h>
 
int main(){
	long long int A, B, N;
 
	scanf("%lld %lld %lld", &N, &A, &B);
 
	if(A == B) {
		printf("1");
	}

	else if(N == 1 && A != B) {
		printf("0");
	}

	else if(A > B) {
		printf("0");
	}

	else if(A < B) {
		printf("%lld", (B - A) * (N - 2) + 1);
	}
 
}

Measured memory_bytes: 128
import sys
import bisect
#t=int(input())
t=1
for _ in range(t):
    #r,g,b=map(int,input().split())
    #l=list(map(int,input().split()))
    #l2=list(map(int,input().split()))
    #n=int(input())
    #l=list(map(int,input().split()))
    r=0
    maxi=0
    s=input()
    for i in range(len(s)):
        if s[i]=='R':
            r+=1
        else:
            maxi=max(maxi,r)
            r=0
    maxi=max(maxi,r)
    print(maxi)

Measured memory_bytes: 80128
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){

	int a,b,c,d,m=0,s;
	cin>>a>>b>>c>>d;
	s=a+b+c+d;
	for(;;){
        if(s>=60)m++,s-=60;
        else break;
	}
	cout<<m<<endl<<s<<endl;


	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
  char d[][8]={"0111111","0000110","1011011","1001111","1100110",
	       "1101101","1111101","0100111","1111111","1101111"};
  int n,m,i;
  while(scanf("%d",&n),n+1){
    char l[8]={"0000000"};
    while(n--){
      scanf("%d",&m);
      for(i=0;i<7;i++){
	if(l[i]==d[m][i])printf("0");
	else             printf("1");
	l[i]=d[m][i];
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 572
import bisect
n = int(input())
l = list(map(lambda x:int(x),input().split()))
l = sorted(l)

ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += bisect.bisect_left(l,l[i]+l[j])-j-1
        
print(ans)

Measured memory_bytes: 3188
import math
a, b = list(map(int, input().split()))

ret = -1
for i in range(15000):
  x = math.floor(i * 0.08)
  if x > a:
    break
  y = math.floor(i * 0.1)
  if y > b:
    break
  if x == a and y == b:
    ret = i
    break
print(ret)

Measured memory_bytes: 38256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S;
int L,i;
map<char,int> cnt;
inline void solve(){
  IN(S);
  L=S.size();
  REP(i,L)cnt[S[i]]++;
  OUT(cnt['+']-cnt['-']);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

struct UF {
	vector<int> data;
	UF(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll dfs(const vector<vector<P>> &v,int node,int pre, int depth,int k,int st){
    if(depth==k){
        if(k>2 && v[node].size()==2){
            if(v[node][0].first==st) return v[node][0].second;
            else if(v[node][1].first==st) return v[node][1].second;
        } 
        return 0;
    }
    if(v[node].size()==1 && node!=st) return -INF;
    for(int i=0;i<2;i++){
        P p=v[node][i];
        if(p.first==pre) continue;
        else return p.second+dfs(v,p.first,node,depth+1,k,st);
    }
    return -INF;
}

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

    int n,k,s;
    while(cin>>n>>k>>s,n){
        vector<ll> x(n),y(n),z(n);
        vector<vector<P>> g(n);
        UF uf(n);
        for(int i=0;i<n;i++){
            cin>>x[i]>>y[i]>>z[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(abs(x[i]-x[j])>=s || abs(y[i]-y[j])>=s || abs(z[i]-z[j])>=s) continue;
                ll dx=s-abs(x[i]-x[j]), dy=s-abs(y[i]-y[j]), dz=s-abs(z[i]-z[j]);
                ll dif=2*(dx*dy+dy*dz+dz*dx);
                g[i].push_back(P(j,dif));
                g[j].push_back(P(i,dif));
                uf.unite(i,j);
                //cout<<i<<" "<<j<<" "<<dif<<endl;
            }
        }
        bool f=false;
        ll res=s*s*6*k, ma=res;
        for(int i=0;i<n;i++){
            if(uf.size(i)<k) continue;
            f=true;
            if(g[i].size()==0) continue;
            if(g[i].size()==1) res=min(res,ma-dfs(g,i,-1,1,k,i));
            else{
                int p=g[i][0].first,q=g[i][1].first;
                res=min(res,ma-dfs(g,i,p,1,k,i));
                res=min(res,ma-dfs(g,i,q,1,k,i));
            }
        }
        if(!f){
            cout<<-1<<endl;
            continue;
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef long long lli;

lli get_digit(lli a){
	lli res = 0, tmp = a;
	if(a == 0) return 1;
	while(tmp > 0){
		res++;
		tmp /= 10;
	}
	return res;
}

lli mypow(lli a, lli b){
	lli digit = get_digit(a);
	if(digit * b > 12) return -1;
	lli res = 1;
	for(int i=0;i<b;i++){
		res *= a;
		if(res > 1e9) return -1;
	}
	return res;
}

int main(){
	lli n, T;
	string s;
	cin >> n >> T;
	cin >> s;
	lli sum = 0;
	for(int i=0;i<s.size();i++){
		if('0' <= s[i] && s[i] <= '9'){
			lli tmp = mypow(n, s[i] - '0');
			if(tmp == -1 || sum + tmp > 1e9){
				sum = -1;
				break;
			}
			sum += tmp;
		}
	}
	if(sum != -1){
		lli a = get_digit(sum), b = get_digit(T);
		if(a + b > 12 || sum * T > 1e9) sum = -1;
		else sum *= T;
	}
	if(sum == -1) cout << "TLE" << endl;
	else cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(void)
{
  int N,M,i,num=0;
  scanf("%d %d",&N,&M);
  int A[M];
  for(i=0;i<M;i++){
    scanf("%d",&A[i]);
    num=num+A[i];
  }
  if(num>N)
    printf("-1");
  else
    printf("%d",N-num);
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin >> n;
    stack< int > stk;
    for(int i=0;i<n;i++){
        cin >> x;
        if(stk.empty() || stk.top()>= x)   stk.push(x);
    }
    cout << stk.size() << endl;
}


Measured memory_bytes: 1024