akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 * 
 * https://atcoder.jp/contests/abc177/submissions/16388865 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int[] a = new int[h], b = new int[h];
			IntStream.range(0, h).forEach(i -> {
				a[i] = scanner.nextInt() - 1;
				b[i] = scanner.nextInt();
			});
			SortedMap<Integer, Integer> currToOrigin = new TreeMap<>();
			IntStream.range(0, w).forEach(j -> currToOrigin.put(j, j));
			int[] gaps = new int[w], results = new int[h];
			gaps[0] = w;
			Arrays.fill(results, -1);
			int minGapIndex = 0, maxGapIndex = 0;
			for (int i = 0; (i < h) && !currToOrigin.isEmpty(); i++) {
				SortedMap<Integer, Integer> subMap = currToOrigin.subMap(a[i], b[i]);
				if (!subMap.isEmpty()) {
					int maxOrigin = subMap.get(subMap.lastKey());
					subMap.forEach((key, value) -> gaps[key - value]--);
					subMap.clear();
					if ((b[i] < w) && !currToOrigin.containsKey(b[i])) {
						currToOrigin.put(b[i], maxOrigin);
						gaps[b[i] - maxOrigin]++;
						maxGapIndex = Math.max(maxGapIndex, b[i] - maxOrigin);
					}
					while ((minGapIndex <= maxGapIndex) && (0 == gaps[minGapIndex])) {
						minGapIndex++;
					}
				}
				results[i] = (minGapIndex <= maxGapIndex) ? minGapIndex + i + 1 : -1;
			}
			Arrays.stream(results).forEach(System.out::println);
		}
	}
}


Measured memory_bytes: 80444
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int INF = 1 << 29;

using P = pair<int, int>;

int solve(const vec<int, 2> G, int S, int T) {
  int N = G.size();
  vec<int, 2> dist = make_v(N, 3, INF);
  dist[S][0] = 0;
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.emplace(0, S * 3);
  while (!Q.empty()) {
    auto p = Q.top();
    Q.pop();
    int cost = p.fst;
    int id = p.snd;
    int v = id / 3, m = id % 3;
    if (dist[v][m] < cost) continue;
    for (int u : G[v]) {
      int ncost = cost + 1;
      int nm = (m + 1) % 3;
      if (dist[u][nm] <= ncost) continue;
      dist[u][nm] = ncost;
      Q.emplace(ncost, u * 3 + nm);
    }
  }
  if (dist[T][0] < INF) {
    return dist[T][0] / 3;
  }
  return -1;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    vec<int, 2> G(N);
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back(b);
    }
    int S, T;
    cin >> S >> T;
    --S;
    --T;
    cout << solve(G, S, T) << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,m;cin>>n>>m;
	string s;cin>>s;
	vi l(m),r(m);
	rep(i,m){
		cin>>l[i]>>r[i];
		l[i]--;
		r[i]--;
	}
	int x=s.size();
	int sum[m+1];
	sum[0]=0;
	rep(i,x-1){
		if(s[i]=='A'&&s[i+1]=='C'){
			sum[i+1]=sum[i]+1;
		}
		else{
			sum[i+1]=sum[i];
		}
	}
	rep(i,m){
		cout<<sum[r[i]]-sum[l[i]]<<endl;
	}
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P> bridge(M);
	for (int i = 0; i < M; i++) {
		cin >> bridge[i].second >> bridge[i].first;
		bridge[i].first--;  bridge[i].second--;
	}
	sort(bridge.begin(), bridge.end());
	
	vector<bool> used(N - 1);
	for (int i = 0; i < N - 1; i++) used[i] = false;
	int last = -1;
	for (int i = 0; i < M; i++) {
		int a = bridge[i].second;
		int b = bridge[i].first;
		if (last >= a) continue;
		else {
			used[b - 1] = true;
			last = b - 1;
		}
	}

	int ret = 0;
	for (int i = 0; i < N - 1; i++) {
		if (used[i]) ret++;
	}

	cout << ret << endl;
}

Measured memory_bytes: 1024
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M = map(int, input().split())
S = sum(list(map(int, input().split())))

print(-1 if S > N else N - S)

