akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MOD = 1000000007;

int main(int argc, char **argv)
{
  #ifdef LOCAL
    freopen("in.txt", "r", stdin);
  #endif

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

  int n, k; cin >> n >> k;

  int N = 2*n+10;
  vector<vector<int>> comb(N+1, vector<int>(N+1, 0));
  for(int i=0; i<=N; i++) {
    for(int j=0; j<=i; j++) {
      if(j == 0 || j == i) comb[i][j] = 1;
      else comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
    }
  }

  auto H = [&comb](int n, int k) {
    return comb[n+k-1][k];
  };

  auto H0 = [&](int n, int k) {
    if(n>k) return 0;
    return H(n, k-n);
  };

  cout << n-k+1 << '\n';
  for(int i=2; i<=k; i++) {
    int res = 0;
    for(int j=1; j<=n-k; j++) {
      int t = 1;
      t = (1LL * t * H0(i, k)) % MOD;
      t = (1LL * t * H0(i-1, j)) % MOD;
      t = (1LL * t * H(2, n-j-k)) % MOD;
      res = (res + t) % MOD;
    }
    cout << res << '\n';
  }

  return 0;
}

Measured memory_bytes: 63360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
#include <ctype.h>
#include <math.h>
#define ll long long
char toupper(char c);
char toupper(char c)
{
    return (c - 0x20);
}

using namespace std;
int main()
{
  int a,b,c;
  cin >> a>>b>>c;
  if(a==-c+2*b)
  {
    cout << "YES" << endl;
    return 0;
  }
  cout <<"NO"<< endl;

return 0;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as BS

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

display :: [(Int, Int)] -> String
display [] = ""
display (z : zs)
  | snd z == 1 = "+" ++ show (fst z) ++ display zs
  | otherwise = "-" ++ show (fst z) ++ display zs

calc :: Int -> [Int] ->[[Int]] -> String
calc a ns (st : sts)
  | a + sum(map (\x -> fst x * snd x) zs) == 7 = show a ++ display zs ++ "=7"
  | otherwise = calc a ns sts
  where
    zs = zip ns st

main = do
  [s] <- getString
  let [a, b, c, d] = map (\n -> read [n] :: Int) s
  let sts = replicateM 3 [1, (-1)]
  putStrLn $ calc a [b, c, d] sts


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


int main()
{
	ll n,m,v[105]={},w[105]={},dp[105][100005]={};
	cin>>n>>m;
	for(ll i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if(j-w[i]>=0&&dp[i-1][j-w[i]]+v[i]>dp[i-1][j])dp[i][j]=dp[i-1][j-w[i]]+v[i];
			else dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}

Measured memory_bytes: 82304
import java.util.*;
import java.math.*;

public class Main {

    static long MOD = 1000000007;



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        HashMap<Long,Boolean> map = new HashMap<>();
        ArrayList<Long> list = new ArrayList<>();
        for(int i = 1; i * i <= n; i++) {
            if(!map.containsKey(i)) {
                map.put((long)i,true);
                list.add((long)i);
            }
            if(!map.containsKey(n / i)) {
                map.put((long)(n/i),true);
                list.add(n/i);
            }
        }
        Collections.sort(list);
        int m = list.size();

        long[][] dp = new long[(int)k+1][m];
        for(int i = 0; i < m; i++) {
            dp[0][i] = 1;
        }

        for (int j = 0;j < (int)k;j++) {
			dp[j+1][m-1]=dp[j][0];
			for (int i = m - 2; i >= 0; i--) {
				dp[j+1][i]= (dp[j+1][i+1] + (list.get(m - i - 1) - list.get(m - i - 2)) * dp[j][m - i - 1]) % MOD;
			}
		}

        System.out.println(dp[(int)k][0]);

    }
}

Measured memory_bytes: 92104
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
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);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
  	if(s=="Sunny") cout<<"Cloudy"<<"\n";
  	else if(s=="Cloudy") cout<<"Rainy"<<"\n";
  	else if(s=="Rainy") cout<<"Sunny"<<"\n";
  
}



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

using namespace std;

int main(){
  int a, b, c;
  int x, y;
  cin >> a >> b >> c >> x >> y;
  
  int cost = 0;
  cost += min(a + b, 2 * c) * min(x, y);
  if(x > y){
    if(a > 2 * c) cost += 2 * c * (x - y);
    else cost += a * (x - y);
  }else{
    if(b > 2 * c) cost += 2 * c * (y - x);
    else cost += b * (y - x);
  }
  
  cout << cost << endl;
  
  return 0;
}

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


