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

int abs(int x){
    return x>0?x:-x;
}

int main(){
    int A,B;
    scanf("%d%d",&A,&B);
    if(A<=B){
        if((A<0&&B<=0)||(A>=0))
            printf("%d",B-A);
        else//-10 11
            printf("%d",abs(abs(A)-abs(B))+1);
    }
    else{
        if((A<0)||(A>0&&B>0))//-10 -20 20 10
            printf("%d",A-B+2);
        else//10 -20  20 -10
            printf("%d",abs(abs(B)-abs(A))+1);
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/16  Problem: ABC 076 C / Link: http://abc076.contest.atcoder.jp/tasks/abc076_c  ----- */


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

	string s, t; cin >> s >> t;
	const string inf = string(100, '~');
	string ans = inf;
	FOR(i, 0, SZ(s) - SZ(t) + 1) {
		bool ok = 1;
		FOR(j, 0, SZ(t)) {
			int p = i+j;
			DD(de(t[j],s[p]))
			ok &= (s[p] == '?' || s[p] == t[j]);
		}
		DD(de(i,ok))
		if (ok) {
			string ret = s.substr(0, i) + t + s.substr(i + SZ(t));
			for (auto &c : ret) {
				if (c == '?')c = 'a';
			}
			ans = min(ans, ret);
		}
	}


	cout << (ans!=inf? ans : "UNRESTORABLE") << "\n";

	return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;
    int arr[n], pre[n];

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

    pre[0] = abs(arr[0] - 0);

    for (int i = 1; i < n; i++)
        pre[i] = abs(arr[i] - arr[i - 1]) + pre[i - 1];

    for (int i = 0; i < n; i++) {
        if (!i)
            cout << abs(arr[1] - 0) + (pre[n - 1] - pre[1]) + abs(arr[n - 1] - 0);
        else if (i == n - 1)
            cout << pre[n - 2] + abs(arr[n - 2] - 0);
        else
            cout << pre[i - 1] + (pre[n - 1] - pre[i + 1]) + abs(arr[i + 1] - arr[i - 1]) + abs(arr[n - 1] - 0);

        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 2048
using System;
using System.Collections.Generic;

class IDONTKNOWCSHARP
{
    public static void Main()
    {
        string[] values = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        int num = int.Parse(values[0]);
        int K = int.Parse(values[1]);
        int v=0;
        int[] fruits =Convert(Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
        Array.Sort(fruits);
        for(int i = 0; i < K; i++)
        {
            v+=fruits[i];
        }

       Console.WriteLine(v);
    }

    static int[] Convert(string[] a)
    {
        int[] b = new int[a.Length];
        for (int i = 0; i < a.Length; i++)
        {
            b[i] = int.Parse(a[i]);
        }

        return b;
    }

}

Measured memory_bytes: 27736
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] number = new int[3];
    int sum = 0;
    
    for(int i=0;i<3;i++){
      number[i] = sc.nextInt();
      sum += number[i];
    }
    int K = sc.nextInt();
    int max = number[0];
    
    for(int j=0;j<2;j++){
      if(number[j+1]>number[j]){
        max = number[j+1];
      }
    }
    int answer = (int)(sum-max+max*Math.pow(2,K));
    System.out.println(answer);
  }
}
    

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

int main(){
    int N,M;
    cin >> N >> M;
    int a[M];
    int b[M];
    
    for(int i=0;i<M;i++){cin >> a[i] >> b[i];}
    
    vector<int> vec1(N,0);
    vector<int> vec2(N,0);
    
    
    
    //1と組みになるものを格納
    for (int i=0;i<M;i++){
        if (a[i]==1) vec1[b[i]]=1;}
    
    
    
  
    //Nと組みになるものを格納
    for (int i=0;i<M;i++){
        if (b[i]==N) vec2[a[i]]=1; }

    
    
    for (int i=1;i <N;i++){
        if (vec1[i]*vec2[i]){
            cout << "POSSIBLE";goto Exit;
        }
    }
    
    cout << "IMPOSSIBLE";
    Exit: ;
    
}




Measured memory_bytes: 3328
#include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, i, count);
		}
	}

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

	return 0;
}

Measured memory_bytes: 3116
# https://atcoder.jp/contests/arc102/tasks/arc102_a

n, k = map(int, input().split())

dp = [0] * k

for i in range(1, n + 1):
    m = i % k
    dp[m] += 1
