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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

long long pref[200005];

long long sum(int i, int j) {
    return pref[j] - pref[i-1];
}

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

    int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> pref[i];
        pref[i] += pref[i-1];
    }

    long long ret = LLONG_MAX;
    for (int i=3, j=2, k=4; i<=n-1; i++) {
        while (j + 1 < i && sum(1, j) <= sum(j + 1, i - 1))
            j++;
        while (k + 1 <= n && sum(i, k) <= sum(k + 1, n))
            k++;
        for (int a : {j, j + 1})
            if (a < i)
                for (int b : {k, k + 1})
                    if (b <= n)
                        ret = min(ret, max({sum(1, a - 1), sum(a, i - 1), sum(i, b - 1), sum(b, n)})
                                    - min({sum(1, a - 1), sum(a, i - 1), sum(i, b - 1), sum(b, n)}));
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 5212
#include <stdio.h>

int main(){
  int i,n,crda,crdb,scra,scrb;
  while(scanf("%d",&n)){
    if(n==0)break;
    scra=0;scrb=0;
    for(i=0;i<n;i++){
      scanf("%d %d",&crda,&crdb);
      if(crda>crdb)scra+=crda+crdb;
      else if(crda<crdb)scrb+=crda+crdb;
      else {scra+=crda;scrb+=crdb;}
    }
    printf("%d %d\n",scra,scrb);
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

//AtCoder Beginner Contest 155
//B	Papers, Please
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(sc.next());

		}
		sc.close();

		String ans = "APPROVED";
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 0) {
				if (A[i] % 3 != 0 && A[i] % 5 != 0) {
					ans = "DENIED";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
const ll mod=998244353;
typedef pair<ll,ll>P;
int n;
P a[N];
ll dp[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
        scanf("%lld%lld",&a[i].first,&a[i].second);
    sort(a+1,a+1+n);
    dp[n+1]=1;
    stack<P>st;
    for(int i=n;i;i--){
        ll x=a[i].first+a[i].second,mox=i+1;
        while(st.size()&&x>st.top().first){
            mox=st.top().second;
            st.pop();
        }
        st.push(P(a[i].first,mox));
        dp[i]=(dp[i+1]+dp[mox])%mod;
    }
    cout<<dp[1]<<endl;
	return 0;
}


Measured memory_bytes: 6528
import sys
input=sys.stdin.readline

n=int(input())
a=[]
for i in range(n):
    a+=[tuple(map(int,input().split()))]
a.sort(key=lambda x:(x[1],x[0]))

cnt=0
ans='Yes'
for k,v in a:
    cnt+=k
    if cnt>v:
        ans='No'
        break
print(ans)



Measured memory_bytes: 44524
#include <iostream>
#include <vector>

const long long INF = 1LL << 60;
// long long early = 0;
long long h[100010];
long long dp[100010];

long long calc_dist(int n)
{
    if (n == 1) return 0;
    if (dp[n] != INF) {
//         early++;
        return dp[n];
    }
    if (n == 2) return dp[n] = abs(h[n] - h[n-1]);
    return dp[n] = std::min(calc_dist(n-1) + abs(h[n] - h[n-1]), calc_dist(n-2) + abs(h[n] - h[n-2]));
}

int main()
{
    int n;
    std::cin >> n;
    for (int i = 1; (i <= n); ++i) {
        std::cin >> h[i];
        dp[i] = INF;
    }
    std::cout << calc_dist(n) << std::endl;
//     std::cout << early << std::endl;
    return 0;
}


Measured memory_bytes: 3328
n,k=map(int,input().split())
p=list(map(int,input().split()))
e=0
for i in range(k):
  e+=p[i]
f=e
for i in range(n-k):
  f=f-p[i]+p[i+k]
  e=max(e,f)
print((e+k)/2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#include <queue>
#include <cstring>
#define mp make_pair
#define pb push_back
#define p push

#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long int

#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld%lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);

#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE 1000000007
#define MAXN 100005

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;



int main(){
    IOS
ll n,d;
   cin >> n;
   vi vec;
   vi vec2;
    for (int cur,i = 0; i <n ; ++i) {
             cin >> cur;
             vec.pb(cur);
             vec2.pb(cur);
    }
    sort(BEND2(vec));
    for (int j = 0; j <vec2.size() ; ++j) {
        if(vec2[j] == vec[0])cout << vec[1]<<"\n";
        else cout << vec[0]<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3436
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
string S;
vector<pair<char, int>> v;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  cin >> S;
  int i = 0;
  while (i < N) {
    char c = S[i];
    int cnt = 1;
    i++;
    while (i < N && S[i] == c) {
      cnt++;
      i++;
    }
    v.push_back(make_pair(c, cnt));
  }

  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += (v[i].second - 1);
  }

  int cnt = 0;
  for (int i = 1; i < v.size() - 1; i += 2) {
    if (cnt < K) {
      ans += 2;
    }
    cnt++;
  }
  if (cnt < K && v.size() % 2 == 0) {
    ans++;
  }

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

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

int main() {
 string s;
  cin >> s;
  vector<int> v(s.size());
  int x=0;
  for (int i=0;i<s.size();i++){
    if (s.at(i)=='A')
      v.at(x)++;
      else if (s.at(i)=='C')
       v.at(x)++;
         else if (s.at(i)=='G')
           v.at(x)++;
            else if (s.at(i)=='T')
              v.at(x)++;
    else x++;
  }
  sort(v.begin(),v.end());
  reverse(v.begin(), v.end());
  cout <<v.at(0);
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(n<a)
    {
        cout<<n<<endl;
        return 0;
    }
    n=n-a;
    n=n%b;
    cout<<n<<endl;
    return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n = 5;
    int s = 1+2+3+4+5;
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        s -= v;
    }
    cout << s << endl;
}



Measured memory_bytes: 3600
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool a=false, b=false, c=false;
  for(int i=0; i<3; i++){
    if( s[i] == 'a' ) a=true;
    if( s[i] == 'b' ) b=true;
    if( s[i] == 'c' ) c=true;
  }
  if( a && b && c ) printf("Yes\n");
  else printf("No\n");


  return 0;
  
}


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

int main () {
    int N, M; cin >> N >> M;
    vector<string> A(N); rep(i, N) cin >> A[i];
    vector<string> B(M); rep(i, M) cin >> B[i];

    bool can = false;
    for (int l = 0; l <= N-M; l++) {
        for (int k = 0; k <= N-M; k++) {
            bool can2 = true;
            rep(i, M) {
                rep(j, M) {
                    if (A[i+k][j+l] != B[i][j]) can2 = false;  
                }
            }
        if (can2) can = true;
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
///FUCKOUT
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<ll, ll>;

#define int ll

const int N = 1e5+5, M = 1e6 + 5, LG = 17, MOD = 1e6 + 3;
const int BLOCK = 55;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;
using ull = unsigned long long;

typedef long long LL;
map<int,int> mp;
int dp[105][105][305];
int w[105];
int v[105];
int n, W;
int solve(int idx, int cnt, int wt){
  if(idx == n)
    return 0;
  int &ret = dp[idx][cnt][wt];
  if(~ret)
    return ret;
  ret = solve(idx+1,cnt,wt);
  if(cnt && wt >= w[idx] - w[0])
    ret = max(ret, solve(idx+1,cnt-1,wt - w[idx] + w[0]) + v[idx]);
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> n >> W;

  memset(dp,-1,sizeof dp);

  f(i,0,n){
    cin >> w[i] >> v[i];
  }
  int ans = 0;
  f(i,0,n+1)if(1ll * w[0] * i <= W){
    ans=max(ans,solve(0,i,min(3*i,W-w[0]*i)));
  }
  cout << ans << '\n';

  return 0;
}


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

long long gcd(long long a,long long b)
{
    long long temp;
    while(b)
    {    
        temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int main()
{
	long long n,m;
	cin>>n>>m;
	long long l=n*m/gcd(n,m);
	//cout<<l;
	string s,t;
	cin>>s;
	cin>>t;
	//cout<<s;
	//cout<<t;
	
	long long ln=l/n;
	long long lm=l/m;
	long long t1=0,t2=0;
	long long flag=1;
	while(t1<n && t2<m)
	{
		if(t1*ln<t2*lm) t1++;
		else if(t1*ln>t2*lm) t2++;
		else{
			if(s[t1] != t[t2]){
				flag=0;
				break;
			}
			else{
				t1++;
				t2++;
			}
		}
	}
	if(flag)
	{
		
		
			cout<<l<<'\n';
		
	}
	else cout<<"-1"<<'\n';
	
	
	
	return 0;	
} 

Measured memory_bytes: 512
h,w,n = map(int, input().split())
stage = [input() for i in range(h)]
starts = [str(i) for i in range(n)]
goals = [str(i+1) for i in range(n)]
starts_y = [0 for i in range(n)]
starts_x = [0 for i in range(n)]
goals_y = [0 for i in range(n)]
goals_x = [0 for i in range(n)]

starts[0] = "S"
for y in range(h):
	for x in range(w):
		if stage[y][x] in starts:
			starts_y[starts.index(stage[y][x])] = y
			starts_x[starts.index(stage[y][x])] = x
		if stage[y][x] in goals:
			goals_y[goals.index(stage[y][x])] = y
			goals_x[goals.index(stage[y][x])] = x

move_y = [1,-1,0,0]
move_x = [0,0,1,-1]
sum = 0

for start_y, start_x, goal_y, goal_x in zip(starts_y, starts_x, goals_y, goals_x):
	bfs_map = [[-1 for j in range(w)] for i in range(h)]
	data_y = [start_y]
	data_x = [start_x]
	bfs_map[start_y][start_x] = 0
	goal = False
	
	while len(data_y) != 0 and not goal:
		y = data_y.pop(0)
		x = data_x.pop(0)
		goal = False
	
		for i in range(4):
			ny = y + move_y[i]
			nx = x + move_x[i]
			
			if ny >= 0 and ny < h and nx >= 0 and nx < w:
				if bfs_map[ny][nx] == -1 and stage[ny][nx] != "X":
					bfs_map[ny][nx] = bfs_map[y][x]+1
					data_y.append(ny)
					data_x.append(nx)
			if bfs_map[goal_y][goal_x] != -1:
				sum += bfs_map[goal_y][goal_x]
				goal = True
				break

print(sum)


Measured memory_bytes: 36504
import sys
sys.setrecursionlimit(10**7)
def main(n,ki,uv):
  # n: 頂点数
  # ki: 木
  # Euler Tour の構築
  S=[] # Euler Tour
  F=[0]*n # F[v]:vにはじめて訪れるステップ
  depth=[0]*n # 0を根としたときの深さ
  def dfs(v,pare,d):
      F[v]=len(S)
      depth[v]=d
      S.append(v)
      for i,w in ki[v]:
          if w==pare:continue
          dfs(w,v,d+1)
          S.append(v)
  dfs(0,-1,0)
  # Sをセグメント木に乗せる
  # u,vのLCAを求める:S[F[u]:F[v]+1]のなかでdepthが最小の頂点を探せば良い
  # F[u]:uに初めてたどるつくステップ
  # S[F[u]:F[v]+1]:はじめてuにたどり着いてつぎにvにたどるつくまでに訪れる頂点
  # 存在しない範囲は深さが他よりも大きくなるようにする
  INF = (n, None)
  # LCAを計算するクエリの前計算
  M = 2*n
  M0 = 2**(M-1).bit_length() # M以上で最小の2のべき乗
  data = [INF]*(2*M0)
  for i, v in enumerate(S):
    data[M0-1+i] = (depth[v], i)
  for i in range(M0-2, -1, -1):
    data[i] = min(data[2*i+1], data[2*i+2])
  # LCAの計算 (generatorで最小値を求める)
  def _query(a, b):
    yield INF
    a += M0; b += M0
    while a < b:
      if b & 1:
        b -= 1
        yield data[b-1]
      if a & 1:
        yield data[a-1]
        a += 1
      a >>= 1; b >>= 1
  # LCAの計算 (外から呼び出す関数)
  def query(u, v):
    fu = F[u]; fv = F[v]
    if fu > fv:
      fu, fv = fv, fu
    return S[min(_query(fu, fv+1))[1]]
  

  todo=[[0,[]]]
  path=[[]]*n
  mi=[1]*n
  while todo:
    v,ary=todo.pop()
    path[v]=ary
    mi[v]=0
    for i,nv in ki[v]:
      if mi[nv]==1:
        todo.append([nv,ary+[i]])
        mi[nv]=1
  #print(path)
  for i in range(n):
    path[i]=set(path[i])
  memo={}
  ans=0
  for i in range(2**m):
    chk=set(())
    for j in range(m):
      if (i>>j)&1:
        chk.add(j)
    must_w=set(())
    for c in chk:
      if c in memo:
        tmp=memo[c]
      else:
        u,v=uv[c]
        dd=query(u,v)
        tmp=path[u].union(path[v])
        tmp=tmp-path[dd]
        memo[c]=tmp
      must_w=must_w.union(tmp)
    t=n-1-len(must_w)
    if len(chk)%2==1:
      ans-=pow(2,t)
    else:
      ans+=pow(2,t)
  print(ans)
if __name__=='__main__':
  n=int(input())
  ki=[[] for _ in range(n)]
  for i in range(n-1):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    ki[u].append([i,v])
    ki[v].append([i,u])
  m=int(input())
  uv=[]
  for _ in range(m):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    uv.append([u,v])
  main(n,ki,uv)


Measured memory_bytes: 75516
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-6;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

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

int n,v[55];
double ans;
main() {
    file("walk");
    ios;
    cin>>n;
    fo(i,1,n,1) cin>>v[i];
    sort(v+1,v+n+1);
    ans=v[1]+0.0;
    fo(i,2,n,1) ans+=0.0+v[i],ans*=0.5;
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}
/**

*/


Measured memory_bytes: 256
n = int(input())
ans1=1 
ans2=1
ans3=1

mod = 1000000007

for i in range(n):
    ans1 = (ans1*10)%mod
    
for i in range(n):
    ans2 = (ans2*9)%mod

for i in range(n):
    ans3 = (ans3*8)%mod

print((ans1-2*ans2+ans3)%mod)

Measured memory_bytes: 9172
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = nextInt()
	}

	ans := 0
	tmp := 0
	r := 0
	for l := 0; l < n; l++ {
		for r < n && tmp^as[r] == tmp+as[r] {
			tmp += as[r]
			r++
		}

		ans += r - l

		if l == r {
			r++
		} else {
			tmp -= as[l]
		}
	}

	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int max3 = max(A,max(B,C))*3;
  int ans =0;
  
  int check = A + B + C;
  
  while(1){
    if(max3 <= check){
      if(check %3 ==0){
        break;
      }
    }
    check += 2;
    ans++;
  }
  
  cout << ans << endl;
}


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

using namespace std;
int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int k;
  cin >> k;
  if (e - a <= k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cassert>
#include <queue>
#include <utility>
#include <type_traits>
#include <algorithm>

/*
last-updated: 2020/03/03

辺の容量は非負の実数である必要がある。

Dinic(size_type n) : 頂点数を n とする

size_type size() const noexcept : 頂点数を返す
void add_edge(size_type i, size_type j, value_type c) : u -> v へ容量 c の辺を張る
value_type max_flow(size_type s, size_type t) : O(V^2 E) s -> t の最大フローを返す
*/

template<typename T>
struct Dinic {
public:
	using value_type = T;
	using size_type = std::size_t;
	
	Dinic(size_type n) : g(std::vector<std::vector<Edge>>(n)) {}
	
	size_type size() const noexcept { return g.size(); }
	
	void add_edge(size_type i, size_type j, value_type c) {
		assert(i < size() && j < size() && c >= 0);
		g[i].push_back({j, g[j].size(), c});
		g[j].push_back({i, g[i].size() - 1, 0});
	}
	
	value_type max_flow(size_type s, size_type t) {
		value_type res = 0;
		while (bfs(s), ~level[t]) {
			iter.assign(size(), 0);
			value_type f;
			while ((f = dfs(s, t, INF)) > EPS) res += f;
		}
		return res;
	}
	
private:
	struct Edge { size_type to, rev; value_type c; };
	std::vector<std::vector<Edge>> g;
	static constexpr value_type EPS = std::is_floating_point<value_type>() ? 1e-6 : 0;
	static constexpr value_type INF = 1e9 + 100;
	std::vector<size_type> iter, level;
	
	void bfs(size_type s) {
		level.assign(size(), -1);
		std::queue<size_type> que;
		que.push(s);
		level[s] = 0;
		while (!que.empty()) {
			size_type u = que.front(); que.pop();
			for (Edge & e : g[u]) {
				if (e.c <= EPS || ~level[e.to]) continue;
				que.push(e.to);
				level[e.to] = level[u] + 1;
			}
		}
	}
	
	value_type dfs(size_type u, size_type t, value_type f) {
		if (u == t) return f;
		for (size_type & i = iter[u]; i < g[u].size(); ++i) {
			const Edge & e = g[u][i];
			if (e.c <= EPS || level[u] >= level[e.to]) continue;
			value_type cur = dfs(e.to, t, std::min(f, e.c));
			if (cur > EPS) {
				g[u][i].c -= cur;
				g[e.to][e.rev].c += cur;
				return cur;
			}
		}
		return 0;
	}
};

#include <cstdio>

int main() {
	int V, E;
	scanf("%d %d", &V, &E);
	Dinic<int> dinic(V);
	while (E--) {
		int u, v, c;
		scanf("%d %d %d", &u, &v, &c);
		dinic.add_edge(u, v, c);
	}
	printf("%d\n", dinic.max_flow(0, V - 1));
	return 0;
}


Measured memory_bytes: 2856
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> cnt;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        cnt[A[i]]++;
    }
    // (cnt, ele)
    vector<P> temp;
    for(auto it = cnt.begin(); it != cnt.end(); ++it){
        temp.push_back(P(it->second, it->first));
    }
    
    cout << (temp.size() % 2 == 0 ? temp.size() - 1 : temp.size()) << endl;
}


Measured memory_bytes: 6520
//https://vjudge.net/contest/335628#problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 100005;
vi lst;
int n;

bool compare(int a, int b){
    return a > b;
}

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int maxPower = 0, h;
    int cnt = 0;
    cin >> n >> h;
    //debug(n); debug(h);
    rep(i, 1, n){
        int a, b; cin >> a >> b;
        maxPower = max(a, maxPower);
        lst.pb(b);
    }
    //debug(maxPower);
    sort(all(lst), compare);
    foreach(v, lst){
        if(v <= maxPower) break;
        h -= v;
        cnt++;
        if(h <= 0) break;
    }
    if(h <= 0){
        cout << cnt;
        return 0;
    }
    //debug(h); debug(maxPower);
    cnt += ceil(1.0 * h/maxPower);
    cout << cnt;
    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(register int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**********head by yjjr**********
#define pb push_back
#define inf 1e9
const int maxn=66,maxm=1e6+6,dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},mod=1e9+7;
struct node{int x,y;}a[maxn<<1],que[maxn*maxn*4];
int n,m,K,ans,lx,ly,cnt[maxn][maxn],s1[maxm],s2[maxm],dis[maxn][maxn],head,tail;
bool fb[maxn][maxn],mark1[maxm],mark2[maxm];
vector<int>px,py;
void vnique(vector <int> &r){
    sort(r.begin(),r.end());
    auto t=unique(r.begin(),r.end());
    r.erase(t,r.end());
}
void bfs(int x,int y){
    rep(i,0,lx)rep(j,0,ly)dis[i][j]=inf;
    dis[x][y]=0;que[head=tail=1]=(node){x,y};
    while(head<=tail){
        int nx=que[head].x,ny=que[head++].y;
        rep(i,0,3){
            int nex=nx+dx[i],ney=ny+dy[i];
            if(nex>lx||nex<0||ney>ly||ney<0||dis[nex][ney]<=dis[nx][ny]+1||fb[nex][ney])continue;
            dis[nex][ney]=dis[nx][ny]+1;que[++tail]=(node){nex,ney};
        }
    }
}
int main()
{
    n=read(),m=read(),K=read();
    px.pb(1);px.pb(n+1);py.pb(1);py.pb(m+1);
    rep(i,1,n)s1[i]=m;
    rep(i,1,m)s2[i]=n;
    rep(i,1,K){
        a[i].x=read()+1,a[i].y=read()+1;
        px.pb(a[i].x),px.pb(a[i].x+1);
        py.pb(a[i].y),py.pb(a[i].y+1);
        s1[a[i].x]--,mark1[a[i].x]=1;
        s2[a[i].y]--,mark2[a[i].y]=1;
    }
    rep(i,1,n)s1[i]=(s1[i]+s1[i-1])%mod;
    rep(i,1,m)s2[i]=(s2[i]+s2[i-1])%mod;
    rep(i,1,n-1)if(!mark1[i]&&!mark1[i+1])ans=(ans+1ll*2*s1[i]*(s1[n]-s1[i]))%mod;
    rep(i,1,m-1)if(!mark2[i]&&!mark2[i+1])ans=(ans+1ll*2*s2[i]*(s2[m]-s2[i]))%mod;
    vnique(px);vnique(py);lx=px.size()-2;ly=py.size()-2;
    rep(i,1,K)
        fb[lower_bound(px.begin(),px.end(),a[i].x)-px.begin()][lower_bound(py.begin(),py.end(),a[i].y)-py.begin()]=1;
    rep(i,0,lx)rep(j,0,ly)cnt[i][j]=1ll*(px[i+1]-px[i])*(py[j+1]-py[j])%mod;
    rep(i,0,lx)rep(j,0,ly)
        if(!fb[i][j]){
            bfs(i,j);
            rep(k,0,lx)rep(p,0,ly)
                if(!fb[k][p])ans=(ans+1ll*cnt[i][j]*dis[k][p]%mod*cnt[k][p])%mod; 
        }
    ans=(ans+mod)%mod;ans=1ll*ans*(mod/2+1)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8320
from itertools import permutations as p
def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d
n,m,r=map(int,input().split())
d=[[10**9]*n for i in range(n)] 
rl=list(map(int,input().split()))
for i in range(m):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for i in range(n):
    d[i][i]=0
dl=wf(d)
pl=list(p(rl,r))
x=10**9
for i in pl:
  t=0
  for j in range(r-1):
    t+=dl[i[j]-1][i[j+1]-1]
  x=min(x,t)
print(x)

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

int n,x[205],y[205],mod=998244353,ans,two[205]={1};

signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) two[i]=two[i-1]*2%mod;
	ans=(two[n]-1-n-(n-1)*n/2+mod)%mod;
	for(int i=1;i<=n;i++) scanf("%d%d",x+i,y+i);
	for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){
		int tot=0;
		for(int k=j+1;k<=n;k++) if((y[i]-y[j])*(x[j]-x[k])==(x[i]-x[j])*(y[j]-y[k])) tot++;
		ans=(ans-two[tot]+mod+1)%mod;
	}
	printf("%lld",ans);
}

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    int graph[15][15];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            graph[i][j]=-1;
        }
    }

    vector<int>A(N);
    vector<vector<int>> x(N,vector<int>(N));
    vector<vector<int>> y(N,vector<int>(N));
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=0;j<A[i];j++){
            cin>>x[i][j]>>y[i][j];
            graph[i][x[i][j]-1]=y[i][j];
        }
    }

    int ans=0;
    for(int i=0;i<(1<<N);i++){
        vector<int> d;
        for(int j=0;j<N;j++){
            if(i&(1<<j)){
                d.push_back(1);
            }else{
                d.push_back(0);
            }
        }
        bool ok=true;
        for(int a=0;a<d.size();a++){
            if(d[a]!=0){
                for(int b=0;b<d.size();b++){
                    if(graph[a][b]==-1) continue;
                    if(graph[a][b]!=d[b]) ok=false;
                }
            }
            if(!ok) break;
        }
        if(ok) ans=max(ans,__builtin_popcount(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
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 fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int modpow(int a, int n, int mod) {
    int hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
ll n;
ll ans;
/*signed*/int main(void) {
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ans = INF;
    for (ll i = -100; i < 101; ++i) {
        ll b = 0;
        rep(j, n) b += abs(i - a[j]) * abs(i - a[j]);
        ans = min(ans, b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	if a <= 8 && b <= 8 {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


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


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

  vector<ll> mat(n+1),mit(n+1),t(n+1);
  t[n]=a[n];
  if(n==0){
    if(a[0]==1){
      cout << '1' << endl;
    }else{
      cout << "-1" << endl;
    }
    return 0;
  }
  for(int i=n-1;i>=0;--i){
    if(i==n-1){
      mat[i]=a[n]+a[i];
      mit[i]=(a[n]+1)/2+a[i];
    }else{
      mat[i]=mat[i+1]+a[i];
      mit[i]=(mit[i+1]+1)/2+a[i];
    }
  }
  if(mit[0]>1 || mat[0]<1){
    cout << "-1" << endl;
    return 0;
  }
  t[0]=1;
  vector<ll> ans(n+1);
  ans[0]=1;
  ans[n]=a[n];
  for(int i=1;i<n;++i){
    ll ma=t[i-1]*2;
    ans[i]=min(ma,mat[i]);
    t[i]=ans[i]-a[i];
  }
  ll cal=0;
  for(int i=0;i<=n;++i) cal+=ans[i];
  cout << cal << endl;
  return 0;
}


Measured memory_bytes: 7096
//nani?
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf=1e7;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MAX_N = 1e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------

ll a[MAX_N];

int main(){
    fastio;
    ll n,m;
 	cin>>n>>m;
	ll sum=0;	
  	f(i,0,m){
      	cin>>a[i];
    	sum+=a[i];
    }
  	if(n-sum>=0) cout<<n-sum<<endl;
  	else cout<<-1<<endl;
    
    
} 

Measured memory_bytes: 3720
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
int main()
{
	ll a,b,k;
	cin>>k>>a>>b;
	int s=0;
	for(;a<=b;a++){
		if(a%k==0) {s=1;cout<<"OK\n";break;}

	}
	if(s!=1) cout<<"NG\n";
	return 0;
}

Measured memory_bytes: 3624
/**
 *		author:  zvm
 *		created: 25.09.2020 16:33:02
**/

#include <bits/stdc++.h>

using namespace std ;

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

	int x, y, z ;
	cin >> x >> y >> z ;

	cout << (x-z)/(y+z) << endl ;
}


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

using namespace std;

vector<int> G[100000];
int a[100000];
bool used[100000] = {false};

int cnt;

int dfs(int n, int m){
    if(a[n] < a[m]) m = n;
    used[n] = true;
    for(int i  = 0; i < G[n].size(); i++){
        if(!used[G[n][i]]) m = dfs(G[n][i], m);
    }
    return m;
}

int main(){
    int N, M;
    long ans = 0;
    cin >> N >> M;
    for(int i= 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
        //cout << x << y << endl;
    } 
    for(int i = 0; i < N; i++){
        if(!used[i]){
            int idx = dfs(i, i);
            ans += a[idx];
            a[idx] = __INT_MAX__;
        } 
    }
    sort(a, a+N);
    for(int i = 0; i < N-M-2; i++){
        if(a[i] == __INT_MAX__){
            cout << "Impossible" << endl;
            return 0;
        }
        ans += a[i];
    }
    if(N-M == 1){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 6272
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
vector<int> start_ptr;
vector<int> end_ptr;
void dfs(const Graph &G, int v, int &ptr) {
    seen[v] = true;
    start_ptr[v]=ptr;
    ptr++;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, ptr); // 再帰的に探索
    }
    end_ptr[v]=ptr;
    ptr++;
}

int main() {
    // 頂点数と辺数
    int N; cin >> N;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        for(int j=0;j<b;j++){
            int v; cin >>v;
        
        G[a-1].push_back(v-1);
        }
    }

    // 全頂点が訪問済みになるまで探索
    seen.assign(N, false);
    int ptr=1;
    start_ptr.resize(N);
    end_ptr.resize(N);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v, ptr); // v が未探索なら v を始点とした DFS を行う
    }
    for(int i=0;i<N;i++){
    cout << i+1 <<" "<<start_ptr[i]<<" "<<end_ptr[i]<< endl;
    }
}



Measured memory_bytes: 3132
let _ = 
  let num_mon = [0;31;29;31;30;31;30;31;31;30;31;30] in
  let rec take n = function
    | [] -> []
    | hd :: tl when n = 0 -> []
    | hd :: tl -> hd :: take (n - 1) tl in
  let num_of_day m d = List.fold_left (+) 0 (take m num_mon) + d in
  let whatday m d =
    match num_of_day m d mod 7 with
    | 0 -> "Wednesday"
    | 1 -> "Thursday"
    | 2 -> "Friday"
    | 3 -> "Saturday"
    | 4 -> "Sunday"
    | 5 -> "Monday"
    | 6 -> "Tuesday"
    | _ -> failwith "whatday" in
  try 
    while true do
      let m, d = Scanf.scanf "%d %d\n" (fun m d -> (m, d)) in
      if m = 0 then raise End_of_file else print_endline @@ whatday m d
    done
  with
    End_of_file -> ()

Measured memory_bytes: 2164
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(k:i64)(list:[i64]));
    list.into_iter()
        .map(|x| std::cmp::min(x.abs(), (x - k).abs()) * 2)
        .sum::<i64>()
        .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "1\n10\n2" => "4",
    test2: "2\n9\n3 6" => "12",
    test3: "5\n20\n11 12 9 17 12" => "74",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N, ans="No";
  cin >> N;
  
  if (N[1] == N[2] &&(N[0] == N[1] || N[2] == N[3])) ans="Yes";
    
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

int N, K;
vector<int> A;

int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}

bool solve()
{
    if(N == 1) return A[0] == K;

    int gcd_all = gcd(A[0], A[1]);
    FOR(i, 2, N) {
        gcd_all = gcd(gcd_all, A[i]);
    }

    for(int e : A) {
        if(e == K) return true;

        if(e > K && (e-K) % gcd_all == 0) return true;
    }

    return false;
}

int main()
{
    cin >> N >> K;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
    }

    bool res = solve();
    cout << (res ? "POSSIBLE" : "IMPOSSIBLE") << "\n";

    return 0;
}