int main() {
    int n,d,x;
    cin>>n>>d>>x;
    int num[n],count=x;
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
        count+=ceil((double)d/num[i]);
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    ll N, M;
    vector<ll> A;
    cin >> N >> M;

    rep(i, 0, N){
        ll num;
        cin >> num;
        rep(ii, 0, num){
            ll temp;
            cin >> temp;
            A.push_back(temp);
        }
    }
    ll ansCnt = 0;
    rep(i, 0, M){
        ll tempCnt = count(begin(A), end(A), i+1);
        if (tempCnt == N) ansCnt++;
    }
    cout << ansCnt << endl;

    return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
p = list(map(int, input().split()))

p.sort()

def main():

    if len(p) == 0:
        print(X)
        return

    if X < p[0] and p[-1] < X:
        print(X)

    keep = True
    i = 0
    while keep:
        left_found = (X - i) not in p
        right_found = (X + i) not in p

        if left_found and right_found:
            print(X-i)
            keep = False
        elif left_found:
            print(X-i)
            keep = False
        elif right_found:
            print(X+i)
            keep = False


        i += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b, int c){
	if(a < b + c && b < c + a && c < a + b) return 1;
	return 0;
}
int main(){
	vector<int> stik;
	int n, r, qnt = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &r);
		stik.push_back(r);
	}
	sort(stik.begin(), stik.end());
	for(int i = 2; i < n; ++i){
		for(int j = i-1; j > 0; --j){
			for(int k = j-1; k >= 0; --k){
				if(stik[k] >= stik[j] + stik[i]) break;
				qnt += comp(stik[k], stik[j], stik[i]);
			}
		}
	}
	printf("%d\n", qnt);
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
int main(void){
	int n;
	vector<int> a;
	int c;
	a.push_back(2);
	a.push_back(3);
	for (int i = 2; i < 510000; i++){
		for (int j = 1; j < a.size(); j++){
			if (a[j] * a[j]>2*i+1){
				a.push_back(2*i+1);
				break;
			}
			if ((2*i+1)%a[j] == 0)break;
		}
	}

	while (scanf("%d", &n) != EOF){
		c = 0;
		for (int i = 0; a[i] <= n; i++)c++;
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 2780
from collections import deque
num=deque([1,2,3,4,5,6,7,8,9])
cnt=0
K=int(input())
while(True):
    a=num.popleft()
    cnt+=1
    if cnt==K:
        print(a)
        exit()
    if a%10==0:
        a1=a*10
        a2=a1+1
        num.append(a1)
        num.append(a2)
    elif a%10==9:
        a1=a*10+(a%10)-1
        a2=a*10+(a%10)
        num.append(a1)
        num.append(a2)
    else:
        a1 = a * 10 + (a % 10) - 1
        a2 = a * 10 + (a % 10)
        a3 = a * 10 + (a % 10) + 1
        num.append(a1)
        num.append(a2)
        num.append(a3)




Measured memory_bytes: 18624
N, M, X, Y = map(int, input().split())
x     = list(map(int, input().split()))
y     = list(map(int, input().split()))
assert len(x) == N and len(y) == M

mx = max(x)
my = min(y)
nowar = mx < my and mx < Y and X < my

print("No War" if nowar else "War")

Measured memory_bytes: 3060
abc = sorted(map(int, input().split()))
o = [i%2 for i in abc]
b = 0
if o.count(1)==1:
    b += 1
    for i in range(3): abc[i] += 1^o[i]
if o.count(1)==2:
    b += 1
    for i in range(3): abc[i] += o[i]
print((abc[2]-abc[1])//2+(abc[2]-abc[0])//2+b)

Measured memory_bytes: 3064
H, N = list(map(int, input().split()))
A = [[0]*2 for _ in range(N)]
for _ in range(N):
    A[_][0], A[_][1] = list(map(int, input().split()))
# print(A)
# A.sort(key=lambda x: x[1])

INF = float('inf')
dp = [INF]*(H+1)
dp[0] = 0

for i in range(H):
    if dp[i] == INF:
        continue
    for j in range(N):
        a = A[j][0]
        b = A[j][1]
        if i+a >= H:
            dp[H] = min(dp[H], dp[i]+b)
        else:
            dp[i+a] = min(dp[i+a], dp[i]+b)
print(dp[H])

Measured memory_bytes: 74424
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  if(b%a==0){
    cout << a+b << endl;
    return 0;
  }
  else{
    cout << b-a << endl;
    return 0;
  }
}


Measured memory_bytes: 256
N, A = map(int, input().split())
nums = list(map(int, input().split()))
MAX = A*N
dp = [[0 for _ in range(A*N+1)] for _ in range(N+1)]
dp[0][0] = 1
for k, num in enumerate(nums, start=1):
  for i in range(N-1, -1, -1):
    for j in range(A*N-1, -1, -1):
      if j + num <= A*N:
        dp[i+1][j+num] += dp[i][j]
ans = 0
for i in range(1, N+1):
  ans += dp[i][i*A]
print(ans)

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , x;
int p[MAXX];
bool used[MAXX];

int main()
{
    _FastIO;
    cin >> x >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        used[p[i] + 100] = true;
    }
    int ans = x;
    for(int i = 0; i < 101; i++){
        if(!used[x - i + 100]){
            ans = x - i;
            break;
        }
        if(!used[x + i + 100]){
            ans = x + i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
n , m = map(int, input().split())
H  = list(map(int, input().split()))

t = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    t[a - 1] = max(t[a -1], H[b -1])
    t[b - 1] = max(t[b -1], H[a -1])
    
result = 0
for i in range(n):
    if H[i] > t[i]:
        result += 1
print(result)

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

using namespace std;

const int MAXN = 200010;

int n, m;
int a[MAXN];
vector < int > g[MAXN];
pair<int, int> edges[MAXN];

string ansS;
map<pair<int, int>, int> ansC;

int visited[MAXN];

int dfs(int v, int cost, int color) {
  ansS[v] = (color ? 'B' : 'W');
  visited[v] = 1;
  int found = 0;
  for(int s : g[v]) if(!visited[s] && a[s] == a[v]) {
    ansC[make_pair(s, v)] = ansC[make_pair(v, s)] = cost;
    dfs(s, cost, 1 - color);
    found = 1;
  }
  return found;
}

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

  vector < int > p;

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

  ansS = string(n, '*');

  for(int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
    edges[i] = {u, v};
  }

  sort(p.begin(), p.end(), [&](int x, int y) {
    return a[x] < a[y];
  });

  for(int i = 0; i < n; ++i) {
    int v = p[i];
    if(visited[v]) continue;
    if(!dfs(v, a[v], 0)) {
      ansS[v] = '*';
      for(int s : g[v]) {
        if(ansS[s] != '*') {
          if(ansS[v] == '*') {
            ansS[v] = (ansS[s] == 'B' ? 'W' : 'B');
            ansC[make_pair(s, v)] = ansC[make_pair(v, s)] = a[v];
          }
          else {
            if(ansS[v] != ansS[s]) {
              ansC[make_pair(s, v)] = ansC[make_pair(v, s)] = a[v];
            }
            else {
              ansC[make_pair(s, v)] = ansC[make_pair(v, s)] = a[v] - a[s];
            }
          }
        }
      }
      if(ansS[v] == '*') return cout << -1, 0;
    }

  }

  cout << ansS << "\n";
  for(int i = 0; i < m; ++i) {
  //  cout << edges[i] << endl;
    if(!ansC.count(edges[i])) cout << (int) 1e9 << "\n";
    else cout << ansC[edges[i]] << "\n";
  }

  return 0;
}


Measured memory_bytes: 37752
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  
  for(int i = 1; i < s.size() + 1; i++){
    if(i % 2 != 0){
      cout << s[i-1];
    }
  }
  cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#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 SZ(x)      ((int) (x).size())
using ll = long long;


int main() {
  int n, k;
  cin >> n >> k;
  vector <int> p(n);
  REP(i, n) {
	cin >> p[i];
  }
  vector <int> s(n + 1, 0);
  REP1(i, n) {
	s[i] = s[i - 1] + p[i - 1];
  }
  int ans = 0;
  REP(i, n - k + 1) {
	ans = max(ans, s[i + k] - s[i]);
  }
  printf("%.16f\n", static_cast <double>(ans + k) / 2.0);
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
    ll w[n];
    w[0]=a[0];
    for(int i=1;i<n;i++)
    w[i]=w[i-1]+a[i];
   
   
    ll dp[n][n];
    
    memset(dp,0,sizeof dp);

    for(int l=2;l<=n;l++)
    {
    for(int i=0;i<=n-l;i++)
    {
    int j=i+l-1;
    ll wt=w[j];
    if(i>=1)
    wt=wt-w[i-1];
    dp[i][j]=LLONG_MAX;
    for(int k=i;k<j;k++)
    {
    dp[i][j]=min(dp[i][k]+dp[k+1][j],dp[i][j]);
    }
    dp[i][j]+=wt;
    }
    }
    cout<<dp[0][n-1];
	return 0;
}

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

const int INF = 1e9;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > k) a[i] = 0;
    }

    int ans = INF;
    map<int, int> mp;
    for (int l = 0, r = 0; l < n; l++) {
        while (r < n and mp.size() < k) {
            if (a[r] > 0) mp[a[r]]++;
            r++;
        }
        if (mp.size() == k) {
            ans = min(ans, r - l);
        }
        if (a[l] > 0) {
            if (--mp[a[l]] == 0) mp.erase(a[l]);
        }
    }

    if (ans == INF) ans = 0;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 7788
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
#define int ll
vector<vector<ll>> memot(3e3+3, vector<ll>(3e3, -1));
vector<vector<ll>> memoj(3e3+3, vector<ll>(3e3, -1));
vector<ll> pref(3e3+3);

ll jiro(vector<int> &v, int l, int r);

ll taro(vector<int> &v, int l, int r){
	if(l == r){
		return v[l]; 
	}
	if(memot[l][r] != -1)
		return memot[l][r];
	ll f, ff, b, bb;
	if(l > 0){
		ff = pref[r] - pref[l-1] - jiro(v, l+1, r);
		bb = pref[r] - pref[l-1] - jiro(v, l, r-1);

		f = ff - jiro(v, l+1, r);
		b = bb - jiro(v, l, r-1);
	}else{
		ff = pref[r] - jiro(v, l+1, r);
		bb = pref[r] - jiro(v, l, r-1);		

		f = ff - jiro(v, l+1, r);
		b = bb - jiro(v, l, r-1);		
	}
	if(f > b)
		memot[l][r] = ff;
	else
		memot[l][r] = bb;
	return memot[l][r];
}

ll jiro(vector<int> &v, int l, int r){
	if(l == r){
		return v[l]; 
	}
	if(memoj[l][r] != -1)
		return memoj[l][r];
	ll f, ff, b, bb;
	if(l > 0){
		ff = taro(v, l+1, r) - pref[r] + pref[l-1];
		ff = -ff;
		f = taro(v, l+1, r) - ff; 
		bb = taro(v, l, r-1) - pref[r] - pref[l-1];
		bb = -bb;
		b = taro(v, l, r-1) - bb;
	}else{
		ff = taro(v, l+1, r) - pref[r];
		bb = taro(v, l, r-1) - pref[r];
		ff = -ff;
		bb = -bb;
		f = taro(v, l+1, r) - ff;
		b = taro(v, l, r-1) - bb;
	}
	if(f < b){
		memoj[l][r] = ff;
	}else{
		memoj[l][r] = bb;
	}
	return memoj[l][r];
}
ll t(vector<int> &v, int l, int r);
ll j(vector<int> &v, int l, int r){
	if(l == r)
		return -v[l];
	if(memoj[l][r] != -1)
		return memoj[l][r];
	ll f, b;
	f = t(v, l+1, r)-v[l];
	b = t(v, l, r-1)-v[r];
	return memoj[l][r] = min(f, b);
}
ll t(vector<int> &v, int l, int r){
	if(l == r)
		return v[l];
	if(memot[l][r] != -1)
		return memot[l][r];
	ll f, b;
	f = j(v, l+1, r)+v[l];
	b = j(v, l, r-1)+v[r];
	return memot[l][r] = max(f, b);
}

signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n; 
	cin>>n;
	vector<int> v(n);
	for(int &i : v)
		cin>>i;
	pref[0] = v[0];
	for(int i = 1; i < n; i++){
		pref[i] = pref[i-1]+v[i];
	}
	cout<<t(v, 0, n-1);
	
}