ans = dp[0] ** 3
if k % 2 == 0:
    ans += dp[k // 2] ** 3
print(ans)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1003,INF=1<<30;

int dp[MAX][53][53];

struct KMP{
    vector<int> A;
    string S;
    
    void init(string &T){
        S=T;
        A.assign(S.size()+1,0);
        A[0]=-1;
        int j=-1;
        
        for(int i=0;i<S.size();i++){
            while(j>=0&&S[i]!=S[j]) j=A[j];
            j++;
            
            A[i+1]=j;
        }
    }
    
    vector<int> match(string &C,string &T){
        init(C);
        vector<int> B;
        int m=0,i=0;
        
        while(m+i<T.size()){
            if(S[i]==T[m+i]){
                i++;
                if(i==S.size()){
                    B.push_back(m);
                    m+=i-A[i];
                    i=A[i];
                }
            }else{
                m+=i-A[i];
                if(i>0) i=A[i];
            }
        }
        
        return B;
    }//SがTの中に含まれる開始位置を返す
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    
    int ans=0;
    
    for(int l=0;l<N;l++){
        KMP k;
        string T=S.substr(l,N-l);
        k.init(T);
        
        for(int i=0;i<=N-l;i++){
            ans=max(ans,min(k.A[i],i/2));
        }
    }
    
    cout<<ans<<endl;
}



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

s = input()
s_list = list(s)
min_count = float("inf")

for char in set(s_list):
    w_list = s_list[:]
    after_list = []

    count = 0
    while len(set(w_list)) != 1:
        after_list = []
        for i in range(len(w_list) - 1):
            if w_list[i + 1] == char:
                after_list += [char]
            else:
                after_list += w_list[i]
        count += 1
        w_list = after_list

    if count < min_count:
        min_count = count
        ans = "".join(w_list)

ans = min_count
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define mod int(1e9+7)
#define N 2010
using namespace std;
ll fact[N];
ll power(ll x, ll n) {
	if (n == 0ll)
		return 1ll;
	ll y = power(x, n / 2ll);
	y = (y * y) % mod;
	if (n % 2ll)
		return (x * y) % mod;
	return y;
}
ll ncr(int n, int r) {
	if (n < r || n < 0 || r < 0)
		return 0ll;
	ll num = fact[n], den = (fact[r] * fact[n - r]) % mod;
	return (num * power(den, mod - 2ll)) % mod;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	int S;
	cin >> S;
	fact[0] = 1ll;
	for (int i = 1; i < N; i++)
		fact[i] = (1ll * i * fact[i - 1]) % mod;
	ll ans = 0ll;
	for (int n = 1; 3 * n <= S; n++)
		ans = (ans + ncr(S - 2 * n - 1, S - 3 * n)) % mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
   string s;

    cin >> s;

    if(s == "Sunny"){
      cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
      cout << "Rainy" << endl;
    }else{
      cout << "Sunny" << endl;
    }

}



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

int main()
{
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0, j = s.size(); i < j; i++)
	{
		if (s[i] == 'A')
		{
			a++;
		}
		else if (s[i] == 'B')
		{
			b++;
		}
	}
	if (a == 3 || b == 3)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	
}



Measured memory_bytes: 256
C = []
for i in range(3):
    C.append(list(map(int, input().split())))

def solve():
    def_x = C[0][0] - C[0][1]
    if def_x != (C[1][0] - C[1][1]) or def_x != (C[2][0] - C[2][1]):
        print("No")
        return
    def_x = C[0][1] - C[0][2]
    if def_x != (C[1][1] - C[1][2]) or def_x != (C[2][1] - C[2][2]):
        print("No")
        return
    def_y = C[0][0] - C[1][0]
    if def_y != (C[0][1] - C[1][1]) or def_y != (C[0][2] - C[1][2]):
        print("No")
        return
    def_y = C[0][0] - C[2][0]
    if def_y != (C[0][1] - C[2][1]) or def_y != (C[0][2] - C[2][2]):
        print("No")
        return
    print("Yes")
    
    
    
solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
char s[10];
int n;
int main(void) {
    scanf("%d", &n);
    puts("0");
    fflush(stdout);
    scanf("%s", s);
    bool flag1, flag2;
    if(s[0] ==  'V') return 0;
    if(s[0] == 'M') flag1 = 1;
    else flag1 = 0;
    int l = 0, r = n;
    while(l < r) {
        int m = (l + r) >> 1;
        printf("%d\n", m);
        fflush(stdout);
        scanf("%s", s);
        if(s[0] == 'V') return 0;
        if(s[0] == 'M') flag2 = 1;
        else flag2 = 0;
        int t = m - l;
        if(!(t & 1)) {
            if(flag1 == flag2) l = m;
            else r = m;
        } else {
            if(flag1 == flag2) r = m;
            else l = m, flag1 = flag2;
        }
    }
    fflush(stdout);
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int x,n,a[111];
bool b[111];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout); 
	cin>>x>>n;
	fo(i,0,n){
		cin>>a[i];
		b[a[i]]=1;
	}
	int s=x,g=0;
	fo(i,0,111) if(!b[i])if(abs(x-i)<s)s=abs(x-i),g=i;
	cout<<g<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdbool.h>
