akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static class Combination {

        long[] factorial;
        int maxN;
        long Module;

        public Combination(final int maxN, final long Module) {
            this.maxN = maxN;
            factorial = new long[maxN];
            this.Module = Module;
        }

        public void init() {
            factorial[0] = 1;
            factorial[1] = 1;
            for (int i = 2; i < maxN; ++i) {
                factorial[i] = ((factorial[i - 1] % Module) * (i % Module)) % Module;
            }
        }

        // find x[0] and y[0] such that a * x[0] + b * y[0] = 1, return gcd(a, b)
        long extgcd(long a, long b, long[] x, long[] y) {
            long d = a;
            if (b != 0) {
                d = extgcd(b, a % b, y, x);
                y[0] -= (a / b) * x[0];
            } else {
                x[0] = 1;
                y[0] = 0;
            }
            return d;
        }

        /**
         * to find (1 / a) mod m
         * that is, find x, such that a * x = 1 (mod m)
         * that is, { a * x - 1 = k * m}
         * that is, find x and k, such that a * x + k * m = 1. We can use extgcd algorithm
         */
        long inverseModule(long a, long m) {
            long[] x = new long[1];
            long[] y = new long[1];
            extgcd(a, m, x, y);
            return (m + x[0] % m) % m;
        }

        /**
         * find fetch n kinds from m kinds, mod k.
         * nCm = n! / (m! * (n - m)!)
         * nCm mod k = (n! (mod k) * (1 / (m!)) mod k * (1 / ((n - m)!)) mod k) mod k
         */
        long nCm(int n, int m, long k) {
            if (n < 0 || m < 0 || n < m) {
                return 0;
            }
            return (factorial[n] % k * inverseModule(factorial[m], k) % k
                    * inverseModule(factorial[n - m], k) % k) % k;
        }
    }

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

        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int maxN = 200005;
        long Module = 1000000007;

        Combination combination = new Combination(maxN, Module);
        combination.init();
        long result = 0;

        for (int j = b + 1; j <= w; ++j) {
            result +=
                    (combination.nCm(h - a - 1 + j - 1, j - 1, Module) % Module)
            * (combination.nCm(a - 1 + w - 1 - (j - 1), a - 1, Module) % Module);
            result %= Module;

        }
        System.out.println(result);

    }
}


Measured memory_bytes: 40020
#include <iostream>

using namespace std;

typedef long long ll;

bool query (ll n) {
  cout << "? " << n << endl;

  char ans;
  cin >> ans;
  return (ans == 'Y');
}

void report (ll n) {
  cout << "! " << n << endl;
  exit(0);
}

void solve_powers () {
  ll cur = 9;
  while (true) {
    if (query(cur)) {
      report((cur + 1) / 10);
    } else {
      cur = (cur + 1) * 10 - 1;
    }
  }
}

void solve_others () {
  ll cur = 10;
  ll l, r;
  while (true) {
    if (!query(cur)) {
      l = cur / 10;
      r = cur - 1;
      break;
    } else {
      cur *= 10;
    }
  }
  
  for (ll k = 1LL << 32; k != 0; k /= 2) {
    if (l + k <= r && !query(10LL * (l + k))) {
      l += k;
    }
  }

  report(l + 1);
}

int main () {
  if (query(10000000001LL)) {
    solve_powers();
  } else {
    solve_others();
  }
}


Measured memory_bytes: 596
#include <stdio.h>

int isprime(int n){
    for(int i=2; i*i<=n; i++){
        if(n%i==0)
        return 0;
    }
    return 1;
}


int main(){
    int num;
    while(1){
        scanf("%d", &num);
        if(num==0)break;
        for(int i=num; i>2; i--){
            if(isprime(i)==1)
                if(isprime(i-2)==1){
                    printf("%d %d\n", i-2, i);
                    break;
                }
        }
    }
    return 0;
}

Measured memory_bytes: 2628
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

// void __print(int x) {cerr << x;}
// void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
// void __print(unsigned x) {cerr << x;}
// void __print(unsigned long x) {cerr << x;}
// void __print(unsigned long long x) {cerr << x;}
// void __print(float x) {cerr << x;}
// void __print(double x) {cerr << x;}
// void __print(long double x) {cerr << x;}
// void __print(char x) {cerr << '' << x << '';}
// void __print(const char *x) {cerr << '"' << x << '"';}
// void __print(const string &x) {cerr << '"' << x << '"';}
// void __print(bool x) {cerr << (x ? "true" : "false");}