Measured memory_bytes: 141440
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    string s[n];
    rep(i,n)cin >> s[i];
    int flag = 1;
    rep(i,n){
        rep(j,n){
            if(s[i][j] == '#')flag = 0;
        }
    }
    if(flag)dame;

    int ans = 1001001001;
    int need = n;
    rep(i,n){
        flag = 1;
        rep(j,n){
            if(s[j][i] == '.')flag = 0;
        }
        need -= flag;
    }

    rep(i,n){
        int tmp = 0;
        rep(j,n){
            if(s[i][j] == '.')tmp++;
        }
        flag = 1;
        rep(j,n){
            if(s[j][i] == '#')flag = 0;
        }
        tmp += flag;
        tmp += need;
        ans = min(ans,tmp);
    }

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


Measured memory_bytes: 512
sprime,t = 2.times.map{gets.chomp}
lens = sprime.length
lent = t.length
s = []
ans = "" << sprime
for i in 0..lens-lent
  ans = "" << sprime
  f = 0
  for j in i..i+lent-1
    if sprime[j] == t[j-i] || sprime[j] == "?"
      ans[j] = t[j-i]
    else
      f = 1
      break
    end
  end
  if f == 1
    next
  end
  if i != 0
    for j in 0..i-1
      if sprime[j] == "?"
        ans[j] = "a"
      end
    end
  end
  if i != lens-lent
    for j in i+lent..lens-1
      if sprime[j] == "?"
        ans[j] = "a"
      end
    end
  end
  s << ans