#define M 8
#define NFR -1
#define FR 1


int row[M], col[M], dpos[2*M-1], dneg[2*M-1];



bool S[M][M];



void initialize(){
  int i;
  for( i = 0 ; i < M ; i++){
    row[i] = FR;
    col[i] = FR;
  }
  for( i = 0 ; i < 2*M-1 ; i++){
    dpos[i] = FR;
    dneg[i] = FR;
  }
}




void print(){
  int i, j;
  for( i = 0 ; i < M ; i++){
    for( j = 0 ; j < M ; j++){
      if( S[i][j] ){
        if( row[i] != j) return;
      }
    }
  }

  for( i = 0 ; i < M ; i++ ){
    for( j = 0 ; j < M ; j++ ){
      if(row[i] != j)
      printf(".");
      else printf("Q");
    }
    printf("\n");
  }
}

void qeen(int i){
  int j;
  if( i == M ){
    print();
    return;
  }

  for( j = 0 ; j < M ; j++ ){
    if( col[j] == NFR || dpos[i+j] == NFR || dneg[i-j+(M-1)] == NFR) continue;
    row[i] = j;
    col[j] = NFR;
    dpos[i+j] = NFR;
    dneg[i-j+(M-1)] = NFR;
    qeen(i+1);
    row[i] = FR;
    col[j] = FR;
    dpos[i+j] = FR;
    dneg[i-j+(M-1)] = FR;
  }
}

int main(){
  int i, j, k, r, c;

  initialize();

  for( i = 0 ; i < M ; i++){
    for( j = 0 ; j < M ; j++){
      S[i][j] = false;
    }
  }

  scanf("%d", &k);
  for( i = 0 ; i < k ; i++){
    scanf("%d%d", &r, &c);
    S[r][c] = true;
  }
  qeen(0);

  return 0;
}



Measured memory_bytes: 2096
#include<stdio.h>

int main()
{	
	int n,X,m,tot;
	int min=100001;
	int t=0;
	scanf("%d%d",&n,&X);
	for(int i = 0; i < n; i++)
	{
		scanf("%d",&m);
		if(m<min)
		{
			min=m;
		}
		t=t+m;
	}
	tot=(X-t)/min+n;
	printf("%d",tot); 
	return 0;
}


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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

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

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

  LL ans = 0;
  LL X;
  cin >> X;

  LL temp = X / 500;
  ans = temp * 1000;
  X = X % 500;
  // debug(X);
  temp = X / 5;
  ans += temp * 5;

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 764
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mod 1000000007
#define inf 1e18
#define setbits(x) __builtin_popcount(x)
#define zrbits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define fi(i,n) for(int i = 0;i < n;i++)
#define fd(i,n) for(int i = n;i >= 0;i--)
int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int gcd(int a, int b){if(b == 0)return a;return gcd(b, a%b);}
int max(int a,int b){if(a > b)return a;return b;}
int min(int a,int b){if(a < b)return a;return b;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    int arr[n];
    fi(i,n)cin>>arr[i];
    int ans[n];
    if(n == 0 || n == 1)
    {
    	cout<<0<<endl;
    	return 0;
    }
    if(n == 2)
    {
    	cout<<dif(arr[0],arr[1])<<endl;
    	return 0;
    }
    fi(i,n)ans[i] = 9999999999;
    ans[0] = 0;
    ans[1] = dif(arr[0],arr[1]);
    for(int i = 2;i < n;i++)
    {
    	int t = max(0,(i - k));
    	for(int j = t;j < i;j++)
    	{
    		ans[i] = min(ans[i],ans[j] + dif(arr[i],arr[j]));
    	//	cout<<ans[j]<<" "<<j<<"  ";
    	}
    	//cout<<endl;
    }
  //  fi(i,n)cout<<ans[i]<<" ";
    cout<<ans[n - 1];
	return 0;
}


Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 300005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;




