akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair< int, int > Pi;

bool cmp(const pair< Pi, Pi >& p, const pair< Pi, Pi >& q)
{
  if(p.first.first + p.second.first, q.first.first + q.second.first)
    return(p.first.first + p.second.first < q.first.first + q.second.first);
  return(p.first.first * p.first.second + p.second.first * p.second.second <
         q.first.first * p.first.second + q.second.first * q.second.second);
}

// ax + by = d
pair< Pi, Pi > ask(int a, int b, int d)
{
  pair< Pi, Pi > ret({INF, INF}, {INF, INF});
  for(int x = 0; x < 50000; x++) {
    int f = abs(d - a * x);
    if(f % b == 0) ret = min(ret, {{x, a}, {f / b, b}}, cmp);
  }
  return(ret);
}

int main()
{
  int a, b, d;
  while(cin >> a >> b >> d, a) {
    auto alpha = ask(a, b, d), beta = ask(b, a, d);
    auto ret = min(alpha, beta, cmp);
    if(ret == beta) swap(ret.first, ret.second);
    cout << ret.first.first << " " << ret.second.first << endl;
  }
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> P;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    string S;
    cin >> S;
    int A = S.size() - 1;

    while (A > 0) {
        if (A % 2 != 0) {
            A--;
            continue;
        }
        for (int i = 0; i < A / 2; i++) {
            if (S.at(i) != S.at(i + A / 2)) {
                break;
            }
            if (i == A / 2 - 1) {
                cout << A << endl;
                return 0;
            }
        }
        A--;
    }
}

Measured memory_bytes: 256
#coding:utf-8
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    m1, d1 = LMIIS()
    m2, d2 = LMIIS()

    if m1 != m2:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
