akhauriyash/Code-Regression huggingface dataset:
/*
cat <<EOF >mistaken-paste
*/

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define BIG 2000000007
#define VERYBIG 200000000000007LL

#define MOD 1000000007
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 300000
#define M_MAX 200000

typedef struct {
	int32_t a;
	int32_t b;
} hw;

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	hwll a;
	hwll b;
} linell;


typedef struct {
	ull s;
	ull t;
	int32_t c;
} struct_a;

typedef struct {
	int32_t from;
	int32_t to;
	sll cost;
} struct_b;

ull n, m;
ull h, w;
ull k;
ull q;
ull vua, vub, vuc, vud, vue, vuf;
sll vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull a[N_MAX];

ull cards[M_MAX];
ull pairs[M_MAX];

int32_t pullcomp (const void *left, const void *right) {
	ull l = *(ull*)left;
	ull r = *(ull*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

ull solve () {
	sll i, j, ki;
	sll result = 0;

	qsort(a, n, sizeof(ull), pullcomp);

	i = 0;
	while (i < n) {
		j = i;
		while (j < n && a[j] == a[i]) j++;
		
		cards[a[i] % m] += (j - i);
		pairs[a[i] % m] += (j - i) / 2;

		i = j;
	}

	i = 0;
	while (true) {
		j = (m - i) % m;
		if (j < i) break;

		if (i == j) {
			result += cards[i] / 2;
		} else {
			sll shorteri, longeri;
			if (cards[i] > cards[j]) {
				shorteri = j;
				longeri = i;
			} else {
				shorteri = i;
				longeri = j;
			}

			result += (cards[shorteri] + umin(pairs[longeri], (cards[longeri] - cards[shorteri]) / 2));
		}

		i++;
	}

	printf("%llu\n", result);

	return 0;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	scanf("%llu%llu", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%llu", &a[i]);
	}

	solve();

	return 0;
}


Measured memory_bytes: 3452
#include <stdio.h>
#include <math.h>
//#include <algorithm>

static long long calc( long n, long long x )
{
    if(n==0) {
        return 1;
    }

    long long a = (long long)(pow( (double)2.0, (double)(n+2) ) - 3 + 0.1);
    if(x == a) {
        return (long long)(pow( (double)2.0, (double)(n+1)) - 1 + 0.1);
    }

    long long b = (long long)(pow( (double)2.0, (double)(n+1) ) - 3 + 0.1); 

    if(x==1) {
        return 0;
    }
    else if(x<=b+1) {
        return calc( n-1, x-1 );
    }
    else if(x==b+2) {
        return (1 + calc( n-1, b ) );
    }
    else if(x==b*2+3) {
        return (1 + 2 * calc( n-1, b ) );
    }
    else {
        return (1 + calc( n-1, b ) + calc( n-1, x-b-2));
    }

    return 1000000;
}

int main(int argc, char* argv[])
{
    long n;
    long long x;
    scanf("%ld %lld", &n, &x);

    long long ans = calc( n, x );

    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <climits>
#include <limits>
#define inf 1000000000000000000

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define pair(A, B) make_pair(A, B)

using namespace std;

typedef pair<int, int> pi;
typedef pair<pair<int, int>, int> pii;

void performA() {
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
    return;
  }
  cout << "No" << endl;
  return;
}

void performB() {
  int n; cin >> n;
  int pts = (n/500) * 1000;
  n %= 500;
  pts += (n/5) * 5;
  cout << pts << endl;
}

void performC() {
  int k, n; cin >> k >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  int diff = 0;
  int prev = v[0];
  int first = prev;
  for (int i = 1; i < n; i++) {
    int t = v[i];
    diff = max(diff, min(fabs(t - prev), fabs(k - max(t, prev) + min(t, prev))));
    prev = t;
  }
  int t = first;
  diff = max(diff, min(fabs(t - prev), fabs(k - max(t, prev) + min(t, prev))));
  cout << (k - diff) << endl;
}

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

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = a - 2 * b;
		System.out.println(c > 0 ? c : 0);
	}
}


Measured memory_bytes: 21460
N, K = map(int, input().split())

mod = 10 ** 9 + 7


def comb(n, r):
    den = 1
    num = 1
    for i in range(r):
        den *= (n - i)
        den %= mod
        num *= (i + 1)
        num %= mod
    return den * pow(num, mod - 2, mod) % mod


for i in range(K):
    print(comb(N - K + 1, i + 1) * comb(K - 1, i - 1 + 1) % mod)


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
static const int MAX = 100;

int BubbleSort(int* A, int n) {
    int flag = 1;
    int temp, count = 0;
    while (flag) {
        flag = 0;
        for(int j = n-1; j >= 1; --j) {
            if (A[j] < A[j-1]) {
                temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
                flag = 1;
                count++;
            }
        }
    }
    return count;
}