int main()
{


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

    int n, x, t;
    cin>>n>>x>>t;
    int k = (n/x);
    if(n%x)k++;
    cout<<k*t<<endl;


}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <bitset>
#include <utility>
#include <queue>
#include <deque>

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    vector<int> v;
    for(int i=1;i<N;++i){
        v.emplace_back(i);
    }
    vector<vector<int>> e(N, vector<int>());

    int a,b;
    for(int m=0;m<M;++m){
        cin >> a >> b;
        e[a-1].emplace_back(b-1);
        e[b-1].emplace_back(a-1);
    }

    int ans(0);
    bool f;
    do{
        f = true;
        if( find( e[0].begin(), e[0].end(), v[0] ) == e[0].end()) f = false;
        if(f){
            for(int i=0;i<N-2;++i){
                if( find( e[v[i]].begin(), e[v[i]].end(), v[i+1] ) == e[v[i]].end()) {
                    f = false;
                    break;
                }
            }
        }
        if(f) ++ans;
        
    }while( next_permutation( v.begin(), v.end()  ));
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int a=0;
  int temp;
  for(int i=0;i<4;i++){
    cin >> temp;
    a+=temp;
  }
  //int b=0;
  int ab=a;
  for(int i=0;i<4;i++){
    cin >> temp;
    ab-=temp;
  }
  if(ab<0){
    cout <<(a-ab)<<endl;
  }else{
      cout << a<< endl;
    }
}

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

const int INF = 1000000007;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pr;

int main(){
    int m;
    string train;
    cin >> m;
    set<string> pat;
    while(m--){
        cin >> train;
        for(int i = 1; i < train.size(); i++){
            string s1 = train.substr(0, i);
            string s2 = train.substr(i);
            string r1(s1), r2(s2);
            reverse(r1.begin(), r1.end());
            reverse(r2.begin(), r2.end());
            pat.insert(s1 + s2);
            pat.insert(s2 + s1);
            pat.insert(r1 + s2);
            pat.insert(r2 + s1);
            pat.insert(s1 + r2);
            pat.insert(s2 + r1);
            pat.insert(r1 + r2);
            pat.insert(r2 + r1);
        }
        cout << pat.size() << endl;
        pat.clear();
    }
    
    return 0;
}

Measured memory_bytes: 1292
open Num
       
let () =
  let m = num_of_int 1000000007 in
  let n = read_int () in
  let s1 = read_line () in
  let s2 = read_line () in
  let rec iter r p x =
    if x >= n then r
    else
      if x = 0 then
        if s1.[x] = s2.[x] then iter (num_of_int 3) 1 (x+1) else iter (num_of_int 6) 2 (x+2)
      else
        if s1.[x] = s2.[x] then
          if p = 1 then iter (mod_num ((num_of_int 2) */ r) m) 1 (x+1) else iter r 1 (x+1)
        else
          if p = 1 then iter (mod_num ((num_of_int 2) */ r) m) 2 (x+2) else iter (mod_num ((num_of_int 3) */ r) m) 2 (x+2)
  in
  iter (num_of_int 0) 0 0 |> string_of_num |> print_endline


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int n,t;
    cin >> n >> t;
    int c[n],d[n];
    for (int i=0; i<n; i++){
        cin >> c[i] >> d[i];
    }
    int cost=100000;

    for (int i=0; i<n; i++){
        if (d[i]<=t){
            cost=min(cost,c[i]);
        }
    }
    if (cost==100000){
        cout << "TLE" << endl;
    }
    else {
        cout << cost << endl;
    }
}




Measured memory_bytes: 256
/*

2013/04/19 10:39

0577：こんなお店は嫌だ。
	・よくわからない文字列が書かれている古い看板を使って、お店の看板を作る店。

結果：Wrong answer.

・何が間違ってるのかも分からないけれど、初めて出来た再帰関数なので、とりあえずセーブ。

--------------------------------------------------------------------------

*/

#include <stdio.h>
#include <string.h>

int check00(char name[], int len_name, char data[], int len_d, int x, int y, int sa);
void dummy();

int main()
{
	char str[101];
	char name[101];
	char data[101];
	int N;
	int i, k, m;
	int dist, count = 0;
	int len_name, len_d;
	int X = 0;
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);
	scanf("%s", name);
	len_name = strlen(name);
	for(i=0; i<N; i++){										//全体（データセット）を管理するループ
		scanf("%s", data);
		len_d = strlen(data);
		for(k = 0; k <= (len_d - len_name); k++){				//1文字目を探すループ
			if(data[k]==name[0]){
				for(m = k+1; m <= (len_d - (len_name-1)); m++){		//2文字目を探すループ
					if(data[m] == name[1]){
						dist = m - k;
						if(check00(name, len_name, data, len_d, 1, m, dist)){	//3文字目以降は全て関数で探す。
							count++;
							//printf("成功！\n\n");							//チェック用。
							goto next;												//データセットを抜ける（次のデータセットへ）。
						}
					}
				}
			}
		}
next:	dummy();																	//Cではbreak (ラベル名);ができないらしいので、gotoで代用。
	}
	
	printf("%d\n", count);
	
	return 0;
}