//
// Created on 2020/09/27.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    if(n == 1){
        cout<<"Hello World"<<endl;
        return 0;
    }else{
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
void solve()
{
	ll n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 == 0)
	{
		string s1;
		string s2;
		for (int i = 0; i < (n / 2); i++)
		{
			s1 += s[i];
		}
		for (int i = (n / 2); i < n; i++)
		{
			s2 += s[i];
		}
		//cout << s1 << " " << s2 << endl;
		if (s1 == s2)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	else
	{
		cout << "No" << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t = 1;
	while (t--)
	{
		solve();
	}
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 3E3+7;

long long f[N][N];
string a,b;
vector<char> res;

int main()
{
    cin>>a>>b;
    
    int n = a.size();
    int m = b.size();
    
    a = ' ' + a;
    b = ' ' + b;
    
    for (int i = 1;i <= n;++i)
        if (a[1] == b[i]) f[1][i] = 1;
    
    for (int i = 1;i <= m;++i)
        if (a[i] == b[1]) f[i][1] = 1;
    
    for (int i = 1;i <= n;++i)
        for (int j = 1;j <= m;++j)
            if (a[i] == b[j]) f[i][j] = f[i-1][j-1] + 1;
            else f[i][j] = max(f[i-1][j],max(f[i][j-1],max(f[i-1][j-1],f[i][j])));
    
    while (n > 0 && m > 0)
    {
        if (a[n] == b[m])
        {
            res.push_back(a[n]);
            --n;
            --m;
        }
        else if (f[n][m] == f[n-1][m]) --n;
        else if (f[n][m] == f[n][m-1]) --m;
    }
    
    reverse(res.begin(),res.end());
    for (int i = 0;i < (int)res.size(); ++i) cout<<res[i];
}

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

int main() {
  string S; cin >> S;
  long long K; cin >> K;
  int i = 0;
  while (S[i] == '1') {
    K -= 1;
    if (K == 0) break;
    i++;
  }
  cout << S[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    ll n; cin >>n;
    vector<ll> t(n); vector<ll> a(n);
    REP(i,n) cin >> t[i] >> a[i];

    ll anst = t[0], ansa = a[0];

    for (ll i = 1; i < n; i++) {
        ll st = anst/t[i];
        if (anst % t[i] != 0) {
            st++;
        } 
        ll sa = ansa/a[i];
        if (ansa % a[i] != 0) {
            sa++;
        }
        if (sa > st) {
            anst = t[i]*sa;
            ansa = a[i]*sa;
        } else {
            anst = t[i]*st;
            ansa = a[i]*st;
        }
    }

    cout << anst + ansa << endl;
    
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  int n = s.size();
  string ans = "AC";
  if ( s[0] != 'A' )  ans = "WA";
  int cnt = 0;
  for ( int i = 1; i < n; ++i ) {
    if ( isupper ( s[i] ) ) {
      if ( i == 1 || i == n-1 || s[i] != 'C' ) {
        ans = "WA";
      }
      ++cnt;
    }
  }
  if ( cnt != 1 )  ans = "WA";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import numpy as np

N,M = map(int,input().split())
A = np.array([input().split() for _ in range(N)],dtype=np.int32)

"""
最人気を消去しない → それが採用
消去 → 消去
"""

answer = 10**10
for _ in range(M):
    counter = np.bincount(A[:,0])
    i = counter.argmax()
    max_cnt = counter[i]
    if answer > max_cnt:
        answer = max_cnt
    A = A[A != i].reshape(N,-1)

print(answer)

Measured memory_bytes: 19344
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define mid (l+r>>1)
#define M 200020
using namespace std;
int read(){
	int nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int num[M],p[M<<2][2],tg[M<<2],mk[M<<2];
int n,m,X,R[M],PS[M],tk[M],G[M],tim[M];
bool cmpnum(int i,int j){return G[i]<G[j];}
inline void pushdown(int x){
	if(mk[x]>-1){
		mk[x<<1]=mk[x<<1|1]=mk[x],tg[x<<1]=tg[x<<1|1]=0;
		p[x<<1][0]=p[x<<1|1][0]=mk[x];
		p[x<<1][1]=p[x<<1|1][1]=mk[x];
	}
	if(tg[x]){
		tg[x<<1]+=tg[x],tg[x<<1|1]+=tg[x];
		p[x<<1][0]+=tg[x],p[x<<1|1][0]+=tg[x];
		p[x<<1][1]+=tg[x],p[x<<1|1][1]+=tg[x];
	}
	mk[x]=-1,tg[x]=0;
}
inline void pushup(int x){p[x][0]=p[x<<1][0],p[x][1]=p[x<<1|1][1];}
void build(int x,int l,int r){
	tg[x]=0,mk[x]=-1;
	if(l==r){p[x][0]=p[x][1]=num[l];return;}
	build(x<<1,l,mid),build(x<<1|1,mid+1,r);
	pushup(x);
}
int getnum(int x,int l,int r,int pos){
	if(l==r) return p[x][0];
	int NUM; pushdown(x);
	if(pos<=mid) NUM=getnum(x<<1,l,mid,pos);
	else NUM=getnum(x<<1|1,mid+1,r,pos);
	pushup(x); return NUM;
}
void add(int x,int l,int r,int dt){
	if(p[x][0]+dt>=X) p[x][0]=p[x][1]=mk[x]=X,tg[x]=0;
	else if(p[x][1]+dt<=0) p[x][0]=p[x][1]=mk[x]=0,tg[x]=0;
	else if(0<=p[x][0]+dt&&p[x][1]+dt<=X){p[x][0]+=dt,p[x][1]+=dt,tg[x]+=dt;}
	else pushdown(x),add(x<<1,l,mid,dt),add(x<<1|1,mid+1,r,dt),pushup(x);
}
int main(){
	X=read(),m=read();
	for(int i=1;i<=m;i++) R[i]=read();
	n=read();
	for(int i=1;i<=n;i++) tim[i]=read(),G[i]=read(),PS[i]=i;
	sort(PS+1,PS+n+1,cmpnum),R[++m]=tim[n]+1;
	for(int i=1;i<=n;i++) num[i]=G[PS[i]],tk[PS[i]]=i;
	build(1,1,n);
	for(int i=1,kd=-1,now=0;i<=m;i++,kd=-kd){
		while(now<n&&tim[now+1]<=R[i]){
			now++; int x=getnum(1,1,n,tk[now]);
			x+=kd*(tim[now]-R[i-1]),printf("%d\n",max(min(x,X),0));
		}
		add(1,1,n,(R[i]-R[i-1])*kd);
	}
	return 0;
}

Measured memory_bytes: 13056
import heapq

N, H = map(int, input().split())
b = []
max_a = 0
for i in range(N):
    ai, bi = map(int, input().split())
    heapq.heappush(b, -bi)
    max_a = max(ai, max_a)

ans = 0
while b != [] and H > 0:
    bi = -heapq.heappop(b)
    if bi < max_a:
        break
    H -= bi
    ans += 1
if H > 0:
    ans += (H + max_a - 1) // max_a
print(ans)


Measured memory_bytes: 7116
k,s = map(int,input().split())

cnt = 0
for i in range(0, k+1):
    #cnt += 1:
        for j in range(0, k+1):
            t = s - i - j
            if t <=k and 0 <= t:
                cnt += 1
            #print(cnt)
            #print(i, j, t)
print(cnt)

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, m;
	cin >> n >> m;

	map<int, pair<int, int>> mp;
	for (int i = 0; i < m; i++) {
		int p, y;
		cin >> p >> y;
		p--;
		mp[y] = make_pair(p, i);
	}

	vector<string> ans(m);
	vector<int> cnts(n);
	for (auto m : mp) {
		int pv = m.second.first;
		int pi = m.second.second;

		ostringstream sout;
		sout << std::setfill('0') << std::setw(6) << (pv + 1);
		string a = sout.str();

		cnts[pv]++;
		ostringstream sout2;
		sout2 << std::setfill('0') << std::setw(6) << cnts[pv];
		string b = sout2.str();

		ans[pi] = a + b;
	}

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

	return 0;
}


Measured memory_bytes: 13696
n, T = gets.strip.split.map(&:to_i)

a = n.times.map { gets.strip.split.map(&:to_i) }
cs = a.select { |c, t| t <= T }.map { |c, t| c }
# p a
# p cs
puts cs.size > 0 ? cs.min : 'TLE'


Measured memory_bytes: 1788
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
std::string s;

int main(){
    scanf("%ld", &n);
    std::cin >> s;
    s.push_back('A');
    long ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] != s[i+1]){
            ans++;
        }
    }
    printf("%ld\n", ans);
}


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

void solve(int n){
	vector<int> p;
	for(int i=2; i<=2*n; ++i){
		bool f = false;
		for(auto j : p){
			if(j * j > i) break;
			if(i % j == 0){
				f = true;
				break;
			}
		}
		if(!f) p.push_back(i);
	}
	cout << p.size() - (int)(upper_bound(p.begin(), p.end(), n) - p.begin()) << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}


Measured memory_bytes: 3200
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};
typedef BinaryIndexedTree<int> BIT;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    BIT bit[2];
    rep(i, 2) {
        bit[i] = BIT(N);
        rep(j, N) {
            int a;
            cin >> a;
            bit[i].add(j, a);
        }
    }

    int ans = 0;
    rep(i, N) {
        smax(ans, bit[0].sum(0, i + 1) + bit[1].sum(i, N));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {

  val MOD = 1000L * 1000L * 1000L + 7

  implicit class RichLong(value :Long) {
    def add(l: Long): Long = (value + l) % MOD
  }

  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val tmp1, tmp2 = sc.next()

  val t1 = tmp1.zipWithIndex
    .filter(t => t._2 == 0 || (tmp1(t._2 - 1) != t._1))
    .map(_._1)
  val t2 = tmp2.zipWithIndex
    .filter(t => t._2 == 0 || (tmp2(t._2 - 1) != t._1))
    .map(_._1)

  val sum = t1.zip(t2)
    .foldLeft(Array.fill(9)(-1L)) {
      case (mem, (c1, c2)) =>
        if (mem(0) < 0L) {
          if (c1 == c2) {
            val seq = Array.fill(9)(0L)
            seq(0) = 1
            seq(1) = 1
            seq(2) = 1
            seq
          } else {
            val seq = Array.fill(9)(1L)
            seq(0) = 0
            seq(1) = 0
            seq(2) = 0
            seq
          }
        } else {
          if (c1 == c2) {
            val seq = Array.fill(9)(0L)
            seq(0) = mem(1).add(mem(2))
              .add(mem(4)).add(mem(7))
            seq(1) = mem(2).add(mem(0))
              .add(mem(5)).add(mem(8))
            seq(2) = mem(0).add(mem(1))
              .add(mem(3)).add(mem(6))
            seq
          } else {
            val seq = Array.fill(9)(0L)
            seq(3) = mem(2).add(mem(4))
              .add(mem(5)).add(mem(6))
            seq(4) = mem(0).add(mem(3))
              .add(mem(5)).add(mem(7))
            seq(5) = mem(1).add(mem(3))
              .add(mem(4)).add(mem(8))
            seq(6) = mem(2).add(mem(7))
              .add(mem(8)).add(mem(3))
            seq(7) = mem(0).add(mem(8))
              .add(mem(6)).add(mem(4))
            seq(8) = mem(1).add(mem(6))
              .add(mem(7)).add(mem(5))
            seq
          }
        }
    }

  println(sum.foldLeft(0L) {
    case (s, v) => s.add(v)
  })
}


Measured memory_bytes: 27180
#include<cstdio>
#include<algorithm>
using namespace std;
#define MN 300000
int p[MN+5];
bool cmp(int a,int b){return a>b;}
int main()
{
	int n,a,b,i,j,k;
	scanf("%d%d%d",&n,&a,&b);
	if(a>n||b>n||b<(n+a-1)/a||b>n-a+1)return 0*puts("-1");
	for(i=1,k=n;i<=n;i+=a)for(j=min(n,i+a-1);j>=i;--j)p[j]=k--;
	for(i=(n+a-1)/a,j=n;i<b;++i,--j)if(j%a==1)--j;
	sort(p+j,p+n+1,cmp);
	for(i=1;i<=n;++i)printf("%d ",p[i]);
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string s, t;
    cin >> s >> t;
    bool ans = false;

    for(int i=0; i<s.length(); i++){
        if(s==t){
            ans = true;
            break;
        }
        s = s.back() + s.substr(0, s.length()-1);
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

for i in reversed(range(1,n)):
  if h[i-1] - h[i] == 1:
    h[i-1] -= 1
  elif h[i-1] - h[i] > 1:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 14396
#最近だいぶC問題が簡単に感じるようになってきたのは
#問題のあたりの問題か、成長か
#でも、場合わけ足りないこと多いから注意
n,k = map(int,input().split())
import math

ans = 0
for i in range(1,n+1):
  if i<k:
    c =math.ceil(math.log2(k/i))
    ans += ((1/2)**c)*(1/n)
  else:
    ans +=  1/n
    
print(ans)

Measured memory_bytes: 3060
import random
import sys
import time
import copy

input = sys.stdin.readline

def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(d):
        s.append(list(map(int, input().split())))
    
    start_time = time.time()
    beamwidth = 5
    ans = [[] for _ in range(beamwidth)]
    suff = 0
    # while True:
    #     elapsed_time = time.time() - start_time
    #     if elapsed_time >= 1.8:
    #         break
        
    # ここから
    topk = [{"last": [0 for _ in range(26)], "score": 0, "ans": []} for _ in range(beamwidth)]
    for i in range(d):
        # print(i)
        # print(*topk, sep='\n')
        # 各候補に対して top-k を生成
        nnnnn = []  # top-k * top-k 
        for bi in range(beamwidth):
            last = topk[bi]["last"]
            tmpsufss = []
            for con in range(26):
                tmpsufss.sort(key=lambda x: -x["score"])
                ttttt = topk[bi]["score"] + s[i][con]
                minus = 0
                for j in range(26):
                    if con == j:
                        continue
                    minus -= (i - last[j]) * c[j]
                ttttt += minus

                if len(tmpsufss) < beamwidth:
                    tmpsufss.append({
                        "last": last,
                        "score": ttttt,
                        "ans": copy.deepcopy(topk[bi]["ans"])
                    })
                    tmpsufss[-1]["last"][con] = i
                    tmpsufss[-1]["ans"].append(con)
                else:
                    if tmpsufss[-1]["score"] < ttttt:
                        tmpsufss.pop()
                        tmpsufss.append({
                            "last": last,
                            "score": ttttt,
                            "ans": copy.deepcopy(topk[bi]["ans"])
                        })
                        tmpsufss[-1]["last"][con] = i
                        tmpsufss[-1]["ans"].append(con)
            nnnnn.extend(tmpsufss)

        nnnnn.sort(key=lambda x: -x["score"])
        topk = nnnnn[:beamwidth]
        

    print(*[a + 1 for a in topk[0]["ans"]])

if __name__ == '__main__':
    main()


Measured memory_bytes: 10048
# coding: utf8

def read_int():
    return int(input())
 
 
def read_int_n():
    return list(map(int, input().split()))
 
 
def read_str():
    return input()
 

if __name__ == "__main__":
    s = read_str()
    ans = 1000
    for i in range(len(s) - 2):
        num = abs(int(s[i:i+3]) - 753)
        if ans > num:
            ans = num
    print(ans)

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

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

    ll resp=0;

    int n;
    cin>>n;

    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            resp+=i;
        }
    }

    cout<<resp;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(int x, int y) { return x < y ? x : y; }
const int Maxn = 1e5 + 5;
inline int read()
{
	rg int res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, tot, sum, a[Maxn],ans;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		tot += a[i];
	}
	ans = tot;
	for (int i = 1; i <= n; i++)
	{
		sum += a[i];
		ans = min(ans, abs(tot - 2 * sum));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 998244353;

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	vll a(n), b(n), c(n);
	rep(i, n) {
		cin >> a[i] >> b[i];
		ans -= b[i];
		c[i] = a[i] + b[i];
	}
	vsort(c);
	for (int i = 0; i < n; i += 2) {
		ans += c[n - 1 - i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define N 1005
#define INF 0x3f3f3f3f 
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans;
 
int main(){
    ll n, k;
    cin >> n >> k;
    map <int,ll> mp;
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        mp[a]+=b;
    }
    ll cntr = 0;
    for(auto i:mp){
        cntr+=i.second;
        if(cntr >= k){
            cout << i.first;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 7504
def resolve():
    A, V = list(map(int, input().split()))
    B, W = list(map(int, input().split()))
    T = int(input())
    if V < W:
        print('NO')
        return
    else:
        if abs(V-W) * T >= abs(A-B):
            print('YES')
            return
    print('NO')
    return

resolve()

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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> K(Q); cin >> K;

    vector<int> sumd(N), summ(N), ic;
    vector<ll> sumdm(N);
    sumd[0] = S[0] == 'D';
    summ[0] = S[0] == 'M';
    sumdm[0] = 0;
    for (int i = 1; i < N; i++) {
        sumd[i] = sumd[i-1] + (S[i] == 'D');
        summ[i] = summ[i-1] + (S[i] == 'M');
        sumdm[i] = sumdm[i-1] + (S[i] == 'M' ? sumd[i] : 0);
        if (S[i] == 'C') ic.push_back(i);
    }

    for (int k : K) {
        ll ans = 0;
        for (const int& i : ic) {
            ll dm = sumdm[i-1];
            if (i - k >= 0) {
                dm -= sumdm[i-k];
                dm -= (ll)sumd[i-k] * (summ[i-1] - summ[i-k]);
            }
            ans += dm;
        }
        cout << ans << endl;
    }
}


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

const int INF = 1LL << 60;
vector<int> divisor(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; i++) {
        if(n % i != 0)
            continue;
        ret.push_back(i);
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;

    auto v = divisor(N);

    int ans = INF;
    for (auto a : v) {
        ans = min(a - 1 + N / a - 1, ans);
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 384
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    a, b, c = map(int, input().split())
    k = int(input())
    i = 0
    while a >= b:
        b *= 2
        i+= 1
    while b >= c:
        c *= 2
        i+=1
    if i <= k:
        print('Yes')
    else:
        print('No')
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int fact(int n)
{
    if (n == 0)
        return 1;
    if (n == 1)
        return 1;
    return fact(n - 1);
}

int main()
{
    int N;
    cin >> N;
    int P[N], Q[N];

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

    int a = 1;
    int P_copy[N];
    memcpy(P_copy, P, sizeof(P));
    do
    {
        bool flag = true;
        for (int i = 0; i < N; i++)
        {
            if (P_copy[i] != P[i])
            {
                flag = false;
                break;
            }
        }
        a++;
    } while (next_permutation(P, P + N));

    int b = 1;
    int Q_copy[N];
    memcpy(Q_copy, Q, sizeof(Q));
    do
    {
        bool flag = true;
        for (int i = 0; i < N; i++)
        {
            if (Q_copy[i] != Q[i])
            {
                flag = false;
                break;
            }
        }
        b++;
    } while (next_permutation(Q, Q + N));
    cout << abs(a - b) << endl;
}


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

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for (int &pi: p) cin >> pi;
    vector<int> dp(n + 1);
    for (int cur: p) dp[cur] = dp[cur - 1] + 1;
    int res = n - *max_element(dp.begin(), dp.end());
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        
        int max = -1;
        int min = 101;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();

            if (max < a[i])
                max = a[i];
            
            if(min > a[i])
                min = a[i];
        }

        int hp_min = Integer.MAX_VALUE;
        for (int i = min; i <= max; i++) {
            int hp = 0;
            for (int j = 0; j < a.length; j++) {
                hp += Math.pow(a[j] - i, 2);
            }
            if (hp < hp_min) {
                hp_min = hp;
            }
        }

        System.out.println(hp_min);
    }
}

Measured memory_bytes: 21844
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

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

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

		int H = sc.nextInt();
		int W = sc.nextInt();

		boolean[][] s = new boolean[H][W]; // '#'->false '.'->true

		for (int i = 0; i < H; i++) {
			String str = sc.next();
			for (int j = 0; j < W; j++) {
				s[i][j] = str.charAt(j) == '.' ? true : false;
			}
		}

		int[][] yoko = new int[H][W];
		for (int i = 0; i < H; i++) {
			if (s[i][0]) {
				yoko[i][0] = 1;
			} else {
				yoko[i][0] = 0;
			}
			for (int j = 1; j < W; j++) {
				if (s[i][j]) {
					yoko[i][j] = yoko[i][j - 1] + 1;
				} else {
					yoko[i][j] = 0;
				}
			}

			for (int j = W - 1; j >= 0; j--) {
				if (yoko[i][j] != 0 && j != W - 1 && yoko[i][j + 1] != 0) {
					yoko[i][j] = yoko[i][j + 1];
				}
			}
		}

		int[][] tate = new int[H][W];

		for (int j = 0; j < W; j++) {
			if (s[0][j]) {
				tate[0][j] = 1;
			} else {
				tate[0][j] = 0;
			}
			for (int i = 1; i < H; i++) {
				if (s[i][j]) {
					tate[i][j] = tate[i - 1][j] + 1;
				} else {
					tate[i][j] = 0;
				}
			}

			for (int i = H - 1; i >= 0; i--) {
				if (tate[i][j] != 0 && i != H - 1 && tate[i + 1][j] != 0) {
					tate[i][j] = tate[i + 1][j];
				}
			}
		}

		int ans = Integer.MIN_VALUE;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				ans = Math.max(ans, yoko[i][j] + tate[i][j] - 1); //ランプを置いた場所を2重にカウントしてるので1引く
			}
		}

		out.println(ans);

		sc.close();

	}

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

}


Measured memory_bytes: 80796
fun main(args: Array<String>) {
    val A = IntArray(readLine()!!.toInt()) { readLine()!!.toInt() }

    var index = 1 - 1
    var count = 0
    while (count <= A.size) {
        count++
        val light = A[index]
        if (light == 2) {
            println(count)
            return
        }
        index = light - 1
    }
    println(-1)
}



Measured memory_bytes: 39388
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

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

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

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,k,ans = 0,cnt = 0;
    bool f = false;
    cin >> n >> k;
    vector<ll> a(n),t(n * 2);
    rep0(i, n)cin >> a[i];
    do{
        f = false;
        rep0(i, n - 1){
            if(a[i] > a[i + 1]){
                f = true;
                ++cnt;
                swap(a[i], a[i + 1]);
            }
        }
    }while(f);
    
    rep0(i, n * 2){
        t[i] = a[i % n];
    }
    
    ans = cnt * k % mod;
    cnt = 0;
    do{
        f = false;
        rep0(i, n * 2 - 1){
            if(t[i] > t[i + 1]){
                f = true;
                ++cnt;
                swap(t[i], t[i + 1]);
            }
        }
    }while(f);
    ans += cnt * ((k * (k - 1) / 2) % mod);
    pf(ans % mod)
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  if (k > (n - 1) * (n - 2) / 2) {
    puts ("-1");
    return;
  }
  i32 cnt = n - 1 + ((n - 1) * (n - 2) / 2 - k);
  printf ("%" PRIi32 "\n", cnt);
  for (i32 i = 1; i < n; ++i) {
    printf ("%" PRIi32 " %" PRIi32 "\n", 1, i + 1);
  }
  i32 t = (n - 1) * (n - 2) / 2 - k;
  for (i32 i = 1; t > 0; ++i) {
    for (i32 j = i + 1; j < n && t > 0; ++j, --t) {
      printf ("%" PRIi32 " %" PRIi32 "\n", i + 1, j + 1);
    }
  }
}