int main(int argc, char const *argv[]) {
    int A[MAX];
    int n, count;
    //??\???????????°???????´?
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    count = BubbleSort(A, n);

    cout << A[0];
    for(int i = 1; i < n; ++i) {
        cout << " " << A[i] << flush;
    }
    cout << endl;
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner cin=new Scanner(System.in);
		while(cin.hasNext()){
			int n=cin.nextInt();
			int a=cin.nextInt();
			int b=cin.nextInt();
			String s=cin.next();
			int cur=0;
			int curb=0;
			for(int i=0;i<n;i++){
				char tmp=s.charAt(i);
				boolean flag=false;
				if(tmp=='a'){
					if(cur<a+b){
						flag=true;
						cur++;
					}
				}
				if(tmp=='b'){
					if(cur<a+b&&curb<b){
						flag=true;
						cur++;
						curb++;
					}
				}
				if(flag)System.out.println("Yes");
				else
					System.out.println("No");
			}
			
			
		}
	}
}

Measured memory_bytes: 23676
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();
        var segtree = new SegmentTree<int>(A, 0, GCD);
        var ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans = Max(ans, GCD(segtree.Query(0, i), segtree.Query(i + 1, N)));
        }
        WriteLine(ans);
    }

    static int GCD(int a, int b)
    {
        while (b != 0)
        {
            var c = a;
            a = b;
            b = c % b;
        }
        return a;
    }
}

public class SegmentTree<T>//Tがstring以外の参照型だとEの扱いが･･･単位元に対する書き換えは起こらない保証ある･･･？
{
    T[] buffer;
    int N;
    T IE;
    Func<T, T, T> Op;//デリゲート遅そう　

    public SegmentTree(T[] init, T E, Func<T, T, T> op)
    {
        //var c = 1;
        //while (c < init.Length) c <<= 1;
        N = init.Length;
        buffer = new T[N * 2 - 1];
        Array.Copy(init, 0, buffer, N - 1, init.Length);
        //Array.Fill(buffer, E, init.Length + N - 1, buffer.Length - init.Length - N + 1);// NETCOREAPP Only
        for (int i = init.Length + N - 1; i < buffer.Length; i++) buffer[i] = E;
        for (int i = N - 2; i >= 0; i--)
        {
            buffer[i] = op(buffer[i * 2 + 1], buffer[i * 2 + 2]);
        }
        Op = op;
        IE = E;
    }

    public void Update(int index, T value)//[0, N)アクセス可
    {
        index += N - 1;
        buffer[index] = value;
        while (index > 0)
        {
            index = (index - 1) / 2;
            buffer[index] = Op(buffer[index * 2 + 1], buffer[index * 2 + 2]);
        }
    }

    public T this[int index]
    {
        set//setの式形式はC#7.0以降
        {
            Update(index, value);
        }
        get
        {
            return buffer[index + N - 1];
        }
    }

    public T Query(int l, int r)
    {
        var lv = IE;
        var rv = IE;
        l += N - 1;
        r += N - 1;
        while (l < r)
        {
            if ((l & 1) == 0)
            {
                lv = Op(lv, buffer[l]);
            }
            if ((r & 1) == 0)
            {
                rv = Op(buffer[r - 1], rv);
            }
            l /= 2;
            r = (r - 1) / 2;
        }
        return Op(lv, rv);
    }
}


Measured memory_bytes: 29148
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
ll a[105];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	int n,k;
 	cin>>n>>k;
 	for(int i=0;i<k;i++)
 	{
 		int d;
		cin>>d;
		 while(d--)
            {
                  int temp;
                  cin >> temp;
                  a[temp]=1;
            }
	}
	     int ans=0;
      for (int i=1; i<=n; i++)
      {
            if (a[i]==0)
                  ans++;
      }cout << ans << endl;
}

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