Measured memory_bytes: 640
n=int(input())
A,C,G,T,M,R=0,1,2,3,10**9+7,range(4)
dp=[[[[0]*4for k in R]for j in R]for i in range(n+1)]
dp[0][T][T][T]=1
for i in range(1,n+1):
  for j in R:
    for k in R:
      for l in R:
        for m in R:
          if not(any(t==(k,l,m)for t in((A,G,C),(A,C,G),(G,A,C)))or(j,l,m)==(A,G,C)or(j,k,m)==(A,G,C)):dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(c for a in dp[n]for b in a for c in b)%M)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  string s;
  int count = 0;

  cin >> s;

  for (int i = 0; i < 3; i++){
    if (s.at(i) == 'o'){
      count++;
    }
  }
  cout << 700 + count*100 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 201

int main(void) {
    int i, n;
    char str[MAX], buf[MAX];
    while(scanf("%s", str), strcmp(str, "-")) {
        for(scanf("%d", &i); i--; strcpy(str, buf)) {
            scanf("%d", &n);
            strcpy(buf, str + n), strncat(buf, str, n);
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        string s;
        cin >> s;
        int n = stoi(s);
        int sum = 0;
        for (int i = 0; i < s.size(); i ++) {
                sum += s[i] - '0';
        }
        puts(n % sum == 0 ? "Yes" : "No");
        return 0;
}



Measured memory_bytes: 256
import scala.io.Source.stdin

object Main extends App {
  stdin.getLines.foreach { s =>
    val n = s.split(" ").map(_.toDouble)
    val a = n(2)-n(0);val b = n(3)-n(1);val c = n(6)-n(4);val d = n(7)-n(5)
    if( Math.abs((a*c)+(b*d)) < 0.0000000001) println("YES") else println("NO")
  }
}

Measured memory_bytes: 44072
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int main() {
    long long l,r;cin>>l>>r;
    if(r-l>3000)cout<<0<<endl;
    else{
        long long res=2018;
        for(long long i=l;i<r;i++){
            for(long long j=i+1;j<=r;j++){
                res=min(res,(i*j)%2019);
            }
        }
        cout<<res<<endl;
    }
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll INF = 1e15;

ll n, k, mn, res = -INF;
vector<ll> p, c, ord;
vector<bool> vis;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k; mn = n;
    p.assign(n, 0);
    c.assign(n, 0);
    vis.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> p[i]; p[i]--;
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i];
    }
    for(int i = 0; i < n; ++i){
        if(vis[i]) continue;
        ord.clear(); int j = i;
        while(!vis[j]){
            ord.pb(c[j]); vis[j] = 1;
            j = p[j];
        }
        vector<ll> pref(sz(ord) + 1, 0);
        for(int x = 0; x < sz(ord); ++x){
            pref[x + 1] = pref[x] + ord[x];
        }
        //start index, length
        auto f = [&](int a, int b)->ll{
            ll s = a + b + 1;
            ll cur = pref[min(s, (ll)sz(ord))] - pref[a];
            if(s > sz(ord)){
                s -= sz(ord);
                cur += pref[s];
            }
            return cur;
        };
        for(int x = 0; x < sz(ord); ++x){
            for(int y = 0; y < min((ll)sz(ord), k); ++y){
                ckmax(res, f(x, y));
                // if(f(x, y) == 14 || f(x, y) + ((k - y)/sz(ord) * f(0, sz(ord) - 1)) == 14){
                //     for(auto i : ord) cout << i << " ";
                //     cout << "\n" << i << "\n";
                //     for(auto i : pref) cout << i << ' ';
                //     cout << "\n";
                //     cout << f(x, y) << " " << x << " " << y << "\n";
                // }
                ckmax(res, f(x, y) + ((k - y - 1)/sz(ord) * f(0, sz(ord) - 1)));
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3832
#include<stdio.h>
#include<limits.h>

#define NK 100000

int n, k;
int w[NK], P=INT_MAX;

int main( int argc, char *argv[] ) 
{
	int i, j, start;
	int sum;
	int truck, truckCnt, loadings, miniLoadings;

	scanf( "%d%d", &n, &k );

	sum = miniLoadings = 0;
	for ( i=0; i<n; i++ ) {
		scanf( "%d", &w[i] );
		sum += w[i];
		if( miniLoadings < w[i] ) {
			miniLoadings = w[i];
		}
	}
	if( 1 == k ) {
        P = sum;    
    } else if( n == k ) {
    	P = miniLoadings;
    } else {
    	miniLoadings = sum/k;
		start = loadings = 0;
		for( i=0; i<n; i++ ) {
			loadings += w[i];
			if( P <= loadings ) { 
				loadings -= w[ start++ ];
				loadings -= w[ i-- ];
				continue;
			}
			if( miniLoadings < loadings ) {
				truck = 0;
				truckCnt = k;
				for( j=0; truckCnt!=0 &&  j<n; j++ ) {
					truck += w[j];
					if( loadings < truck ) {
						truckCnt--;
						j--;
						truck = 0;
					}
				}
				if( truckCnt && loadings < P ) {
					P = loadings;
					loadings -= w[ start++ ];
					loadings -= w[ i-- ];
				} else {
					miniLoadings = loadings;
				}
			}
		}
	}

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

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

int a=0;
int b=0;
int c=0;

void count(string s, int n){
    if(s.at(n) == 'a') a++;
    else if(s.at(n) == 'b') b++;
    else c++;
}

int main(){
    string s;
    cin >> s;
    count(s, 0);
    count(s,1);
    count(s,2);

    if(a==1 && b == 1 && c==1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if (n == 0){
		printf("0\n");
		return 0;
	}
	string s, a[4] = {"10", "11", "00", "01"}, b[4] = {"10", "11", "", "1"};
	while (n < -2 || n > 1){
		for (int i = -2; i < 2; i++){
			if ((n - i) % 4 == 0){
				s = a[i + 2] + s;
				n = (n - i) / 4;
				break;
			}
		}
	}
	cout << b[n + 2] << s;
}

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

typedef long long ll;
const int MAX_N = 2 * 100000;

int main() {
	int N;
	static ll B[MAX_N];

	std::cin >> N;
	for(int i = 0; i < N; ++i) {
		ll A;
		std::cin >> A;
		B[i] = A - (i + 1);
	}
	std::sort(B, B + N);

	ll ans = 0, b = B[N / 2];
	for(int i = 0; i < N; ++i) {
		ans += std::abs(b - B[i]);
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 1792