// template<typename T, typename V>
// void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
// template<typename T>
// void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
// void _print() {cerr << "]\n";}
// template <typename T, typename... V>
// void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
// #ifndef ONLINE_JUDGE
// #define debug(x...) cerr << "[" << #x << /"] = ["; _print(x)
// #else
// #define debug(x...)
// #endif

ll power(ll a,ll b)
{
    if(b==0) return 1;
    ll temp = MOD(power(a,b/2),mod);
    if(b&1)
    {
        return MOD((MOD((temp*temp),mod)*a),mod);
    }
    else
    {
        return MOD((temp*temp),mod);
    }
    
}

int main()
{
    //fastio
    ll n;
    sfl(n);
    ll nfact=1;
    if(n<2)
    {
        cout<<0;
        return 0;
    }
    ll i=2;
    ll ans = 0;
    ans = MOD(power(10,n),mod);
    ans = MOD((ans+power(8,n)),mod);
    ans = MOD((ans - power(9,n)),mod);
    ans = MOD((ans - power(9,n)),mod);
    
    cout<<ans<<endl;

}

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

typedef long long LL;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

set <char> S;

int main()
{
    //ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin>>s;

    for(int i = 0; i < s.size(); i++)
        S.insert(s[i]);

    for(char c = 'a'; c <= 'z'; c++)
    {
        if(S.find(c) == S.end())
        {
            cout<<c<<"\n";
            return 0;
        }
    }

    cout<<"None\n";
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX=301;
vector<int> prime;
bool isprime[MAX];
void sieve(){
	for(int i=3; i<MAX; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(int i=3; i<MAX; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(int j=2*i; j<MAX; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}
int x[303];
int main()
{
	int q;
	cin>>q;
	for(int i=0; i<q; i++){
		int m, xi; cin>>m>>xi;
		x[m]=xi;
	}
	vector<vector<int>> vx[303];
	sieve();
	for(int i=2; i<=300; i++){
		vector<int> v(prime.size());
		int x=i;
		int k=0;
		for(int j=0; j<prime.size(); j++){
			while(x%prime[j]==0){
				x/=prime[j];
				v[j]++;
				k=max(k, j);
			}
		}
		v.push_back(i);
		vx[k].push_back(v);
	}
	map<vector<int>, int> mp;
	vector<int> v0(1);
	int s0=0;
	for(int i=0; i<9; i++){
		s0+=x[1<<i];
		mp[v0]=s0;
		v0[0]++;
	}
	for(int i=0; i<prime.size()-1; i++){
		int q=prime[i+1];
		map<vector<int>, int> tmp;
		for(auto p:mp){
			vector<int> v=p.first;
			for(int j=0; j<=i; j++){
				int x1=1;
				for(int k=0; k<v[j]; k++){
					x1*=prime[j];
					if(x1>300/q){
						v[j]=k;
						break;
					}
				}
			}
			int x1=1;
			v.push_back(0);
			for(int j=0; j<10; j++){
				int s=0;
				for(auto w:vx[i+1]){
					bool dame=0;
					for(int k=0; k<=i+1; k++){
						if(w[k]>v[k]){
							dame=1;
							break;
						}
					}
					if(!dame){
						s+=x[w.back()];
					}
				}
				if(tmp.find(v)==tmp.end()) tmp[v]=p.second+s;
				else tmp[v]=max(tmp[v], p.second+s);
				v.back()++;
				x1*=q;
				if(x1>300) break;
			}
		}
		swap(mp, tmp);
		//cout<<prime[i]<<" "<<mp.size()<<endl;
	}
	int ans=0;
	for(auto p:mp){
		ans=max(ans, p.second);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

struct Bar{
  int x;
  int y;
};

int main(){
  int total_vertical_bars;
  int total_horizontal_bars;
  int max_height;
  int total_selected_bars;
  while(~scanf("%d %d %d %d",
	       &total_vertical_bars,
	       &total_horizontal_bars,
	       &max_height,
	       &total_selected_bars)){
    if(total_vertical_bars == 0
       && total_horizontal_bars == 0
       && max_height == 0
       && total_selected_bars == 0) break;

    int sum = 0;
    int points[1001];
    memset(points,0,sizeof(points));
    for(int i=0;i<total_vertical_bars;i++){
      scanf("%d",points + i);
    }
    vector<int> bars[1001];
    memset(bars,0,sizeof(bars));
    for(int i=0;i<total_horizontal_bars;i++){
      int x,y;
      scanf("%d %d",&x,&y);
      bars[y-1].push_back(x-1);
    }

    int matrix[1001];
    for(int i=0;i<total_vertical_bars;i++) matrix[i] = i;

    vector<P> change;
    vector<P> log;

    int max_idx = 0;
    for(int height=0,idx=0;height < max_height;height++){
      for(int i=0;i<bars[height].size();i++,idx++){
	int x = bars[height][i];
	change.push_back(P(matrix[x],matrix[x+1]));
	swap(matrix[x],matrix[x+1]);
	max_idx = max(max_idx,idx);
      }
    }


    for(int height=max_height-1,idx=max_idx;height >= 0;height--){
      for(int i=bars[height].size()-1;i >= 0;i--,idx--){
	int x = bars[height][i];
	log.push_back(P(points[x],points[x+1]));
	swap(points[x],points[x+1]);
      }
    }

    reverse(log.begin(),log.end());

    int res = 0;
    for(int i=0;i<total_selected_bars;i++){
      res += points[i];
    }

    int base = res;
    int idx = 0;
    for(int height=0;height < max_height;height++){
      for(int i=0;i<bars[height].size();i++){
	if(change[idx].first >= total_selected_bars
	   && change[idx].second < total_selected_bars){
	  res = min(res,
		    base
		    - log[idx].first
		    + log[idx].second);
	}
	
	if(change[idx].first < total_selected_bars
	   && change[idx].second >= total_selected_bars){
	  res = min(res,
		    base
		    + log[idx].first
		    - log[idx].second);
	}
	idx++;
      }
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> G(3*N);
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v; u--, v--;
        G[0*N+u].push_back(1*N+v);
        G[1*N+u].push_back(2*N+v);
        G[2*N+u].push_back(0*N+v);
    }
    int S, T; cin >> S >> T; S--, T--;
    queue<pair<int, int>> Q;
    Q.emplace(0, S);
    vector<bool> visited(3*N);
    while (!Q.empty()) {
        int d, i; tie(d, i) = Q.front(); Q.pop();
        if (visited[i]) continue;
        visited[i] = true;
        if (i == T) {
            cout << d / 3 << endl;
            return 0;
        }
        for (int next : G[i]) {
            if (!visited[next]) {
                Q.emplace(d+1, next);
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int n, a[114514];
vector<int> b;
int main(void){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if (i==0 || a[i-1] != a[i]) b.push_back(a[i]);
  }
  int ans = 1;
  for(int i=1;i+1<b.size();i++){
    if (b[i-1] > b[i] && b[i] < b[i+1]) {ans++; i++;}
    else if (b[i-1] < b[i] && b[i] > b[i+1]) {ans++; i++;}
  }
  cout << ans << endl;
  return 0;
  
}


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

const int mxN=15,mxM=1e3+10,mK=5e3+10,INF=1e8+10;
int n,m,k,x;
int total;
pair<int,int>v[mxM];
int dp[mxM][mK];

int solve(int index,int val){
    if(index==m && val!=total)return INF;
    if(val==total)return 0;
    if(dp[index][val]!=-1)return dp[index][val];
    return dp[index][val]=min(solve(index+1,val),solve(index+1,val|v[index].second)+v[index].first);
}
int32_t main(){
    memset(dp,-1,sizeof(dp));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    total=pow(2,n)-1;
    for(int i=0;i<m;i++){
        cin>>v[i].first>>k;
        v[i].second=0;
        for(int j=0;j<k;j++){
            cin>>x;
            v[i].second|=(1<<x-1);
        }

    }
    sort(v,v+m);
    int resp=solve(0,0);
    (resp==INF)?cout<<-1:cout<<resp;

}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 3, 0);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	int res = 0;
	for (int i = 2; i < n; i++)
	{
		if ((a[i] >= a[i - 1] && a[i] <= a[i + 1]) || (a[i] <= a[i - 1] && a[i] >= a[i + 1]))
		{
			res++;
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
static int N=100;
int main(){
  int i,p[N+1],m[N+1][N+1],n,j,k,l;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
for(i=1;i<=n;i++){
    m[i][i]=0;
  }
   for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=l+i-1;
      m[i][j]=2097152;
      for(k=i;k<j;k++){
	if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2100
n = int(input())
count_taro = 0
count_hanako = 0
for i in range(n):
  taro,hanako = map(str, input().split())
  if taro > hanako:
    count_taro += 3
  if hanako > taro:
    count_hanako += 3
  if hanako == taro:
    count_hanako += 1
    count_taro += 1
print(count_taro, count_hanako)


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

const int N = 2e5 + 10, MOD = 2019;
int cnt[N];

int main() {
	string s;
	cin >> s;
	int res = 0, t = 1, num = 0;
	cnt[0] = 1;
	for(int i = s.size() - 1; ~i; --i) {
		num = (num + (s[i] - '0') * t) % MOD;
		res += cnt[num];
		cnt[num]++;
		t = t * 10 % MOD;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3848
s = input()

flag = True
for i, si in enumerate(s):
    if (i+1) % 2 == 1:
        if not si in ["R", "U", "D"]:
            flag = False
            break
    else:
        if not si in ["L", "U", "D"]:
            flag = False
            break
        
if flag:
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3060
n = int(input())
al = list(map(int, input().split()))
s = sum(al)

cnt = 0
i = 0
while cnt < s/2:
    cnt += al[i]
    i += 1

s1 = sum(al[0:i])-sum(al[i:])
s2 = sum(al[0:i-1]) - sum(al[i-1:])

if s1 < 0:
    s1 = -s1
if s2 < 0:
    s2 = -s2
print(min(s1, s2))

Measured memory_bytes: 31744
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <random>
#include <chrono>
using namespace std;

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

	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[i] && b[i] == c[i])
		{
			continue;
		}
		else if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i])
		{
			ans++;
		}
		else
		{
			ans += 2;
		}
	}
	cout << ans << "\n";

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static int C(char a) {
		if(a=='#') {
		return 1;
		}
		else {
			return 0;
		}
	}
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		String c[]=new String[a];
		String d[][]=new String[a+1][b+1];
		for(int i=0;i!=a;i++) {
			c[i]=scan.next();
		}
		for(int i=0;i!=a;i++) {
			for(int j=0;j!=b;j++) {
				int count=0;
				if(c[i].charAt(j)=='#') {
					d[i][j]="#";
					continue;
				}
				else {
					if(j==0&&i==0) {
						if(b!=1) {
							count+=C(c[i].charAt(j+1));
							if(a!=1) {
								count+=C(c[i+1].charAt(j));
								count+=C(c[i+1].charAt(j+1));	
							}
							}
						else {
							if(a!=1) {
								count+=C(c[i+1].charAt(j));
							}
						}
					}
					else if(j==b-1&&i==a-1){
						if(a!=1) {
							if(b!=1){
								count+=C(c[i].charAt(j-1));
							}
							count+=C(c[i-1].charAt(j));
							count+=C(c[i-1].charAt(j-1));
						}
					}
					else if(j==0&&i==a-1) {
						if(b!=1) {
							count+=C(c[i-1].charAt(j+1));
							count+=C(c[i].charAt(j+1));
						}
						count+=C(c[i-1].charAt(j));
					}
					else if(j==b-1&&i==0){
						if(a!=1) {
							count+=C(c[i+1].charAt(j));
							count+=C(c[i+1].charAt(j-1));
						}
						count+=C(c[i].charAt(j-1));
					}
				else if(j==0) {
					if(b!=1) {
						count+=C(c[i+1].charAt(j+1));
						count+=C(c[i].charAt(j+1));
						count+=C(c[i-1].charAt(j+1));
						}
					count+=C(c[i+1].charAt(j));
					count+=C(c[i-1].charAt(j));
				}
				else if(i==0) {
					if(a!=1) {
						count+=C(c[i+1].charAt(j+1));
						count+=C(c[i+1].charAt(j));
						count+=C(c[i+1].charAt(j-1));
					}
					count+=C(c[i].charAt(j+1));
					count+=C(c[i].charAt(j-1));
				}
				else if(j==b-1) {
					count+=C(c[i].charAt(j-1));
					count+=C(c[i-1].charAt(j));
					count+=C(c[i-1].charAt(j-1));
					count+=C(c[i+1].charAt(j));
					count+=C(c[i+1].charAt(j-1));
				}
				else if(i==a-1) {
					count+=C(c[i].charAt(j-1));
					count+=C(c[i].charAt(j+1));
					count+=C(c[i-1].charAt(j-1));
					count+=C(c[i-1].charAt(j));
					count+=C(c[i-1].charAt(j+1));
				}
				else {
					count+=C(c[i].charAt(j-1));
					count+=C(c[i].charAt(j+1));
					count+=C(c[i+1].charAt(j-1));
					count+=C(c[i+1].charAt(j));
					count+=C(c[i+1].charAt(j+1));
					count+=C(c[i-1].charAt(j-1));
					count+=C(c[i-1].charAt(j));
					count+=C(c[i-1].charAt(j+1));
				}
					d[i][j]=String.valueOf(count);
				}
			}
		}
		for(int i=0;i!=a;i++) {
			for(int j=0;j!=b;j++) {
			System.out.print(d[i][j]);	
			}
			System.out.println();
			}
	}
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e16+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h,w;
	cin >> h >> w;
	FOR(i,0,w+2)cout<<'#';
	cout<<endl;
	FOR(i,0,h){
		cout<<'#';
		string s;
		cin>>s;
		cout<<s;
		cout<<'#'<<endl;
	}
	FOR(i,0,w+2)cout<<'#';
}	

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


int main(){
    LL a,b,c,k;cin >> a >> b >> c >> k;
    LL mx = 0;
    if(k <= a + b) mx = min(a,k);
    else mx = a - (k - (a + b));
    cout << mx << endl;
    return 0;
}



Measured memory_bytes: 3532
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve(l1, r1, l2, r2):
    if r1 < l2 or r2 < l1:
        return None
    elif l1 < l2 and r1 < r2:
        return [l2, r1]
    elif l1 >= l2 and r1 <= r2:
        return [l1, r1]
    elif l1 <= l2 and r2 <= r1:
        return [l2, r2]
    else:
        return [l1, r2]


def main():
    n, m = map(int, input().split())
    ans = [1, n]
    for _ in range(m):
        l, r = map(int, input().split())
        # print(l, r)
        ans = solve(ans[0], ans[1], l, r)
        # print(ans)
        if ans is None:
            print(0)
            exit(0)
    print(ans[1] - ans[0] + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N, M; 
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(3*N);
  REP(i, M){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v+N, 1);
    graph[u+N].emplace_back(v+2*N, 1);
    graph[u+2*N].emplace_back(v, 1);
  }

  int s, t;
  cin >> s >> t;
  s--; t--;

  vector<int> dist = dijkstra(s, 3*N, graph);
  if(dist[t] == INF) dist[t] = -3;

  cout << dist[t]/3 << endl;

  return 0;
}

Measured memory_bytes: 35456
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 2e5 + 123;
int n, a[N], b[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    set <pii> st;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        st.insert({b[i], i});
    }
    b[0] = b[n], b[n + 1] = b[1];
    ll ans = 0;
    while (!st.empty()) {
        pii v = *(--st.end());
        st.erase(--st.end());
        int val = v.fi, ind = v.se;
        if (val > a[ind]) {
            if (val <= b[ind - 1] + b[ind + 1]) {
                cout << -1;
                return 0;
            }
            int dif = val - a[ind];
            if (dif % (b[ind - 1] + b[ind + 1]) == 0) {
                ans += dif / (b[ind - 1] + b[ind + 1]);
                val = a[ind];
            }   else {
                ans += val / (b[ind - 1] + b[ind + 1]);
                val %= b[ind - 1] + b[ind + 1];
                st.insert({val, ind});
            }
            if (val < a[ind]) {
                cout << -1;
                return 0;
            }
            b[ind] = val;
            if (ind == n) {
                b[0] = val;
            }
            if (ind == 1) {
                b[n + 1] = val;
            }
        }
    }
    cout << ans;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const ll INF = 2e18;
const ll BORD = 1e9;

int q;
ll n, a, b, c, d;

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

    cin >> q;
    while (q--){
        cin >> n >> a >> b >> c >> d;
        map<ll, ll> dp;
        map<ll, bool> vis;

        dp[n] = 0;
        priority_queue<ll> pq;
        pq.push(n);
        while (!pq.empty()){
            auto temp = pq.top();
            pq.pop();
            if (vis[temp]) continue;
            vis[temp] = 1;

            ll dpcur = dp[temp];
            for (ll mar=-4;mar<=4;mar++){
                ll tam = abs(mar) * d;
                ll ncur = mar + temp;
                if (ncur < 0) continue;
                if (ncur == 0){
                    if (dp[ncur] == 0) dp[ncur] = dp[temp] + tam;
                    else dp[ncur] = min(dp[ncur], dp[temp] + tam);
                    continue;
                }
                if (ncur % 2 == 0){
                    ll sim = dp[ncur / 2];
                    if (sim != 0) dp[ncur / 2] = min(sim, dp[temp] + tam + a);
                    else dp[ncur / 2] = dp[temp] + tam + a;
                    pq.push(ncur / 2);
                }
                if (ncur % 3 == 0){
                    ll sim = dp[ncur / 3];
                    if (sim != 0) dp[ncur / 3] = min(sim, dp[temp] + tam + b);
                    else dp[ncur / 3] = dp[temp] + tam + b;
                    pq.push(ncur / 3);
                }
                if (ncur % 5 == 0){
                    ll sim = dp[ncur / 5];
                    if (sim != 0) dp[ncur / 5] = min(sim, dp[temp] + tam + c);
                    else dp[ncur / 5] = dp[temp] + tam + c;
                    pq.push(ncur / 5);
                }
            }
        }
        ll ans = INF;
        for (auto x : dp){
            if (x.fi >= INF / d) continue;
            ans = min(ans, x.se + x.fi * d);
        }
        cout << ans << el;
    }

    return 0;
}

Measured memory_bytes: 9656
#include <bits/stdc++.h>
#define MAXN 200000+5
using namespace std;

int n, ans;
pair <int, int> x, y, k;
int num[MAXN];
int a[MAXN], b[MAXN];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> num[i];
		if (i % 2) a[num[i]]++;
		else b[num[i]]++;
	}
	for (int i = 1; i <= MAXN; i++) {
		if (a[i] > x.second) {
			x.second = a[i];
			x.first = i;
		}
		if (b[i] > y.second) {
			y.second = b[i];
			y.first = i;
		}
	}
	ans = n;
	if (x.first == y.first) {
		b[y.first] = -1;
		for (int i = 1; i <= MAXN; i++) {
			if (b[i] > k.second) {
				k.second = b[i];
				k.first = i;
			}
		}
		ans = min(ans, n - k.second - x.second);
		k.second = a[x.first] = -1;
		for (int i = 1; i <= MAXN; i++) {
			if (a[i] > k.second) {
				k.second = a[i];
				k.first = i;
			}
		}
		ans = min(ans, n - k.second - y.second);
		cout << ans << endl;
		return 0;
	}
	ans = n - x.second - y.second;
	cout << ans << endl;
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  
  int x=0;
  
  while(n)
  {
      int temp = n%10;
      
      if(temp==7)
      {
          x=1;
          break;
      }
      
      n=n/10;
  }
  
  if(x==1)
  cout<<"Yes";
  else
  cout<<"No";
}

Measured memory_bytes: 3632
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let a: u32 = read();
    let b: u32 = read();

    println!("{}", 6 - a - b);
}


Measured memory_bytes: 4352
n = gets.to_i
nums = gets.split.map(&:to_i)
multiple_of_4 = 0
multiple_of_2 = 0
nums.each do |num|
  if num % 4 == 0
    multiple_of_4 += 1
  elsif num % 2 == 0
    multiple_of_2 += 1
  end
end
possible = multiple_of_4 * 2 + multiple_of_2
possible += 1 if multiple_of_2 == 0

puts n <= possible ? "Yes" : "No"


Measured memory_bytes: 8452
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

s = input()
n = len(s)
bcs = 0  # bc: 1  bcbc: 2
cbcs = 0  # c: 1  cbc: 2
sum = 0
for i in range(n-1,-1,-1):
    if s[i]=='C':
        cbcs = bcs+1
        bcs = 0
    elif s[i]=='B':
        if i<n-1 and s[i+1]=='C':
            bcs = cbcs
        else:
            bcs = 0
        cbcs = 0
    else:
        sum += bcs
        cbcs = 0

print(sum)


Measured memory_bytes: 40288
#include <iostream>

int main()
{
    while (true){
    int a, b, result;
    char op;
    
    std::cin >> a >> op >> b;
    
    if (op == '?')
        break;
    else if (op == '+')
        result = a+b;
    else if (op == '-')
        result = a-b;
    else if (op == '*')
        result = a*b;
    else
        result = a/b;
        
    std::cout << result << std::endl;
    }
    
    return 0;
}


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

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

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
  REP(i, a.size()) cin >> a[i];
}

void LOG(int x) { cerr << x << "\n"; }
void LOG(vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }

signed main() {
  int n;
  cin >> n;
  vector<int> c(n - 1), s(n - 1), f(n - 1);
  REP(i, n - 1) cin >> c[i] >> s[i] >> f[i];
  REP(start, n) {
    int x = 0;
    REP(i, n - 1 - start) {
      int j = start + i;
      x = max(ceil(x, f[j]) * f[j], s[j]) + c[j];
    }
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s[200007];
int mi2[200007],num[200007];
const int mod = 998244353;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n>>s;
    mi2[0]=1;
    for(int i=1;i<=n;++i)
        mi2[i]=2ll*mi2[i-1]%mod;
    for(int i=1;i<=n;i+=2)if(n%i==0){
        int length=n/i;
        bool flag=1;
        for(int j=0;j<n&&flag;++j){
            if(s[j]=='1'){
                if(j<length||s[j-length]=='1'){
                    num[length]=(num[length]+(j<length?mi2[length-j-1]:1))%mod;
                }
            }
            if(j>=length&&s[j]==s[j-length])
                flag=0;
        }
        if(flag)
            num[length]=(num[length]+1)%mod;
    }
    int ans=0;
    for(int i=1;i<=n;++i)if(n%i==0&&(n/i)&1&&num[i]){
        ans=(ans+2ll*num[i]*i)%mod;
        for(int j=i*2;j<=n;j+=i)
            num[j]=(num[j]+mod-num[i])%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2048
# AGC032 Problem-B

n = int(input())

table =  [[ 1 for i in range(0, n)] for j in range (0,n)]

#print (table)

if n % 2 == 1 : # odd
    m = n-2
else :
    m = n-1

for i in range (0, n) : 
    table[i][m-i] = 0
#print (table)

print (n*(n-1)//2 - n//2 )
for i in range (0,n):
    for j in range (0,i):
        if table[i][j] ==1 :
            print (i+1, j+1)




Measured memory_bytes: 3700
#include <stdio.h>

int main (){
  int n,flag=0,c=0;
  scanf("%d", &n);
  int a[n];

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  while(1)
  {
    for (int i = 0; i < n; i++){
      if(a[i] % 2 != 0){
        flag=1;
        break;
        }
    }
    if(flag) break;

    if(!flag){
      c++;
      for (int i = 0; i < n; i++)
        a[i]=a[i]/2;
    }
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  char c = getchar();
  switch (c) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      printf("vowel\n");
      break;
    default:
      printf("consonant\n");
  }
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var a = int.Parse(spl[0]);
        var b = int.Parse(spl[1]);

        Func<string, bool> f = (s) => {
            for (int j = 0; j < s.Length / 2; j++) {
                if (s[j] != s[s.Length - j - 1]) return false;
            }
            return true;
        };

        int c = 0;
        for(int i=a; i<=b; i++) {
            c += f(i.ToString()) ? 1 : 0;
        }

        return c;
    }


    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 15188
#include <iostream>
using namespace std;
int main(){
	int A;
	int B;
	int C;
	int D;
	
	cin >> A >> B >> C >> D;
	
	if((A*B)>=(C*D)){
		cout<<A*B<<endl;}
	else{
		cout<<C*D<<endl;}

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n[2];
	while(cin>>n[0]>>n[1],n[0],n[1]){
		int num[2][101],sum[2]={};
		for(int i=0;i<2;i++){
			for(int j=0;j<n[i];j++){
				cin>>num[i][j];
				sum[i]+=num[i][j];
			}
			sort(num[i],num[i]+n[i]);
		}
		int ans[2]={101,101};
		for(int i=0;i<n[0]&&i<ans[0]+ans[1];i++){
			int now[2]={sum[0]-num[0][i],sum[1]+num[0][i]};
			for(int j=0;j<n[1];j++){
				if(now[0]+num[1][j]==now[1]-num[1][j]){
					if(num[0][i]+num[1][j]<ans[0]+ans[1]){
						swap(num[0][i],ans[0]);
						swap(num[1][j],ans[1]);
					}
					break;
				}
			}
		}
		if(ans[0]==101)cout<<-1<<endl;
		else cout<<ans[0]<<" "<<ans[1]<<endl;
	}
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 28;
constexpr lint   INFL = 1LL << 60;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int s;
  cin >> s;
  unordered_map<int, int> checked;
  for (int i = 1;; ++i) {
    if (checked.find(s) == checked.end()) checked[s] = i;
    else {
      cout << i << endl;
      break;
    }
    s = s & 1 ? 3 * s + 1 : s / 2;
  }
  return 0;
}

Measured memory_bytes: 256
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n;
	cin >> n;
	vl ans(n + 1, 0);
	FOR(x, 1, 100)
	{
		FOR(y, 1, 100)
		{
			FOR(z, 1, 100)
			{
				ll val = (binexp(x + y, 2, inf) + binexp(y + z, 2, inf) + binexp(z + x, 2, inf)) / 2;
				if (val <= n)
					++ans[val];
			}
		}
	}
	FOR(i, 1, n)	cout << ans[i] << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}


Measured memory_bytes: 3736
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];
	REP(i, N) {
		A[i] -= (i + 1);
	}
	sort(ALL(A));

	ll val;
	if (IsOdd(N)) {
		val = A[N / 2];
	} else {
		if (abs(A[N / 2]) < abs(A[N / 2 - 1])) {
			val = A[N / 2 - 1];
		} else {
			val = A[N / 2];
		}
	}

	REP(i, N) {
		A[i] -= val;
	}

	ll ans = 0;
	REP(i, N) {
		ans += abs(A[i]);
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  str line;
  cin >> line;

  printf("%c%d%c",line.front(),line.length() - 2,line.back());
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int N, K, i = 1, j, k;
	double winP = 0;
	scanf("%d %d", &N, &K);
	while (i <= N) {
		if (i < K) {
			j = 0; k = i;
			while (k < K) {
				k *= 2;
				j++;
			}
			winP += pow(2.0, -(double)j);
		}
		else winP += 1;

		i++;
	}
	printf("%5.14f", winP / N);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,a[100005];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;int x=0;
	FOR(i,1,n){
		cin>>a[i];x=x^a[i];
	}
	int t=((1ll<<60)-1)^x,l,ans=0,c;
	FOR(i,1,n)a[i]=a[i]&t;
	for(int i=59;i>=0;i--){
		t=(1ll<<i);l=-1;
		FOR(j,1,n){
			if(t&a[j]){
				l=j;break;
			}
		}
		if(l==-1)continue;
		if(!(ans&t))ans=ans^a[l];
		c=a[l];
		FOR(j,l,n){
			if(t&a[j])a[j]=a[j]^c;
		}
	}
	cout<<ans*2+x;
	RE 0;
}



Measured memory_bytes: 1024
s = input()
t = input()
sl = int(len(s))
tl = int(len(t))

for i in range(sl - tl, -1, -1):
    if s[i] == t[0] or s[i] == "?":
        for j in range(tl):
            if s[i + j] != t[j] and s[i+j] != "?":
                break
        else:
            print((s[:i] + t + s[i + len(t):]).replace("?", "a"))
            exit()

print("UNRESTORABLE")


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;

		int money = 100000;
		try {
			if ((line = br.readLine()) != null) {
				line = line.trim();
				int weeks = Integer.parseInt(line);
				if(weeks <= 0 || weeks > 100) System.exit(-1);
				
				for(int i = 0; i < weeks; i++) {
					money *= 1.05;
					if(money % 1000 != 0) {
						money += 1000 - (money % 1000);
					}
				}
				System.out.println(money);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16864
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    bool flg = false;
    rep(i, m) {
        cin >> a[i];
        if ( a[i] == x ) flg = true;
    }
    int idx = upper_bound(a.begin(), a.end(), x) - a.begin();
    if ( idx < m / 2 ) {
        cout << idx << endl;
    }
    else if ( flg ) {
        cout << m - idx - 1 << endl;
    }
    else {
        cout << m - idx << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int search(int);
int S[100000];
int T[50000];
int n,q;

int main(){
  int i,count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

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

  for(i=0;i<q;i++){
    count=count+search(T[i]);
  }

  printf("%d\n",count);
  return 0;
}

int search(int a){

  int L=0,R,M;
  R=n;
  
  while(L<R){
    M=(L+R)/2;
    if(S[M]==a) return 1;
    else if(S[M]<a) L=M+1;
    else if(S[M]>a) R=M;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define DEBUG(X) cerr<<"  "<<#X<<" = "<<X<<endl;
#define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl;
#define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;};
#define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;}
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)

int x,a,b;

int main() {
  cin >> x >> a >> b;
  string s;
  if (x>=b-a&&b-a>0) {
    s = "safe";
  } else if (b-a<=0) {
    s = "delicious";
  } else {
    s = "dangerous";
  }
  cout << s << endl;
}


Measured memory_bytes: 256