Measured memory_bytes: 10384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n%k;
  ll ans = min(a, k-a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<unordered_map>

int main() {
	char c;
  	std::cin >> c;
    const std::unordered_map<char, char> table = {
      {'A', 'T'},
      {'C', 'G'},
      {'T', 'A'},
      {'G', 'C'}
    };
  
    std::cout << table.at(c) << std::endl;
	return 0;
}

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

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    if (N % (max(H, W)) == 0)
    {
        cout << N / max(H, W) << endl;
    }
    else
    {
        cout << (N / max(H, W)) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 11;
#define LL long long
LL X[N], Y[N], len[111];
int n, tot;
int nex[5] = {-1, 1, 0, 0};
int ney[5] = {0, 0, -1, 1};
char mp[5] = {'L', 'R', 'D', 'U'};
int main(){
	cin>>n;
	int flag = -1;
	for(int i = 1;i <= n; i++){
		cin>>X[i]>>Y[i];
		if(flag == -1)flag = (abs(X[i]) + abs(Y[i])) % 2;
		else if(flag != (abs(X[i]) + abs(Y[i])) % 2){
			puts("-1");
			return 0;
		}
	}
	if(!flag)
		len[++tot] = 1;
	for(int i = 1;i <= 31; i++)len[++tot] = 1 << (i - 1);
	sort(len + 1, len + 1 + tot, greater<LL>());
	printf("%d\n", tot);
	for(int i = 1;i <= tot; i++){
		printf("%lld ", len[i]);
	}
	puts("");
	for(int i = 1;i <= n; i++){
		LL nx = 0, ny = 0;
		for(int j = 1;j <= tot; j++){
			int pos = 0;
			LL mi = 5e9;
			for(int k = 0;k < 4; k++){
				LL tox = nx + nex[k] * len[j];
				LL toy = ny + ney[k] * len[j];
				if(abs(X[i] - tox) + abs(Y[i] - toy) < mi){
					mi = abs(X[i] - tox) + abs(Y[i] - toy);
					pos = k;
				}
			}
			printf("%c", mp[pos]);
			nx = nx + nex[pos] * len[j]; ny = ny + ney[pos] * len[j];
		}
		puts("");
//		printf("nx=%lld ny=%lld\n", nx, ny);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H,W,i,j;
    
    while (1) {
        scanf("%d %d",&H,&W);
        if (H==0&&W==0) {
            break;
        }
        for (i=1; i<=H; i++) {
            for (j=1; j<=W; j++) {
                if ((j+i)% 2==0) {
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main(){
  int a,f,r,p=0;
  while(1){
    scanf("%d%d%d",&a,&f,&r);
    if(a==-1 && f==-1 && r==-1)break;
    p=a+f;
    if(a==-1 || f==-1)printf("F\n");
    else if(80 <= p)printf("A\n");
    else if(65 <= p)printf("B\n");
    else if(50 <= p || 50 <= r )printf("C\n");
    else if(30 <= p)printf("D\n");
    else printf("F\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
int func(int x)
{
	int a = 0;
	while(x % 100 == 0){
		x /= 100;
		a++;
	}

	return a;
}
int main()
{
	int d, n, cnt = 0, num = 1;
	scanf("%d%d", &d, &n);

	while(cnt < n){
		if(func(num) == d){
			cnt++;
		}
		++num;
	}

	printf("%d\n", num - 1);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	int a[200010];
	long long int b[200010];
	int N = 2;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
	}
	long long int sum = 0;
	long long int m, n;
	for(int j=1;j<=N;j++)
	{
		sum = sum + a[j];
	}
	m = sum;
	n = sum;
	long long int x[200009], y[200009];
	for (int j = 1; j <= (N - 1); j++)
	{
		y[j] = sum - a[j];
		sum = sum - a[j];
	}
	for (int k = 1; k <= (N - 1); k++)
	{
		x[k] = m - y[k];
		m = n;
	}
	for (int n = 1; n <= (N - 1); n++)
	{
		b[n] = abs(x[n] - y[n]);
	}
	long long int min = b[1];
	for (int i = 2; i <= N - 1; i++)
	{
		if (min > b[i])
			min = b[i];
	}
	cout << min<<endl;
	return 0;
}

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

int main()
{
    int s;
    cin >> s;
    
    cout << s / 3600 << ':' << (s - ((s / 3600) * 3600)) / 60 << ':' << s - (((s / 3600) * 3600) + ((s - ((s / 3600) * 3600)) / 60) * 60) << endl;
}



Measured memory_bytes: 3096
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[5];
 int arr_2[5];
 
 int main()
 {
   int n;
   while(1)
   {
     cin>>n;
     if(n==0) break;
     else arr[0]=n;
     for(int i=1;i<5;i++) cin>>arr[i];
     int min=4;
     int max=0;
     for(int i=0;i<5;i++) arr_2[i]=arr[i];
     sort(arr_2,arr_2+5);
     int count=0;
     for(int i=0;i<4;i++)
     {
       if((arr_2[i+1]-arr_2[i])==1) count++;          
     }
     if(count==2)
     {
       int count2=5;
       while(count2--) cout<<"3"<<endl;          
     }
   else
   {
     for(int i=0;i<5;i++)
     {
       if(arr[i]>max) max=arr[i];
       if(arr[i]<min) min=arr[i];        
     }  
     if(min==1&&max==2)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==2&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==2) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==1&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"2"<<endl;
         else cout<<"1"<<endl;        
       }                  
     }
     else if(min==max)
     {
       int count3=5;
       while(count3--) cout<<"3"<<endl;     
     }
   }
   }
   //while(1);
   return 0;
 }

 
 

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

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

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

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;


long depths[100005];

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

  long n;
  cin >> n;

  vector<long> a(n);
  long mx = -INF;
  long mn = INF;
  rep(i, n) {
    cin >> a[i];
    mx = max(mx, a[i]);
    mn = min(mn, a[i]);
  }

  cout << 2*n-2 << endl; 
  if (abs(mx) >= abs(mn)) {
    int idx = -1;
    rep(i, n) {
      if (a[i] == mx) idx = i+1;
    }
    rep(i, n) {
      if (i+1 == idx) continue;
      cout << idx << " " << i+1 << endl;
    }
    rep(i, n-1) {
      cout << i+1 << " " << i+2 << endl;
    }
  } else {
    int idx = -1;
    rep(i, n) {
      if (a[i] == mn) idx = i+1;
    }
    rep(i, n) {
      if (i+1 == idx) continue;
      cout << idx << " " << i+1 << endl;
    }
    per(i, n-1) {
      cout << i+2 << " " << i+1 << endl;
    }
  }
}


Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(int)

N = int(input())
S = input()

x = 0
for i in range(N):
    if S[i] == 'I':
        x += 1
    else:
        x -= 1
    d[i] = x

ans = [0]
for k, v in d.items():
    ans.append(v)

print(max(ans))


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

int main(){
  int N;
  int j;
   int cnt;
  int result=100;
  cin >> N;
 vector<int> A(N) ;
  
  for ( int i=0 ; i < N ; i ++){
    cin >> A.at(i);
    j=2;
    cnt = 0;
    while( A.at(i) % j ==0){
      j *=2;
      cnt++;
     }   
  result = min(result, cnt);
  }
   cout << result << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;

int main()
{
    cin >> N >> M;
    vector<vector<int>> G(N);
    vector<vector<int>> d(N, vector<int>(3, 1e9));
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    int s, t;
    cin >> s >> t;
    s--, t--;
    queue<pair<int, int>> que;
    d[s][0] = 0;
    que.push(make_pair(s, 0));
    while (!que.empty())
    {
        auto p = que.front();
        int u = p.first, c = p.second;
        que.pop();
        for (auto &nv : G[u])
        {
            if (d[nv][(c + 1) % 3] > d[u][c] + 1)
            {
                d[nv][(c + 1) % 3] = d[u][c] + 1;
                que.push(make_pair(nv, (c + 1) % 3));
            }
        }
    }
    cout << (d[t][0] % 3 == 0 ? d[t][0] / 3 : -1) << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int  A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A==B&&A!=C||A==C&&A!=B||B==C&&B!=A)
        printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
    using namespace std;
    int main()
    {

        string S, T;
        cin >> S >> T;
        int count = 0;
        for(int i = 0; i < 3; i++){
            if(S[i] == T[i]) {
                count++;
            }
        }
        cout << count << endl;
        
        return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N,i;
    int p[51];
    int count = 0;

    scanf("%d",&N);
    for(i=0; i<N; i++){
        scanf("%d",&p[i]);
    }

    for(i=0; i<N; i++){
        if(p[i] != i+1){
            count++;
        }
    }

    if(count <=2){
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
#pragma comment(linker, "/STACK:128777216")
#pragma GCC optimize("fast-maths")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#include <complex>
using namespace std;

#define forx(_name, _from, _to, _value) for (int _name = _from; _name < _to; _name += _value)
#define rforx(_name, _from, _to, _value) for (int _name = _from; _name > _to; _name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST, _SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-6;
mt19937 rndm;

void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	string FILENAME = "\-_-/";
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	//freopen((FILENAME + ".in").c_str(), "rt", stdin);
	//freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}

const int maxn = 2e5 + 500;

bool used[maxn];
vector<int> mt[maxn];

int dfs(int v) {
	int res = 0;
	used[v] = 1;
	for (int i = 0; i < mt[v].size(); ++i) {
		int to = mt[v][i];
		if (!used[to])
			res += dfs(to);
	}
	return res + 1;
}

int main() {
	/* File On */
	start();
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		mt[u].emplace_back(v);
		mt[v].emplace_back(u);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (!used[i])
			ans = max(ans, dfs(i));
	}
	cout << ans;
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a; scanf("%d", &a);
	std::string s; cin >> s;

	if(a >= 3200) printf("%s\n", s.c_str());
	else printf("red\n");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
    M = B[N // 2]
    m = A[N // 2]
    print(M - m + 1)

else:
    M = (B[N // 2 - 1] + B[N // 2]) / 2
    m = (A[N // 2 - 1] + A[N // 2]) / 2
    print(int((M - m - 0.5) * 2 + 2))


Measured memory_bytes: 25560
#include<iostream>
#include<map>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		map<int,int> n;
		n[a]++,n[b]++;
		while(cin>>a>>b,a)n[a]++,n[b]++;
		if(n[1]&1==1&&n[2]&1==1){
			for(__typeof(n.begin()) i=n.begin();i!=n.end();i++)if(i->first>2&&i->second%2){
				cout<<"NG"<<endl; goto END;
			}
			cout<<"OK"<<endl;
		}else cout<<"NG"<<endl;
		END:;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=4e18+1;
const ll MOD=1e9+7;

ll L,R;
int main(){
    cin>>L>>R;
    if(R-L>=2019){
        cout<<0<<endl;
        return 0;
    }
    ll ans=INF;
    for(ll i=L;i<=R;i++){
        for(ll j=i+1;j<=R;j++){
            ans=min(i*j%2019,ans);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
 
using namespace std;
 

bool is1keta(vector<long long>& k){
    long long sum=0;
    for(auto i:k){
        sum += i;
    }
    return sum <= 1;
}


int main(){
    int M;
    cin >> M;
    long long keta=0LL;
    long long sum=0LL;
    for(int i=0;i<M;i++){
        long long d, c;
        cin >> d >> c;
        sum += d*c;
        keta += c;
    }
    printf("%lld\n", keta-1 + (sum-1)/9 );
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int colla(int x){
  if(x%2==0) return x/2;
  else return 3*x+1;}

int main() {
  int n;
  cin>>n;
  if(n==1||n==2||n==4) cout<<4<<endl;
else{
  int count=1;
  while(n!=1){
    n=colla(n);
    count++;
}
  cout<<count+1<<endl;
}
}


Measured memory_bytes: 256
n, k = gets.strip.split.map(&:to_i)
s = gets.strip.split('')

rl = s.inject([]) {|memo, c|
  if memo.last.nil?
    memo << [c]
  elsif memo.last.last == c
    memo.last << c
  else
    memo << [c]
  end
  memo
}

counted_rl = rl.map(&:length)

if counted_rl.length-1 < k*2
  p counted_rl.inject(:+)-1
  exit
end

#p rl
#p counted_rl

result = counted_rl.inject(:+) - counted_rl.length+k*2
p result




Measured memory_bytes: 12668
from collections import deque

n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for i in range(n)]
# print(ants)

ants_t = []
count = 0
for ant in ants:
    ant_t = ant
    if ant[1] == 1:
        c, ant_t[0] = divmod(t + ant[0], l)
        # count += c
    else:
        c, ant_t[0] = divmod(-t + ant[0], l)
        # count -= c
    ants_t.append(ant_t)
    count += c
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

# if ants_d[0][1] == 1:
#     ants_d.rotate(count)
# else:
#     ants_d.rotate(-count)
ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print( (ant[0]) % l )


Measured memory_bytes: 68696
def main():
  import sys
  buf=sys.stdin.buffer
  h,w=map(int,buf.readline().split())
  s=buf.readline()
  a=b=x=y=s[0]==35
  d=[b]
  e=[a]
  for i in range(1,w):
    f=s[i]==35
    b+=a^f
    a=f
    d+=b,
    e+=a,
  for s in buf.read().split():
    f=s[0]==35
    y+=x^f
    b=y
    a=x=f
    p=[b]
    q=[a]
    for i in range(1,w):
      f=s[i]==35
      b+=a^f
      c=d[i]+(f^e[i])
      if b>c:b=c
      a=f
      p+=b,
      q+=a,
    d=p
    e=q
  print(b+1>>1)
main()

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

int main()
{
  string S;
  cin >> S;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(vector<T> a){
    for (const auto& ai : a) cout << ai << " ";
    cout << endl;
}
vector<string> Yes = {"No", "Yes"};

int main(){
    LINT(n, K);
    lint k = K;
    vlint a(n); line(a);
    vlint route;
    for (auto&& p : a) p --;
    lint now, freq, flg, i;
    now = 0; freq = 0; flg = 0;
    set<int> t; t.insert(0);
    while (k > 0){
        now = a[now];
        k --;
        if (t.find(now) != t.end()){
            flg = 1;
            break;
        }
        t.insert(now);
    }
    if (flg){
        route.pb(now); i = now; now = a[now];
        while (now != i){
            route.pb(now); now = a[now];
        }
        freq = Size(route);
        if ((k+1)%freq == 0){
            cout << route.back() + 1 << endl;
        }
        else{
            cout << route[(k+1)%freq - 1] + 1 << endl;
        }
    }
    else{
        cout << now + 1 << endl;
    }
}


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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	string ansS;
	{
		int memo = 0;
		int minmemo = 0;
		for (int i = 0; i < S.size(); ++i) {
			if ('(' == S[i]) {
				memo++;
			}
			else {
				memo--;
			}
			minmemo = min(memo, minmemo);
		}
		for (int i = 0; i < (-1 * minmemo); ++i) {
			ansS += "(";
		}
		ansS += S;
	}
	{
		int memo = 0;
		for (int i = 0; i < ansS.size(); ++i) {
			if ('(' == ansS[i]) {
				memo++;
			}
			else {
				memo--;
			}
		}
		for (int i = 0; i < memo; ++i) {
			ansS += ")";
		}
	}
	cout << ansS << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()


int main(){
    string L;
    cin >> L;

    vll ms(L.length()+1, 0);
    ll n = 1;
    rep(i, L.length()+1){
        ms[i] = n;
        n = (n*3) % 1000000007;
    }

    function<ll(ll n)> f = [&](ll n){
        if(n>=L.length()) return 1ll;
        ll count = 0;
        if(L[n]=='1'){
            ll r = (ll)L.length() - n - 1;
            count += ms[r];
            count = (count + 2*f(n+1)) % 1000000007;
        }
        else{
            count = (count + f(n+1)) % 1000000007;
        }
        return count;
    };

    cout << f(0) << endl;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
    int n;
    cin >> n;
    vector<int> a(87);
    a[0] = 2;
    a[1] = 1;
    FOR(i,2,87){
        a[i] = a[i-1]+a[i-2];
    }
    cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int k,n;

int main(){
    cin >> k >> n;
    vector<int> a(n),b(n);

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

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

    int max = b[0];
    for(int i = 0; i < n-1; i++){
        if(b[i+1] > max) max = b[i+1];

    }

    cout << k - max << endl;
}

Measured memory_bytes: 1792
N,M,K=map(int,input().split())
a=[]
ans=-1
for _ in range(N):
    A=list(map(int,input().split()))
    a.append(A)
for i in range(2**N):
    skill=[0]*(M)
    flag=0
    money=0
    for j in range(N):
        if ((i>>j)&1):
            money+=a[j][0]
            for k in range(1,M+1):
                skill[k-1]+=a[j][k]
    for l in skill:
        if l<K:
            flag=1
            break
    if flag==0:
        if ans==-1:
            ans=money
        else:
            ans=min(money,ans)
print(ans)

Measured memory_bytes: 9236
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////


int main(){
    string s;
    
    int ans = 0,index = 1;
    cin >> s;

    while(s.size() > 2 && index < (int)s.size()-1){
        //cout << s << endl;
        if(s[index-1] != s[index+1]){
            s.erase(index,1);
            ans++;
            if(index > 1)index--;
        }else{
            index++;
        }
    }
    //cout << s << endl;
    if(ans%2 == 0)cout << "Second" << endl;
    else cout << "First" << endl;
    
	return 0;
}

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

int main() {
  int H,W,h,w;
  scanf("%d%d%d%d",&H,&W,&h,&w);
  int X=H*W;
  int Y=H*w+W*h-h*w;
 printf("%d",X-Y); 
}


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


const int INF = 1e10;


int main() {
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<int>> S(H);
	for (int i = 0; i < H; ++i) {
		string s;
		cin >> s;
		S[i] = vector<int>(W);
		for (int j = 0; j < W; ++j)
			S[i][j] = s[j] - '0';
	}

	int ans = INF;
	for (int hcut = 0; hcut < (1 << (H - 1)); ++hcut) {
		vector<int> hgrp(H);
		hgrp[0] = 0;
		for (int i = 0; i < (H - 1); ++i) {
			if ((hcut >> i) & 1) hgrp[i + 1] = hgrp[i] + 1;
			else hgrp[i + 1] = hgrp[i];
		}

		int G = hgrp[H - 1] + 1; // horizontal group size
		vector<vector<int>> S2(G);
		for (int i = 0; i < G; ++i)
			S2[i] = vector<int>(W);
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				S2[hgrp[i]][j] += S[i][j];

		bool cannot = false;
		for (int i = 0; i < G; ++i)
			for (int j = 0; j < W; ++j)
				cannot |= S2[i][j] > K;
		if (cannot) continue;

		vector<int> wc_cnt(G);
		int cut = G - 1;
		for (int i = 0; i < G; ++i) wc_cnt[i] = S2[i][0];
		for (int i = 1; i < W; ++i) {
			bool tobecut = false;
			for (int j = 0; j < G; ++j) {
				wc_cnt[j] += S2[j][i];
				if (wc_cnt[j] > K) tobecut = true;
			}

			if (tobecut) {
				++cut;
				for (int j = 0; j < G; ++j)
					wc_cnt[j] = S2[j][i];
			}
		}

		ans = min(ans, cut);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3152
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 = sc.nextInt();
        if (a + b + c >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }

}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n, m;

bool contaminated[MAX_N];
int bole_num[MAX_N];

int ans = 0;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  contaminated[1] = true;
  bole_num[1] = 1;

  for (int i = 2; i <= n; ++i) {
    contaminated[i] = false;
    bole_num[i] = 1;
  }

  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);

    int move_num = (bole_num[x] > 0) ? 1 : 0;

    if (contaminated[x]) {
      if (move_num == 1) {
        contaminated[y] = true;
        bole_num[x] -= move_num;
        bole_num[y] += move_num;
        if (bole_num[x] == 0) contaminated[x] = false;
      }
    }
    else {
      bole_num[x] -= move_num;
      bole_num[y] += move_num;
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (contaminated[i]) ans += 1;
  }

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

  return 0;
}


Measured memory_bytes: 768
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3943369
#include <bits/stdc++.h>
using namespace std;

const int MOD = (1e9 + 7);
int dp[3111][3111];
int T[3111][3111];

int add(int a, int b){
    a += b;
    while(a >= MOD) a -= MOD;
    return a;
}

// l ～ r番目 までの 総和
// @param l: 先頭要素の場所.
// @param r: 末尾要素の場所.
// @return : 総和を返却.
int sum(int i, int l, int r){
    l = max(l, 0);
    if(l > r)  return 0;
    if(l == 0) return T[i][r];
    else       return add(T[i][r], MOD - T[i][l - 1]);
}

int main(){
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    char C[3210];
    scanf("%s", C);
    string S(C);
    
    // 2. dp更新.
    dp[0][0] = 1;
    T[0][0] = 1;
    for(int i = 1; i < N; i++){
        char c = S[i - 1];
        for(int j = 0; j <= i ; j++){
            // choose j here
            if(c == '<') dp[i][j] = sum(i - 1, 0, j - 1);
            else         dp[i][j] = sum(i - 1, j, i - 1);
        }
        for(int j = 0; j <= i; j++){
            T[i][j] = dp[i][j];
            if(j > 0) T[i][j] = add(T[i][j], T[i][j - 1]);
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++) ans = add(ans, dp[N - 1][i]);
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 73216
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ans=1919810;
int main()
{
	cin>>s>>t;
	for(int i=0;i+t.size()<=s.size();i++)
	{
		int res=0;
		for(int l=0;l<t.size();l++)
			if(t[l]!=s[i+l])
				res++;
		ans=min(ans,res);
	}
	cout<<ans;
	return 0;
} 

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

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int in[MX];
vi adj[MX];
vi adj1[MX];
bool vis[MX];
int val[MX];
vi ans;
int cur=0,n,m;
void topsort(){
	for(int i=1;i<=n;i++){
			if(in[i]==0 and !vis[i]){
				ans.pb(i);
				vis[i]=true;
			}
	}
	while(ans.size()!=n){
		int i=ans[cur];
		cur++;
		for(auto it:adj[i]){
			in[it]--;
			if(in[it]==0 and !vis[it]){
				ans.pb(it);
				vis[it]=true;
			}
		}
	}
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj1[y].pb(x);
		in[y]++;
	}
	topsort();
	for(int i=0;i<ans.size();i++){
		for(auto it:adj1[ans[i]]){
			val[ans[i]]=max(1+val[it],val[ans[i]]);
		}
	}
	cout<<*max_element(val,val+MX);
}

Measured memory_bytes: 24568
#include <iostream>

using namespace std;

int main()
{
    int n, height, max = 0, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> height;
        if (max <= height)
        {
            max = height;
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 100000007
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define FOR(i,k,n) for(int i=k;i<n+k;i++)
#define ALL(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);
#define deg(x) cout<<"--"<<x<<endl;
int II(){int q;scanf("%d",&q);return q;}
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};
int dxx[]={0,-1,-1,-1,0,1,1,1};
int dyy[]={-1,-1,0,1,1,1,0,-1};
#define int ll
void solve(){
	int n;cin>>n;
	int ar[n+10];
	for(int i=1; i<=n; i++){
		int q;cin>>q;
		ar[i]=q-i;
	}
	sort(ar+1,ar+1+n);
	int arr[]={ar[(n+1)/2],ar[1],ar[n]};
	int mi=1e16;
	for(int i=0; i<3; i++){
		int to=0;
		for(int j=1; j<=n; j++){
			to+=abs(ar[j]-arr[i]);
		}
		mi=min(mi,to);
	}
	cout<<mi<<endl;
}
 
main(){
 	
    int tt=1;
    int cas=1;
    while(tt--){
        //printf("Case %d: ",cas++);
        solve();
    }
}

Measured memory_bytes: 1792
// luogu-judger-enable-o2
#include <cstdlib>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
#define mem(a,b) memset(a,b,sizeof(a))
#define  INF 0x3f3f3f3f
//__builtin_popcount
using namespace std;
//priority_queue
const ll MAX=100000;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}

ll F[100003];
ll Find(ll a)
{
    return F[a]<0?a:F[a]=Find(F[a]);
}
ll same(ll a,ll b)
{
    if(Find(a)==Find(b))return 1;
    return 0;
}
void up(ll a,ll b)
{
    ll x,y;
    x=Find(a);
    y=Find(b);//cout<<F[x]<<" "<<F[y]<<endl;
    if(x!=y)
        F[y]+=F[x],F[x]=y;


}
int a[100003],b[200003];
set<int>q;
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
   scanf("%d",&a[i]);
   int sum=0;
 for(int i=1;i<=n;i++)
 {
      if(sum==0)
      {
          b[sum++]=-a[i];
      }
      else {

        int z=upper_bound(b,b+sum,-a[i])-b;
        if(z!=sum)
        {
            b[z]=-a[i];
        }
        else {
            b[sum++]=-a[i];
        }
      }
 }
  cout<<sum;
}



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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

bool noElm(const vector<vector<pair<int, int>>> &v) {
  for(int i=0;i<(int)(v.size());++i) {
    if((int)(v[i].size()) > 0) {
      return false;
    }
  }
  return true;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, l; cin >> n >> l;
    if(n == 0 && l == 0) break;
    vector<vector<pair<int, int>>> v(l+1);
    for(int i=1;i<=n;++i) {
      char d; int p; cin >> d >> p;
      if(d == 'R') {
        v[p].push_back(make_pair(i, 1));
      } else {
        v[p].push_back(make_pair(i, -1));
      }
    }

    int ex = -1;
    int cnt = 0;
    while(!noElm(v)) {
      cnt++;
      vector<vector<pair<int, int>>> newv(l+1);
      bool nowex = false;
      for(int i=1;i<l;++i) {
        if((int)(v[i].size()) == 2) {
          v[i][0].second = -v[i][0].second;
          v[i][1].second = -v[i][1].second;
          newv[i+v[i][0].second].push_back(v[i][0]);
          newv[i+v[i][1].second].push_back(v[i][1]);
        } else if((int)(v[i].size()) == 1) {
          newv[i+v[i][0].second].push_back(v[i][0]);
        }
        if(i == 1 && (int)(newv[0].size() == 1)) {
          ex = newv[0][0].first;
          nowex = true;
        } else if(!nowex && i == l-1 && (int)(newv[l].size()) == 1) {
          ex = newv[l][0].first;
        }
      }
      copy(newv.begin(), newv.end(), v.begin());

/*       for(int i=0;i<(int)(v.size());++i) {
        for(int j=0;j<(int)(v[i].size());++j) {
          cout << v[i][j].first << " ";
        }
        cout << endl;
      } */
    }
    cout << cnt-1 << " " << ex << endl;
  }
}



Measured memory_bytes: 3088
n = int(input())

F = []
P = []
for i in range(n):
  f = int(input().replace(" ", ""), 2)#2進数で保持
  F.append(f)
  
for i in range(n):
  p = list(map(int,input().split()))
  P.append(p)
  
ans = -10 ** (7+2)

for i in range(1, 2**10):
  total_income = 0
  for j, income in enumerate(P):
    num = bin(i & F[j]).count("1")
    total_income += income[num]

  ans = max(ans,total_income)

  
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
#include <set>
#include <iomanip>


using namespace std;
typedef long double ld;
typedef long long ll;
const int MAX = 60;
typedef complex<long double> Point;


namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
    }
}

struct Circle {
    Point c;
    ld r;

    vector<Point> cross(const Circle &other) {
        vector<Point> ret;
        ld dist = abs(c - other.c);
        ld rc = (dist * dist + r * r - other.r * other.r) / (2 * dist);
        ld dfr = r * r - rc * rc;
        if (abs(dfr) < 1e-6) dfr = 0.0;
        if (dfr < 0.0) {
            return ret;
        }
        ld rs = sqrt(dfr);
        Point diff = (other.c - c) / dist;
        ret.push_back(c + diff * Point{rc, rs});
        if (dfr != 0.0) {
            ret.push_back(c + diff * Point{rc, -rs});
        }
        return ret;
    }
};

const ld eps = 1e-9;
int n, k;
Circle m[MAX + 1];
int c[MAX + 1];


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n >> k;

    set<Point> centers;
    for (int i = 0; i < n; ++i) {
        ld xc, yc;
        cin >> xc >> yc >> c[i];
        m[i] = {Point{xc, yc}};
        centers.insert(m[i].c);
    }

    ld hi = 1e6;
    ld lo = 0;
    for (int ii = 0; ii < 100; ++ii) {
        ld t = lo + (hi - lo) / 2;
        set<Point> candidate(centers);

        for (int i = 0; i < n; ++i) {
            m[i].r = (ld) t / (ld) c[i];
            for (int j = 0; j < n; ++j) {
                if (i == j) continue;
                m[j].r = (ld) t / (ld) c[j];
                auto ret = m[i].cross(m[j]);
                for (auto pt : ret) {
                    candidate.insert(pt);
                }
            }
        }

        int mc = 0;
        for (auto pt : candidate) {
            int count = 0;
            for (int i = 0; i < n; ++i) {
                ld diff = abs(m[i].c - pt);
                if (diff < m[i].r + eps) {
                    ++count;
                }
            }
            mc = max(mc, count);
        }

        if (mc < k) {
            lo = t + eps;
        } else {
            hi = t;
        }
    }

    cout << lo;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()
#define clr(a,v) memset((a),(v),sizeof(a))

constexpr int MAX_N = 5000;

int N, K;
int a[MAX_N];
bool dp[MAX_N+10][5010];
int ans;

bool C( int idx )
{
  clr( dp, false );

  dp[0][0] = true;
  rep( i, N ) rep( k, K+1 )
  {
    dp[i+1][k] |= dp[i][k];

    if( k-a[i] >= 0 && i != idx )
      dp[i+1][k] |= dp[i][k-a[i]];
  }

  for( int k = std::max( K-a[idx], 0 ); k < K; ++k ) if( dp[N][k] )
    return true;

  return false;
}

int main()
{
  scanf( "%d%d", &N, &K );
  rep( i, N )
    scanf( "%d", a+i ), a[i] = std::min( a[i], K );

  ans = N;

  std::sort( a, a+N );

  int lb = -1, ub = N;
  while( ub-lb > 1 )
  {
    int mid = (lb+ub)/2;

    if( C(mid) )
      ub = mid;
    else
      lb = mid;
  }

  printf( "%d\n", lb+1 );

  return 0;
}

Measured memory_bytes: 24704
/* abc067-A.c  
gcc abc067-A.c -o abc067-A */

#include <stdio.h>

int main(){

	int A, B;
	int wa;

	scanf("%d%d", &A, &B);
	wa = A+B;
	if (A%3==0 || B%3==0 || wa%3==0){
		printf("Possible");
	}
	else 
		printf("Impossible");

return 0;
}



Measured memory_bytes: 128
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	long D, ans;
	long[] pow = new long[20];
	void Solve()
	{
		D = F();
		pow[0] = 1;
		for (var i = 1; i < 20; i++) pow[i] = pow[i - 1] * 10;
		WriteLine(Calc(D));
	}
	long Calc(long D)
	{
		if (D % 9 != 0) return 0;
		D /= 9;
		ans = 0;
		for (var n = 1; n <= 18; n++) DFS(new int[n / 2], n, D, 0);
		return ans;
	}
	void DFS(int[] a, int n, long d, int i)
	{
		if (i == n / 2)
		{
			if (d != 0) return;
			var p = a[0] >= 0 ? 9L - a[0] : 10 + a[0];
			for (var j = 1; j < n / 2; j++) p *= 10 - Abs(a[j]);
			ans += (n % 2 == 0 ? 1 : 10) * p;
		}
		else
		{
			var c = (pow[n - i - 1] - pow[i]) / 9;
			var t = d / c;
			if (d < 0 && d % c != 0) t++;
			foreach (var z in new HashSet<long> { t, t + 1, t - 1, 9, -9, t + 2, t - 2 })
				if (-9 <= z && z <= 9)
				{
					a[i] = (int)z;
					DFS(a, n, d - z * c, i + 1);
				}
		}
	}
}

Measured memory_bytes: 17488
N = int(input())
wd = []
for i in range(1, 7):
    wd.append(6**i)
for i in range(1, 6):
    wd.append(9**i)
wd.append(1)

dp = [N]*(N+1)
dp[0] = 0

for i in wd:
    for j in range(i, N+1):
        dp[j] = min(dp[j], dp[j-i]+1)

print(dp[N])

Measured memory_bytes: 4276
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int main(){

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;
cout << n*n;
    return 0;

}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0
for a in range(0,A+1):
  for b in range(0,B+1):
    for c in range(0,C+1):
      n=0
      n+=500*a+100*b+50*c
      if X==n:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll x, k, d; cin >> x >> k >> d;
    
    ll res = x % d;
    
    if(abs(x - res) / d <= k){
        k -= abs(x - res) / d;
        
    	if(k % 2 == 0){
    		print(abs(res))
    	}else{
            print(abs(d - abs(res)));
    	}

    	return 0;
    }
    
    print(min(abs(x + k * d), abs(x - k * d)))
    
    return 0;
}

Measured memory_bytes: 3664