akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,m;
int father[100010],cnt[100010];
int findfather(int a){
	int x=a;
	while(father[a]!=a){
		a=father[a];
	}
	while(father[x]!=x){
		int z=x;
		x=father[x];
		father[z]=a;
	}
	return a;
}
void Union(int a,int b){
	int faA=findfather(a);
	int faB=findfather(b);
	if(faA!=faB){
		father[faA]=faB;
	}
}
int main(){
	int x,y;
	cin>>n>>m;
	for(int i=1;i<=n;i++)father[i]=i;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		Union(x,y);
	}
	for(int i=1;i<=n;i++){
		cnt[findfather(i)]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(cnt[i])ans++;
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 4364
int main(int argc, const char * argv[]) {
    int n,a[4][13],x,y;
    char c=0;
    char t[]="SHCD";
    scanf("%d",&n);
    //初期化
    for(int i=0;i<4;i++) {
        for(int j=0;j<13;j++){
            a[i][j]=0;
        }
    }
//    input
    for(int i=0;i<n;i++){
        scanf("%*c %c %d",&c,&x);
//        if(c=='S')y=0;
//        else if(c=='H')y=1;
//        else if(c=='C')y=2;
//        else if(c=='D')y=3;
//        else y=0;
        for(y=0;c!=t[y]&&y<4;y++);
        a[y][x-1]=1;
    }
    //output
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(a[i][j]==0){
                printf("%c %d\n",t[i],j+1);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2044
x,k,d = map(int, input().split())
ans = 0
if abs(x) > k * d:
    ans = abs(x) - k * d
else:
    t = abs(x) // d
    a = k - t
    b = abs(x) % d
    if a%2 == 0:
        ans = b
    else:
        ans = d-b

print(ans)

Measured memory_bytes: 9180
s = input()
c0 = 0
c1 = 0
for i in range(len(s)):
    if s[i] == "1":
        c1 += 1
    else:
        c0 += 1

if len(s) == 1:
    print(0)
else:
    print(min(c0, c1) * 2)


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

import sys
import pprint
from collections import deque


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	h, w = map(int, sys.stdin.readline().split())
	ch, cw = map(int, sys.stdin.readline().split())
	dh, dw = map(int, sys.stdin.readline().split())
	s = [sys.stdin.readline().rstrip() for i in [0]*h]
	graph = [[[] for i in [0]*w] for j in [0]*h]
	
	def getMaze(x, y):
		if not (0 <= x < w and 0 <= y < h):
			return -1
		return s[y][x]

	for y in range(h):
		for x in range(w):
			if s[y][x] == "#":
				continue
			


	# log.print(graph)
	stack = deque([(cw-1, ch-1)])
	dist = [[float("inf")]*w for i in range(h)]
	while len(stack) != 0:
		x, y = stack.popleft()
		log.print(x, y, dist[y][x])
		if dist[y][x] == float("inf"):
			dist[y][x] = 0
		d = dist[y][x]
		nexts = []
		for i in range(-2, 2+1):
			for j in range(-2, 2+1):
				if (i, j) == (0, 0):
					continue
				if getMaze(x + i, y + j) == ".":
					if (i, j) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
						nexts.append((x + i, y + j, 0))
					else:
						nexts.append((x + i, y + j, 1))
		for next in nexts:
			nx, ny, cost = next
			if dist[ny][nx] > d + cost:
				dist[ny][nx] = d + cost
				if cost == 1:
					stack.append((nx, ny))
				else:
					stack.appendleft((nx, ny))
	log.print(dist)
	if dist[dh-1][dw-1] == float("inf"):
		print(-1)
	else:
		print(dist[dh-1][dw-1])
	
	


main()

Measured memory_bytes: 140848
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[N - 1] - a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    ll zeros = (h - 2) * (w - 2);
    map<pii, int> cnt;
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    for (int i = 0; i < n; ++i) {
        cnt[{a[i], b[i]}]++;
        for (int j = 0; j < 8; ++j) {
            ll na = a[i] + dx[j];
            ll nb = b[i] + dy[j];
            cnt[{na, nb}]++;
        }
    }
    vl ret(10, 0);
    ret[0] = zeros;
    for (auto &p : cnt) {
        ll na = p.first.first;
        ll nb = p.first.second;
        if (1 <= na && na < h - 1 && 1 <= nb && nb < w - 1) {
            ret[p.second]++;
            ret[0]--;
        }
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

void inputList(vector<ll>* list, ll n, int sortType = 0)
{
  repl(i, n)
  {
    ll tmp;
    cin >> tmp;
    list->push_back(tmp);
  }
  if(sortType == 0)
  {
    sort(list->begin(), list->end());
  }
  else if(sortType == 1)
  {
    sort(list->begin(), list->end(), greater<ll>());
  }
}

void greatFirst(ll& a, ll& b)
{
  if(a < b)
  {
    ll tmp = a;
    a = b;
    b = tmp;
  }
}

struct Temp{
  int a;
  int b;
  int c;
  int d;
  
  Temp(int _a, int _b, int _c, int _d)
  {
    a = _a;
    b = _b;
    c = _c;
    d = _d;
  }
};

int answer(vector<Temp>* list, int num, int keta, int m, int n)
{
  int ans = 0;
  if(keta == n)
  {
    vector<int> numList;
    rep(i, n)
    {
      numList.insert(numList.begin(), num % 10);
      num = num / 10;
    }
    
    for(auto x = list->begin(); x != list->end(); ++x)
    {
      Temp v = *x;
      if(numList[v.b] - numList[v.a] == v.c)
      {
        ans += v.d;
      }
    }
  }
  else
  {
    for(int i = num % 10; i < m; i++)
    {
      ans = max(ans, answer(list, num*10 + i, keta + 1, m , n));
    }
  }
  return ans;
}

int main()
{
  int n,m,q;
  cin >> n >> m >> q;
  int ans = 0;
  vector<Temp> list;

  rep(i, q)
  {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    list.push_back(Temp(a-1,b-1,c,d));
  }
  
  ans = answer(&list, 0, 1, m, n);
  
  cout << fixed << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	while(1){
		int n,x,y;
		P p[220];
		cin>>n;
		if(n==0)break;
		p[0].first=p[0].second=0;
		REP(i,1,n){
			cin>>x>>y;
			int px=p[x].first,py=p[x].second;
			if(y==0)p[i].first=px-1,p[i].second=py;
			else if(y==1)p[i].first=px,p[i].second=py-1;
			else if(y==2)p[i].first=px+1,p[i].second=py;
			else if(y==3)p[i].first=px,p[i].second=p[x].second+1;
		}
		int x_ma=0,x_mi=0,y_ma=0,y_mi=0;
		rep(i,n){
			x_ma=max((int)p[i].first,x_ma);
			x_mi=min((int)p[i].first,x_mi);
			y_ma=max((int)p[i].second,y_ma);
			y_mi=min((int)p[i].second,y_mi);
		}
		cout<<x_ma-x_mi+1<<" "<<y_ma-y_mi+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 2996
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REPR(i,n) for(int i=n-1; i>=(int)(0); i--)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()
//**関数リスト**//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) {
	ll keta = 1;
	while (F / 10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll isPrime(ll x) {
	ll i;
	if (x < 2) {
		return 0;
	}
	else if (x == 2) {
		return 1;
	}
	else if (x % 2 == 0) {
		return 0;
	}
	else {
		for (i = 3; i * i <= x; i += 2) {
			if (x % 1 == 0) {
				return 0;
			}
		}
		return 1;
	}
}
void eratos(vl isPrime) {
	//(注)isPrimeのサイズはN+1にする！実際にはmain内に配置して使用
	ll i, j;
	REP(i, isPrime.size()) {
		isPrime[i] = 1;
	}
	isPrime[0] = 0; isPrime[1] = 0;
	for (i = 2; i * i <= isPrime.size() - 1; i++) {
		if (isPrime[i] == 1) {
			j = i * 2;
			while (j <= isPrime.size() - 1) {
				isPrime[j] = 0;
				j = j + i;
			}
		}
	}
}
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;
}
void bitSearch(ll n) {
	//実際にはコピーして中身を改変して使う
	ll i;
	REP(i, pow(2, n)) {
		ll p = i;
		REP(i, n) {
			cout << p % 2;
			p /= 2;
		}
		cout << endl;
	}
}

void bfs(ll now) {
	//中身は毎回書き換えて使用
	queue<ll> Q;
	Q.push(now);
	ll u;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		//ll v=;
		//Q.push(v);
	}
}
//**定義場所**//
ll i, j, k, l, m, n;
ll N, M, K, H, W;
ll MOD = 1000000007;
ll ans = 0;
//***********//

int main() {
	ll D;
	cin >> N >> D;
	if (N % (D * 2 + 1) == 0) {
		cout << N / (D * 2 + 1);
	}
	else {
		cout << (N / (D * 2 + 1)) + 1;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,x=0,i;
scanf("%d",&a);
scanf("%d",&b);

for(i=0;i<2;i++){
if(a>b){
x=x+a;
a=a-1;
}else{
x=x+b;
b=b-1;
}
}


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

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void){
  int i;
  char a[100], b[100];
  scanf("%s%s", a, b);
  for( i = 0; i < strlen(a); i++){
    if( a[i] != b[i]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 1624
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int n,k,a[100010],ans=0;
int main() {
cin>>n>>k;
for(int i=1;i<=n;i++)
 cin>>a[i];
for(int i=1;i<=n;i++){ 
 if(a[i]==1){
  int re=k-1;
  for(int j=i-1;j>=1;j--){
   if(re==0){ans++; re=k-1;}
   re--;
  }
  for(int j=i+1;j<=n;j++){
   if(re==0){ans++;re=k-1;}
   re--;
  }
  ans++;
  break;
 }
}
//if(n==k)cout<<1<<endl;
//else{ if(k==2) cout<<n-1<<endl;
 cout<<ans<<endl;
//}
system("pause");
return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

  sort(d.begin(), d.end());
  int a = d[n / 2 - 1];
  int b = d[n / 2];
  int ans = b - a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long N,K;
  cin >> N >> K;
  pair<long long, long long> vect[N];
  long long a,b;
  for(long long i = 0; i < N ; ++i){
    cin >> vect[i].first >> vect[i].second ;
  }
  sort(vect, vect+N);
  long long  index = 0;
  long long  counter = vect[0].second;
  while(counter < K){
    ++index;
    counter += vect[index].second;
  }
  cout << vect[index].first << endl;
}

Measured memory_bytes: 1792
a = int(input())
b = int(input())
c = int(input())
x = int(input())

l = 0

def pattern(a, b, c, x):
	if x == 0:
		return 1
	else:
		if (500 * a + 100 * b + 50 * c < x):
			return 0
		elif (x >= 500) and (a >= 1):
			return pattern(a - 1, b, c, x - 500) + pattern(0, b, c, x)
		elif (x >= 100) and (b >= 1):
			return pattern(a, b - 1, c, x - 100) + pattern(a, 0, c, x)
		elif (x >= 50) and (c >= 1):
			return pattern(a, b, c - 1, x - 50) + pattern(a, b, 0, x)
		else:
			return 0

ans = pattern(a, b, c, x)

print(ans)

Measured memory_bytes: 3064
#include <iostream>

int main(int argc, char const *argv[]) {
  int H1, M1, H2, M2, K;
  std::cin >> H1 >> M1 >> H2 >> M2 >> K;
  int s = 60*H1 + M1;
  int f = 60*H2 + M2;
  std::cout << f - s - K << std::endl;
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace codeTester.contest190818
{
    class ProblemC
    {
        static int n = 0;
        static List<double> valueList = new List<double>();
        static string answer = "";

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            n = int.Parse(Console.ReadLine());
            valueList = ReadSpaceSeparatedValuesDobule();
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        public static List<double> ReadSpaceSeparatedValuesDobule()
        {
            List<double> values = new List<double>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(double.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            double firstValue = valueList.Min();
            double aValue = valueList.OrderBy(v => v).Aggregate(firstValue, (ans, n) => (ans + n) / 2);

            answer = aValue.ToString();
        }

        static void Output()
        {
            Console.WriteLine(answer);
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            Console.WriteLine(msg);
        }
    }
}


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

int main(){
    int N;
    ll x;
    cin >> N >> x;
    ll a[100000], ans = 0, dif;
    for(int i=0;i<N;i++){
        cin >> a[i];
        if(i == 0){
            if(a[i] > x){
                dif = a[i] - x;
                ans += dif;
                a[i] -= dif;
            }
        }else{
            if(a[i-1] + a[i] > x){
                dif = (a[i-1] + a[i]) - x;
                ans += dif;
                a[i] -= dif;
            }
        }
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int i;
  int H, N;
  int sum = 0;

  cin >> H >> N;
  
  int *A = new int[N];
  
  for(i = 0; i < N; i++){
    cin >> A[i];
  }
  
  for(i = 0; i < N; i++){
    sum += A[i];
  }
  
  if(sum >= H){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll s;
    Scll(s);


    ll ans = 114514;
    while( s > 99 ){
        ans = min<ll>( abs<ll>( s%1000 - 753 ) , ans);
        s /= 10;
    }

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


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

const ll MAX = 1e18;

void solve() {
    int n;
    cin >> n;
    vector<ll> as(n);
    F0R (i, n) cin >> as[i];
    if (count(ALL(as), 0ll)) {
	cout << 0 << endl;
	return;
    }
    ll res = 1;
    for (ll a : as) {
	if (a > MAX / res || a * res > MAX) {
	    cout << -1 << endl;
	    return;
	} 
        res *= a;
    }
    cout << res << endl;
}

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

    int tt = 1;
    FOR (t, 1, tt + 1) {
	// cout << "Case #" << t << ": ";
	solve();
    }

    return 0;
}


Measured memory_bytes: 3956
/* Filename: ABC074B.java
 * Author: Mushiyo
 */
import java.util.Scanner;

public class Main {

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

		while(input.hasNext()){
			int N = input.nextInt();
			int K = input.nextInt();
			
			int distSum = 0;
			for(int i = 0; i < N; ++i){
				int x = input.nextInt();
				
				int min = Math.min(x, K - x);
				distSum += min * 2;
			}
			
			System.out.println(distSum);
		}
	}

}


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

struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
//#define int ll

int h,w;
int d[11][11];
int num[10];

void warshall_floyd(){
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}

signed main(){
    scanf("%d%d",&h,&w);
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++) scanf("%d",&d[i][j]);
    }
    warshall_floyd();

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int tmp;
            scanf("%d",&tmp);
            if(tmp!=-1) num[tmp] ++;
        }
    }

    int ans = 0;

    ans += num[0] * d[0][1];

    for(int i=2;i<=9;i++){
        ans += num[i] * d[i][1];
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9+7;
const double PI = 3.14159265359;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll sum = 0;
	for(int i=0;i<m;i++){
		ll x;
		cin>>x;
		sum += x;
	}
	
	if(sum>n){
		cout<<"-1";
		return 0;
	}
	cout<<n - sum;
	
	
	return 0;
}
































Measured memory_bytes: 3620
/*Author - Saikia*/
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define N 998244353
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define INF 1000000000
 
ll modInverse(ll a, ll m);
ll power(ll x, unsigned ll y, unsigned ll m);
ll logint(ll x,ll y); 
ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {// q is quotient
        ll q = a / m;
        ll t = m;
        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y; 
        // Update y and x
        y = x - q * y;
        x = t;
    }
    // Make x positive
    if (x < 0)
       x += m0;
    return x;
}
void pairsort(ll a[],ll b[], ll n)
{   pair<ll, ll> pairt[n];
    // Storing the respective array
    // elements in pairs.
    for (ll i = 0; i < n; i++)
    {   pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    // Sorting the pair array.
    sort(pairt, pairt + n);
    // Modifying original arrays
    for (ll i = 0; i < n; i++)
    {   a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll logint(ll x,ll y)
{   ll ans=0;
    ll a=1;
    for(ll i=0;i<x;i++)
    {   if(x<=a)
        {    return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n, k;
    cin>>n>>k;
    ll  ar[n];
    REP(i, 0, n){
        cin>>ar[i];
    }
    bool dp[k+1];
    memset(dp, false, sizeof(dp));
    dp[0] = true;
    REP(i, 1, k+1){
        for(auto x:ar){
            if(i-x > 0 && !dp[i-x]){dp[i] = true;}
            else if(i==x){dp[i] = true;}
        }
    }
    if(dp[k]){cout<<"First";}
    else{cout<<"Second";}
}


Measured memory_bytes: 384
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int min = 10000;
		for(int i = 0; i < s.length() - 2; i++){
			String s2 = s.substring(i,i+3);
			int num = Integer.parseInt(s2);
			if(min > Math.abs(753 - num)){
				min = Math.abs(753 - num);
			}
		}
		System.out.print(min);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
void allcout(auto V) {
    for(auto x : V) cout << x << ' ';
    cout << endl;
}
signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N, vector<int>(N, -1));
    vector<vector<int>> dis(N, vector<int>(N, INF));
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a][b] = c;
        G[b][a] = c;
        dis[a][b] = c;
        dis[b][a] = c;
    }
    rep(k, N) rep(i, N) rep(j, N) {
        chmin(dis[i][j], dis[i][k] + dis[k][j]);
    }
    int ans = 0;
    for(int i = 0; i < N; i++)
        for(int j = i + 1; j < N; j++) {
            if(G[i][j] == -1) continue;
            if(G[i][j] > dis[i][j]) ans++;
        }
    cout << ans << endl;
}


Measured memory_bytes: 384
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

ll nC2(ll n){
    return (n*(n-1))/2;
}
int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    ll n;
    cin>>n;
    ll a[n], cnt[n+1]={0};
    for(ll i=0;i<n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    //for(ll i=1;i<=n;i++)   cout<<cnt[i]<<" ";
    //cout<<"\n";
    ll comp[n+1] = {0};
    for(ll i=1;i<=n;i++){
        if(cnt[i]>0)    comp[i] += nC2(cnt[i]);
        comp[i] += comp[i-1];
        //cout<<comp[i]<<endl;
    }

    for(ll i=0;i<n;i++){
        ll sum=comp[n] - (cnt[a[i]]-1);
            //if(a[i]==j && cnt[j]>0) num--;
            //cout<<"--- "<<num<<endl;
            //if(num>0)
            //    sum += nC2(num);
        //}
        cout<<sum<<endl;
    }
    return 0;
}



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

int n,b,zero;
long long a,product,arr[100001];
bool large;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	product = 1;
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
		if(arr[i] == 0) zero++;
	}
	for(int i = 1;i <= n;i++){
		if(zero < 1){
			if(product <= 1000000000000000000 / arr[i]){
				product = product * arr[i];
			}
			else{
				large = true;
				cout<<-1<<endl;
				break;
			}
		}else{
			cout<<0<<endl;
			large = true;
			break;
		}
	}
	if(!large){
		cout<<product<<endl;
	}
}


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

constexpr int MAX = 1000;
int dp[MAX+1][MAX+1];

int main() {
  int N;
  cin >> N;
  for (int n{}; n < N; ++n) {
    string s, t;
    cin >> s >> t;
    for (size_t i{}; i < s.length(); ++i) {
      for (size_t j{}; j < t.length(); ++j) {
        if (s[i] == t[j])
          dp[i+1][j+1] = dp[i][j] + 1;
        else
          dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
    cout << dp[s.length()][t.length()] << endl;
  }
  return 0;
}



Measured memory_bytes: 7092
#include <iostream>
#include<bits/stdc++.h>
#define int long long int
#define e 1000000007
using namespace std;

 
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 int n;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }int sum =0 ;
 for(int i=1;i<n;i++){
    if(a[i] < a[i-1] ){
        int d = a[i-1]-a[i];
        sum += d;
        a[i] += d;
    }
 }
 cout<<sum;
}

Measured memory_bytes: 5188
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	if(n == 1)puts("Hello World");
	else{
		int a, b;
		cin >> a >> b;
		cout << a + b << '\n';
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using Int = long long;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main()
{
    Int X, Y; cin >> X >> Y;
    if (abs(X - Y) == 0 || abs(X - Y) == 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
B = [list(map(int, input().split())) for i in range(n)]
A = [int(input()) for i in range(m)]

for i in range(n) :
    ans = 0
    for j in range(m) :
        ans += A[j] * B[i][j]
    print(ans)    


Measured memory_bytes: 6012
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
    int n;
    cin >> n;
    int cc = n;
    int a = 0;
    while (cc != 0)
    {
        a += cc % 10;
        cc /= 10;
    }
    if (n % a == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

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

    ll sol = 0;
    for(int i=0; i<n; i++)
        sol += a[i]-1;
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;

    int ans = (1900 * m + 100 * (n - m)) * (1 << m);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,flag=1,i,x=0,y=0,s,c=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        int a,b,t,z;
        scanf("%d%d%d",&t,&a,&b);
        z=t;
        t=t-c;
        if(t<0)
            t=-t;
        s=a+b-x-y;
        if(s<0)
            s=-s;
        if(t-s>=0)
        {
            if((t-s)%2!=0)
            {
                flag=0;
                printf("No\n");
                break;
            }
            x=a;y=b;c=z;
        }
        else
        {
            flag=0;
            printf("No\n");
            break;
        }

    }
    if(flag)
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int N, K;
  cin >> N >> K;

  vector<int> V(N);
  for(int i = 0; i < N; i++) cin >> V[i];

  int ans = 0;


  for(int i = 0; i <= K; i++){
    for(int j = 0; i+j <= K; j++){
      if(i+j > N) continue;
      if(i+j == 0) continue;
      int sum = 0;
      vector<int> have;
      for(int k = 0; k < i; k++){
        have.push_back(V[k]);
      }
      for(int k = 0; k < j; k++){
        have.push_back(V[N-1-k]);
      }
      sort(have.begin(), have.end());
      int rest = K - i - j;
      int start = 0;
      while(rest > 0){
        if(have[start] < 0){
          start += 1;
          rest -= 1;
        } else {
          break;
        }
        if(start == i+j) break;
      }

      for(;start < i+j; start++){
        sum += have[start];
      }

      if(sum > ans) ans = sum;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

a = raw_input()
a = a.split()
a = map(int,a)

count_2 = 0
count_4 = 0

for i in a:
    if i % 4 == 0:
        count_4 += 1
    elif i % 2 == 0:
        count_2 += 1

if count_4 >= n/2:
    print "Yes"
elif count_4*2 + count_2 >= n:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 11296
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vl b = a;
    for (int i = 0; i < n; ++i) {
        b[i] = max(b[i], 0LL);
    }
    for (int i = 1; i < n; ++i) {
        b[i] += b[i - 1];
        a[i] += a[i - 1];
    }
    ll ret = 0;
    for (int i = 0; i < n - k + 1; ++i) {
        ll temp = a[i + k - 1];
        temp += b[n - 1] - b[i + k - 1];
        if (i != 0) {
            temp -= a[i - 1];
            temp += b[i - 1];
        }
        chmax(ret, temp);
        temp = b[n - 1] - b[i + k - 1];
        if (i != 0) {
            temp += b[i - 1];
        }
        chmax(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1792
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.08 17:35:29
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



struct StronglyConnectedComponents {
private:
    vector<vector<int>> g, rg;
    vector<int> order; 
    vector<bool> visited;
    int V;
    void dfs(int v) {
        if (visited[v]) return;
        visited[v] = true;
        for (int u : g[v]) dfs(u);
        order.push_back(v);
    }
    void rdfs(int v, int c) {
        if (comp[v] != -1) return;
        comp[v] = c;
        for (int u : rg[v]) rdfs(u, c);
    }
public:
    vector<vector<int>> Graph; 
    vector<int> comp; 
    StronglyConnectedComponents(int v) : V(v) {
        g.resize(v);
        rg.resize(v);
        visited.resize(v);
        comp.resize(v);
    }
    void add_edge(int from, int to) {
        g[from].push_back(to);
        rg[to].push_back(from);
    }
    void build() {
        Graph = vector<vector<int>>();
        order = vector<int>();
        visited.assign(V, false);
        comp.assign(V, -1);
        for (int i = 0; i < V; i++) dfs(i);
        reverse(order.begin(), order.end());
        int number = 0;
        for (int i = 0; i < V; i++) {
            if (comp[order[i]] == -1) {
                rdfs(order[i], number++);
            }
        }
        Graph.resize(number);
        for (int i = 0; i < V; i++) {
            for (int v : g[i]) {
                if (comp[i] == comp[v]) continue;
                Graph[comp[i]].push_back(comp[v]);
            }
        }
    }
};
int main() {
    int n,d;cin >> n >> d;
    vector<int> x(n),y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    StronglyConnectedComponents scc(2 * n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (abs(x[i] - x[j]) < d) {
                scc.add_edge(i,j+n);
                scc.add_edge(j,i+n);
            }
            if (abs(x[i] - y[j]) < d) {
                scc.add_edge(i,j);
                scc.add_edge(j+n,i+n);
            }
            if (abs(y[i] - x[j]) < d) {
                scc.add_edge(i+n,j+n);
                scc.add_edge(j,i);
            }
            if (abs(y[i] - y[j]) < d) {
                scc.add_edge(i+n,j);
                scc.add_edge(j+n,i);
            }
        }
    }
    scc.build();
    bool ok = true;
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if (scc.comp[i] == scc.comp[i+n]) {
            ok = false;
            break;
        }
        else {
            if (scc.comp[i] > scc.comp[i + n]) {
                ans.push_back(x[i]);
            }
            else {
                ans.push_back(y[i]);
            }
        }
    }
    if (ok) {
        puts("Yes");
        for (int i = 0; i < n; i++) {
            cout << ans[i] << endl;
        }
    }
    else puts("No");
    return 0;
}

Measured memory_bytes: 3932
def f(b, n):
    if n < b:
        return n
    else:
        q, r = divmod(n, b)
        return f(b, q) + r

n = int(input())
s = int(input())
if n == s:
    print(n+1)
else:
    b = 2
    while b*b <= n:
        if f(b, n) == s:
            print(b)
            break
        b += 1
    else:
        p = 1
        ans = 10**13
        while p*p <= n:
            b = (n - s) // p + 1
            if p < b and s - p < b and f(b, n) == s:
                ans = min(ans, b)
            p += 1
        if ans == 10**13:
            print(-1)
        else:
            print(ans)

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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    int tmp = INF;
    rep(i,S.size()){
        bool flag = true;
        rep(j,T.size()) {
            if(i+j > (int)S.size()-1 || (S[i+j] != T[j] && S[i+j] != '?')) {
                flag = false;
                break;
            }
        }
        if(flag) {
            tmp = i;
            break;
        }
    }

    if(tmp == INF){
        cout << "UNRESTORABLE";
        return 0;
    }

    rep(i,S.size()){
        if(i < tmp || i > tmp + (int)T.size() -1){
            ans += (S[i]!='?'?S[i]:'a');
        } else {
            ans += T[i-tmp];
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


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

using namespace std;
int x[200010],y[200010];
vector<int> v[200010];
set<int> st[200010];
int main(){
	int i,h,w,n,ans = 200010;
	cin >> h >> w >> n;
	for(i=0;i<n;i++){
		cin >> x[i] >> y[i];
		v[y[i]].push_back(x[i]);
		st[y[i]].insert(x[i]);
	}
	for(i=1;i<=h;i++){
		sort(v[i].begin(),v[i].end());
		v[i].push_back(h+1);
	}
	int s = 1,t = 1,res = 0;
	for(i=1;i<=h;i++){ 
		auto it = upper_bound(v[t].begin(),v[t].end(),s);
		int k = *it;
		ans = min(ans,res + k - s);
		if(k==s+1) break;
		s++;
		if(!st[t+1].count(s) && t<w) t++;
		res++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 31872
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

n,k,q=invr()

ara=[k]*n

for i in range(q):
	x=inp()
	x-=1
	ara[x]+=1

for i in range(n):
	if ara[i]-q>0:
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 11656
N, M = map(int, input().split())
K, S = [], []
for _ in range(M):
	k, *s = map(int, input().split())
	K.append(k)
	S.append(list(map(lambda x: x-1, s)))
p = list(map(int, input().split()))
res = 0
for i in range(1<<N):
	flag = True
	for j in range(M):
		cnt = 0
		for k in S[j]:
			if (i >> k) & 1:
				cnt += 1
		if cnt%2 != p[j]:
			flag = False
			
	if flag: res += 1
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
#define int long long

#define fr(s,n,i) for(int i=s;i<n;i++)
#define fr_(s,n,i) for(int i=s;i>=n;i--)

int MOD = 1000000007;

void solve();

signed main() {
    solve();
    return 0;
}

void solve(){
    int a,b;
    cin >> a >> b;
    if(b%a){
        cout << b-a;
    } else {
        cout<<a+b;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int i;
string str;
int Expression();
int Term();
int Factor();
int No(int);
int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> str;
    i = 0;
    cout << Expression() << endl;
  }
}
int Expression(){
  int res = Term();
  while(1){
    switch(str[i]){
    case '+':
      i++;
      res += Term();
      break;
    case '-':
      i++;
      res -= Term();
      break;
    default:
      return res;
    }
  }
}
int Term(){
  int res = Factor();
  while(true){
    switch(str[i]){
    case '(':
      i++;
      res += Factor();
      break;
    case '*':
      i++;
      res *= Factor();
      break;
    case '/':
      i++;
      res /= Factor();
      break;
    default:
      return res;
    }
  }
}
int Factor(){
  int res = 0;
  switch(str[i]){
  case '(':
    i++;
    res = Expression();
    i++;
    return res;
  default:
    return No(i);
  }
}
int No(int old){
  while(isdigit(str[i])) i++;
  return atoi((str.substr(old,i)).c_str());
}

Measured memory_bytes: 1220
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  ll h[NN], cost[NN];

  for (size_t i = 0; i < NN; i++) {
    std::cin >> h[i];
    cost[i] = 0;
  }

  cost[0] = 0;
  cost[1] = abs(h[1]-h[0]);

  for (size_t i = 2; i < NN; i++) {
    ll cost1, cost2;
    cost1 = cost[i-1] + abs(h[i]-h[i-1]);
    cost2 = cost[i-2] + abs(h[i]-h[i-2]);

    if (cost1>cost2) {
      cost[i] = cost2;
    }else{
      cost[i] = cost1;
    }
  }

  // std::cout << "print cost ---------" << '\n';
  // for (size_t i = 0; i < NN; i++) {
  //   std::cout << cost[i] << '\n';
  // }
  // 
  // std::cout << "print h ---------" << '\n';
  // for (size_t i = 0; i < NN; i++) {
  //   std::cout << h[i] << '\n';
  // }

  std::cout << cost[NN-1] << '\n';


  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
ll n;
cin>>n;
ll sum = 0;
vcl a(n);
for(ll i = 0;i < n;i++){
    cin >> a[i];
    sum += a[i];
    sum %= mod;
}
ll ans = 0;
for(ll i = 0;i < n;i++){
    sum -= a[i];
    if(sum<0) sum += mod;
    ans += a[i]*sum;
    ans %= mod;
}

cout << ans << endl;
}


Measured memory_bytes: 4756
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func solve(nums []int) float64 {
	return float64(nums[0]*nums[1]) * 0.5
}

func main() {
	in := read()
	nums := []int{}
	for _, c := range strings.Split(in, " ") {
		n, _ := strconv.Atoi(c)
		nums = append(nums, n)
	}
	ans := solve(nums)
	fmt.Println(ans)
}

Measured memory_bytes: 640
var body = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (chunk) {
    body += chunk;
});

process.stdin.on('end', function () {
    var data = body.split('\n');
    var output = [];
    for(var i = 0; i < data.length; i++) {
        if(0 != data[i]) {
            output.push('Case ' + (i + 1) + ': ' + data[i]);
        }
    }
    console.log(output.join('\n'));
});

Measured memory_bytes: 19364
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <sstream>

using namespace std;

/*
// atcoder to_stringは使えるっぽい？
string to_string(int i){
  stringstream ss;
  ss << i;
  return ss.str();
}
*/

int main(){
  int H, W;
  int N;
  cin >> H >> W >> N;
  string outstr[H];
  int c = 0;
  int r = 0;
  for(int i=0;i<N;++i){
    int p;
    cin >> p;
    while(p>0){
      //cout<<"inp,"<<W<<","<<r<<","<<p<<endl;
      int wnum = min(W-r,p); //幾つ書き込むか
      if(c%2==0){
	for(int j=0;j<wnum;++j){
	  outstr[c] += to_string(i+1);
	  if(r != W-1){
	    outstr[c] += " "; // 一番最後にスペースを入れない
	  }
	  r+=1;
	}
      }else{
	for(int j=0;j<wnum;++j){
	  if(r!=0){
	    outstr[c] = to_string(i+1)+" " + outstr[c];
	  }else{
	    outstr[c] = to_string(i+1);
	  }
	  r+=1;
	}
      }
      p-=wnum;
      //cout<<wnum<<","<<c<<","<<r<<","<<p<<endl;
      if(r==W){
	c++;
	r=0;
      }

    }
  }
  for(int i=0;i<H;++i){
    cout<<outstr[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <limits.h>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

#include <bits/stdc++.h>

namespace test {
std::string to_string(char val) {
    return std::string(1, val);
    // return std::string{val};
}
}  // namespace test

using namespace std;

int main(void) {
    int n; int *a; cin >> n; a = new int[n+2]; for(int i = 1; i <= n; i++) cin >> a[i];
    int result = 1;

    int *left, *right; left = new int[n+2], right = new int[n+2];

    for(int i = 1; i <= n; i++){
        left[i] = __gcd(a[i], left[i - 1]);
    }

    for(int i = n; i >= 0; i--){
        right[i] = __gcd(a[i], right[i + 1]);
    }

    for(int i = 1; i <=n; i++){
        result = max( __gcd(left[i - 1],right[i + 1]) , result);
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1408