end
if s.empty?
  puts "UNRESTORABLE"
else
  puts s.sort[0]
end

Measured memory_bytes: 1788
#include <cstdio>

int main() {
    //入力
    int W,H,x,y,r;
    std::scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) {
        std::printf("Yes");
    }
    else {
        std::printf("No");
    }
    std::printf("\n");
    
    return 0;
}


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

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;

	while(t--) {
		ll n, d;
		cin>>n>>d;

		if(n%2 == 1) cout<<(127*(n-1) + d)<<endl;
		else cout<<((127*(n-1)) + (d^127))<<endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long 
#define INF (ll)1e18 + 50
#define MAXN (int)2e5 + 50
#define fi first
#define se second
#define MOD 1000000007
#define all(v)((v).begin()), ((v).end())
#define A 911382323
#define B 972663749


set<int> ini, vis;
int vec[MAXN];

int32_t main() {
    
    string s1, s2; cin >> s1 >> s2;
    cout  << s2 << s1;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))


bool Comp(pair<ll,ll> &f1,pair<ll,ll> &f2){
    return f1.first<f2.first;
}

int main(){
    ll ans,n,k;
    cin >>n>>k;
    vector< pair<ll,ll> > ab;
    for(int i=0;i<n;i++){
        ll a,b;
        cin >>a>>b;
        ab.push_back(make_pair(a,b));
    }
    sort(ab.begin(),ab.end(),Comp);
    ll num=0;
    for(int i=0;i<ab.size();i++){
        num+=ab[i].second;
        ans=ab[i].first;
        if (num>=k)break;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int main() {
#ifdef LOCAL
  freopen("h.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  string s;
  cin >> s;
  bool a, b;
  a = (stoi(s.substr(0, 2)) <= 12 && stoi(s.substr(0, 2)) > 0);
  b = (stoi(s.substr(2, 4)) <= 12 && stoi(s.substr(2, 4)) > 0);
  if (a && b)
    cout << "AMBIGUOUS" << endl;
  else if (b)
    cout << "YYMM" << endl;
  else if (a)
    cout << "MMYY" << endl;
  else
    cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

using namespace std;


using int64 = long long;
const int mod = (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  vector< int > L(N);
  cin >> L;
  sort(begin(L), end(L));
  int ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      for(int k = j + 1; k < N; k++) {
        if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) {
          if(L[i] + L[j] > L[k]) ++ret;
        }
      }
    }
  }
  cout << ret << "\n";
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  int a,b;
  cin >> a >> b;
  if(a>2*b) cout << a-2*b << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

// 10111011

struct body{
    int idx;
    std::vector<int> legs;
};

int main(){
    std::string G;
    std::cin >> G;
    int n = G.length();
    //std::cout << G[0] << G[n-1] << std::endl;
    if (G[0] != '1' || G[n-1] != '0'){
        std::cout << -1 << std::endl;
        return 0;
    }
    else if (n == 2){
        std::cout << 1 << ' ' << 2 << std::endl;
        return 0;
    }
    for(int i = 1; i < n-1; i++){
        if(G[i] != G[n-i-2]){
            //std::cout << "hello" << std::endl;
            std::cout << -1 << std::endl;
            return 0;
        }
    }
    std::vector<body> bodies;
    int body_length = 0;
    for(int i = 0; i < n-1; i++){
        if(G[i] == '1'){
            body tmp;
            tmp.idx = i+2;
            body_length++;
            bodies.push_back(tmp);
            if (i == 0){
                bodies[0].legs.push_back(1);
            }
        }
        else {
            if(i != n-1) bodies[body_length-1].legs.push_back(i+2);
        }
    }
    for(int i = 0; i < body_length; i++){
        int body_idx = bodies[i].idx;
        if(i != 0){
            std::cout << body_idx << " " << bodies[i-1].idx << std::endl;
        }
        for(auto const& cidx: bodies[i].legs){
            std::cout << cidx << " " << body_idx << std::endl;
        }
    }

    return 0;

}


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

int power[100000] = {0};
int sort_min(const void *a, const void* b)
{
	//printf("%d %d\n", *(int*)b , *(int*)a);
	return (*(int*)b - *(int*)a);
}

int battle(int n)
{
	int i = 0;
	int no = 0;
	int del = 0;
	do {
		qsort(power, n, sizeof(int), sort_min);
		n -= del;
		del = 0;
		no = 0;
		//printf("n=%d\n",n);
		if (power[n-1] == 1) {
			return 1;
		}
		for(i = 0; i < (n-1); i++) {
			if ((power[i]%power[n-1]) == 0) {
				power[i] = 0;
			    no = 0;
			    del++;
			} else {
				power[i] = (power[i]%power[n-1]);
				no = 1;
				break;
			}
		}
	    if(no == 0) {
			//printf("no\n");
	    	return power[n-1];
	    }
		//printf("loop\n");
	} while(n > 1);
	//printf("xx\n");
	return power[1];
}


int main()
{
	int n_monster = 0;
	int i = 0;
	int val = 0;

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

	val = battle(n_monster);
	printf("%d\n",val);
	return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int A,B,flg=0;
  scanf("%d %d",&A,&B);
  for(int i = 1 ; i <= 1009 ; i++){
    if(floor(i*0.08) == A && floor(i*0.1) == B){
      printf("%d",i);
      flg++;
      break;
    }
  }
  if(flg == 0){
    printf("-1");
  }
  return 0;
}

Measured memory_bytes: 128
from collections import Counter
N=int(input())
a = [input() for i in range(N)]
c=Counter(a)
d=c.most_common()
e=[]

e.append(d[0][0])

for j in range(len(d)-1):
  if d[0][1]==d[j+1][1]:
    e.append(d[j+1][0])
f=sorted(e)
for i in range(len(f)):
  print(f[i])

   

Measured memory_bytes: 120016
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);++i)
#define pb(x) push_back(x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
LL a,b,c;
int main() {
	cin>>a>>b>>c;
	LL x=4*a*b;
	LL y=c-a-b;
	if(y<0){
		puts("No");
		return 0;
	}
	y*=y;
	if(x<y) puts("Yes");
	else puts("No");
	return 0;
}



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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};