int main(void){
    string s;
    cin>>s;
    string r="Sunny";
    
    if(s=="Sunny"){
        r="Cloudy";
    }else if(s=="Cloudy"){
        r="Rainy";
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 3*1e3 + 10;
// make sure N size is correctttt!!!!!!!!!

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

int solve(int idx1, int idx2, int person){
   if(idx1 > idx2){
      return 0;
   }
   int &ans = dp[idx1][idx2][person];
   if(ans != -1){
      return ans;
   }
   if(person == 0){
      ans = max(a[idx1]+solve(idx1+1, idx2, 1^person), a[idx2]+solve(idx1, idx2-1, 1^person));
   }
   else{
      ans = min(-a[idx1]+solve(idx1+1, idx2, 1^person), -a[idx2]+solve(idx1, idx2-1, 1^person));
   }
   return ans;
}

int32_t main(){_

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

   memset(dp, -1, sizeof dp);
   cout<<solve(0,n-1,0);

   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 141952
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		int n = scanner.nextInt();
		int sr = scanner.nextInt();
		int sc = scanner.nextInt();
		String s = scanner.next();
		String t = scanner.next();
		boolean end = false;
		//左から
		int hidari = sc;
		if (s.charAt(0) == 'L') {
			hidari--;
		}
		for (int i = 0; i < n - 1; i++) {
			if (hidari == 0) {
				end = true;
				break;
			} else {
				if (t.charAt(i) == 'R') {
					hidari = Math.min(hidari + 1, w);
				}
				if (s.charAt(i + 1) == 'L') {
					hidari--;
				}
			}
		}
		if (hidari == 0) {
			end = true;
		}
		//右から
		int migi = sc;
		if (s.charAt(0) == 'R') {
			migi++;
		}
		for (int i = 0; i < n - 1; i++) {
			if (migi == w + 1) {
				end = true;
				break;
			} else {
				if (t.charAt(i) == 'L') {
					migi = Math.max(1, migi - 1);
				}
				if (s.charAt(i + 1) == 'R') {
					migi++;
				}
			}
		}
		if (migi == w + 1) {
			end = true;
		}
		//上
		int ue = sr;
		if (s.charAt(0) == 'U') {
			ue--;
		}
		for (int i = 0; i < n - 1; i++) {
			if (ue == 0) {
				end = true;
				break;
			} else {
				if (t.charAt(i) == 'D') {
					ue = Math.min(ue + 1, h);
				}
				if (s.charAt(i + 1) == 'U') {
					ue--;
				}
			}
		}
		if (ue == 0) {
			end = true;
		}
		//下から
		int sita = sr;
		if (s.charAt(0) == 'D') {
			sita++;
		}
		for (int i = 0; i < n - 1; i++) {
			if (sita == h + 1) {
				end = true;
				break;
			} else {
				if (t.charAt(i) == 'U') {
					sita = Math.max(1, sita - 1);
				}
				if (s.charAt(i + 1) == 'D') {
					sita++;
				}
			}
		}
		if (sita == h + 1) {
			end = true;
		}
		if (!end) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 28540
#include <iostream>

using namespace std;

main(){
  int sum;
  while(1){
    cin >> sum;
    if(sum==0) break;

    int tmp;
    for(int i=0;i<9;i++){
      cin >> tmp;
      sum-=tmp;
    }
    cout << sum << endl;
  }
  return 0;
}

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

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

using namespace std;

int toTime(string s) { 
  int h,m;
  stringstream ss;
  s[2] = ' ';
  ss << s;
  ss >> h;
  ss >> m;
  return h * 60 + m;
}

string input[200][4];
int main(){
  int n,T;
  cin >> n >> T;
  typedef pair<string,int> si;
  vector<si> vec;
  
  rep(i,n) rep(j,4) cin >> input[i][j];
  rep(i,n-1){
    int time1=toTime(input[i][2]),time2=toTime(input[i+1][0]);
    if(time2-time1>=T) vec.push_back(si(input[i][3],time2-time1));
  }
  cout << vec.size() << endl;
  rep(i,vec.size()){
    cout << vec[i].first << " " << vec[i].second << endl;
  }
  return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

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

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

    // 入力
    int x, t;
    cin >> x >> t;

    // 処理
    // 出力
    cout << max(x - t, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int a,b;
    cin >> a >> b;
    if(a<=b){
        cout << a << endl;
    }else{
        cout << a-1 << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<a.size();i+=2)
        if(a[i]=='L')
    {
        cout<<"No";
        return 0;
    }
    for(int i=1;i<a.size();i+=2)
        if(a[i]=='R')
    {
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/aising2019/tasks/aising2019_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

struct UnionFind {
  struct Node {
    ll parent;
    ll size;
  };
  vector<Node> tree;

  UnionFind(ll size) : tree(size) {
    for (ll i = 0; i < size; i++) {
      tree[i].parent = i;
      tree[i].size = 1;
    }
  }

  ll find(ll x) {
    if (tree[x].parent == x)
      return x;
    else
      return tree[x].parent = find(tree[x].parent);
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree[x].size < tree[y].size) swap(x, y);

    tree[y].parent = x;
    tree[x].size += tree[y].size;
  }

  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
};

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vi dx = {0, 0, 1, -1};
  vi dy = {1, -1, 0, 0};
  UnionFind uf(h*w);
  rep(i, h) rep(j, w) rep(k, 4) {
    int ni = i+dx[k];
    int nj = j+dy[k];
    if (0 <= ni && ni < h && 0 <= nj && nj < w && s[i][j] != s[ni][nj]) {
      uf.unite(i*w + j, ni*w + nj);
    }
  }

  vector<ll> black(h*w, 0), white(h*w, 0);
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') black[uf.find(i*w + j)]++;
    else white[uf.find(i*w + j)]++;
  }

  ll ans = 0;
  rep(i, h*w) {
    ans += black[i] * white[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 5504
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100005;

int A[N];
LL AS[N], SS[N];
int n;
LL ans[N];
vector<pii > Q;

LL diff(int idx, int val) {
  return abs(A[idx] - val);
}

bool check(int x, int y, int val) {
  int d = n - y;
  int l = y + 1 - d;
  if(l < 2) return true;
  return diff(l - 1, val) > diff(y, val);
}

int main() {
  int q;
  S2(n,q);
  rep(i,1,n+1) {
    S(A[i]);
    AS[i] = A[i];
    if(i >= 2) {
      AS[i] += AS[i - 2];
    }
  }

  for(int i = n; i >= 1; i--) {
    SS[i] = SS[i + 1] + A[i];
  }

  rep(i,0,q) {
    int x;
    S(x);
    Q.pb(mp(x, i));
  }
  sort(all(Q));
  int idx = 0;
  int cl = n / 2;
  rep(i,0,q) {
    int x = Q[i].FF;
    while(idx < n && A[idx + 1] <= x) {
      idx++;
      while(cl < n - 1 && check(idx, cl + 1, x)) {
        cl++;
      }
      cl = max(cl, idx);
    }
    while(cl < n - 1 && check(idx, cl + 1, x)) {
      cl++;
    }
    cl = max(cl, idx);

    // printf("%d %d %d\n",x,idx,cl);

    if(idx >= n - 1) {
      ans[Q[i].SS] = AS[n];
      continue;
    } else if(!idx) {
      ans[Q[i].SS] = SS[n / 2 + 1];
      continue;
    }
    LL res = SS[cl + 1];
    int l = cl - (n - cl);
    if(l > 0) {
      res += AS[l];
    }
    ans[Q[i].SS] = res;
  }
  rep(i,0,q) {
    printf("%lld\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 5364
#include <iostream>
#include <cmath>

int main() {
    int D, N;
    std::cin >> D >> N;

    if (N == 100) {
        std::cout << 101 * (int)std::pow(100, D) << std::endl;
    } else {
        std::cout << N * (int)std::pow(100, D) << std::endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

const int MAXN = 2002;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;

template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}

template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}

template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}

int n;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y second

ppi p[MAXN];

bool check(int x, int y) {
	int pos = 1;
	while(p[pos].Y == 0) pos++;
	int tmp = abs(x - p[pos].X.X), tmp2 = abs(y - p[pos].X.Y);
	int h = p[pos].Y + tmp + tmp2;
	for(int i = 1; i <= n; i++) {
		if(i == pos) continue;
		tmp = abs(x - p[i].X.X), tmp2 = abs(y - p[i].X.Y);
		if(h - tmp - tmp2 < 0) {
			if(p[i].Y == 0) continue;
			else return 0;
		}
		if(p[i].Y + tmp + tmp2 != h) return 0;
	}
	return 1;
}

signed main() {
	read(n);
	srand((unsigned int) time(NULL));
	for(int i = 1; i <= n; i++) {
		read(p[i].X.X), read(p[i].X.Y);
		read(p[i].Y);
	}
	random_shuffle(p + 1, p + n + 1);
	for(int i = 0; i <= 100; i++) {
		for(int j = 0; j <= 100; j++) {
			if(check(i, j)) {
				int pos = 1;
				while(p[pos].Y == 0) pos++;
				int tmp = abs(i - p[pos].X.X), tmp2 = abs(j - p[pos].X.Y);
				int h = p[pos].Y + tmp + tmp2;
				printf("%d %d %d\n", i, j, h);
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
  int n, x;
  while(true) {
    int ans = 0;
    cin >> n >> x;
    if (n == 0 && x == 0) break;

    for(int i = 1; i <= n; ++i) {
      for(int j = i + 1; j <= n; ++j) {
        for(int k = j + 1; k <= n; ++k) {
          if((i + j + k) == x) ans++;
        }
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3092
#01:36
s = input()
n = len(s)
if s[-1] == '1':
  print(-1)
  exit()
t = s[:-1]
if t[::-1] != t:
  print(-1)
  exit()
if s[0] == '0':
  print(-1)
  exit()
print(0+1,1+1)
now = 0
for i in range(2,n):
  print(now+1,i+1)
  if s[i-1] == '1':
    now = i

Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin >> s;
    if (s == "keyence") {
        cout << "YES\n";
        return 0;
    }
    for (int i = 0; i < s.size(); i++) {
        for (int j = i; j < s.size(); j++) {
            string w;
            for (int k = 0; k < s.size(); k++) {
                if (k < i || k > j) {
                    w += s[k];
                }
            }
            if (w == "keyence") {
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
    return 0;
}

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

int alpha_to_int(char a) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.find(a);
}

char int_to_alpha(int i) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.at(i);
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> cnt(n+1, vector<int>(26));
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        while(s.size()) {
            int j = alpha_to_int(s.back());
            cnt[i][j]++;
            s.pop_back();
        }
    }
    for (int j = 0; j < 26; j++) {
        cnt[n][j] = 51;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 26; j++) {
            cnt[n][j] = min(cnt[i][j], cnt[n][j]);
        }
    }
    string ans;
    for (int j = 0; j < 26; j++) {
        int sum_cnt = cnt[n][j];
        if (sum_cnt > 0) {
            for (int i = 0; i < sum_cnt; i++) {
                ans += int_to_alpha(j);
            }
        }
    }
    cout << ans << endl;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int N,M;
  cin>>N>>M;
  bool flag = false;
  for(int i(1);i<=M;i++){
    int a = i;
    int b = N+1-i;
    //cout << i << " " << N+1 - i << endl;
    if(N % 4 == 2 && (N - 2)/2 == b - a - 1){
      //cout << N/2 << " " << N/2 + 1 << endl;
      flag = true;
      cout << a << " " << b-1 << endl;
    }else if(N%4 == 0 && (N-2)/2 == b - a){
      flag = true;
      cout << a << " " << b-1 << endl;
    }else{
      if(flag == false){
        cout << a << " " << b << endl;
      }else{
        cout << a << " " << b-1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<iomanip>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    double b = 0.0;
    for(int i = 0; i < n; i++){
        b += 1.0 / a[i];
    }
    double ans = 1 / b;
    cout << setprecision(9) << ans << endl;
    return 0;
}


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


int main(){
	ll a;
	double b;
	cin >> a >> b;
	b = b*100+0.5;
	ll ans = (a * (ll)b)/100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3708
x=int(input())
from numpy import mod

if x <= 3:
    ans=x
    prime=True
elif mod(x,2)==0:
    prime=False
else:
    # check prime or not
    for i in range(3,x+1,2):
        if mod(x,i)==0:
            if i==x:
                prime=True
                ans=x
            else:
                prime=False
                break
if prime==False: # look for prime
    if mod(x,2)==0:
        x2=x-1
    else:
        x2=x-2
            
    while (prime==False):
        x2= x2+2
        prime=True
        for i in range(3,x2+1,2):
            if mod(x2,i)==0:
                if i==x2:
                    prime=True
                    ans=x2
                else:
                    prime=False
                    break
    

print(ans)


Measured memory_bytes: 12504
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    ll n, m, d;
    cin >> n >> m >> d;

    long double dd;
    dd = m-1;
    dd /= n;
    dd /= n;
    dd *= n-d;
    if(d) dd *= 2;

    cout << fixed << setprecision(10);

    cout << dd << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)




int main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A + B >= X && X >= A)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}



Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


s=input()
a=s.count('a')
b=s.count('b')
c=s.count('c')
 
print('YES' if max(a,b,c)-min(a,b,c)<=1 else 'NO')

Measured memory_bytes: 5304
#include<stdio.h>

int func(int);

int main()
{
  int i;
  int n;
  int a;
  int count = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ )
  {
    scanf("%d", &a);
    if ( func(a) ) count++;
  }
  //printf("%d",a);
  printf("%d\n", count);
  return 0;
}

int func(int value)
{
  int i;
  if ( value < 2 )
  {
    return 0;
  }
  else if ( value == 2 )
  {
    return 1;
  }
  if ( value % 2 == 0 )
  {
    return 0;
  }
  for ( i = 3; i*i <= value; i += 2 )
  {
    if ( value % i == 0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2084
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int N = 111;
int n;
int a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	int d = n;
	while(a[d] == 0) d--;
	int r = 0;
	while(a[r] == 0) r++;
	if ((d + 1) / 2 != r)
	{
		printf("Impossible\n");
		return 0;
	}
	if (a[r] != 1 + (d % 2))
	{
		printf("Impossible\n");
		return 0;
	}
	for (int i = r + 1; i <= d; i++)
	{
		if (a[i] < 2)
		{
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");

	return 0;
}

Measured memory_bytes: 256
Z=[]
b=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[6,4,2]]
for i in range(3):
    Z+=[int(x) for x in input().split()]
        
N=int(input())
bingo=0
for i in range(N):
    x=int(input())
    if x in Z:
        Z[Z.index(x)] = 0
    if i>1:
        for j in range(8):
            if Z[b[j][0]]+Z[b[j][1]]+Z[b[j][2]] == 0:
                      bingo = 1
                      break
    if bingo == 1: break
                      
if bingo == 1:print("Yes")
else: print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, ans = 0, a, b, ct, r;
	
	cin >> n;
	vector<long long> x(n);
	for (i = 0; i < n; i++) cin >> x[i];
	sort(x.rbegin(), x.rend());

	priority_queue<tuple<long long, long long, long long>> pq;
	pq.push({ x[0], x[0], x[0] });

	for (i = 1; i < n; i++) {
		tie(r, a, b) = pq.top();
		pq.pop();

		ans += r;

		pq.push({ x[i], a, x[i] });
		pq.push({ x[i], b, x[i] });
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 10652
from heapq import heappush, heappop
n = input()
h = [-10000]*4
for i in range(n):
    a = input()
    heappush(h, -a)
    heappop(h)
h = [str(-a) for a in h]
ans = []
for i in range(3):
    for j in range(i+1, 4):
        ans.append(int(h[i]+h[j]))
        ans.append(int(h[j]+h[i]))
ans.sort()
print ans[2]

Measured memory_bytes: 4716
using System;
using System.Collections.Generic;
using System.Linq;

public class S
{

    private const long DP_INIT_MINUS1 = -1;
    private const double DP_INIT_DOUBLE_MINUS1 = -1.0;
	private const long MOD = 1000000007;


    //s
    private const int FIRST_WIN = 1;
    private const int SECOND_WIN = 0;

    private static long[,] dp;
    private static long[] cSum;


    public static void Main()
	{
		/*
        var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        var N = input[0];
        var M = input[1];
        */

        var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        var N = input[0];
        //solver(N);
        solver(N,Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse));
    }

    public static void solver(int N, double[] input){

        /*
            ABC 138 C "Alchemist"
            とどのつまり、合成に使用された素材の価値は減ると書いてある。
            じゃあ、一番良いものは最後の合成で、その1回前の合成は次に良いもので…となるから、
            価値の低いものから順に合成していけばよい。本当に？

        
         */


         Array.Sort(input);
         double result = input[0];
         for(int i = 1; i < N; i++){
             result = (result + input[i]) / 2;
         }

         Console.WriteLine(result);


    }

}

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

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

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

template< typename T >
T kruskal(Edges< T > &edges, int V) {  
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return (a.cost < b.cost);
  });
  UnionFind tree(V);
  T ret = 0;
  int cnt = 0;
  int ans = 0;
  for(auto &e : edges) {
    if(tree.unite(e.src, e.to)) {
      cnt++;
      if ( cnt == V/2 ) ans = e.cost;      
      ret += e.cost;
    }
  }
  return (ans);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  while ( cin >> n >> m, n ) {
    Edges<int> E;
    for ( int i = 0; i < m; i++ ) {
      int s, t, c;
      cin >> s >> t >> c;
      s--; t--;
      E.push_back(edge<int>(s, t, c));      
    }

    cout << kruskal(E, n) << endl;    
  }
  
  return 0;
}



Measured memory_bytes: 3576
#include<cstdio>
#include<cstring>
char s[200];
int main()
{
    scanf("%s",s);
    int n=strlen(s),flag=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='C')
            flag=1;
        if(s[i]=='F')
        {
            if(flag)
            {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int calc2DivTimes(int val) {
    int cnt = 0;
    while (val % 2 == 0) {
        val /= 2;
        cnt++;
    }

    return cnt;
}

int main() {
    int N;
    cin >> N;
    
    int maxCnt = 0;
    int maxNum = 1;
    while (N != 0) {
        int tempCnt = calc2DivTimes(N);
        if (tempCnt > maxCnt) {
            maxCnt = tempCnt;
            maxNum = N;
        }
        N--;
    }

    cout << maxNum << endl;

    return 0;
}

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

int main() {
	int N;
	string S, T;
	cin >> N;
	cin >> S >> T;

	for (int i = 0; i < N; i++) {
		cout << S.at(i) << T.at(i);
	}
	cout << endl;
}

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

using namespace std;
const int N = 1e5+7;

int w[N],v[N];
long long dp[110][N];

int main()
{
	int n,W;
	cin>>n>>W;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	
	for(int i=1;i<=n;i++){
		for(int j = 1;j <= W;j ++){  //选 
			dp[i][j] = dp[i-1][j];
			if(j>=w[i]) dp[i][j] = max(dp[i-1][j-w[i]]+v[i],dp[i][j]);
		}
	}
	cout<<dp[n][W];
	return 0;
} 

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

namespace ITP1_8_C
{
	class Program
	{
		static void Main(string[] args)
		{
			List<string> vs = new List<string>();
			Dictionary<char, int> dict = new Dictionary<char, int> {
				{'a', 0}, {'b', 0}, {'c', 0}, {'d', 0}, {'e', 0},
				{'f', 0}, {'g', 0}, {'h', 0}, {'i', 0}, {'j', 0},
				{'k', 0}, {'l', 0}, {'m', 0}, {'n', 0}, {'o', 0},
				{'p', 0}, {'q', 0}, {'r', 0}, {'s', 0}, {'t', 0},
				{'u', 0}, {'v', 0}, {'w', 0}, {'x', 0}, {'y', 0}, {'z', 0}
			};

			// 入力
			while(true) {
				string str = Console.ReadLine();
				if(str == null) {
					break;
				}

				vs.Add(str);
			}

			// カウント
			foreach(string v in vs) {
				foreach(char c in v) {
					if(dict.ContainsKey(char.ToLower(c))) {
						dict[char.ToLower(c)]++;
					}
				}
			}

			// 出力
			foreach(KeyValuePair<char, int> d in dict) {
				Console.WriteLine($"{d.Key} : {d.Value}");
			}
		}
	}
}



Measured memory_bytes: 18080
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	double x1, y1, x2, y2, x3, y3;
	char c;
	double veku[2];
	while (cin >> x1 >> c >> y1 >> c >> x2 >> c >> y2 >> c >> x3 >> c >> y3) {
		veku[0] = x2 - x1;
		veku[1] = y2 - y1;
		if (fabs(veku[0]) <= 0.0001) {
			printf("%.6f %.6f\n", -x3, y3);
		} else {
			double kaku = -atan(veku[1]/veku[0]);
			double x4, y4, x5, y5;
			double b = y2 - (veku[1]/veku[0])*x2;
			x4 = cos(kaku)*x3-sin(kaku)*(y3-b);
			y4 = sin(kaku)*x3+cos(kaku)*(y3-b);
			y4 = -y4;
			x5 = cos(-kaku)*x4-sin(-kaku)*y4;
			y5 = sin(-kaku)*x4+cos(-kaku)*y4;
			printf("%.6f %.6f\n", x5, y5+b);
		}
	}
	return 0;
}

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

using namespace std ;

#define inf 0x3f3f3f3f
#define ll long long

ll n , s ;

ll f( ll b , ll n ) {
	return n < b ? n : f( b , n / b ) + n % b ;
}

int main() {
	scanf( "%lld%lld" , &n , &s ) ;
	if( s > n ) return puts( "-1" ) , 0 ;
	if( s == n ) return printf( "%lld\n" , n + 1 ) , 0 ;
	ll m = sqrt( n ) + 1 ;
	for( ll i = 2 ; i <= m ; i ++ ) {
		if( f( i , n ) == s ) 
			return printf( "%lld" , i ) , 0 ;
	}
	ll ans = 1e11 ; n -= s ;
	for( ll i = 1 ; i * i <= n ; i ++ ) {
		if( n % i == 0 ) {
			ll b = n / i + 1 , c = s - i ;
			if( c >= 0 && b >= 2 && c < b && i < b ) 
				ans = min( ans , b ) ; 
		}
	}
	printf( "%lld\n" , ans != 1e11 ? ans : -1 ) ;
	return 0 ;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  using i128 = __int128_t;
  Int n,m,a,b,p,q;
  cin>>n>>m>>a>>b>>p>>q;
  
  i128 N(n),M(m),A(a),B(b),P(p),Q(q);


  auto calc=[&](i128 a,i128 b)->i128{return a<=b?b-a:a-b;};
  
  if(a==1&&b==1){
    i128 need=M/(P+Q);
    if(need<=N){
      i128 ans=calc(M,need*(P+Q));
      if(need-1>=0) chmin(ans,calc(M,(need-1)*(P+Q)));
      if(need+1<=N) chmin(ans,calc(M,(need+1)*(P+Q)));
      cout<<Int(ans)<<endl;
      return 0;
    }
    cout<<Int(M-N*(P+Q))<<endl;
    return 0;
  }
  
  vector<i128> vs;  
  for(Int i=0;i<n;i++){
    vs.emplace_back(P+Q);
    if(P+Q>M) break;
    P*=A;
    Q*=B;
  }
  
  const Int H = 20;
  i128 ans=M;
  vector<i128> hs;
  
  for(Int bit=0;bit<(1LL<<H);bit++){
    i128 tmp=0;
    for(Int i=0;i<(Int)vs.size();i++){
      if((~bit>>i)&1) continue;
      tmp+=vs[i];
    }
    hs.emplace_back(tmp);
    chmin(ans,calc(M,tmp));
  }
  sort(hs.begin(),hs.end());
  hs.erase(unique(hs.begin(),hs.end()),hs.end());
  
  if(vs.size()>H){
    Int R=vs.size()-H;
    for(Int bit=0;bit<(1LL<<R);bit++){      
      i128 tmp=0;
      for(Int i=H;i<(Int)vs.size();i++){
        if((~bit>>(i-H))&1) continue;
        tmp+=vs[i];
      }
      auto it=upper_bound(hs.begin(),hs.end(),M-tmp);
      if(it!=hs.end()) chmin(ans,calc(M,tmp+*it));
      ++it;
      if(it!=hs.end()) chmin(ans,calc(M,tmp+*it));

      for(Int k=0;k<3;k++){
        if(it!=hs.begin()) --it;
        chmin(ans,calc(M,tmp+*it));
      }
    }
  }
  cout<<(Int)ans<<endl;
  return 0;
}



Measured memory_bytes: 19520
from functools import reduce
import collections
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    N = int(input())
    a = list(int(_) for _ in input().split())
    a.sort()
    d = collections.defaultdict(int)
    for i in range(N):
        d[a[i]] +=1
    cnt = 0
    ans = 0

    for key in d:
        cnt = d[key]
        if key-1 in d:
            cnt += d[key-1]
        if key+1 in d:
            cnt += d[key+1] 
        ans = max(cnt,ans)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 14588
#include<iostream>

using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="a")cout<<"b\n";
    else if(s=="b")cout<<"c\n";
    else if(s=="c")cout<<"d\n";
    else if(s=="d")cout<<"e\n";
    else if(s=="e")cout<<"f\n";
    else if(s=="f")cout<<"g\n";
    else if(s=="g")cout<<"h\n";
    else if(s=="h")cout<<"i\n";
    else if(s=="i")cout<<"j\n";
    else if(s=="j")cout<<"k\n";
    else if(s=="k")cout<<"l\n";
    else if(s=="l")cout<<"m\n";
    else if(s=="m")cout<<"n\n";
    else if(s=="n")cout<<"o\n";
    else if(s=="o")cout<<"p\n";
    else if(s=="p")cout<<"q\n";
    else if(s=="q")cout<<"r\n";
    else if(s=="r")cout<<"s\n";
    else if(s=="s")cout<<"t\n";
    else if(s=="t")cout<<"u\n";
    else if(s=="u")cout<<"v\n";
    else if(s=="v")cout<<"w\n";
    else if(s=="w")cout<<"x\n";
    else if(s=="x")cout<<"y\n";
    else if(s=="y")cout<<"z\n";
    else cout<<"a\n";


    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++){
    cin >> L.at(i) >> R.at(i);
  }
  int maxL = L.at(0);
  int minR = R.at(0);
  for (int i = 0; i < M; i++){
    if (maxL < L.at(i))
    maxL = L.at(i);
    if (minR > R.at(i))
    minR = R.at(i);
  }
  int ans = minR - maxL + 1;
  cout << max(ans, 0) << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

struct edge{
	int to,cost;
	edge(){}
	edge(int a,int b):to(a),cost(b){}
};

vector<edge> G[1010];

int base[1010],dif[1010];
int cnt[1010][2];
int V;

queue<int> que;
void bfs(int s){
	base[s]=s;
	dif[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int u=G[v][i].to;
			int c=G[v][i].cost;
			if(base[u]!=-1) continue;
			base[u]=s;
			dif[u]=dif[v]^c;
			que.push(u);
		}
	}
}

int dp[1010][1010];

int N,P1,P2;

void init(){
	for(int i=0;i<1010;i++){
		G[i].clear();
		base[i]=-1;
		dif[i]=-1;
	}
}

int main(){
	while(true){
		scanf("%d%d%d",&N,&P1,&P2);
		if(N==0&&P1==0&&P2==0) break;
		init();
		for(int i=0;i<N;i++){
			int u,v;
			char ch[10];
			scanf("%d%d%s",&u,&v,ch);
			u--;v--;
			int c;
			if(ch[0]=='y') c=0;
			else c=1;
			G[u].push_back(edge(v,c));
			G[v].push_back(edge(u,c));
		}
		V=P1+P2;
		for(int i=0;i<V;i++){
			if(base[i]==-1){
				bfs(i);
			}
		}
	/*	for(int i=0;i<V;i++){
			printf("%d %d\n",base[i],dif[i]);
		}*/
		for(int i=0;i<V;i++) for(int j=0;j<2;j++) cnt[i][j]=0;
		for(int i=0;i<V;i++){
			cnt[base[i]][dif[i]]++;
		}
		bool flg=true;
		for(int i=0;i<V;i++){
			if(cnt[i][0]!=0&&cnt[i][0]==cnt[i][1]){
				flg=false;
			}
		}
		if(flg==false){
			printf("no\n");
			continue;
		}
		for(int i=0;i<=V;i++) for(int j=0;j<=V;j++) dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<V;i++){
			for(int j=0;j<=V;j++){
				int a=cnt[i][0];
				int b=cnt[i][1];
				if(a==0&&b==0){
					dp[i+1][j]=dp[i][j];
					continue;
				}
				if(j+a<=V){
					dp[i+1][j+a]+=dp[i][j];
					dp[i+1][j+a]=min(dp[i+1][j+a],2);
				}
				if(j+b<=V){
					dp[i+1][j+b]+=dp[i][j];
					dp[i+1][j+b]=min(dp[i+1][j+b],2);
				}
			}
		}
		if(dp[V][P1]==2){
			printf("no\n");
			continue;
		}
		vector<int> ans;
		int cur=P1;
		for(int i=V;i>=1;i--){
			if(cnt[i-1][0]==0&&cnt[i-1][1]==0) continue;
			int a=cnt[i-1][0],b=cnt[i-1][1];
			if(cur-a>=0&&dp[i-1][cur-a]>0){
				for(int v=0;v<V;v++){
					if(base[v]==i-1&&dif[v]==0){
						ans.push_back(v);
					}
				}
				cur-=a;
			}else{
				for(int v=0;v<V;v++){
					if(base[v]==i-1&&dif[v]==1){
						ans.push_back(v);
					}
				}
				cur-=b;
			}
		}
		sort(ans.begin(),ans.end());
		for(int i=0;i<ans.size();i++){
			printf("%d\n",ans[i]+1);
		}
		printf("end\n");
	}
	return 0;
}

Measured memory_bytes: 2936
N = int(input())
t = x = y = 0
judge = True
for i in range(N):
    nt, nx, ny = map(int, input().split())
    dt = nt - t
    dxy = abs(nx - x) + abs(ny - y)
    if dxy > dt or (dxy - dt) % 2 == 1: judge = False
    t = nt
    x = nx
    y = ny
print("Yes" if judge else "No")

Measured memory_bytes: 3064
N, T = map(int,input().split())
c = []
t = []

for i in range(N):
  a, b = map(int,input().split())
  c.append(a)
  t.append(b)
  
min_cost = 10**4
for i in range(N):
  if t[i]<=T and min_cost>c[i]:
    min_cost=c[i]

if min_cost==10**4:
  print("TLE")
else:
  print(int(min_cost))

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

int main(){
	cin>>str;
	int f=0;
	for(int i=0;i<str.length();i++){
		if(str[i]=='C')f=1;
		if(f==1&&str[i]=='F'){f=2;break;}
	}
	if(f==2)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main(){
  int k;
  cin>>k;
  if(k%2==0||k%5==0){
     cout<<-1<<endl;
     return 0;
  }

  ll p=7%k;
  ll x=p;
  int ans=0;
  while(x%k!=0){
     p=p*10%k;
     x+=p; 
     ans++;
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 3620
import sys; readline = sys.stdin.readline
from collections import deque


N = int(readline())
L = list(map(int, readline().split()))

L.sort()

Ns = [0] * (2*10**3 + 10)

for l in L:
    Ns[l] += 1

cNs = [0] * len(Ns)
for i in range(1, len(Ns)):
    cNs[i] = cNs[i - 1] + Ns[i]

count = 0
for i in range(N - 1, -1, -1):
    for j in range(i - 1, -1, -1):
        toosmall = cNs[L[i] - L[j]]
        count += max(0, j - toosmall)

        

print(count)

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

int main() {
    string g;
    while (cin >> g, g != "#") {
        int y, m, d; cin >> y >> m >> d;
        if (y > 31 || (y == 31 && m >= 5)) {
            g = "?";
            y = y - 30;
        }
        cout << g << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}


Measured memory_bytes: 3184