int check00(char name[], int len_name, char data[], int len_d, int x, int y, int dist)
{
	//printf("	受け取ったdist = %d\n", dist);
	if(x >= len_name-1){
		return 1;
	}
	else if(y+dist >= len_d){
		return 0;
	}
	else if(data[y+dist] == name[x+1]){
		return check00(name, len_name, data, len_d, x+1, y+dist, dist);
	}
	else{
		return 0;
	}
	/*																							//最初に思いついたアルゴリズムver.	後になってもっと簡単なのを思いついたので、それに変えた。
	else{																								//こんな風にを考えていた、という記録として残しておく。
		for(i = y + 1; i <= (len_d - (len_name-x)); i++){
			if(name[x+1] == data[i]){
				dist = i - y;
				if(dist != sa){
					return 0;
				}
				else{
					return check00(name, len_name, data, len_d, x+1, i, sa);
				}
			}
		}
	}
	*/
}

void dummy()
{
	//printf("dummy!\n");
	return;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
#define int ll
const int N=55;
const int M=N*N*N;
const int inf=0x3f3f3f3f3f3f3f3f;
int n,m,D,Maxn;
int fa[N],s[M],q[M];
ll Ans,f[M],g[M];
struct Node{int v;ll w;}p[N];
bool cmp(Node A,Node B){return A.v*B.w>B.v*A.w;}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read(),m=read(),D=read(),p[1].w=read(),p[1].v=1;
	for(int i=2;i<=n;i++)p[i].w=read(),fa[i]=read(),p[i].v=1;
	for(int i=n;i>=1;i--)p[fa[i]].w+=p[i].w,p[fa[i]].v+=p[i].v;
	sort(p+1,p+n+1,cmp);
	memset(f,0x3f,sizeof(f)),f[0]=0;
	for(int k=1;k<=n;k++){
		Maxn+=min(n,D)*p[k].v;
		for(int i=0;i<=Maxn;i++)g[i]=f[i];
		for(int x=0;x<p[k].v;x++){
			int top=0,l=1,r=0;
			for(int i=x;i<=Maxn;i+=p[k].v)s[++top]=i;
			for(int i=1;i<=top;i++){
				while(l<=r&&i-q[l]>min(n,D))l++;
				if(l<=r)f[s[i]]=min(f[s[i]],g[s[q[l]]]+(i-q[l])*p[k].w);
				if(g[s[i]]!=inf){
					while(l<=r&&g[s[q[r]]]+(i-q[r])*p[k].w>g[s[i]])r--;
					q[++r]=i;	
				}
			}
		}
	}
	for(int i=0;i<=Maxn;i++)
	if(f[i]<=m){
		int res=m-f[i];ll ans=i;
		for(int j=1;j<=n;j++){
			int t=res/p[j].w;
			if(p[j].v<n)t=min(t,D-min(n,D));
			res-=p[j].w*t,ans+=p[j].v*t;
		}Ans=max(Ans,ans);
	}printf("%lld",Ans);
	return 0;
}


Measured memory_bytes: 6012
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

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