string n, m;
int f, k, l;

int main(){

	cin >> n >> m;
	if(n.size() > m.size()){
		cout << "GREATER" << endl;
	}else if(n.size() < m.size()){
		cout << "LESS" << endl;
	}else if(n.size() == m.size()){
		f++;
	}
	if(f == 1){
		for(int i = 0;i < n.size();i++){
			k = n[i] - '0';
			l = m[i] - '0';
			if(k > l){
				cout << "GREATER" << endl;
				break;
			}else if(k < l){
				cout << "LESS" << endl;
				break;
			}
			if(i == n.size() - 1){
				cout << "EQUAL" << endl; 
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fs first
#define sc second
#define P pair<int, int>
#define mk_p make_pair
int n, a[200010];
map<int, int> mp;
char s[1111111];
int main(){
	cin>>s + 1;
	int len = strlen(s + 1);
	for(int i = 1;i <= len; i++)printf("x");
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 100010
int abs(int a){
	if(a>0) return a;
	else return -a;
} 
int main(){
	int n,A[maxn],dp[maxn];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&A[i]);
	dp[n-1]=0;
	dp[n-2]=abs(A[n-2]-A[n-1]);
	for(int i=n-3;i>=0;i--)
	dp[i]=min(dp[i+1]+abs(A[i]-A[i+1]),dp[i+2]+abs(A[i]-A[i+2]));
	printf("%d",dp[0]);	
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i).first >> a.at(i).second;
  }
  sort(ALL(a));
  ll result = 0;
  for(int i = 0; i < N; i++){
    if(a.at(i).second <= M){
      result += a.at(i).first * a.at(i).second;
      M -= a.at(i).second;
    }
    else{
      result += M * a.at(i).first;
      break;
    }
  }
  cout << result << endl;

}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      if (W[i] == W[j]) {
        cout << "No" << '\n';
        return 0;
      }
    }
  }
  for (int i = 0; i < N - 1; i++) {
    if (W[i][(int)W[i].size() - 1] != W[i + 1][0]) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

ll modpow(ll a, ll n, ll m = MOD) {
    ll ret = 1;
    ll now = a;
    while (n > 0) {
        if (n % 2 == 1) ret = ret * now % m;
        now = now * now % m;
        n /= 2;
    }
    return ret;
}
struct Combination {
    vector<ll> kaijou;
    Combination() : kaijou(1001001, 1) {
        rep(i, 1001000) kaijou[i + 1] = (kaijou[i] * (i + 1)) % MOD;
    }
    ll modinv(ll a, ll m) {
        ll b = m, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    ll c(int x, int y) {
        if (x < y || y < 0) return 0;
        return kaijou[x] * modinv(kaijou[x - y] * kaijou[y], MOD) % MOD;
    }
    ll h(int x, int y) {
        return c(x + y - 1, y);
    }
};

int main() {
    Combination comb;
    ll n, m;
    cin >> n >> m;
    vector<ll> vec;
    for (int d = 2; d <= sqrt(m); d++) {
        if (m % d > 0) continue;
        ll cnt = 0;
        while (m % d == 0) {
            m /= d;
            cnt++;
        }
        vec.push_back(cnt);
    }
    if (m > 1) vec.push_back(1);
    ll ans = 1;
    for (ll x : vec) {
        (ans *= comb.h(n, x)) %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
  
  int N, L; cin >> N >> L; int a[N]; int sum = 0;
  
  for (int i = 0; i < N; i++) {
    a[i] = L + i;
    sum += a[i];
  }
  
  if (0 < a[0]) cout << sum - a[0] << endl;
  
  else if (a[N - 1] < 0) cout << sum - a[N - 1] << endl;
  
  else cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  bool outflag = false;
  if( s.at(0) != 'A') outflag = true;
  if( s.at(1) <= 90 ) outflag = true;
  if( s.at(s.size()-1) <= 90 ) outflag = true;

  int c_count = 0;
  for(int i=2; i<s.size()-1; i++){
    if( s.at(i) == 'C' ) c_count++;
  }

  if( c_count == 1 && !outflag ){
    std::cout << "AC" << '\n';
  }else{
    std::cout << "WA" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int n, i;
    cin >> n >> i;
    cout << n-i+1 << endl;
}

Measured memory_bytes: 256
K,N = map(int, input().split())
List = list(map(int, input().split()))
#print(K-List[N-1])
#List.append(K-List[N-1])
dif=[List[0]]
for i in range(1,N):
    dif.append(List[i]-List[i-1])
#print(dif)
dif[0]+=K-List[N-1]
ma=max(dif)
print(sum(dif)-ma)

Measured memory_bytes: 26420
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATakahashiCalendar solver = new ATakahashiCalendar();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATakahashiCalendar {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int m = in.scanInt();
            int d = in.scanInt();
            int ans = 0;
            for (int i = 22; i <= d; i++) {
                if (i % 10 >= 2 && (i / 10) >= 2) {
                    if ((i % 10) * (i / 10) >= 1 && (i % 10) * (i / 10) <= m) ans++;
                }
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

int main(){
  ll n;
  cin>>n;
  ll num[5];
  for(int i=0;i<5;i++) cin>>num[i];
  sort(num,num+5);
  cout<<(n-1)/num[0]+5<<endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s;cin>>s;
  int result=0, c=0;

  rep(i, s.size()){
    
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')c++;
    else{
      result = max(result, c);
      c=0;
    }
  }
  result = max(result, c);

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
def make_divisor(n):
    divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisor.append(i)
    divisor.append(n)
    return divisor

N = int(input())
a = make_divisor(N)

sum = 0
for i in a:
    if N // i - 1 > i:
        sum += (N // i) - 1

print(sum)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A;
    int tmp;
    int sum = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> tmp;
        A.emplace_back(tmp);
    }

    vector<int> B;
    int from = 0;
    int num = 0;
    for (int n : A)
    {
        for (int i = from; i < n; i++)
        {
            B.emplace_back(num);
        }
        num += 1;
        from = n;
        
    }
    for (int i = from; i <= N; i++)
    {
        B.emplace_back(num);
    }
    

    cout << min(B[X], B[N] - B[X]) << endl;
    
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  string cantalk = "No";
  
  if (max(a,c) - min(a,c) <= d)
    cantalk = "Yes";
  else if (max(a,b) - min(a,b) <= d && max(b,c) - min(b,c) <= d)
    cantalk = "Yes";
    
  cout << cantalk << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

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

    int K = sc.nextInt();
    int S = sc.nextInt();
    int count = 0;
    for (int a = 0; a <= K; a++) {
      for (int b = 0; b <= K; b++) {
        if (S - (a + b) <= K && S - (a + b) >= 0) count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> capital(M * 2);
  vector<int> count(N);
  for (int i = 0; i < M * 2; i++){
    cin >> capital.at(i);
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M * 2; j++){
      if (capital.at(j) == i + 1){
        count.at(i)++;
      }
    }
  }
  for (int i = 0; i < count.size(); i++){
    cout << count.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    val MOD = 1000000007L
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        var a = 1L
        repeat(N) {
            a *= 10
            a %= MOD
        }
        var c = 1L
        repeat(N) {
            c *= 8
            c %= MOD
        }
        a += c
        a %= MOD

        var b = 1L
        repeat(N) {
            b *= 9
            b %= MOD
        }
        b *= 2
        b %= MOD

        a -= b
        a %= MOD
        if (a < 0) a += MOD
        pw.println(a)

    }
}


Measured memory_bytes: 36368
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			var a = cin.ArrayInt(n, -1);

			int max = m;
			var minus = new int[max];
			var plus = new int[max];
			long init = 0;
			for (int i = 1; i < n; i++) {
				if (a[i] > a[i - 1]) {
					init += a[i] - a[i - 1];

					if (a[i - 1] + 2 <= a[i]) {
						minus[a[i - 1] + 2] += -1;
						if (a[i] + 1 < m) {
							minus[a[i] + 1] += 1;
						}
					}

					if (a[i] + 1 != m) {
						plus[((a[i] + 1) % m)] += Math.Max(0, a[i] - a[i - 1] - 1);
					}
				} else {
					init += a[i] + 1;

					if (a[i - 1] + 2 < m) {
						minus[a[i - 1] + 2] += -1;
						if (a[i - 1] + 2 != m - 1) {
							minus[m - 1] += 1;
						}
					}

					if (a[i - 1] == m - 1) {
						if (a[i] > 0) {
							minus[1] += -1;
							minus[a[i] + 1] += 1;
						}
					} else {
						if (a[i] > 0) {
							minus[0] += -1;
							minus[a[i] + 1] += 1;
						}
					}

					plus[((a[i] + 1) % m)] += Math.Max(0, a[i] + m - a[i - 1] - 1);
				}
			}

			for (int i = 1; i < max; i++) {
				minus[i] += minus[i - 1];
			}

			var sum = new int[max];
			for (int i = 0; i < max; i++) {
				sum[i] = minus[i] + plus[i];
			}

			long value = init;
			long ans = init;
			for (int i = 1; i < m; i++) {
				value += sum[i];
				ans = Math.Min(ans, value);
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 19040
#include <iostream>

using namespace std;

long min(long a,long b){
	return a < b ? a : b;
}

int main(void){
	long s,c;
	long res = 0;
	cin >> s >> c;
	res += min(s,c/2);
	c -= res * 2;
	if(c > 3)res += c/4;
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int v, w;
    char t;
    ll d;
    string s;
    vector<tuple<int, int, char, ll, string>> T;
    rep(i, n) {
        cin >> v >> w >> t >> d >> s;
        T.emplace_back(v, w, t, d, s);
    }
    sort(T.begin(), T.end());
    rep(i, n) cout << get<0>(T[i]) << " " << get<1>(T[i]) << " " << get<2>(T[i])
                   << " " << get<3>(T[i]) << " " << get<4>(T[i]) << endl;
}



Measured memory_bytes: 11176
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#define maxn 1020
#define N 99999999999
using namespace std;
int n,tot;
inline int read(){

    int x = 0,f = 1; char c = getchar();
    while ((c < '0' || c > '9') && c != EOF) {if (c == '-') f = -1;c = getchar();}

    while ((c <='9' && c >='0') && c != EOF) {x = x * 10 + c - '0';c = getchar();}
    return x * f;
}
int head[maxn],nex[maxn],to[maxn],v[maxn];
void add(int x,int y)
{to[++tot]=y;
	nex[tot]=head[x];
	 head[x]=tot;
}
int dp[maxn][maxn*5],temp[maxn*5];
int dfs(int r)
{
	dp[r][0]=0;
	for(int i=head[r];i;i=nex[i])
	{
		int w=dfs(to[i]),b=v[to[i]];

		memcpy(temp,dp[r],sizeof(temp));
		memset(dp[r],0x3f,sizeof(dp[r]));

		for(int j=0;j<=v[r];j++)
		{
			if(j+w<=v[r])
            {if(temp[j]+b<dp[r][j+w])
            {
                dp[r][j+w]=temp[j]+b;
            }
               }
			if(j+b<=v[r])
            {
                if(dp[r][j+b]>temp[j]+w)
                {
                   dp[r][j+b]=temp[j]+w;
                }
            }

		}

	}

	int ans=dp[0][0];

	for(int i=0;i<=v[r];i++)
    {
        if(ans>dp[r][i])
        {
           ans=dp[r][i];
        }
    }
	return ans;
}
int main()
{
	memset(dp,0x3f,sizeof(dp));
    n=read();
	for(int i=2;i<=n;i++)
	{
		int x;
		x=read();
		add(x,i);
	}
	for(int i=1;i<=n;i++)
        v[i]=read();
        int p=0;
	int res=dfs(p+1);
	if(res<dp[0][0])
		return printf("POSSIBLE\n"),0;
	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 20608
import numpy as np
 
MAX_DIGIT = 60
MOD = 10**9 + 7
 
N = int(input())
A = np.array([int(a) for a in input().split()])
 
answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD
    answer += (base * s * (N - s)) % MOD
 
answer %= MOD
print(answer)

Measured memory_bytes: 49940