akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x, y, h = [], [], []

for i in range(n):
    X, Y, H = map(int, input().split())
    x.append(X)
    y.append(Y)
    h.append(H)

for X in range(101):
    for Y in range(101):
        for i in range(n):
            H = h[i] + abs(x[i] - X) + abs(y[i] - Y)
            if all(h[j] == max(H - abs(x[j] - X) - abs(y[j] - Y), 0) for j in range(n)):
                print(X, Y, H)
                break

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

int main() {
    ll x, y, ans = 0;
    cin >> x >> y;
    while(x<=y) {
        ans++;
        x*=2; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define reg register
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n;
ll a[N],ans,ave;
inline ll read()
{
	ll x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
int main()
{
	n=read();
	for (reg int i=1;i<=n;i++) a[i]=read()-i;
	sort(a+1,a+n+1); ave=(n&1?a[(n+1)>>1]:(a[n>>1]+a[n>>1|1])>>1);
	for (reg int i=1;i<=n;i++) ans+=abs(a[i]-ave);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    LL x,k,d;cin >> x >> k >> d;
    x = abs(x);
    LL a = x - d * (x / d), ai = x / d;
    LL b = abs(x - d * (ai + 1)), bi = ai + 1;
    if(k <= ai){
        cout << x - k * d << endl;
    }
    else{
        if(k % 2 == ai % 2){
            cout << a << endl;
        }
        else{
            cout << b << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n; cin >> n;
        vector<vll> a(n+5,vll(3));


        rep(i,n){
            rep(j,3){
                cin >> a[i][j];
            }
        }

        vector<vll> d(n+5,vll(3));
        rep(i,3)d[0][i]=a[0][i];

        repA(i,1,n-1){
            rep(j,3){
                ll mx =0;
                rep(k,3){
                    if(k!=j){
                        mx = max(mx,d[i-1][k]);
                    }
                }
                d[i][j] = mx+a[i][j];
            }
        }

        ll ans =0;
        rep(i,3){
            ans = max(ans,d[n-1][i]);
        }
        cout << ans << endl;
    }
}


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

int main() {
    string s; cin >> s;
    long long _ = 1, a = 0, ab = 0, abc = 0;
    for (char ch: s) {
        if (ch == 'A') a += _;
        if (ch == 'B') ab += a;
        if (ch == 'C') abc += ab;
        if (ch == '?') {
            abc = abc * 3 + ab;
            ab = ab * 3 + a;
            a = a * 3 + _;
            _ = _ * 3;
        }
        _ %= MOD, a %= MOD, ab %= MOD, abc %= MOD;
    }
    cout << abc << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000000
# define mm 1000000007
# define pi acos(-1)
# define fi first
# define se second

using namespace std;

signed main()
{
    gok

       int n;
       cin>>n;
       int a[n-1];
       map<int,int> mp;
       for(int i=0;i<n-1;i++){
        cin>>a[i];
        mp[a[i]]++;
       }
       for(int i=1;i<=n;i++)
       {
           cout<<mp[i]<<endl;
       }





















      return 0;
    }


Measured memory_bytes: 17720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e5;
const int size=1e5;
const int inf=1e9;
int main(){
	int a,b,c;cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
idx = 0
ipyList = []
for i in range(M):
    idx += 1
    ipy = [int(i) for i in input().split()]
    ipy.insert(0, idx)
    ipyList.append(ipy)

ipyList = sorted(ipyList, key=lambda ipy: ipy[2])
cityMap = {}
for ipy in ipyList:
    if ipy[1] in cityMap.keys():
        cityMap[ipy[1]] += 1
    else:
        cityMap[ipy[1]] = 1
    ipy[2] = cityMap[ipy[1]]

ipyList = sorted(ipyList, key=lambda ipy: ipy[0])
for ipy in ipyList:
    print(str(ipy[1]).zfill(6) + str(ipy[2]).zfill(6))

Measured memory_bytes: 33624
import numpy as np

N, K = map(int, input().split())
H = np.array(list(map(int, input().split())))

"""
dp[i]: 足場iにいるときのコストの総和の最小値
"""

dp = np.zeros(N, dtype=np.int64)

for i in range(1, N):
    left = max(0, i - K)
    dp[i] = np.min(dp[left:i] + np.abs(H[i] - H[left:i]))

print(dp[N - 1])


Measured memory_bytes: 22904
#include<stdio.h>

int main(void){
   char s[100];
   int k;
   int n=0;

   scanf("%d",&k);
   scanf("%s",s);

   for(int i=0;s[i]!='\0';i++){
      n++;
   }

   if(n<=k){
      printf("%s",s);
   }else{
      for(int j=0;j<k;j++){
        printf("%c",s[j]);
      }
      printf("...");
   }

   return 0;
}


Measured memory_bytes: 1704
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = list(accumulate(LI()))
total = A[-1]
ret = INF
for i in range(n - 1):
    ret = min(ret, abs(total - A[i] -  A[i]))


print(ret)

Measured memory_bytes: 78704
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX = 2e5+6;
bool prime[10000009];
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<6-(a+b);
    
}

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

int a[3][3];

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

    for(int i=0;i<9;i++)cin>>a[i/3][i%3];

    int n=0;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int b;
        cin>>b;
        for(int j=0;j<9;j++) if(b==a[j/3][j%3])a[j/3][j%3]=0;
    }

    for(int i=0;i<3;i++)
    {
        if(a[i][0]+a[i][1]+a[i][2]==0)
        {
            cout<<"Yes\n";
            return 0;
        }
        if(a[0][i]+a[1][i]+a[2][i]==0)
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    if(a[0][0]+a[1][1]+a[2][2]==0)
    {
        cout<<"Yes\n";
        return 0;
    }
    if(a[0][2]+a[1][1]+a[2][0]==0)
    {
        cout<<"Yes\n";
        return 0;
    }

    cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
string S,T;
int N;

bool fall(char for_dir, char rev_dir, int s, int size){
  int index_for=1,index_rev=size;
  int i;REP(i,N){
    int I = N-i-1;
    if(T[I] == for_dir && index_rev != size) index_rev++;
    if(T[I] == rev_dir && index_for != 1 ) index_for--;
    if(S[I] == for_dir) index_for++;
    if(S[I] == rev_dir) index_rev--;
    if(index_for > index_rev) return true;
  }
  return index_for > s || s > index_rev;
}

int main(void){
  int H,W;
  //開始位置
  int sr,sc;
  cin >> H >> W >> N;
  cin >> sr >> sc;
  cin >> S >> T;
  bool res = true;

  if(fall('U','D',sr ,H)) res = false;
  if(fall('L','R',sc ,W)) res = false;

  if(res) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 776
N, Q = [int(x) for x in input().split()]
S = 'X' + input()
lr = [[int(x) for x in input().split()] for _ in range(Q)]

cum = [0] * (N + 1)
for i in range(1, N + 1):
    cum[i] = cum[i - 1]
    if S[i - 1 : i + 1] == 'AC':
        cum[i] += 1

for j in range(Q):
    print(cum[lr[j][1]] - cum[lr[j][0]])

Measured memory_bytes: 24456
import sys
input = sys.stdin.buffer.readline

def main():
    H,W,D = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(H)]
    Q = int(input())
    test = [list(map(int,input().split())) for _ in range(Q)]
    
    at = [None for _ in range(H*W)]
    for x in range(H):
        for y in range(W):
            at[A[x][y]-1] = (x,y)
            
    def move(x,y):
        dx = abs(at[y][0]-at[x][0])
        dy = abs(at[y][1]-at[x][1])
        return dx + dy
            
    cost = [[0 for _ in range(-(-H*W//D))] for _ in range(D)]
    for i in range(D):
        do = -(-(H*W-i)//D)
        for j in range(do-1):
            cost[i][j+1] = cost[i][j] + move(D*j+i,D*(j+1)+i)
            
    for i in range(Q):
        start,goal = test[i]
        v = start % D - 1
        u = -(-start // D) - 1
        w = -(-goal // D) - 1
        print(cost[v][w]-cost[v][u])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 45112
/* Arunava Chakraborty [ @iArunava ] */

/* Postal Code - AtCoder */

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a = 0, b = 0, i = 0;
    string add = "";
    scanf ("%d%d", &a, &b);
    cin >> add;
    for (i = 0; i < add.size(); ++i) {
        if (add[i] >= 48 && add[i] <= 57) continue;
        else {
            if (i == a && add[a] == '-') continue;
            cout << "No\n";
            return 0;
        }
    }
    add[a] == '-' ? printf ("Yes\n") : printf ("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[11];
  scanf("%s",s);
  int len=strlen(s);
  long long count=0,num=1;
  long long a[11];
  int i,j;
  for(i=0;i<len;i++){
    a[i]=s[i]-'0';
    num*=2;
  }
  num/=2;
  for(i=0;i<len;i++){
    long long power=num;
    if(i!=0)
      power/=2;
    for(j=i;j<len;j++){
      if(power==1)
        count+=a[i];
      else{
        if(j!=len-1)
          power/=2;
        count+=a[i]*power;
        a[i]=a[i]*10+a[j+1];
      }
    }
  }
  printf("%lld\n",count);
  return 0;
}

Measured memory_bytes: 1732
N, P = map(int, input().split())
A = list(map(int, input().split()))

dic = {"even":0, "odd":0}
for i in range(N):
    if A[i] % 2 == 0:
        dic["even"] += 1
    else:
        dic["odd"]  += 1

if dic["odd"] == 0:
    if P == 1:
        print(0)
    else:
        print(2 ** dic["even"])

else:
    print(2 ** (N-1))

Measured memory_bytes: 9136
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  string t;
  cin >> t;
  
  ll n = t.size();
  
  ll al[30] = {};
  rep(i, n) al[int(t[i] - 'a')]++;
  ll ans = 0;
  rep(i, int('z'-'a') + 1) ans += al[i] * (al[i] + 1LL) / 2LL;
  cout << 1LL + n * (n + 1LL) / 2LL - ans << endl;
  
  return 0;

}


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    long ans = 0;
    long count = Math.min(N, M / 2);
    ans += count;
    M -= 2 * count;
    ans += M / 4;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21588
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n;
    cin >> n;
    
    vector<pair<ll, ll>> a(n + 1, {0, 0});
    REP(i, n){
        ll t;
        cin >> t;
        a[i] = {t, i};
    }
    
    sort(a.begin(), a.end(), greater<pair<ll, ll>>());
    
    vector<ll> ans(n, 0);
    ll k = n;
    REP(i, n){
        if(k > a[i].second){
            ans[a[i].second] += (a[i].first - a[i + 1].first) * (i + 1);
            k = a[i].second;
        }
        else{
            ans[k] += (a[i].first - a[i + 1].first) * (i + 1);
        }
    }
    
    REP(i, n){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3456
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
	const int MAX = 32768+1;
	bool p[MAX];
	for (int i = 0; i < MAX; ++i)
		p[i] = true;
	p[0] = p[1] = false;
	for (int i = 2; i*i <= MAX; ++i) {
		if (p[i]) {
			for (int j = i+i; j < MAX; j+=i)
				p[j] = false;
		}
	}

	vector<int> prime;
	for (int i = 0; i < MAX; ++i) {
		if (p[i])
			prime.push_back(i);
	}

	int n;
	while (~scanf("%d", &n)) {
		if (n == 0)
			break;

		int ans = 0;
		for (unsigned int i = 0; i < prime.size(); ++i) {
			for (unsigned int j = i; j < prime.size(); ++j) {
				if (prime[i]+prime[j] == n)
					++ans;
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int sum = 0;
    for(int i = 0; i < n; ++i)
        sum += (i < k ? x : y);
    cout << sum << endl;
    return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

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

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

template<class T>
bool chmax(T &a, initializer_list<T> l)
{
	return chmax(a, *max_element(l.begin(), l.end()));
}

template<class T>
bool chmin(T &a, initializer_list<T> l)
{
	return chmin(a, *min_element(l.begin(), l.end));
}

template <typename T>
struct SegTree
{
	using F = function<T(T, T)>; // T*T -> X
	long long N;
	F f;
	const T ex;
	vector<T> dat;
	SegTree(long long n_, F f_, T ex_) : N(), f(f_), ex(ex_), dat(n_*4, ex_)
	{
		long long x = 1;
		while (n_ > x) x <<= 1;
		N = x;
	}

	void set(long long i, T x) {dat[i+N-1] = x;};
	void set(vector<T> &v)
	{
		for (long long i = 0; i < v.size(); ++i)
			set(i, v[i]);
	}

	void build()
	{
		for (long long k = N-2; k >= 0; --k)
			dat[k] = f(dat[k*2+1], dat[k*2+2]);
	}

	void update(long long i, T x)
	{
		i += N-1;
		dat[i] = x;
		while (i > 0)
		{
			i = (i-1)/2;
			dat[i] = f(dat[i*2+1], dat[i*2+2]);
		}
	}

	T query(long long a, long long b) {return query_sub(a, b, 0, 0, N);}
	T query_sub(long long a, long long b, long long k, long long l, long long r)
	{
		if (r <= a || b <= l) return ex;
		if (a <= l && r <= b) return dat[k];
		T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
		T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
		return f(vl, vr);
	}
};


ll N, M;
string S;

int main(int argc, char **argv)
{
	cin >> N >> M >> S;

	auto f = [](P a, P b)
			 {
				 return min(a, b);
			 };

	vector<ll> dp(N+1, INF), from(N+1, -1);
	dp[N] = 0;
	SegTree<P> uf(N+1, f, P(INF, -1));
	REP(i, N)
		uf.set(i, P(INF, i));
	uf.set(N, P(0, N));
	uf.build();

	for (ll n = N-1; n >= 0; --n)
	{
		if (S[n] == '0')
		{
			P p = uf.query(n+1, min(N+1, n+M+1));
			dp[n] = p.first + 1;
			from[n] = p.second;
			uf.update(n, P(dp[n], n));
		}
	}

	if (dp[0] >= INF)
	{
		std::cout << -1 << std::endl;
		return 0;
	}
	else
	{
		ll t = 0;
		while (t != N)
		{
			std::cout << from[t] - t << " ";
			t = from[t];
		}
		std::cout << std::endl;
	}
}


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

int main()
{

  int n,k,i,j,cnt=0;
  cin>>n>>k;

  int h[n];

  for(i=0;i<n;i++)
  {
    cin>>h[i];
    if(h[i]>=k)
      cnt++;
  }
  cout<<cnt<<endl;


  

}


Measured memory_bytes: 640
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt(), x = sc.nextInt();
	    int min =10002;
	    int sum = 0;
	    int cnt =0;
	    for(int i=0;i<n;i++){
	        int t =sc.nextInt();
	        sum+=t;
	        min = Math.min(min, t);
	    }
	    cnt+=n;
	    int val = x-sum;
	    //System.out.println(val);
	    while(val>=min){
	        sum+=min;
	        val-=min;
	        cnt++;
	    }
	    System.out.println(cnt);
	}
}

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

char f(char sw1, char sw2, char tar) {
	if ((sw2 == 'S' && tar == 'o') || (sw2 == 'W' && tar == 'x'))return sw1;
	return sw1 == 'S' ? 'W' : 'S';
}

int main() {
	int n; string s; cin >> n >> s;

	string d[4] = { "SS","SW","WS","WW" };
	for (int i = 0; i < 4; i++) {
		string ans = d[i];
		for (int j = 0; j < n - 2; j++) {
			ans += f(ans[j], ans[j + 1], s[j + 1]);
		}
		if (f(ans[n - 2], ans[n - 1], s[n - 1]) != ans[0])continue;
		if (f(ans[n - 1], ans[0], s[0]) != ans[1])continue;
		cout << ans << endl;
		return 0;
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 776
S = input()
s = list(S)
ans = "No"
if s[0] != s[1]:
    if S.count(s[0]) == 2 and S.count(s[1]) == 2:
        ans = "Yes"
elif s[0] != s[2]:
    if S.count(s[0]) == 2 and S.count(s[2]) == 2:
        ans = "Yes"
print(ans)


Measured memory_bytes: 3060
s = list(input())
n = len(s)
k = int(input())
#dp1[i][j] := i桁目まで確定させ、j個0でないものを使った後に、nより小さいことが確定している
#dp2[i][j] := i桁目まで確定させ、j個0出ないものを使った後に、nより小さいことが確定していない
dp1 = [[0 for i in range(k+1)] for j in range(n+1)]
dp2 = [[0 for i in range(k+1)] for j in range(n+1)]
dp1[0][0] = 1
dp1[0][1] = int(s[0]) - 1
dp2[0][1] = 1
for i in range(1,n):
    dp1[i][0] = 1
    for j in range(1,k+1):
        x = int(s[i])
        if x != 0:
            #今回の数字を使うと、確定していないものは確定しない
            dp2[i][j] += dp2[i-1][j-1]
            dp1[i][j] += dp1[i-1][j-1] * 9 + dp2[i-1][j-1] * (x-1)
            dp1[i][j] += dp1[i-1][j] + dp2[i-1][j]
        else:
            dp1[i][j] += dp1[i-1][j-1] * 9 + dp1[i-1][j]
            dp2[i][j] += dp2[i-1][j]
print(dp1[n-1][k] + dp2[n-1][k])

Measured memory_bytes: 38512
$N = gets.to_i
$ss, $sst = [], Array.new($N){Array.new($N)}
$N.times do |i|
    $ss[i] = gets.chomp.split('')
end

$sst = $ss.transpose

def check(a)
    (0...$N).each do |i|
        if $ss[i] != $sst[i]
            return false
        end
    end
    true
end

sum = 0
(0...$N).each do |a|
    sum += 1 if check(a)
    (0...$N).each { |i| $ss[i].rotate!(1) }
    $sst.rotate!(1)
end
puts sum*$N


Measured memory_bytes: 8060
while True:
    m=int(input())
    p=1000-m
    y500=p//500
    x500=p%500
    y100=x500//100
    x100=x500%100
    y50=x100//50
    x50=x100%50
    y10=x50//10
    x10=x50%10
    y5=x10//5
    x5=x10%5
    if m==0:
        break
    print(y500+y100+y50+y10+y5+x5)


Measured memory_bytes: 5588
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
ll num[ten5];
ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    double ans=0.0,half,d,d1,d2;
    //float f,g,h;
    string s,s1;
    //char now,pre,c1,c2;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n>>m;
    if(n%m==0) cout<<-1;
    else
        cout<<n;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define INFINITOLL 1000000000000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    cin >> n;

    ll res = 1;
    bool over = false;
    bool zero = false;

    fo(i, n) {
        ll a;
        cin >> a;

        if ( a == 0 ) zero = true;

        if ( res * a < res ) over = true;
        res *= a;
        // cout << res << " <- res\n";

    }

    cout << (!zero and (over or res > INFINITOLL) ? -1 : res) << endl;

    return 0;
}

Measured memory_bytes: 3632
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll dp[3005][3005];
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    string s1,s2;
    cin>>s1>>s2;
    memset(dp,0,sizeof(dp));
    ll len1 = s1.length();
    ll len2 = s2.length();
    rep(i,1,len1+1)
    {
        rep(j,1,len2+1)
        {
            if(s1[i-1] == s2[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
            
        }
    }
    vector<char>ans;
    ll i = len1;
    ll j = len2;
    
    while(i>=1 && j>=1)
    {
        
        if(dp[i][j] == dp[i-1][j])
        {
            i = i-1;
        }
        else if(dp[i][j] == dp[i][j-1])
        {
            j = j-1;
        }
        else if(dp[i][j] == dp[i-1][j-1]+1)
        {
            ans.pb(s1[i-1]);
            i = i-1;
            j = j-1;
        }
        
    }
    reverse(ans.begin(),ans.end());
    f(ans.size())
    {
        cout<<ans[i];
    }
    cout<<"\n";

    }
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S,Target;
	int counter=0;
	cin >> S;
	Target = S;
	if (Target=="keyence")
	{
		counter++;
	}
	for (size_t i = 0; i < S.size(); i++)
	{
		for (size_t j = 1; j < S.size()-i+1; j++)
		{
			Target.erase(i,j);
			if (!Target.empty()&&Target=="keyence")
			{
				counter++;
			}
			Target = S;
		}

	}
	if (counter != 0) {
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
}

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

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int main(){
  map<string,vi> M;
  char __s[2521];
  while(~scanf("%s",__s)){
    int a;
    cin>>a;
    if(a==1145141919)break;
    M[string(__s)].push_back(a);
  }
  map<string,vi>::iterator iter = M.begin();
  while(iter!=M.end()){
    vi V = iter->second;
    sort(ALL(V));
    cout<<(iter->first)<<endl;
    cout<<V[0];
    REPR(i,V.size())cout<<" "<<V[i];
    cout<<endl;
    ++iter;
  }
  return 0;
}

Measured memory_bytes: 1268
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextLong
    val ABCDE = Array.fill(5)(sc.nextLong)

    val min = ABCDE.min
    val minIdx = ABCDE.indexOf(min)
    val a = ((N + (min - 1)) / min) + (4 - minIdx) + minIdx
    a.toString
  }
}


Measured memory_bytes: 25656
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)



int main()
{
    array<int, 10> a;
    REP(i, 10) {
        cin >> a[i];
    }

    partial_sort(begin(a), begin(a)+3, end(a), greater<int>());

    REP(i, 3) {
        cout << a[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll h,w,a,b;
    ci(h>>w>>a>>b);

  FOR(i,0,h){
    st s="";
    FOR(j,0,w){
      if(i<b&&j<a){
        s+='0';
      }

      else if(i>=b&&j>=a){
        s+='0';
      }

      else{
        s+='1';
      }
    }
    cout<<s<<endl;
  }
}


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

int main() {
    string input;
    cin >> input;
    int sum_of_input = 0;
    for (char i : input){
        sum_of_input += i - '0';
    }
    if (stoi(input) % sum_of_input == 0){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
}


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

int main() {
    int N;
    cin >> N;
    if(N%10==3){
        cout << "bon" << endl;
    }else if(N%10==0 ||N%10==1 ||N%10==6 ||N%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int x, y;
  scanf("%d %d", &x, &y);

  int score = 0;
  if (x == 3) {
    score += 100000;
  } else if (x == 2) {
    score += 200000;
  } else if (x == 1) {
    score += 300000;
  }

  if (y == 3) {
    score += 100000;
  } else if (y == 2) {
    score += 200000;
  } else if (y == 1) {
    score += 300000;
  }

  if (x == 1 && y == 1) {
    score += 400000;
  }


  cout << score << endl;
  
  return 0;
}


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e6 + 10;
// const int mod = (int)1e9 + 7;

int main(int argc, char* argv[]){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    if(k == 1) cout << 0 << endl;
    else cout << n - k << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
ans = 0
sm = 0
for i in range(n):
    if i % 2 == 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
    if i % 2 != 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
print(min(ans, ans1))


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

int main() {
  int n;
  cin>>n;
  pair<int, int> r[n], b[n];
  for (int i=0; i<n; i++) cin>>r[i].first>>r[i].second;
  for (int i=0; i<n; i++) cin>>b[i].first>>b[i].second;
  sort(r, r + n);
  sort(b, b + n);
  bool used[n];
  for (int i=0; i<n; i++) used[i] = false;
  int cnt = 0;
  for (int i=n-1; i>=0; i--) {
    bool found = false;
    int min_d = 200;
    int i_min_d = -1;
    for (int j=0; j<n; j++) {
      if (used[j]) {
        continue;
      }
      if (r[i].first < b[j].first && r[i].second < b[j].second) {
        found = true;
        if (b[j].second <= min_d) {
          min_d = b[j].second;
          i_min_d = j;
        }
      }
    }
    if (found) {
      used[i_min_d] = true;
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin>>n>>m;
  vector<string> verdict(n, "");
  vector<int> wa(n, 0);
  int ans = 0;
  for(int i = 0; i < m; ++i){
    string s;
    int p;
    cin>>p>>s;
    p--;
    if(s == "AC"){
      verdict[p]=s;
    }
    else{
      if(verdict[p]!="AC")wa[p]++;
    }
  }
  int r = 0;
  for(int i = 0; i < n; ++i){
    if(verdict[i]=="AC"){
      r++;
      ans += wa[i];
    }
  }
  cout<<r<<" "<<ans<<endl;
  return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> vv(m);
	for(int i = 0, x; i < n && cin >> x; i++) vv[x % m].emplace_back(x);
	for(int i = 0; i < m; i++) sort(vv[i].begin(), vv[i].end());
	int ans = 0;
	for(int i = 0; i < m; i++){
		int j = (m - i) % m;
		if(i > j) continue;
		if(i == j){
			ans += vv[i].size() / 2;
			continue;
		}
		int p = 0;
		for(int k = 0; k + 1 < vv[i].size(); k++) if(vv[i][k] == vv[i][k + 1]){
			p++;
			k++;
		}
		int q = 0;
		for(int k = 0; k + 1 < vv[j].size(); k++) if(vv[j][k] == vv[j][k + 1]){
			q++;
			k++;
		}
		int is = vv[i].size(), js = vv[j].size();
		if(is > js){
			swap(is, js);
			swap(p, q);
		}
		int sel = min((js - is) / 2, q);
		ans += sel;
		js -= sel * 2;
		ans += min(is, js);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x;
		int y;
		int countDeta;
		int[] detaX = new int[3000];
		int[] detaY = new int[3000];
		for (countDeta = 0; true; countDeta++) {
			x = sc.nextInt();
			y = sc.nextInt();
			if (x == 0 && y == 0) {
				break;
			}
			detaX[countDeta] = x;
			detaY[countDeta] = y;
		}
		for (int i = 0; i < countDeta; i++) {
			if (detaX[i] <= detaY[i]) {
				System.out.println(detaX[i] + " " + detaY[i]);
			} else {
				System.out.println(detaY[i] + " " + detaX[i]);
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 36044
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>

using namespace std;

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

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

int main()
{
  int N;
  int R;

  cin >> N >> R;

  int internal_R;

  if (N >= 10)
  {
    internal_R = R;
  }
  else
  {
    internal_R = R + 100 * (10 - N);
  }

  cout << internal_R;

  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
dp=[0]*(N)
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]))
# print(dp)
print(dp[N-1])

Measured memory_bytes: 84956
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long md;

T[N] toS(T, int N)(T[N] data){ return data; }

long[2][][] memo;
long[2][] dfs(int p) {
    if (g[p].empty) {
        return [[0L, 0L]];
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
    auto buf = Appender!(long[2][])(memo[p]);
    buf.clear();
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1L, rt.length).to!int-1;
        if (idx == -1) continue;
        buf.put([co[0]+ld, rt[idx][1]+rd].toS);
        buf.put([rt[idx][1]+rd, co[0]+ld].toS);
    }
    memo[p] = buf.data;
    sort(memo[p]);
    if (memo[p].empty) return memo[p];
    long ma = 10L^^15;
    int co = 0;
    foreach (e; memo[p]) {
        if (ma <= e[1]) continue;
        ma = min(ma, e[1]);
        memo[p][co] = e;
        co++;
    }
    return memo[p][0..co];
}

//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}

int main() {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    memo = new long[2][][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }

    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


Measured memory_bytes: 93820
N=int(input())
def ok(h,n,w,N):
    if 4*h*n*w==N*(n*w+n*h+h*w):
        return 1
    else:
        return 0

def kiyaku(a,b):
    if b%a==0:
        return 1
    else:
        return 0

def solve(N):

    for i in range(N//4+1,3*N//4+1):
        for j in range(3*N//4+1,3501):
            if 4*i*j-N*(i+j)>0 and kiyaku(4*i*j-N*(i+j),N*i*j):
                return (i,j,N*i*j//(4*i*j-N*(i+j)))
h,n,w=solve(N)
print(h,n,w)

Measured memory_bytes: 3064
N, M = map(int, input().split())
for i,m in enumerate(range(M, 0, -1)):
    if m % 2:
        i = i // 2
        print(str(i+1) + " " + str(i+1+m))
    else:
        i = i // 2
        print(str(N - i - m) + " " + str(N - i))

Measured memory_bytes: 9192
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll n,s,i,l,r,k;
ll f(ll b,ll n){
	ll sum=0;
	while(n){
		sum+=n%b;
		n/=b;
	}
	return sum;
}
void work1(){
	for(i=2;i<=n;i++)
		if(f(i,n)==s){
			printf("%lld",i);
			return;
		}
	printf("-1");
}	
void work2(){
	l=(int)sqrt(n)+10;
	for(i=2;i<l;i++)
		if(f(i,n)==s){
			printf("%lld",i);
			return;
		}
	for(;l<=n;l=r+1){
		r=n/(n/l);
		k=(n-s)/(n/l)+1;
		if(k>1&&f(k,n)==s){
			printf("%lld",k);
			return;
		}
	}
	printf("-1");
}
int main(){
	scanf("%lld%lld",&n,&s);
	if(n==s){
		printf("%lld",n+1);
		return 0;
	}
	if(n<s){
		printf("-1");
		return 0;
	}
	if(n<=1000)
		work1();
	else
		work2();
	//while(1);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
using namespace std;
int n,m,max_status,p[15],ans;
struct node{
	int len,t[15];
}a[15];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
signed main(){
	n=read(),m=read();
	max_status=(1<<n)-1;
	for(int i=1;i<=m;i++){
		a[i].len=read();
		for(int j=1;j<=a[i].len;j++) a[i].t[j]=read();
	}
	for(int i=1;i<=m;i++) p[i]=read();
	for(int zt=0;zt<=max_status;zt++){
		bool fl=1;
		for(int i=1;i<=m;i++){
			int cnt=0;
			for(int j=1;j<=a[i].len;j++){
				if(zt&(1<<(a[i].t[j]-1)))
					cnt++;
			}
			if(cnt%2==1&&!p[i]){
				fl=0;
				break;
			}
			if(cnt%2==0&&p[i]){
				fl=0;
				break;
			}
		}
		if(fl) ans++;
	}
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

sin60 = (math.sqrt)(3)/2
cos60 = 1/2


def koch(n, p1_x, p2_x, p1_y, p2_y):
    if n == 0:
        return

    s_x = (2*p1_x + 1*p2_x) / 3
    s_y = (2*p1_y + 1*p2_y) / 3
    t_x = (1*p1_x + 2*p2_x) / 3
    t_y = (1*p1_y + 2*p2_y) / 3
    u_x = (t_x - s_x)*cos60 - (t_y - s_y)*sin60 + s_x
    u_y = (t_x - s_x)*sin60 + (t_y - s_y)*cos60 + s_y

    koch(n-1, p1_x, s_x, p1_y, s_y)
    print(s_x, s_y)
    koch(n-1, s_x, u_x, s_y, u_y)
    print(u_x, u_y)
    koch(n-1, u_x, t_x, u_y, t_y)
    print(t_x, t_y)
    koch(n-1, t_x, p2_x, t_y, p2_y)


print(0.00000000, 0.00000000)
koch(n, 0, 100, 0, 0)
print(100.00000000, 0.00000000)


Measured memory_bytes: 5756
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int ans=n;
		for(int i=0; i<n-1; i++){
			if(s.charAt(i)==s.charAt(i+1)){
				ans--;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 26776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        long x = in.nextLong();


        System.out.println(f(b, x) - f(a - 1, x));
    }

    private static long f(long n, long x) {
        if (n >= 0) {
            return n / x + 1;
        }
        return 0;
    }
}


Measured memory_bytes: 35820
import math
N = int(input())
n = N
a = []
for i in (n for _ in ([2], range(3, int(math.sqrt(n))+1, 2)) for n in _ ):
    while n%i==0:
        a.append(str(i))
        n //= i
if n>1:
    a.append(str(n))
print(str(N)+": "+(" ".join(a)))

Measured memory_bytes: 7732
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*

*/

ll n,discard,largest;

int main(void){
	cin>>n;
	reg(i,1,n){
		if(i*(i+1)/2>=n){
			largest=i;
			discard=i*(i+1)/2-n;//取り除く数
			break;
		}
	}
	reg(i,1,largest){
		if(i!=discard)cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,n) for(int i=(1);i<(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    vi v(n);
    int odd=0,even=0,num4=0;
    rep(i,n){
        cin>>v[i];
        if(v[i]%4==0)num4++;
        else if(v[i]%2==0)even++;
        else odd++;
    }
    bool fl=1;
    if(even==0 && n/2>num4)fl=0;
    if(even && odd>num4)fl=0;
    cout<<((fl)?"Yes":"No")<<enl;

    return 0;
}


Measured memory_bytes: 3956
def is_triangle(a, b, c):
    return len({a, b, c})==3 and a+b>c and b+c>a and c+a>b

n = int(input())
if n <= 2:
    print(0)
    exit()
*l, = map(int, input().split())
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if is_triangle(l[i], l[j], l[k]):
                ans += 1
print(ans)

Measured memory_bytes: 9196