int main (void) {
  run();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include <map>
#include <queue>

using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;

int main(){
  int n,m; cin>>n>>m;
  int p[n]; bool q[n]={true}; fill(p,p+n,1);

  for(int i=0;i<m;i++) {
    int x,y; cin>>x>>y; x--; y--;
    if (q[x]) {
      if (p[x]==1) {
        q[x]=false; q[y]=true;
      } else {
        q[y]=true;
      }
      p[x]--; p[y]++;
    } else {
      p[x]--; p[y]++;
    }
  }

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


Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int a, b;
	long int ans;
	
	scanf("%ld%ld", &a, &b);
	
	if(a < 2 * b) {
		ans = 0;
	} else {
		ans = a - 2 * b;
	}
	
	printf("%ld", ans);
	
	return 0;
}


Measured memory_bytes: 128
import math as m

S = list(input())
turning_point_indexes = [0]
for i in range(1, len(S)):
    if S[i] != S[i-1]:
        turning_point_indexes.append(i)
turning_point_indexes.append(len(S))

A = [0]*len(S)
for i in range(1, len(turning_point_indexes), 2):
    turning_point_index = turning_point_indexes[i]
    left_count = turning_point_indexes[i] - turning_point_indexes[i-1]
    right_count = turning_point_indexes[i+1] - turning_point_indexes[i]
    A[turning_point_index-1] = m.ceil(left_count/2) + m.floor(right_count/2)
    A[turning_point_index] = m.floor(left_count/2) + m.ceil(right_count/2)

print(*A)

Measured memory_bytes: 15340
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 100'000
struct edge { int u, v, w; };
vector<edge> adj[N+1];
void link(int u, int v, int w) {
    adj[u].push_back({u, v, w});
    adj[v].push_back({v, u, w});
}
bool vis[N+1];
ll d[N+1];
int p[N+1];
void sssp(int s, int n = N) {
    fill(vis, vis + n + 1, false);
    fill(d, d + n + 1, -1);
    fill(p, p + n + 1, -1);
    d[s] = 0;
    priority_queue<pair<ll, int>> pq;
    pq.push({-d[s], s});
    while(not pq.empty()) {
        int u = pq.top().second; pq.pop();
        if(not vis[u]) {
            vis[u] = true;
            for(const edge& e : adj[u]) {
                if(not vis[e.v] and (d[e.v] > d[u] + e.w or d[e.v] == -1)) {
                    d[e.v] = d[u] + e.w;
                    p[e.v] = u;
                    pq.push({-d[e.v], e.v});
                }
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for(int i = 1; i < n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        link(u, v, w);
    }
    int q, k;
    cin >> q >> k;
    sssp(k);
    while(q--) {
        int u, v;
        cin >> u >> v;
        cout << d[u] + d[v] << endl;
    }
    return 0;
}


Measured memory_bytes: 11316
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
ll a[200010];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    ll ans=0;
    Rep(i,1,n){
        if(a[i-1]>a[i]){
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 5196
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

void DFS(int v, int from, int curH, const vector<vi>& g, vi& h, vi& p) {
  p[v] = from;
  h[v] = curH;
  for (int to : g[v]) if (to != from) DFS(to, v, curH + 1, g, h, p);
}

void Output(string s) {
  cout << s << endl;
  exit(0);
}

int main()
{
  int n;
  cin >> n;
  vector<vi> g(n);
  vi d(n);

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

  vi h(n), p(n);
  DFS(0, -1, 0, g, h, p);

  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) v[i] = make_pair(h[i], i);
  sort(v.rbegin(), v.rend());

  vector<bool> live(n, true);
  for (auto cur : v) {
    int i = cur.second;
    if (!live[i]) continue;
    live[i] = false;
    if (d[i] == 0) Output("First");
    d[p[i]]--;
    i = p[i];
    if (d[i] == 0) Output("Second");
    if (d[i] != 1) Output("First");
    live[i] = false;
    d[p[i]]--;
  }
  Output("Second");

  return 0;
}


Measured memory_bytes: 7808
N,M=map(int,input().split())
x=[0]*(N+1)
for i in range(M) :
  a,b=map(int,input().split())
  for j in range(1,N+1) :
    if a==j or b==j :
      x[j]+=1
for i in range(1,N+1) :
  print(x[i])

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		
		for(int i = 0; i < s.length(); i++) {
			if(i+1 == k) {
				System.out.print(Character.toLowerCase(s.charAt(i)));
			} else {
				System.out.print(s.charAt(i));
			}
		}
	}
}


Measured memory_bytes: 35684
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

int n;
vector<vector<int> > v;

int32_t main(){ _
    cin >> n;
    for(int i = 0; i < n; i++){
        int a, b, c;
        vector<int> temp(3);
        cin >> temp[0] >> temp[1] >> temp[2];
        v.pb(temp);
    }
    for(int cx = 0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy++){
            set<int> exact;
            set<int> less;
            for(int i = 0; i < n; i++){
                if(v[i][2] == 0){
                    less.insert((abs(cx - v[i][0]) + abs(cy - v[i][1])));
                }
                else{
                    exact.insert(v[i][2] + (abs(cx - v[i][0]) + abs(cy - v[i][1])));
                }
            }
            // tr(cx, cy, (int()));
            // for(auto i: exact){
            //     tr(i);
            // }
            // for(auto j: less){
            //     tr(j)
            // }
            if((int)exact.size() == 1){
                int a = inf;
                if(!less.empty()){
                    a = *less.begin();
                }
                int b = *exact.begin();
                if(a >= b){
                    cout << cx << " " << cy << " " << b << endl;
                    return 0;
                }
            }
        }
    }
}


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

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

cnt = 0
mode = 0

for i in range(len(A)):
    if i == 0:
        continue
    
    if (A[i] - A[i-1] >= 0 and mode >=0) or (A[i] - A[i-1] <= 0 and mode <= 0):
        if A[i] - A[i-1] > 0:
            mode = 1
        if A[i] - A[i-1] < 0:
            mode = -1
    else:
        mode = 0
        cnt += 1

print(cnt+1)

Measured memory_bytes: 62704
#include<queue>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[31][30],b[30][31],d[30][30],p,w,h,x,y;
  queue<pair<pair<int,int>,int> > c;
  while(cin>>w>>h&&w+h){
    memset(a,-1,sizeof(a));
    memset(b,-1,sizeof(b));
    for(j=1;j<w;j++){
      cin>>a[j][0];
      a[j][0]=-a[j][0];
    }
    for(i=1;i<h;i++){    
      for(j=0;j<w;j++){
	cin>>b[j][i];
	b[j][i]=-b[j][i];
      }
      for(j=1;j<w;j++){
	cin>>a[j][i];
	a[j][i]=-a[j][i];
      }
    }
    memset(d,-1,sizeof(d));
    x=y=0;
    while(c.empty()==0)
      c.pop();
    c.push(make_pair(make_pair(x,y),1));
    while(c.empty()==0){
      x=c.front().first.first;
      y=c.front().first.second;
      p=c.front().second;
      if(x==w-1&&y==h-1)
	break;
      c.pop();
      if(d[x][y]==-1||d[x][y]>p){
	d[x][y]=p;
	if(a[x][y]==0)
	  c.push(make_pair(make_pair(x-1,y),p+1));
	if(a[x+1][y]==0)
	  c.push(make_pair(make_pair(x+1,y),p+1));
	if(b[x][y]==0)
	  c.push(make_pair(make_pair(x,y-1),p+1));
	if(b[x][y+1]==0)
	  c.push(make_pair(make_pair(x,y+1),p+1));
      }
    }
    if(c.empty())
      cout<<0<<endl;
    else
      cout<<p<<endl;
  }
  return 0;
}

Measured memory_bytes: 920
n=int(input())
l=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(l[0]-l[1])
for i in range(2,n):
    dp[i]=min(abs(l[i-1]-l[i])+dp[i-1], abs(l[i-2]-l[i])+dp[i-2])

print(dp[-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int r,c,i,a,b,j,k=1;
    string s;
    map<int,char>mp;
    for(char c='A';c<='Z';c++)
    {
        mp[k++]=c;
    }
    while(cin>>r>>c)
    {
        for(i=1;i<=r;i++)
        {
            for(j=1;j<=c;j++)
            {
                cin>>s;
                if(s=="snuke")
                {
                    a=i;
                    b=j;
                }
            }
        }
        cout<<mp[b]<<a<<endl;
    }
    return 0;
}


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

template <class Abel> struct BIT {
	vector<Abel> dat[2];
	Abel UNITY_SUM = 0;                     // to be set

	/* [1, n] */
	BIT(int n) { init(n); }
	void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

	/* a, b are 1-indexed, [a, b) */
	inline void sub_add(int p, int a, Abel x) {
		for (int i = a; i < (int)dat[p].size(); i += i & -i)
			dat[p][i] = dat[p][i] + x;
	}
	inline void add(int a, int b, Abel x) {
		sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
	}

	/* a is 1-indexed, [a, b) */
	inline Abel sub_sum(int p, int a) {
		Abel res = UNITY_SUM;
		for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
		return res;
	}
	inline Abel sum(int a, int b) {
		return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
	}

	/* debug */
	void print() {
		for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
		cout << endl;
	}
};

int main() {
	int N; cin >> N;
	int Q; cin >> Q;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) cin >> a[i];

	vector<int> lefts(Q), rights(Q), ids(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> lefts[i] >> rights[i];
		--lefts[i];
		ids[i] = i;
	}
	sort(ids.begin(), ids.end(), [&](int i, int j) {
		return rights[i] < rights[j]; });

	BIT<int> bit(N + 5);
	vector<int> prev(1100000, -1);
	vector<int> res(Q, 0);
	int r = 0;
	for (auto i : ids) {
		for (; r < rights[i]; ++r) {
			bit.add(prev[a[r]] + 2, r + 2, 1);
			prev[a[r]] = r;
		}
		int tmp = bit.sum(lefts[i] + 1, lefts[i] + 2);
		res[i] = max(res[i], tmp);
	}
	for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main()
{
	string x;
	int s;
	cin.tie(0);
	while (cin >> x && x != "0") {
		s = 0;
		for (int i = 0; i < x.length(); i++) s += x[i] - '0';
		cout << s << "\n";
	}
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n, m, cnt=0, bcnt=0, mmax=INT_MIN;
    char s[max][11], t[max][11];
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%s", s[i]);
    }
    scanf("%d", &m);
    rep(i, m){
        scanf("%s", t[i]);
    }
    
    rep(i, n){
        cnt=0;
        bcnt=0;
        for(int j=i; j<n; j++){
            if (!strcmp(s[i], s[j])) {
                cnt++;
            }
        }
        rep(k, m){
            if (!strcmp(s[i], t[k])) {
                bcnt++;
            }
        }
        
       // printf("%d,%d", cnt, bcnt);
        if (cnt>=bcnt&&cnt-bcnt>mmax) {
            mmax=cnt-bcnt;
        }
    }
    
    if (mmax!=INT_MIN) {
        printf("%d", mmax);
    } else {
        printf("%d", 0);
    }
    
    return 0;
}


Measured memory_bytes: 1684
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0

int main ()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=(n/(a+b))*a;
    if(n%(a+b)>a)
        ans+=a;
    else
        ans+=(n%(a+b));
    cout<<ans<<endl;
    End;
}
/* pray for me
All is well
*/



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char ABCD[8];
	int search;
	if (scanf("%7s", ABCD) != 1) return 1;
	for (search = 0; search < 8; search++) {
		int e = ABCD[0] - '0';
		int i;
		for (i = 0; i < 3; i++) {
			int d = ABCD[i + 1] - '0';
			if ((search >> i) & 1) e -= d; else e += d;
		}
		if (e == 7) {
			putchar(ABCD[0]);
			for (i = 0; i < 3; i++) {
				putchar((search >> i) & 1 ? '-' : '+');
				putchar(ABCD[i + 1]);
			}
			puts("=7");
			return 0;
		}
	}
	puts("error");
	return 0;
}


Measured memory_bytes: 128
N = int(input())
S = list(input()) #１文字ずつ

ans=0
for i in range(1,N):
    X = S[0:i]
    Y = S[i:N]
    cnt=0
    # print('X.,Y:', X,Y)

    als=[chr(ord('a') + i) for i in range(26)]
    for al in als:
        if (al in X) and (al in Y):
            cnt+=1
    ans=max(ans,cnt)
print(ans)


Measured memory_bytes: 67876