Measured memory_bytes: 3564
/* Problem Description:

*/

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define RREP(i,a,b) for (int i = (a); i > (b); i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define TRvi(it, c) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define inf 0x3f3f3f3f
#define EPS 1e-10
#define PI acos(-1.0)
#define scan(x) scanf("%d",x)
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define LSOne(x) x&(-x)
#define debug(x) cout << #x << " " << x << endl;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int N = 1e5;

vi grp[N];
bool visited[N];
void dfs(int cur){
  for (vi::iterator adj = grp[cur].begin(); adj != grp[cur].end(); adj++){
    if (!visited[*adj]){
      visited[*adj] = true;
      dfs(*adj);
    }
  }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
   //  freopen("in" , "r" , stdin);
   //  freopen("out" , "w" , stdout);
    #endif
    int n, k;
    cin >> n >> k;
    REP(i,0,k){
      int u,v,w;
      cin >> u >> v >> w;
      u--, v--;
      grp[u].pb(v);
      grp[v].pb(u);
    }
    int count = 0;
    REP(i,0,n){
      if (!visited[i]){
        visited[i] = true;
        dfs(i);
        count++;
      }
    }
    cout << count << endl;
    return 0;
 }


Measured memory_bytes: 8960
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
ll gcd(ll x, ll y){
  if(x > y)return gcd(y, x);
  if(x == 0)return y;
  return gcd(y % x, x);
}

int main(int argc, char const* argv[])
{
  ll x, y;
  while(cin >> x >> y){
    ll tmp = gcd(x, y);
    cout << tmp << " " << x * y / tmp << endl;
  }
	return 0;
}



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

using namespace std;

int main() {

	int a,b,c;
	cin >> a >> b >> c;
	if (a == max(a, max(b, c))) {
		cout << a * 10 + b + c << endl;
	}
	else if (b == max(a, max(b, c))) {
		cout << b * 10 + a + c << endl;
	}
	else {
		cout << c * 10 + a + b << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N, Y, x, y, z, sum;

    scanf("%d", &N);
    scanf("%d", &Y);

    for (x = 0; x <= N;x++){
        for (y = 0; y <= N - x;y++){
            z = N - x - y;
            sum = 10000 * x + 5000 * y + 1000 * z;
            if(sum == Y){
                break;
            }
        }
        if(sum == Y){
            break;
        }
    }

    if(sum != Y){
        x = -1;
        y = -1;
        z = -1;
    }

    printf("%d %d %d", x, y, z);
    return 0;
}

Measured memory_bytes: 128
#include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int a,b,c,d;
    int main()
    {
        while(cin>>a>>b>>c>>d)
        {
            int ans=0;
            for(int i=0;i<=100;i++)
            {
                if((i>=a && i<=b) && (i>=c && i<=d))ans++;
            }
            printf("%d\n",ans-1>=0?ans-1:0);
        }
        return 0;
    }

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {

  ll N, D;
  cin >> N >> D;

  ll ans = 0;
  REP(i, N){
    ll x, y;
    cin >> x >> y;
    long double kyori = sqrt(x*x+y*y);
    if(kyori <= D)ans++;
  }

  cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3652
#include <stdio.h>

int main(int argc, char *argv[])
{
 unsigned long a, b;

 while (scanf("%lu %lu\n", &a, &b)!=EOF) {
 unsigned long i, gcd, lcm;

 for (gcd = 1, i = 2; (i <= a) && (i <= b); i++) {
 while (1) {
 if (a % i) break;
 if (b % i) break;
 gcd *= i;
 a /= i, b /= i;
 }
 }
 lcm = a * b * gcd;

 printf("%lu %lu\n", gcd, lcm);
 }

 return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b;
    cin >> a >> b;
    rep(i, 10000) {
        int ta = i * 8 / 100;
        int tb = i * 10 / 100;
        if (ta == a and tb == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n;
    for1(9)
    {
        if(n%i==0&&n/i<=9)c=1;
    }
    if(c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define EPS (1e-8)
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;

double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
 
int ccw(point a,point b,point c){
  point d = b-a;
  point e = c-a;
  if(cross(d,e)>+EPS) return 1;//"COUNTER_CLOCKWISE"
  if(cross(d,e)<-EPS) return 1;//"CLOCKWISE"
  if(dot(d,e)<0) return 2;//"ONLINE_BACK"
  if(abs(d) < abs(e)) return -2;//"ONLINE_FRONT"
  return 0;//"ON_SEGMENT"
}

int main(){
  while(1){
  double d;
  cin>>d;
  if(d<=EPS) break;
  double px,py,vx,vy;
  cin>>px>>py>>vx>>vy;
  int flg=ccw(point(0,0),point(vx,vy),point(px,py))!=1;
  double ans=abs(point(px,py));
  if(px*vx>0||py*vy>0) ans=(1-ans)+1;
  if(d<ans||d<abs(point(px,py))) flg=0;
  if(flg)printf("%lf\n",ans);
  else cout <<"impossible"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
while True:
    L=input().split( )
    H=int(L[0])
    W=int(L[1])
    if H==0 and W==0:
        break
    i=1
    row =''
    while i<=W:
        row=row+"#"
        i+=1
    print(row)
    inside="#"
    j=1
    while j<=W-2:
        inside=inside+"."
        j+=1
    inside=inside+"#"
    k=1
    while k<=H-2:
        print(inside)
        k+=1
    print(row)
    print()


Measured memory_bytes: 5608
Scanf.scanf "%d %s" (fun n x ->
    let rec loop i acc =
        if i = n then acc else
            if x.[i] = '1' then loop (i + 1) (acc + 1)
                           else loop (i + 1) acc
    in

    let longdiv bits =
        let rec loop pos rest =
            if pos = n then rest else
                let rest = rest * 2 + (if x.[pos] = '1' then 1 else 0) in
                let rest = rest mod bits in
                loop (pos + 1) rest
        in
        loop 0 0
    in

    let bits = loop 0 0 in
    let imp = longdiv (bits + 1) in
    let imm = if bits > 2 then longdiv (bits - 1) else 1 in

    let popcount a =
        let rec loop rest acc =
            if rest = 0 then acc else loop (rest lsr 1) (acc + (rest land 1))
        in
        loop a 0
    in
    let powmod a b m =
        let rec loop r x acc =
            if x = 0 then acc else
                loop ((r * r) mod m) (x lsr 1) (if x land 1 = 1 then (r * acc) mod m else acc)
        in
        loop a b 1
    in
    let rec phase2 md c =
        if md = 0 then c else phase2 (md mod (popcount md)) (c + 1)
    in
    let calc i =
        if x.[i] = '1' && bits = 1 then 0 else
            let md = if x.[i] = '1' then ((imm - powmod 2 (n - i - 1) (bits - 1)) mod (bits - 1) + (bits - 1)) mod (bits - 1)
                                    else (imp + powmod 2 (n - i - 1) (bits + 1)) mod (bits + 1)
            in
            phase2 md 1
    in
    for i = 0 to n - 1 do
        Printf.printf "%d\n" @@ calc i
    done
)


Measured memory_bytes: 6604
#include<bits/stdc++.h>
#include<tuple>
using namespace std;
#define ll long long
#define P pair<ll, ll>
int main(){
  ll n,m, a,b, sm=0;
  vector<P> v;
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    v.push_back(P(a,b));
  }
  sort(v.begin(), v.end());
  for(int i=0;i<n && m > 0; i++){
    tie(a,b) = v[i];
    sm += a * min(b,m);
    m -= min(b,m);
  }
  cout << sm << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  string s;
  while(cin>>s){
    for(int i=0;i<s.size();i++){
      s[i]=((s[i]-'A'-3+26)%26)+'A';
    }
    cout<<s<<endl;
  }
}

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

int main() {
  int K, A, B;
  cin >> K;
  cin >> A >> B;
  int c = B - A + 1;//+1は数合わせ
  
  for(int i = 0; i < c; i++){
    if((A + i) % K == 0){
      cout << "OK" << endl;
      break;
    }
    else if(i == c - 1){
      cout << "NG" << endl;
    }
  }
}

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

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int a[200000],b[200000],c[200000];

int main(){
	int n;ll m;int q;cin>>n>>m>>q;
	UnionFind uf(n);
	rep(i,q){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		if(c[i]==0)uf.unite(a[i],b[i]);
	}
	bool f=true;
	rep(i,q){
		if(c[i]==1){
			f=false;
			if(uf.same(a[i],b[i])){
				puts("No");return 0;
			}
		}
	}
	int Min=0;
	int cnt=0;
	rep(i,n){
		if(uf.find(i)!=i)continue;
		cnt++;
		Min+=uf.size(i)-1;
	}
	if(cnt==1){
		if(m==Min)puts("Yes");
		else puts("No");
	}
	else if(cnt==2){
		if(f)puts("Yes");
		else puts("No");
	}
	else if(n-f<=m&&m<=Min+cnt*ll(cnt-1)/2){
		puts("Yes");
	}
	else{
		puts("No");
	}
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i=0;i<S.size();i++){
        if (S[i] != T[i]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3800
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
ans = 0
a.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        b = a[j+1:]
        tmp = a[i] + a[j] - 1
        tt = bisect.bisect_right(b,tmp)
        if tt > 0 :
            ans += tt
print(ans)

Measured memory_bytes: 59644
import java.lang.Math.*
fun main(args:Array<String>?): Unit {
    val (_, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val beauties = readLine()!!.trim().split(' ').map(String::toLong)
    val constraint = Array(m){
        val (left, right) = readLine()!!.trim().split(' ').map(String::toInt)
        Pair(left - 1, right - 1)
    }
    println(
            solve(beauties, constraint)
    )
}

fun solve(beauties: List<Long>, constraint: Array<Pair<Int, Int>>): Long {
    val memo = Array(beauties.size){-1L}
    val sortedConstraint = constraint.sortedBy{it.first}
    val rights = sortedConstraint.map{it.second}.toMutableList()
    for (i in 1 until rights.size){
        rights[i] = max(rights[i], rights[i - 1])
    }
    fun sub(pos: Int, const: Int, constPosition: Int = 0): Long {
        return when{
            pos >= memo.size -> 0
            memo[pos] >= 0 -> memo[pos]
            constPosition < sortedConstraint.size && sortedConstraint[constPosition].first <= pos -> {
                val right = lowerBound(constPosition, sortedConstraint.size){next ->
                    pos < sortedConstraint[next].first
                }
                sub(pos, rights[right - 1], right)
            }
            const <= pos -> {
                memo[pos] = sub(pos + 1, pos + 1, constPosition) + beauties[pos]
                return memo[pos]
            }
            else -> {
                memo[pos] = max(sub(const + 1, const + 1, constPosition) + beauties[pos], sub(pos + 1, const, constPosition))
                memo[pos]
            }
        }
    }
    for (i in beauties.indices.step(100).reversed()){
        val r = lowerBound(0, sortedConstraint.size){pos ->
            i < sortedConstraint[pos].first
        }
        if (r == 0){
            sub(i, i, r)
        }else {
            sub(i, rights[r - 1], r)
        }
    }
    return sub(0, 0, 0)
}
inline fun lowerBound(from: Int, until: Int, predicate: (Int) -> Boolean): Int {
    var left = from
    var right = until
    while(left < right){
        val mid = (left + right) / 2
        if (predicate(mid)){
            right = mid
        }else {
            left = mid + 1
        }
    }
    return right
}


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


using namespace std;

int main(){
    int N;
    cin >> N;
    int p[N];

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

    for(int i = 1;i < N-1; i++){
        if( (min(p[i-1],p[i]) == p[i] && min(p[i],p[i+1]) != p[i])  ||  (min(p[i-1],p[i]) != p[i] && min(p[i],p[i+1]) == p[i])  ){
            ans++;
        }
    }
    
    
    
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
n,m,x1= map(int, input().split())
# 値段,上がる理解度
c= [list(map(int, input().split())) for i in range(n)]

ans=pow(10,9)
for i in range(2**n):
    cnt=0
    x=[0]*m
    for j in range(n):
        if (i>>j)&1:
            cnt+=c[j][0]
            for k in range(1,m+1):
                x[k-1]+=c[j][k]
    if min(x)>=x1:
        ans=min(cnt,ans)

if ans==pow(10,9):
    print(-1)

else:
    print(ans)

Measured memory_bytes: 68588
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto s = sread();
    foreach (i, c; s)
        if (~i & 1)
        {
            write(c);
        }
    writeln();
}


Measured memory_bytes: 508
flag = true
ct, cx, cy = 0, 0, 0

gets.to_i.times do ||
  tt, tx, ty = gets.split.map{|s| s.to_i }
  distance = (cx-tx).abs + (cy-ty).abs
  time = tt - ct

  if distance > time || (time - distance).odd?
    flag = false
    break
  end

  ct, cx, cy = tt, tx, ty
end

puts flag ? "Yes" : "No"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(RALL(x))
#define SUM(x) accumulate(ALL(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, m;
  cin >> n >> m;
  vector<pii> key;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c;
      cin >> c;
      --c;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }

  vi dp(1<<n,INF);
  dp[0] = 0;
  rep(s,1<<n) {
    rep(i,m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t],cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	

	int n;
	cin>>n;
	cin.ignore();
	while(n>0){
		string s;
		bool f=false;
		getline(cin,s);
		for(int b=0;b<=26;b++){
			
			for(int a=0;a<=26;a++){
				string ans=s;
				if(a%2!=0&&a%13!=0){
					for(int i=0;i<ans.size();i++){
						if(ans[i]>='a'&&ans[i]<='z'){
							ans[i]='a'+(a*(ans[i]-'a')+b)%26;
						}
					}
					if(ans.find("that")!=-1||ans.find("this")!=-1){
						cout<<ans<<endl;
						f=true;
						break;
					}
				}
			}
			if(f)
				break;
		}
		
	
		n--;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 505;

int n;
int arr[N][N];

void solve(int l, int r, int c)
{
  if(r - l + 1 <= 1)
    return;
  int mid = (l + r) / 2;
  for(int i = l ; i <= mid ; i++){
    for(int j = mid + 1 ; j <= r; j++){
      arr[i][j] = c;
    }
  }
  solve(l, mid, c + 1);
  solve(mid + 1, r, c + 1);
}

int main()
{
  cin >> n;
  solve(1, n, 1);
  for(int i = 1 ; i <= n ; i++){
    for(int j = i + 1; j <= n ; j++)
      cout << arr[i][j] << " ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
using namespace std;

int main()
{
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double rad_dif,X;
    if(fabs(((H*60 + M)/720) - (M/60)) > 0.5) rad_dif = (1 - fabs(((H*60 + M)/720) - (M/60)))*2*PI;
    else rad_dif = fabs(((H*60 + M)/720) - (M/60))*2*PI;
    X = sqrt(pow(A,2) + pow(B,2) - 2*A*B*cos(rad_dif));
    cout << setprecision(20) << X <<endl;
}

Measured memory_bytes: 4200
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toInt()
        var B = sc.next().toInt()
        var C = sc.next().toInt()
        var K = sc.next().toInt()
        while (K > 0) {
            if (A < B) {
                break
            }
            B *= 2
            K--
        }
        while (K > 0) {
            if (B < C) {
                break
            }
            C *= 2
            K--
        }
        if (A < B && B < C) {
            pw.println("Yes")
        } else {
            pw.println("No")
        }
    }
}


Measured memory_bytes: 36448