akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
ll mazei[110][110];
int main() {
	cin >> n;
	map<ll, ll> mp;
	vector<ll> a(n);
	map<ll,ll> b;
	rep(i, n) {
		ll p;
		cin >> p;
		a[i] = p;
		mp[p]++;
	}
	ll sum = 0;
	ll k = 0;
	ll reset = 0;
	for (auto j = mp.begin(); j != mp.end(); j++) {
		sum += j->second * (j->second - 1) / 2;
		b[j->first] = j->second * (j->second - 1) / 2;
	}
	reset = sum;
	rep(i, n) {
		mp[a[i]]--;
		sum -= b[a[i]];
		sum+=mp[a[i]] * (mp[a[i]] - 1) / 2;
		cout << sum << endl;
		sum = reset;
		mp[a[i]]++;
	}
}

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

namespace ConsoleApp66
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int Anumber = int.Parse(input[0]);
            int Bnumber = int.Parse(input[1]);
            int Cnumber = int.Parse(input[2]);

            for (int i = 0;i<Bnumber; i++)
            {
                if ((Anumber * i) % Bnumber == Cnumber)
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
N = input()
split = N.split(" ")
A = int(split[0])
B = int(split[1])
max_num = A * B
if A < B:
    tmp = A
    A = B
    B = tmp

r = A % B
while r != 0:
    A = B
    B = r
    r = A % B
max_num /= B 
print(int(max_num))

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

int main(){
  string s;
  cin>>s;
  int n = s.length();
  for(int i=0;i<n/2;i++){
    if(s[i] != s[n-1-i]){
      //temp = 1;
      cout<<"No";
      return 0;
    }
  }
  for(int i=0;i<n/4;i++){
    if(s[i] != s[n/2 -1 -i]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.chop.split.map(&:to_i)

def insert_sort(a, n)
  puts a.join(' ')
  1.upto N-1 do |i|
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v
      a[j+1] = a[j]
      j = j - 1
    end
    a[j+1] = v
    puts a.join(' ')
  end
end


insert_sort(A, N)



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

uint64_t wid[8][2];
uint64_t w_c[8];

uint64_t w_f(int64_t w) {
  if (w < 0) {
    return 1;
  } else {
    return w_c[w];
  }
}

int main() {
  int h, w, k;
  std::cin >> h >> w >> k;
  uint64_t amari = 1'000'000'007;
  wid[0][0] = 1;
  wid[0][1] = 0;
  w_c[0] = wid[0][0] + wid[0][1];
  for (int i = 1; i < w; i++) {
    wid[i][0] = wid[i - 1][0] + wid[i - 1][1];
    wid[i][1] = wid[i - 1][0];
    w_c[i] = (wid[i][0] + wid[i][1]) % amari;
  }

  std::vector<std::vector<uint64_t>>
    ans(h + 1, std::vector<uint64_t>(w));
  ans[0][0] = 1;
  for (int i = 1; i < w; i++) {
    ans[0][i] = 0;
  }

  for (int i = 1; i < h + 1; i++) {
    for (int j = 0; j < w; j++) {
      if (j == 0) {
        ans[i][j] = ((ans[i - 1][j] * w_f(w - 2)) % amari
          + (ans[i - 1][j + 1] * w_f(w - 3)) % amari)
          % amari;
      } else if (j == w - 1) {
        ans[i][j] = ((ans[i - 1][j] * w_f(w - 2)) % amari
          + (ans[i - 1][j - 1] * w_f(w - 3)) % amari)
          % amari;
      } else {
        ans[i][j] = ((ans[i - 1][j] * w_f(j - 1) * w_f(w - j - 2))
          % amari
          + (ans[i - 1][j - 1] * w_f(j - 2) * w_f(w - j - 2))
          % amari
          + (ans[i - 1][j + 1] * w_f(j - 1) * w_f(w - j - 3))
          % amari) % amari;
      }
    }
  }
  std::cout << ans[h][k - 1] << std::endl;

  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    
    ll n,m; cin>>n>>m;
    vector<vector<ll>> s(m);
    rep(i,m){
        ll k; cin>>k;
        rep(j,k){
            ll a; cin>>a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<ll> p(m);
    rep(i,m) cin>>p[i];

    ll ans=0;

    for(int bit=0;bit < 1<<n; bit++){
        bool ok=true;
        for(int i=0;i<m;i++){
            ll cnt=0;
            for(auto on:s[i]){
                if(bit & 1<<on) cnt++;
            }
            if(cnt%2!=p[i]) ok=false;
        }
        if(ok) ++ans;
    }

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

Measured memory_bytes: 3564
import collections

n = int(input())
mod = 10 ** 9 + 7
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
    for i in ac.items():
        if i[0] == 0:
            if i[1] != 1:
                print(0)
                exit()
        else:
            if i[1] != 2:
                print(0)
                exit()
    print(2 ** (n // 2) % mod)
else:
    for i in ac.values():
        if i != 2:
            print(0)
            exit()
    print(2 ** (n // 2) % mod)

Measured memory_bytes: 14820
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


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

//INSERT ABOVE HERE
const Int MAX = 505;
Int as[MAX][MAX];
signed main(){
  Int n;
  cin>>n;

  MFP([&](auto dfs,Int l,Int r,Int d)->void{
        if(l+1==r) return;
        Int m=(l+r)>>1;
        for(Int i=l;i<m;i++)
          for(Int j=m;j<r;j++)
            as[i][j]=as[j][i]=d;
        dfs(l,m,d+1);
        dfs(m,r,d+1);
      })(0,n,1);

  for(Int i=0;i+1<n;i++){
    for(Int j=i+1;j<n;j++){
      if(j>i+1) cout<<" ";
      cout<<as[i][j];
    }
    cout<<endl;
  }
  return 0;
}


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

int main(){
	int a,b,mini,maxi;
	scanf("%d %d", &a, &b);
	mini = min(a,b);
	maxi = max(a,b);
	for (int i = 0; i < maxi; ++i)
	{
		printf("%d", mini);
	}
	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
A = []
for i in range(H):
	s = list(input())
	A.append([0 if c == "." else 1 for c in s])
dist = [[0 if r == 0 and c == 0 else 1000 for c in range(W)] for r in range(H)]
for r in range(H):
	for c in range(W):
		if c == 0 and r == 0:
			continue
		if r == 0:
			dist[r][c] = dist[r][c-1] + int(abs(A[r][c] - A[r][c-1]))
		elif c == 0:
			dist[r][c] = dist[r-1][c] + int(abs(A[r][c] - A[r-1][c]))
		else:
			dist[r][c] = min(dist[r][c-1] + int(abs(A[r][c] - A[r][c-1])), dist[r-1][c] + int(abs(A[r][c] - A[r-1][c])))
ans = (dist[H-1][W-1] + 1) // 2
if A[0][0] == 1 and A[H-1][W-1] == 1:
	print(ans + 1)
else:
	print(ans)

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

int main() {
    int n,x,s,ans;
    cin>>x;
    s=x/500;
    ans=s*1000;
    
    s=x%500;
    ans=ans+(s/5)*5;
    cout<<ans;
  return 0;
}

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

B = sorted(B, key=lambda p: p[0])

ans = 0
for bx, by in B:
    ry_max = -1
    idx = -1
    for i, (rx, ry) in enumerate(R):
        if rx < bx and ry < by and ry_max < ry:
            ry_max = ry
            idx = i
    if idx != -1:
        R.pop(idx)
        ans += 1
print(ans)


Measured memory_bytes: 3064
N,K = map(int, input().split())
h = list(map(int, input().split()))

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

for i in range(1,N):
    for j in range(max(i-K,0),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))

print(dp[-1])


Measured memory_bytes: 52448
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k,a,b;
    cin >> k;
    cin >>a>>b;


    bool f =false;
    for(int i=a;i<b+1;i++){
        if (i%k==0){
            f=true;
        }
    }
    if (f) cout << "OK";

    else cout << "NG";


    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e5 + 10;

int n, m;
vector<int> g[maxN];
int vis[maxN];
int dp[maxN];
stack<int> s;
vector<int> ver;

void dfs(int u) {
  s.push(u);
  vis[u] = 1;
  for (auto v : g[u]) {
    if (!vis[v]) dfs(v);
  }
  ver.push_back(u);
  s.pop();
}

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < ver.size(); ++i) {
    int u = ver[i];
    for (auto v : g[u]) {
      dp[u] = max(dp[u], dp[v] + 1);
    }
    ans = max(ans, dp[u]);
  }
  cout << ans;
return 0;
}


Measured memory_bytes: 12776
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr= input.trim().split("\n");
var A= arr[1].split(" ").map(Number).reduce((a,b)=>a+b);
var B= arr[2].split(" ").map(Number).reduce((a,b)=>a+b);
console.log(A*B);


Measured memory_bytes: 41044
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    sort(data.begin(),data.end());
    double ans = data.at(0);
    for (int i = 1; i < N; i++) {
        ans = (ans + data.at(i)) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    int s = 0;
    cin >> n;
    int cn = n;
    while (cn > 0) {
        s = s + cn%10;
        cn = cn/10;
    }
    if (n % s == 0) {
        cout << "Yes";
    }
    else
        cout << "No";
    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


i64 n, s;

int main(){
	cin >> n >> s;
	
	if(n < s){
		cout << -1 << endl;
		return 0;
	}
	
	if(s == n){
		cout << n+1 << endl;
		return 0;
	}
	
	i64 ans = LINF;
	
	for(i64 i = 2; i*i <= n; i++){
		i64 d = n, cnt = 0;
		while(d){
			cnt += d % i;
			d /= i;
		}
		if(cnt == s){
			ans = i;
			break;
		}
	}
	for(i64 i = 1; i < 400000; i++){
		if((n-s) % i == 0){
			i64 d = n, cnt = 0, p = (n-s) / i + 1;
			while(d){
				cnt += d % p;
				d /= p;
			}
			if(cnt == s) ans = min(ans, p);
		}
	}
	
	if(ans == LINF) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

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

results = [-1, -1, -1]
a = sum/1000 - n
k_min = (a * 2 / 9.0).ceil
k_max = (a / 4.0).floor
if k_min <= k_max
  k = k_min
  x = -4*k +   a
  y =  9*k - 2*a
  if x+y <= n
    results = [x, y, n-(x+y)]
  end
end
puts(results.join(' '))


Measured memory_bytes: 1788
import java.util.*;

public class Main {    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);          
           
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        
        if(A.charAt(A.length() - 1) == B.charAt(0) && B.charAt(B.length() - 1) == C.charAt(0)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
         
    }            
}
        

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

using namespace std;

const int INF = 1e9 + 5;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i=0; i<n; i++)
        cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i=0; i<n; i++)
    {
        for (int j = 1; j<=k ; j++)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i+j]));
    }
    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

void insertionSort(int A[],int N){
    int i, j, v;

    for(i = 1; i < N; ++i){
        v = A[i];
        j = i - 1;

        while (j >= 0 && v < A[j]){
            A[j + 1] = A[j];
            j--;
        }

        A[j + 1] = v;
    }
}

int main(){
    int X, N, p[102], num;
    bool flag = 1;

    cin >> X >> N;
    for(int i = 0; i < N; i ++){
        cin >> p[i];
    }
    insertionSort(p, N);

    for(int j = 0; j < N; j ++){
        if(X == p[j]){
            flag = 0;
            num = j;
        }
    }
    if(flag){
        cout << X << endl;
        return 0;
    }
    for(int k = 1; k < N; k ++){
        if(0 <= num - k && p[num - k] != (p[num] - k)){
            cout << p[num] - k << endl;
            return 0;
        }
        if(num + k < N && p[num + k] != (p[num] + k)){
            cout << p[num] + k << endl;
            return 0;
        }
    }
    if (abs(X - p[0]) <= abs(X - p[N - 1])) cout << p[0] - 1;
	else cout << p[N - 1] + 1;
    return 0;
}

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

int main() {

  int n;
  cin >> n;
  int bb[n], i;
  for(i=0; i<n; i++){
    cin >> bb[i];
  }
  int k=0, flag = 0;
  while(1){
    for(i=0; i<n; i++){
      if(bb[i] % 2 == 0){
        bb[i] /= 2;
      } else {
        flag = 1;
        break;
      }
    }
    if(flag) break;
    else k++;
  }
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 256
def rolling(str, n):
    return str[n:len(str)] + str[:n]


def solve():
    S = input()
    T = input()

    for i in range(len(S)):
        if rolling(S, i) == T:
            print("Yes")
            exit()

    print("No")


# Solve
if __name__ == "__main__":
    solve()

 

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int N, Q;
    cin >> N >> Q;
    int a[N - 1], b[N - 1];
    vector<int> adj[N];
    for (int i = 0; i < N - 1; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
    int p[Q];
    ll x[Q];
    ll c[N]{};
    for (int i = 0; i < Q; i++)
    {
        cin >> p[i] >> x[i];
        p[i]--;
        c[p[i]] += x[i];
    }
    ll t = 0;
    deque<int> q;
    q.push_back(0);
    int vis[N]{};
    vis[0] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop_front();
        for (int i : adj[u])
        {
            if (vis[i] == 1)
                continue;
            vis[i] = 1;
            c[i] += c[u];
            q.push_back(i);
        }
    }
    for (int i = 0; i < N; i++)
    {
        cout << c[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 20980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>


using namespace std;

int main() {
  int n;
  cin>>n;
  int ans = 1000 - n%1000;
  if(ans == 1000) ans=0;
  cout<< ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main()
{
    int a, b;
    while(1){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0){
            break;
        }
        else{
            for(int i = 1;i <= a;i++){
                for(int j = 1;j <= b;j++){
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 1992
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;


public class Main{
	static final long MOD = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int req = 1;
		int bre = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != req) {
				bre++;
			} else {
				req++;
			}
		}
		if (bre == n) {
			System.out.println(-1);
		} else {
			System.out.println(bre);
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 24244
//MD. HASNAIN ALI (UNSOLVED)
//I am nobody.

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

#pragma GCC               optimize ("Ofast")
#pragma GCC               optimize("O3")
#define ll                long long
#define lo(i,a,n,x)       for(i=a;i<=n;i=i+x)
#define loi(i,a,n,x)      for(i=a;i>=n;i=i-x) 
#define sca(n)            scanf("%lld", &n)
#define pri(n)            printf("%lld", n)
#define pb(a)             push_back(a)
#define pop()             pop_back()
#define mp                make_pair
#define ff                first
#define ss                second
#define sqr(x)            (x)*(x)
#define VI                vector <int>
#define SZ(a)             (int)a.size()
#define SORT(x)           sort(x.begin(), x.end())
#define REV(x)            reverse(x.begin(), x.end())
#define UNIQUE(v)         (v).erase(unique((v).begin(),(v).end()),(v).end())
#define REV(x)            reverse(x.begin(), x.end())
#define all(x)            x.begin(), x.end()
#define ODD(x)            ((x)&1)==0?(0):(1)
#define TEST_CASE(t)      for(int z=1;z<=t;z++)
#define distance(a,b)     (sq(a.x-b.x) + sq(a.y-b.y))
#define GCD(a, b)         __gcd(a, b)
#define lcm(a, b)         (a)*((b)/gcd(a,b))
#define end0              "\n"
#define end1              cout<<"\n";
#define pi                acos(-1)
#define mod               1000000007
#define inf               999999999999999999
#define eps               10e-9





int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("input-3.txt","r",stdin);
    //freopen("output-3.txt","w",stdout);

    
    ll t,i,j,a,b,p=0;

    cin>>t;

    int x[t+1],y[t+1];

    lo(i,0,t-1,1){
        cin>>x[i]>>y[i];
    }
    lo(i,0,t-1,1){
        if(x[i]==y[i]) p++;
        else p=0;
        if(p==3){
            cout<<"Yes"<<end0;
            goto A;
        } 
    }
    cout<<"No"<<end0;

    A:
    p=0;


    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define MAXN 100
long long K;
char str[MAXN+5];

int main(){
    scanf("%s%I64d",str+1,&K);
    int N=strlen(str+1);
    for(int i=1;i<=min(N*1ll,K);i++)
        if(str[i]>'1'){
            putchar(str[i]);
            return 0;
        }
    putchar('1');
}


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

int main()
{
  int n ;
  cin >> n ;
  vector<int> a1(n) ;
  for(int i=0; i<n; i++)
    cin >> a1.at(i) ;
  vector<int> a2(n) ;
  a2 = a1 ;
  for(int i=0; i<n; i++)
  {
    a2.at(a1.at(i)-1) = i+1 ;
  }
  for(int i=0; i<n; i++)
    cout << a2.at(i) << " " ;
  cout << endl ;
}

Measured memory_bytes: 1536
MOD = 10**9 + 7

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret




N,K = list(map(int,input().split()))
l = list(map(int,input().split()))
l.sort()

ans = 0

for i in range(N):
  ans = (ans + l[i] * (nCr(i,K-1)-nCr(N-1-i,K-1)) ) % MOD
  
print(ans)

Measured memory_bytes: 64040
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int n;
double x[100], y[100];

double distance(double p) {
	double sum = 0;
	for (int i = 0; i<n; i++) {
		double w = abs(x[i] - y[i]);
		sum += pow(w, p);
	}
	return pow(sum, 1.0 / p);
}

int main() {
	cout << fixed << setprecision(12);

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

	cout << distance(1) << endl;
	cout << distance(2) << endl;
	cout << distance(3) << endl;

	double mx = 0;
	for (int i = 0; i<n; i++) {
		mx = max(mx, abs(x[i] - y[i]));
	}
	cout << mx << endl;

	return 0;
}


Measured memory_bytes: 3444
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


g = A[0]
for a in A:
    g = gcd(g, a)
if K <= max(A) and K % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 14224
#include<cstdio>
using namespace std;
template<class T>inline void read(T&a){
	char c=getchar();int f=1;a=0;
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0') a=(a<<1)+(a<<3)+c-48,c=getchar();
	a*=f;
}
template<class T>void write(T a){
	if(a<0) putchar('-'),a=-a;
	if(a>9) write(a/10);
	putchar(a%10+48);
}
const int inf=1e9+10,o=5010;
#define int long long
inline int max(int a,int b){return a>b?a:b;}
int n,k,p[o],c[o],ans=-inf,cnt,f[o],lst,g[o];
signed main(){
	read(n);read(k);for(int i=1;i<=n;++i) read(p[i]);for(int i=1;i<=n;++i) read(c[i]),ans=max(ans,c[i]);
	if(ans<0){write(ans);return 0;}
	for(int i=1;i<=n;++i){g[1]=max(f[cnt=1]=c[p[i]],0);for(int j=p[i];(j^i)&&cnt<k;j=p[j],++cnt)
	g[cnt+1]=max(g[cnt],f[cnt+1]=f[cnt]+c[p[j]]);ans=max(ans,max(k/cnt*f[cnt]+g[k%cnt],g[cnt]));if(k%cnt==0) ans=max(ans,((k/cnt-1)*f[cnt]+g[cnt]));}
	write(ans);
	return 0;
}

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


int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  for(int& a:A) cin >> a;

  map<int, int>M;
  vector<int> C;
  int ans = 0;

  for(int i=0; i<N; i++){
    if(M.find(A[i]) == M.end()){
      M.insert(make_pair(A[i], 1));
    }else{
      M[A[i]]++;
    }
  }

  for(auto i=M.begin(); i!=M.end(); i++){
    C.push_back(i->second);
  }

  sort(C.begin(), C.end());
  if(K>=C.size()) cout << 0 << endl;
  else {
    for(int i=0; i<C.size()-K; i++) ans += C[i];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
void solve(){
    string s; cin >> s;
    string ans;
    for(int i = 0; i < s.size(); ++i){
      if(s[i] == '0') {ans += '0';} 
      else if(s[i] == '1') {ans += '1';} 
      else {if (!ans.empty()) {ans.erase(ans.size()-1, 1);}
        }
    }
    cout << ans << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, s64>;
using PP = pair<P, int>;
const s64 inf = 1e18;
int n;
s64 l;
vector< vector<P> > g;

void dijkstra(int u, vs64& cnt, vs64& lit)
{
    cnt[u] = 0;
    lit[u] = l;
    priority_queue<PP, vector<PP>, greater<PP>> pq;
    pq.push(PP{P{0, -l}, u});
    while (!pq.empty())
    {
        auto dgv = pq.top(); pq.pop();
        s64 num = dgv.first.first;
        s64 gas = -dgv.first.second;
        s64 from = dgv.second;
        if (cnt[from] != num) continue;
        if (lit[from] > gas) continue;
        for (const auto& e : g[from])
        {
            s64 to = e.first;
            s64 cost = e.second;
            s64 remain;
            if (gas - cost < 0)
            {
                remain = l - cost;
                if (cnt[to] > num + 1 || (cnt[to] == num + 1 && lit[to] < remain))
                {
                    cnt[to] = num + 1;
                    lit[to] = remain;
                    pq.push(PP{P{cnt[to], -remain}, to});
                }
            }
            else
            {
                remain = gas - cost;
                if (cnt[to] > num || (cnt[to] == num && lit[to] < remain))
                {
                    cnt[to] = num;
                    lit[to] = remain;
                    pq.push(PP{P{cnt[to], -remain}, to});
                }
            }
        }
    }
}

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

    int m;
    cin >> n >> m >> l;

    g.resize(n);
    vector< vs64 > cnt(n, vs64(n, inf));
    vector< vs64 > lit(n, vs64(n, inf));

    rep (i, m)
    {
        int a, b;
        s64 c;
        cin >> a >> b >> c;
        --a, --b;
        if (c <= l)
        {
            g[a].emplace_back(b, c);
            g[b].emplace_back(a, c);
        }
    }

    rep (i, n)
    {
        dijkstra(i, cnt[i], lit[i]);
    }

    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        --s, --t;
        if (cnt[s][t] == inf) cout << "-1\n";
        else cout << cnt[s][t] << "\n";
    }

    return 0;
}



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

int main(){
	string str;
	getline(cin,str);
	string::iterator sp = str.begin();
	while(sp != str.end()){
		if(islower(*sp)){
			*sp=toupper(*sp);
		}else if(isupper(*sp)){
			*sp=tolower(*sp);
		}
		sp++;
	}
	cout<<str<<endl;
	return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<int>v;
int main()
{
    int k,x;
    cin>>k>>x;
    for(int i=x;i<x+k;i++)
        v.pb(i);
    for(int i=x-1;i>x-k;i--)
         v.pb(i);
   Unique(v);
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 200005;

int n;
int dep[MAXN], dfn[MAXN], piv;
int val[MAXN], par[MAXN];
vector<int> gph[MAXN];
int minv[MAXN], actually[MAXN];

void solve(int x, int p){
	minv[x] = 2e9;
	if(x != p && val[x] != -1){
		minv[x] = val[x];
		return;
	}
	for(auto &i : gph[x]){
		if(i != par[x]){
			solve(i, p);
			minv[x] = min(minv[x], minv[i]);
		}
	}
}

void go(int x, int p){
	for(auto &i : gph[x]){
		if(i != par[x]){
			if(actually[i]) continue;
			if(minv[i] > val[x]){
				val[i] = val[x] + 2;
			}
			else val[i] = val[x];
			go(i, p);
		}
	}
}

void dfs(int x, int p){
	dfn[x] = ++piv;
	for(auto &i : gph[x]){
		if(i != p){
			par[i] = x;
			dep[i] = dep[x] + 1;
			dfs(i, x);
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e; scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	dfs(1, -1);
	memset(val, -1, sizeof(val));
	int q; scanf("%d",&q);
	vector<int> cnd;
	int dap = 2e9;
	while(q--){
		int x, v; scanf("%d %d",&x,&v);
		val[x] = v + dep[x];
		dap = min(dap, v + dep[x]);
		actually[x] = 1;
		cnd.push_back(x);
	}
	if(val[1] > dap){
		puts("No");
		return 0;
	}
	if(val[1] == -1){
		val[1] = dap;
		cnd.push_back(1);
		actually[1] = 1;
	}
	sort(cnd.begin(), cnd.end(), [&](const int &a, const int &b){
		return dfn[a] < dfn[b];
	});
	for(int i=0; i<cnd.size(); i++){
		solve(cnd[i], cnd[i]);
		go(cnd[i], cnd[i]);
	}
	for(int i=1; i<=n; i++){
		for(auto &j : gph[i]){
			if(par[i] == j) continue;
			if(val[j] - val[i] != 2 && val[j] != val[i]){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	for(int i=1; i<=n; i++) printf("%d\n", val[i] - dep[i]);
}


Measured memory_bytes: 16768
disco = list(map(int, input().split()))

prize = 0
cn = disco[0]
sn = disco[1]

if (cn * sn == 1):
    print(1000000)
    exit()

if (cn < 4):
    prize += 400000 - 100000 * cn

if (sn < 4):
    prize += 400000 - 100000 * sn

print(prize)

Measured memory_bytes: 3060
s = int(input())
if s == 1 or s == 2 or s == 4:
    print(4)
else:
    count = 1
    while s!=4:
        if s % 2 == 0:
            s = s//2
            count += 1
        else:
            s = 3 * s + 1
            count += 1
    print(count+3)

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

namespace kyoupuro1
{
    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' '); 
            int x = int.Parse(input[0]),
                y = int .Parse(input[1]);
            Console.WriteLine(x+y/2);
            
        }

        static int A(int x)
        {
            if (x < 0) return 0;
            else return x;
        }

        static List<int> GetPNLs(int max)
        {
            List<int> prime = new List<int>();
            if (max <= 1) return new List<int> {2};
            for (int i = 2; i <= max; i++)
            {
                bool isPrime = true;
                foreach (var p in prime)
                {
                    if (i % p == 0 && i != p)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime) prime.Add(i);
            }
            return prime;
        }

        static int E(int prime, int n)
        {
            int k = n;
            int c = 0;
            while (k % prime == 0)
            {
                k = k / prime;
                c++;
            }
            return c;
        }

        static int C(int a, int b)
        {
            if (a < b) return 0;
            return F(a) / (F(b) * F(a - b));
        }

        static int F(int n)
        {
            if (n > 1)
                return F(n - 1) * n;
            else
                return 1;
        }
    }
}


Measured memory_bytes: 13140
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>  vll;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;

  vll a(n);
  rep(i,n) cin >> a[i];

  map<ll,ll> m;

  rep(i,n)
  {
    m[a[i]]++;
  }

  ll cnt = 0;

  for(auto it:m)
  {
    if(it.first != it.second)
    {
      if(it.first > it.second)
      {
        cnt += it.second;
      }
      else
      {
        cnt += it.second - it.first;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 7040
#define _USE_MATH_DEFINES
 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
 
typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	long long int A, B, C, N;
	cin >> A >> B >> C >> N;
	
	long long int x[1100], y[1100], z[1100];
	
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	
	long long int ans = (A * B + B * C + C * A) * 2 + 6 * N;
	
	for(int i = 0; i < N; i++){
		if(x[i] == 0){
			ans -= 2;
		}
		if(y[i] == 0){
			ans -= 2;
		}
		if(z[i] == 0){
			ans -= 2;
		}
		if(x[i] == A - 1){
			ans -= 2;
		}
		if(y[i] == B - 1){
			ans -= 2;
		}
		if(z[i] == C - 1){
			ans -= 2;
		}
		for(int j = i + 1; j < N; j++){
			if(abs(x[i] - x[j]) + abs(y[i] - y[j]) + abs(z[i] - z[j]) <= 1){
				ans -= 2;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3140
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int total = 0;
        int minus = 10;
        for(int i = 0; i < 5; i++){
            int num = sc.nextInt();
            if(num % 10 > 0 && num % 10 < minus){
                minus = num %  10;
            }
            num += num % 10 == 0 ? 0 : 10 - (num % 10);
            total += num;
        }
        total -= (10 - minus);
        System.out.println(total);
    }
}


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

int main() {
  int N, K; cin >> N >> K;
  string s; cin >> s;
  vector<int> change;
  change.push_back(-1);
  for (int i = 0; i < N-1; i++) {
    if (s[i] != s[i+1]) {change.push_back(i);}
  }
  change.push_back(N-1);
  
  vector<int> leng;
  if (s[0] == '0') {leng.push_back(0);}
  for (int i = 0; i < change.size()-1; i++) {
    leng.push_back(change[i+1]-change[i]);
  }
  if (s[N-1] == '0') {leng.push_back(0);}
  
  //for (int i = 0; i < leng.size(); i++) {cout << leng[i] << endl;}
  
  if (leng.size() < 2*K+1) {cout << N << endl;}
  else {
    int sum = 0;
    for (int i = 0; i < 2*K+1; i++) {
      sum += leng[i];
    }
    priority_queue<int> que;
    que.push(sum);
    
    for (int i = 0; i < leng.size()-(2*K+2); i = i+2) {
      sum = sum - leng[i] - leng[i+1] + leng[i+2*K+1] + leng[i+2*K+2];
      que.push(sum);
    }
    cout << que.top() << endl;
  }
}

Measured memory_bytes: 1592
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        Arrays.setAll(a, i -> scanner.nextInt());
        double average = Arrays.stream(a).average().getAsDouble();
        int ans = n - 1;
        for (int i = n - 2; i >= 0; i--) {
            if (Math.abs(a[i] - average) <= Math.abs(a[ans] - average)) {
                ans = i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 29012
import numpy as np

mod = 998244353
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
S = sum(A)


def fastpow(a, n):
    i = 0
    result = 1
    pow = [a]
    while (1 << i) <= n:
        pow.append(pow[-1] * pow[-1] % mod)
        i += 1
    for j in range(i):
        if (n >> j) % 2 == 1:
            result = result * pow[j] % mod
    return result

# D1[i][r]: i個塗った時点でR=rとなる場合の数
D1 = np.zeros((N+1, S+1), dtype=int)
D1[0][0] = 1
# D2[i][r]: i個塗った時点でR=r, B=0となる場合の数
D2 = np.zeros((N+1, S+1), dtype=int)
D2[0][0] = 1

for i in range(N):
    D1[i+1] += D1[i] * 2
    D1[i+1][A[i]:] += D1[i][:-A[i]]
    D1[i+1] = D1[i+1] % mod

    D2[i+1] += D2[i]
    D2[i+1][A[i]:] += D2[i][:-A[i]]
    D2[i+1] = D2[i+1] % mod

border = (S + 1) // 2

result = fastpow(3, N)
result -= 3 * sum(D1[N][border:])
if border * 2 == S:
    result += 3 * D2[N][border]

print(result % mod)


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

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

int main(){
  int N,X;
  cin >> N >> X;
  int x[N];
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    x[i]=abs(a-X);
    if(i>0)x[i]=gcd_euclid(x[i],x[i-1]);
  }
  cout << x[N-1];
}



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

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

using ll = long long;
using namespace std;

int
main ()
{
    vector<int> f = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int n;
    cin >> n;

    cout << f[n - 1] << endl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))

b_len = len(format(max(A),'b'))
B = [[int(_) for _ in format(a, '0{}b'.format(b_len))] for a in A]
B_t = [list(b) for b in zip(*B)]
B_b = [int(sum(b)<=(N/2)) for b in B_t]
K_b = [int(_) for _ in bin(K)[2:]]


if len(K_b) > len(B_b):
    B_b = K_b[:(len(K_b)-len(B_b))] + B_b
else:
    K_b = [0]*(len(B_b)-len(K_b)) + K_b
import copy
x_b = copy.copy(B_b)
for i in range(len(K_b)):
    if B_b[i] == 0 and K_b[i] == 1:
        break
    elif B_b[i] == 1 and K_b[i] == 0:
        x_b[i] = 0

from functools import reduce

x = int(reduce(lambda x,y:x+y, [str(a) for a in x_b]), 2)

ans = sum(x^a for a in A)
print(ans)


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

int mod = 1'000'000'007;

int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; i++) cin >> t[i];
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> d_t(n, - 1);
    vector<int> d_a(n, - 1);
    d_t[0] = t[0];
    d_a[n - 1] = a[n - 1];
    for (int i = 1; i < n; i++){
        if (t[i] != t[i - 1]) d_t[i] = t[i];
    }
    for (int i = n - 2; i >= 0; i--){
        if (a[i] != a[i + 1]) d_a[i] = a[i];
    }
    vector<int> merges(n, - 1);
    bool flag = true;
    for (int i = 0; i < n; i++){
        if (d_t[i] != - 1 && d_a[i] != - 1){
            if (d_t[i] != d_a[i]) flag = false;
            else merges[i] = 1;
        }
        else if (d_t[i] != - 1) {
            if (t[i] > a[i]) flag = false;
            else merges[i] = 1;
        }
        else if (d_a[i] != - 1){
            if (a[i] > t[i]) flag = false;
            else merges[i] = 1;
        }
    }
    if (!flag){
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++){
        if (merges[i] == - 1) merges[i] = min(t[i], a[i]);
    }
    long long ans = 1;
    for (int i = 0; i < n; i++) ans *= merges[i], ans %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 2176