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

int main(){
	int count=0,K,T,tmp=1,MAX=0;
	cin >> K >> T;
	vector <int> a(T);
	for(int i=0;i<T;i++){
		cin >> a[i];
		MAX+=a[i];
	}
	sort(a.rbegin(),a.rend());
	if(T!=1){
		for(int i=0,j=1;i<MAX;i++){
			if(tmp!=0 && j>0){
				a[0]--;
				tmp=0;
			}else if(j>0){
				a[j]--;
				tmp=j;
				if(a[j]==0){
					j++;
					if(j==T){j=0;}
				}
			}else{
				count = a[0]-1;
				break;
			}
		}
	}else{
		count = K-1;
	}
	cout << count << endl;
	return 0;
}


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

using namespace std;

int main() {
    string w[4] = {"Sunny", "Cloudy", "Rainy", "Sunny"};
    string s;
    cin >> s;
    for (int i = 0; i < 3; ++i) {
        if (w[i] == s) {
            cout << w[i+1] << endl;
            return 0;
        }
    }
}



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

using namespace std;

bool is_war(int *x,int *y,int N,int M){
    for(int z=-100;z<=100;z++){
        bool is_ok = true;
        for(int i=0;i<=N;i++){
            if(x[i]>=z) is_ok = false;
        }
        for(int i=0;i<=M;i++){
            if(y[i]<z) is_ok = false;
        }
        if(is_ok)   return false;
    }
    return true;
}

int main(){
    int N,M; cin >> N >> M;
    int x[101],y[101];
    cin >> x[0] >> y[0];
    for(int i=0;i<N;i++){
        cin >> x[i+1];
    }
    for(int i=0;i<M;i++){
        cin >> y[i+1];
    }
    if(is_war(x,y,N,M)){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<string> S(N);
    REP(i,N){
        S[i] = in<string>();
        sort(ALL(S[i]));
    }
    sort(ALL(S));
    ll answer = 0;
    ll counter = 1;
    string before = "a";
    REP(i,N){
        if(before == S[i]){
            counter++;
        }else{
            if(counter > 1)answer += counter*(counter-1)/2;
            counter = 1;
        }
        before = S[i];
    }
    if(counter > 1)answer += counter*(counter-1)/2;
    cout << answer << "\n";
}

Measured memory_bytes: 5760
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 10000 + 10;

int N;
char S[MAXN];
int x, y;
int P[MAXN];

int A[MAXN], nA, B[MAXN], nB;

int dp[2][MAXN * 2];

int Check(int* a, int n, int target, bool first)
{
	memset(dp, 0, sizeof(dp));

	dp[0][MAXN] = 1;
	for (int i = 0; i < n; i ++)
	{
		int cur = (i & 1);
		int next = cur ^ 1;
		for (int j = 0; j < MAXN * 2; j ++)
			if (dp[cur][j] == i + 1)
			{
				dp[next][j + a[i]] = i + 2;
				if (first && i == 0)
					continue;
				dp[next][j - a[i]] = i + 2;
			}
	}
	return (dp[n % 2][target + MAXN] == n + 1);
}

void Work()
{
	scanf("%s", S);
	N = strlen(S);
	
	int nP = 1;
	for (int i = 0; i < N; i ++)
	{
		if (S[i] == 'F')
			P[nP - 1] ++;
		else
			nP ++;
	}

	nA = nB = 0;
	for (int i = 0; i < nP; i ++)
	{
		if (i % 2 == 0)
			A[nA ++] = P[i];
		else
			B[nB ++] = P[i];
	}

	scanf("%d%d", &x, &y);
	int ok1 = Check(A, nA, x, true);
	int ok2 = Check(B, nB, y, false);
	printf((ok1 && ok2) ? "Yes\n" : "No\n");
}
 
int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 512
"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    
    const cnt = [];
    
    for(let i=0; i<10; i++) {
        cnt.push(new Array(10).fill(0));
    }
    
    for(let i=1; i<=N; i++) {
        const S = String(i);
        const head = parseInt(S[0]);
        const tail = parseInt(S[S.length-1]);
        
        cnt[head][tail]++;
    }
    
    // console.log(cnt.join("\n"));
    
    let answer = 0;
    
    for(let i=0; i<10; i++) {
        for(let j=0; j<10; j++) {
            answer += cnt[i][j] * cnt[j][i];
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 14400
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

ll f(ll n){
  if(n%4 == 0) return n;  //nまでの数の個数が奇数個、かつn-1までの1の組み合わせが偶数個
  if(n%4 == 1) return 1;  //nまでの数の個数が偶数個、かつ1の組み合わせが奇数個
  if(n%4 == 2) return n+1;  //nまでの数の個数が奇数個、かつn-1までの1の組み合わせも奇数個
  return 0;
}

void solve(){
  ll A, B;
  cin >> A >> B;

  cout << (f(A-1) ^ f(B)) << endl;
}

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

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<pair<int, int>> a;
  int st = 0;
  for (int i = 0; i < n; ++i) {
    if (i == n - 1 || s[i] != s[i + 1]) {
      a.emplace_back(i - st + 1, st);
      st = i + 1;
    }
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<int> ans(n + 1, -1);
  for (auto p : a) {
    int l = p.second, len = p.first;
    int r = l + len - 1;
    for (int i = l; i <= r + 1; ++i) {
      if (ans[i] == -1) ans[i] = s[l] == '<' ? i - l : (r + 1) - i;
    }
  }
  long long sum = 0;
  for (int i : ans) {
    sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 5140
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
long long h, w, k, A[309][309], num;
long long cnt[309];
char c[309][309];

void solve(long long cl, long long cr){
    vector<long long> P;

    for(long long y = cl; y <= cr; y++){
        for(long long x = 1; x <= w; x++){
            if(c[y][x] == '#'){
                P.push_back(x);
            }
        }
    }

    sort(P.begin(), P.end());

    for(long long x = 0; x < P.size(); x++){
        long long v1 = 1, v2 = w;
        if(x >= 1){
            v1 = P[x-1] + 1;
        }
        if(x < P.size() - 1){
            v2 = P[x];
        }
        num++;
        for(long long y = cl; y <= cr; y++){
            for(long long k = v1; k <= v2; k++){
                A[y][k] = num;
            }
        }
    }
}

int main(){
    
    cin >> h >> w >> k;

    

    for(long long y = 1; y <= h; y++){
        for(long long x = 1; x <= w; x++){
            cin >> c[y][x];
            if(c[y][x] == '#') cnt[y]++;
        }
    }

    vector<long long> vec;
    for(long long y = 1; y <= h; y++){
        if(cnt[y] >= 1){
            vec.push_back(y);
        }
    }
    for(long long y = 0; y < vec.size(); y++){
        long long v1 = 1, v2 = h;
        if(y >= 1) v1 = vec[y-1] + 1;
        if(y < vec.size() - 1) v2 = vec[y];

        solve(v1, v2);
    } 

    for(long long y = 1; y <= h; y++){
        for(long long x = 1; x <= w; x++){
            printf("%lld ", A[y][x]);
            
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 4548
def main():
    N,M=map(int, input().split())
    a = [-1] * N
    
    for _ in range(M):
        s,c=map(int, input().split())
        if a[s-1] == -1 or a[s-1] == c:
            a[s-1] = c
        else:
            print(-1)
            return
    
    if N > 1 and a[0] == 0:
        print(-1)
        return

    ans = ''
    for i in range(N):
        if a[i] != -1:
            ans += str(a[i])
        elif i == 0 and N > 1:
            ans += '1'
        else:
            ans += '0'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

unordered_map<char, long> mp;
string march = "MARCH";

long foo(long current, long rest) {
  if (rest == 0) return 1;
  if (current == 5) return 0;
  long ans = 0;
  ans += foo(current + 1, rest);
  ans += foo(current + 1, rest - 1) * mp[march[current]];
  return ans;
}

void solve() {
  long N;
  cin >> N;
  rep (i, N) {
    string S;
    cin >> S;
    mp[S[0]]++;
  }
  cout << foo(0, 3) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) return 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if ((i + j) % 2) {
                    cout << '.';
                } else {
                    cout << '#';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int s, w; cin >> s >> w;
  cout << (w >= s ? "unsafe\n" : "safe\n");
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;

int insertion_sort(vector<int> &arr, int g) {
  int n = SZ(arr);
  int cnt = 0;
  FOR(i, g, n) {
    int v = arr.at(i);
    int j = i - g;
    while (j >= 0 and arr.at(j) > v) {
      arr.at(j + g) = arr.at(j);
      j -= g;
      cnt++;
    }
    arr.at(j + g) = v;
  }
  return cnt;
}

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

  int n;
  cin >> n;
  vector<int> arr(n);
  REP(i, n) cin >> arr.at(i);

  vector<int> gs = {1};
  for (int i = 4; i < n; i = 3 * i + 1) {
    gs.push_back(i);
    if (SZ(gs) == 100)
      break;
  }
  reverse(ALL(gs));
  int m = SZ(gs);
  cout << m << endl;
  REP(i, m) cout << (i ? " " : "") << gs.at(i);
  cout << endl;
  int cnt = 0;
  REP(i, m) cnt += insertion_sort(arr, gs.at(i));
  cout << cnt << endl;
  REP(i, n) cout << arr.at(i) << endl;

  return 0;
}


Measured memory_bytes: 6724
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long

int main() {
    vector<int> abc(3);
    for (auto& e: abc) cin >> e;
    sort(abc.begin(), abc.end());
    abc.erase(unique(abc.begin(), abc.end()), abc.end());
    cout << abc.size() << endl;
}

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

using namespace std;

typedef long long llint;

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

Measured memory_bytes: 256
N = int(input())
S = input()

# i番目の人の左にある E, W の数
count_E = [0]
count_W = [0]

for s in S:
    if s == 'E':
        count_E.append(count_E[-1] + 1)
        count_W.append(count_W[-1])
    else:
        count_E.append(count_E[-1])
        count_W.append(count_W[-1] + 1)

ans = 10**6

for i in range(N):
    rotate_left = count_W[i]
    rotate_right = count_E[-1] - count_E[i+1]
    total = rotate_left + rotate_right
    if total < ans:
        ans = total

print(ans)

Measured memory_bytes: 17788
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

//1点更新,区間和
class SegmentTree {
public:
    SegmentTree(ll n) {
        n_ = (ll)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, 0);
    }

    void update(ll x, ll diff) {
        nodes_[x + n_ - 1] += diff;
        for (ll i = (x + n_ - 2) / 2; i > 0; i = (i - 1) / 2) {
            nodes_[i] = nodes_[2 * i + 1] + nodes_[2 * i + 2];
        }
    }

    ll getSum(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return 0;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        ll lv = getSum(a, b, 2 * k + 1, l, (l + r) / 2);
        ll rv = getSum(a, b, 2 * k + 2, (l + r) / 2, r);
        return lv + rv;
    }

private:
    //2のべき乗
    ll n_;
    vector<ll> nodes_;
};


ll MODpow(ll n, ll m, ll mod) {
    ll result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= mod;
        }

        m /= 2;
        n *= n;
        n %= mod;
    }

    return result;
}

int main() {
    ll N;
    cin >> N;
    struct Point {
        ll x, y;
    };
    vector<Point> points(N);
    for (Point& p : points) {
        cin >> p.x >> p.y;
    }

    //座標圧縮
    {
        set<ll> x_st, y_st;
        for (const Point& p : points) {
            x_st.insert(p.x);
            y_st.insert(p.y);
        }
        map<ll, ll> x_mp, y_mp;
        ll num = 0;
        for (const auto& e : x_st) {
            x_mp[e] = num++;
        }
        num = 0;
        for (const auto& e : y_st) {
            y_mp[e] = num++;
        }
        for (Point& p : points) {
            p.x = x_mp[p.x];
            p.y = y_mp[p.y];
        }
    }

    //x順でソート
    sort(points.begin(), points.end(), [](Point& lhs, Point& rhs){
        return lhs.x < rhs.x;
    });

    constexpr ll MAX = 2e5;
    SegmentTree before(MAX + 1), after(MAX + 1);
    for (const Point& p : points) {
        after.update(p.y, 1);
    }

    //i番目の点から見て各象限にある点の個数
    vector<vector<ll>> num(N, vector<ll>(4, 0));

    constexpr ll MOD = 998244353;

    ll ans = 0;

    for (const Point& p : points) {
        //右上
        ll num1 = after.getSum(p.y + 1, MAX + 1);
        ll pat1 = (MODpow(2, num1, MOD) + MOD - 1) % MOD;

        //左上
        ll num2 = before.getSum(p.y + 1, MAX + 1);
        ll pat2 = (MODpow(2, num2, MOD) + MOD - 1) % MOD;

        //左下
        ll num3 = before.getSum(0, p.y);
        ll pat3 = (MODpow(2, num3, MOD) + MOD - 1) % MOD;

        //右下
        ll num4 = after.getSum(0, p.y);
        ll pat4 = (MODpow(2, num4, MOD) + MOD - 1) % MOD;

        //自分を含む
        (ans += MODpow(2, N - 1, MOD)) %= MOD;

        //自分を含まない
        (ans += pat1 * pat3 % MOD * MODpow(2, num2 + num4, MOD) % MOD) %= MOD;
        (ans += pat2 * pat4 % MOD * MODpow(2, num1 + num3, MOD) % MOD) %= MOD;

        //重複を除く
        (ans += MOD - pat1 * pat2 % MOD * pat3 % MOD * pat4 % MOD) %= MOD;

        //更新
        before.update(p.y, 1);
        after.update(p.y, -1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 48512
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
typedef long long ll;
int N;
pair<ll, ll> nums[10000];
pair<ll, ll> ans;

int main(void) {
    // insert code here...
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> nums[i].first;
        cin >> nums[i].second;
    }
    
    ans.first = nums[0].first;
    ans.second = nums[0].second;
    
    for(int i = 1; i < N; i++){
        ll a, b;
        if(ans.first % nums[i].first == 0){
            a = ans.first / nums[i].first;
        }else{
            a = ans.first / nums[i].first + 1;
        }
        
        if(ans.second % nums[i].second == 0){
            b = ans.second / nums[i].second;
        }else{
            b = ans.second / nums[i].second + 1;
        }
        
//        ans.first = nums[i].first * a;
//        ans.second = nums[i].second * b;
        
        if(a < b){
            ans.first = nums[i].first * b;
            ans.second = nums[i].second * b;
        }else{
            ans.first = nums[i].first * a;
            ans.second = nums[i].second * a;
        }
        
    }
    
    cout << ans.first + ans.second << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

const int N = 2e5 + 10;
long long int a[N];
int n;

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	long long int sum = 0;
	
	for(int i = 0;i < n;i++)
	{
		cin >> a[i];
			
		sum += a[i];
		sum %= 1000000007;
	}
	
	long long ans = 0;
	
	for(int i = 0 ; i < n ; i++)
	{
		sum -= a[i];
		while(sum < 0) sum += 1000000007;
		
		ans += a[i] * sum;
		ans %= 1000000007;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4700
# -*- coding: utf-8 -*-
import sys 
from math import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int, readline().split()))
M = max(A) + 1
#0-index
minfactor = [0] * M
minfactor[1] = 1
commondivisor = [0] * M

def seive():
    for i in range(2,M):
        if minfactor[i] == 0:
            for j in range(i*2,M,i):
                if minfactor[j] == 0:
                    minfactor[j] = i
    for i in range(2,M):
        if minfactor[i] == 0:
            minfactor[i] = i  

gc = A[0]
for i in range(1,N):
    gc = gcd(A[i],gc)
    
if gc != 1:
    print('not coprime')
else:
    seive()
    for i in range(N):
        a = A[i]
        while a > 1:
            div = minfactor[a]
            commondivisor[div] += 1
            while a % div == 0:
                a //= div
    if max(commondivisor) <= 1:
        print('pairwise coprime')
    else:
        print('setwise coprime')

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

int main() {
  uint32_t N = 0;
  std::cin >> N;

  std::map<uint64_t, uint64_t> past;
  uint64_t ans = 0;
  for (size_t i = 0; i < N; i++) {
    uint32_t A_i = 0;
    std::cin >> A_i;
    if (i >= A_i) {
      uint32_t current = i - A_i;
      if (past.find(current) != past.end()) {
        ans += past[current];
      }
    }

    past[A_i + i]++;
  }

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

  return 0;
}

Measured memory_bytes: 16100
# -*- coding: utf-8 -*-
# C - Replacing Integer
# 標準入力の取得
N,K = list(map(int, input().split()))

# 求解処理
# "N % K"と"N % K"に対して操作を1回だけ行った際の値を比較
a = N % K
b = abs(a - K)
print(min(a, b))

Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
int main () {
    int A, B, count = 0;
    scanf("%d %d", &A, &B);
    for(int i = A; i <= B; ++i){
        char num[6];
        num[0] = (i / 10000) + 48;
        num[1] = ((i % 10000) / 1000) + 48;
        num[2] = ((i % 1000) / 100) + 48;
        num[3] = ((i % 100) / 10) + 48;
        num[4] = (i % 10) + 48;
        if(num[0] == num[4] && num[1] == num[3]) count++;
    }
    printf("%d\n", count);
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int c[3][3];
	for (int i = 0; i < 3; i++)
		cin >> c[0][i] >> c[1][i] >> c[2][i];
	int a[3], b[3];
	for (a[0] = 0; a[0] <= 100; a[0]++) {
		for (a[1] = 0; a[1] <= 100; a[1]++) {
			for (a[2] = 0; a[2] <= 100; a[2]++) {
				b[0] = c[0][0] - a[0];
				b[1] = c[0][1] - a[0];
				b[2] = c[0][2] - a[0];
				bool f = true;
				for(int i = 0; i < 3; i++)
					for (int j = 0; j < 3; j++) 
						if (c[i][j] != a[i] + b[j])
							f = false;
				if (f) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
#input = lambda: sys.stdin.readline().rstrip()
#区間DP

def main():
  while True:
    n = int(input())
    if(n == 0):
      break
    w = list(map(int, input().split()))
    
    dp = [[0] * (n+1) for _ in range(n+1)]
    
    for gap in range(2,n+1):
      #gapが小さい方から埋めることで漏れをなくす
      for l in range(n-gap+1):
        r = l+gap
        if(dp[l+1][r-1] == gap-2):
          if(abs(w[l]-w[r-1]) <= 1):
            dp[l][r] = gap
            continue
        for k in range(l, r):
          if(dp[l][r] < dp[l][k] + dp[k][r]):
            dp[l][r] = dp[l][k] + dp[k][r]
    print(dp[0][n])
    #print(dp)
    
if __name__ == '__main__':
  main()


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

int main(void) {
  vector<string> vec = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  int i;
  string str;
  cin >> str;
  
  for (i = 0; i < sizeof(vec); i++) {
    if (str == vec[i]) {
      break;
    }
  }
  cout << i + 1 << endl;
}

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

using namespace std;

int main(){
    int n,ans=0;
    cin >>n;
    vector<int> a(n);
    int b_l=a[0],b_r=a[n-1];
    for(auto &e:a) cin >>e;
    vector<int> l(n-1),r(n-1);
    for(int i=0;i<n-1;i++){
        l[i]= __gcd(a[i],b_l);
        r[i]= __gcd(a[n-1-i],b_r);
        b_l = l[i];
        b_r = r[i];
    }

    for(int h=0;h<n-2;h++){
        ans=max(ans,__gcd(l[h],r[n-3-h]));
        //cout << ans<<"\t"<<l[h]<<"\t"<<r[n-3-h] <<endl;
    }

    //cout << l[n-2] <<"\t" <<r[n-2]<<endl;

    ans = max({ans,l[n-2],r[n-2]});
    cout << ans<<endl;

}

Measured memory_bytes: 1408
//g++  5.4.0
// Time_Complexity : O( 2^n * n )
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int mod = 1e9+7;

signed main()
{
    fast;
    int n;
    cin >> n;
    bool can[n][n];
    for(int i=0 ; i<n ; i++ ) 
        for(int j=0 ; j<n ; j++ )  
            cin >> can[i][j];
        
    int dp[(1<<n)];
    memset( dp,0,sizeof(dp) );
    dp[0] = 1;
    
    vector<int> bit[n];
    
    for(int mask=0 ; mask<(1<<n)-1 ; mask++ )
        bit[ __builtin_popcount(mask) ].pb( mask );
    for(int i=0 ; i<n ; i++ )
    {
        for( auto mask : bit[i] )
        {
            for(int j=0 ; j<n ; j++ )
            {
                if( can[i][j] && !(mask & (1<<j)) )
                {
                    dp[ mask ^ (1<<j) ] += dp[mask];
                    dp[ mask ^ (1<<j) ] %= mod;
                }
            }
        }
    }
    
    cout << dp[(1<<n)-1];
}

Measured memory_bytes: 41508
N,M,C = (int(x) for x in input().split())
B = [int(x) for x in input().split()]
ans = 0

for i in range(N):
    A = [int(x) for x in input().split()]
    check = C
    for j in range(M):
        check += A[j]*B[j]
    if check > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}


int main(int argc, const char * argv[]) {
    ll A, B, N; cin >> A >> B >> N;
    
    ll front,back;
    if(N<B-1){
        front = floor((A*N)/B);
        back = A*floor(N/B);
    }else{
        front = floor((A*(B-1))/B);
        back = A*floor((B-1)/B);
    }
    
    cout << front - back << endl;
 
    return 0;
}




Measured memory_bytes: 3528
mod=1777777777
n,ma,mb=map(int,input().split())
d=[[mod for j in range(100)] for i in range(100)]
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(100-a-1,-1,-1):
        for k in range(100-b-1,-1,-1):
            d[j+a][k+b]=min(d[j+a][k+b],d[j][k]+c)
    d[a][b]=min(d[a][b],c)
ans=mod
for i in range(100):
    if i%ma==0 and mb*i//ma<100:
        ans=min(ans,d[i][mb*i//ma])

print([ans,-1][ans==mod])

Measured memory_bytes: 3188
# AOJ ALDS1_14_B "String Search"
# returns i s.t. S[i+j] = T[j] for 0 <= j < len(T)

def RollingHash(S, T, ls):
    if len(S) < len(T):
        return []
    # gcd(h, b) = 1
    h = 10**11+7
    b = 10**7+7
    L = len(T)

    bL = 1
    for i in range(L):
        bL = bL * b % h

    hashS = 0
    for i in range(L):
        hashS = (hashS * b + S[i]) % h

    hashT = 0
    for i in range(L):
        hashT = (hashT * b + T[i]) % h
    
    correctIndexes = [0]*len(S)
    ret = 0
    if hashS == hashT:
        correctIndexes[0] = 1
    for j in range(len(S)-L):
        hashS = (hashS * b - S[j]*bL + S[L+j]) % h
        if hashS == hashT:
            tmp = correctIndexes[j+1-L] + 1
            correctIndexes[j+1] = tmp
            if tmp > ret: ret = tmp
    if ret*L > 2*ls:
        return -1
    return ret


import sys
input = sys.stdin.buffer.readline

S = input().rstrip()
T = input().rstrip()

ls = len(S)
lt = len(T)
S = S*((2*lt+3*ls-1)//ls)
ans = RollingHash(S, T, ls)
print(ans)

Measured memory_bytes: 96236
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N;
int A[100010];


signed main(){
    cin >> N;
    rep(i, 0, N)
        cin >> A[i];

    int S = 0;
    S += abs(A[0]);
    rep(i, 1, N) S += abs(A[i]-A[i-1]);
    S += abs(A[N-1]);

    cout << S-abs(A[0])-abs(A[1]-A[0])+abs(A[1]) << endl;;
    rep(i, 1, N-1) cout << S-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]) << endl;
    cout << S-abs(A[N-1]-A[N-2])-abs(A[N-1])+abs(A[N-2]) << endl;

    return 0;
}

Measured memory_bytes: 2048
N,A,B,C,D = map(int, input().split())
S = input()
S1 = ''

if C < D:
    S1 = S[A-1:D-1]
else:
    S1 = S[A-1:C-1]

fd = S1.find('##')
if fd != -1:
    print('No')
    exit()

if C < D:
    print('Yes')
    exit()

else:

    S2 = S[B-2:D+1]
    fddot = S2.find('...')

    if fddot == -1:
        print('No')

    else:
        print('Yes')


Measured memory_bytes: 3636
#include <stdio.h>
int main(){
    int a[4],b[4],x,y;
    while(scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])!=EOF){
        x=y=0;
        for(int i=0;i<4;i++){
            if(a[i]==b[i])x++;
            else if(a[i]==b[(i+1)%4]||a[i]==b[(i+2)%4]||a[i]==b[(i+3)%4])y++;
            
        }
        printf("%d %d\n",x,y);
    }}

Measured memory_bytes: 2760
#include<iostream>

using namespace std;

int min(int x, int y){
    if(x > y) return y;
    else return x;
}

int main(){
    int n, a[100], b[100], sum = 0;
    cin >> n;
    for(int i = 0; i < n - 1; i++) cin >> b[i];
    for(int i = 0; i < n; i++){
        if(i == 0) a[i] = b[i];
        else if(i == n - 1) a[i] = b[i - 1];
        else a[i] = min(b[i - 1], b[i]);
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

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

int foo(int k) {
    if (k <= 1) return 1;

    int p[1000] = {};
    int q[1001] = {}; // 約数が2個以下だったら0
    for (int i = 2; i < k; i++) {
        if (q[i]) continue;
        for (int j = i * 2; j <= k; j += i) {
            q[j] = 1;
        }
    }
    int n = 0;
    for (int i = 2; i <= k; i++) {
        if (q[i] == 0) p[n++] = i;
    }

    int f[1000] = {};
    for (int i = 2; i <= k; i++) {
        int t = i;
        for (int j = 0; j < n; j++) {
            while (t % p[j] == 0) {
                t /= p[j];
                f[j]++;
            }
            if (t == 1) break;
        }
    }

    //for (int j = 0; j < n; j++) {
    //    std::cout << p[j] << ":" << f[j] << " ";
    //}
    //std::cout << "\n" << n << std::endl;

    uint64_t r = 1;
    for (int j = 0; j < n; j++) {
        if (f[j] == 0) throw;
        r *= f[j] + 1;
        r %= 1000000007;
    }

    return (int)r;
}

int main() {
    int k;
    std::cin >> k;
    std::cout << foo(k) << 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 sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  double n;
  cin >> n;
  bool ok = false;
  for (double i = 1; i <= 9; i++) {
    double a = n / i;
    if (a >= 1 && a <= 9) {
      if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6 || a == 7 || a == 8 || a == 9) ok = true;
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
n = int(input())
import math
import itertools
p = []
q = 0
for i in range(n):
    a,b = map(int,input().split())
    p.append((a,b))
s = itertools.permutations(p, n)
for i in s:
    for j in range(n-1):
        q += ((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
print(q/math.factorial(n))

Measured memory_bytes: 41708
import java.util.Scanner;

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

        int N = sc.nextInt();
        int Q = sc.nextInt();

        String S = sc.next();
        int count = 0;
        int[] table = new int[N+1];

        table[0] = 0;
        for(int i = 1; i<=N; i++) {
            if ( i != N && S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                count++;
            }
            table[i] = count;
        }
        for (int i = 0; i<Q; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            System.out.println((table[r-1])-(table[l-1]));
        }
    }
}

Measured memory_bytes: 71412
# -*- coding:utf-8 -*-

N = int(input())

ans = 9999999
j = N - 1
for i in range(1, N):
    di = sum([int(d) for d in list(str(i))])
    dj = sum([int(d) for d in list(str(j))])
    ans = min(ans, di + dj)
    j -= 1
print(ans)

Measured memory_bytes: 3064
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]
lnum = [0] * N
Alist = [A,B,C]
ans = 2**30+1
for i in range(4**N):
    cnt = -30
    tmp = i
    for j in range(N):
        lnum[j] = tmp%4
        tmp //= 4
    
    if not(1 in lnum and 2 in lnum and 3 in lnum):
        continue
    x = [0] * 3
    for j in range(N):
        if lnum[j] != 0:
            x[lnum[j]-1] += l[j]
            cnt += 10
    for j in range(3):
        cnt += abs(Alist[j]-x[j])
    
    ans = min(ans,cnt)
    
print(ans)
    
        

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_C>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N,W; cin >> N >> W;
    vector<ll> v(N),w(N); for(int i = 0; i < N;i++) cin >> v[i] >> w[i];
    vector<ll> dp(W+1);
    for(int i = 0; i < W;i++){
        for(int j = 0; j < N;j++){
            if(i + w[j] > W) continue;
            dp[i+w[j]] = max(dp[i+w[j]],dp[i]+v[j]);
        }
    }
    res = dp[W];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3304
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  cin >> s;
  string tmp;
  int last_A = 0;
  int first_B = 0;
  int num_of_AB = 0;
  int B_A = 0;
  for (int i = 0; i < N; i++) {
    if (s[i][0] == 'B') first_B++;
    for (int j = 1; j < s[i].size(); j++) {
      if (s[i][j - 1] == 'A' && s[i][j] == 'B') num_of_AB++;
    }
    if (s[i][s[i].size() - 1] == 'A') last_A++;
    if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') {
      B_A++;
    }
  }
  int ans = 0;
  if (B_A > 0) {
    last_A -= B_A;
    first_B -= B_A;
    ans += B_A - 1;
    if (last_A > 0) {
      ans++;
      last_A = max(last_A - 1, 0);
    }
    if (first_B > 0) {
      ans++;
      first_B = max(first_B - 1, 0);
    }
    ans += min(last_A, first_B);
  } else {
    ans += min(last_A, first_B);
  }
  ans += num_of_AB;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <atcoder/all>
using namespace std;using z=long;int main(){z N,Q;cin>>N>>Q;atcoder::fenwick_tree<z> b(N);for(z i=0;i<N;i++){z a;cin>>a;b.add(i,a);}for(z i=0;i<Q;i++){z w,e,r;cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<endl;else b.add(e,r);}}

Measured memory_bytes: 8204
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N; cin >> N;
	if (N == 2) {
		int A, B; cin >> A >> B;
		cout << A + B << endl;
		return;
	}
	cout <<  "Hello World" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 2e5 + 10;
int n, m;
ll a[N];

int main()
{
	ll sum = 0;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	sort(a + 1, a + n + 1);
	sum = (sum + 4 * m - 1) / (4 * m);
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] >= sum) cnt++;
	}
	if (cnt >= m) cout << "Yes\n";
	else cout << "No\n";
}

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

int main() {
  string S, T; cin >> S >>T;
  string t_s = "";
  for (int i=0; i<T.length()-1; i++) {
    t_s += T[i];
  }
  if (S == t_s) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, n, k);
    makev(a, n);
    sort(ALL(a));
    cout << accumulate(a.begin(), a.begin() +k, 0ll);

    return 0;
}

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

int main()
{

        vector<int> H;
        vector<int> W;

        while (1) {
                int h, w;
                cin >> h >> w;
                if (h == 0 && w == 0) {
                        break;
                }
                H.push_back(h);
                W.push_back(w);
        }
        int n = H.size();
        for (int i = 0; i < n; ++i) {

                for (int j = 0; j < H[i]; ++j) {

                        bool all = false;
                        for (int k = 0; k < W[i]; ++k) {
                                char c;
                                if (j == 0 || j == H[i]-1) {
                                        all = true;
                                }
                                if (all) {
                                        c = '#';
                                }
                                else {
                                        if (k == 0 || k == W[i]-1) {
                                                c = '#';
                                        }
                                        else {
                                                c = '.';
                                        }
                                }
                                cout << c;

                        }
                        cout << endl;
                }
                cout << endl;
        }


}



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

int main() {
  int A, B, C, D;
  A =getchar()-'0';
  B =getchar()-'0';
  C =getchar()-'0';
  D =getchar()-'0';
  int S[2] = {1, -1};
  char s[2] = {'+', '-'};
  for (int i=0;i<2;i++) {
    for (int j=0;j<2;j++) {
      for (int k=0;k<2;k++) {
        if(A+B*S[i]+C*S[j]+D*S[k]==7) {
          cout << A << s[i] << B << s[j] << C << s[k] << D << "=7\n";
          return 0;
        }
      }
    }
  }
}

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

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    
    int**a  = new int*[n];
    for(int i = 0; i < n; i++){a[i] = new int[m];}

    int**b  = new int*[m];
    for(int i = 0; i < m; i++){b[i] = new int[l];}

    long long**c  = new long long*[n];
    for(int i = 0; i < n; i++){c[i] = new long long[l];}

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

    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> b[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k < l; k++){
                c[i][k] += a[i][j] * b[j][k]; 
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){        
            if(j != 0){
                cout << " ";
            }
            cout << c[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
 
int main() {
	int A,B,C;
cin>>A>>B>>C;
int k=max({A,B,C});

	int ans=k*10+A+B+C;
   ans-=max({A,B,C});
	ce(ans)
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] k = new int[3];
		for(int i = 0; i < 3; i++) {
			k[i] = sc.nextInt();
		}
		sc.close();
		if(k[0] % 2 == 1 || k[1] % 2 == 1 || k[2] % 2 == 1) {
			System.out.println(0);
			System.exit(0);
		}
		if(k[0] == k[1] || k[1] == k[2]) {
			System.out.println(-1);
			System.exit(0);
		}
		int cnt = 0;
		while(k[0] % 2 == 0 && k[1] % 2 == 0 && k[2] % 2 == 0) {
			int t0 = k[0];
			int t1 = k[1];
			int t2 = k[2];
			k[0] = (t1 + t2) / 2;
			k[1] = (t0 + t2) / 2;
			k[2] = (t0 + t1) / 2;
			cnt++;
		}
		System.out.println(cnt);
	}
}

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> b(n);
  REP(i,n-1)cin >> b.at(i);
  ll ans=b.at(0)+b.at(n-2);
  REP(i,n-2){
    ans += min(b.at(i),b.at(i+1));
  }
  cout << ans << endl;
}

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

using namespace std;

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

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

    int l = 0, r = s.size() - 1;
    int cnt = 0;
    while (l < r) {
        if (s[l] == s[r]) {
            l++;
            r--;
        } else {
            if (s[l] == 'x') {
                cnt++;
                l++;
            } else if (s[r] == 'x') {
                cnt++;
                r--;
            } else {
                cout << "-1" << endl;
                return 0;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize,
        d: i64,
        xy: [(i64, i64); n],
    };
    let mut ans = 0;
    for &(x_i, y_i) in xy.iter() {
        if x_i * x_i + y_i * y_i <= d * d {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
 
const int N   = 3e5+7;
const int MOD = 1e9+7;
const int INF = (~(1<<31));
 
int fre(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
 
inline int read(){
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||'9'<ch;ch=getchar())if(ch=='-') f=-1;
	for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
 
#define lal puts("****");
#define pb  push_back
#define mp  make_pair
#define x   first
#define y   second
 
/*****************************************************************/
 
int a,b;
int s[111];
int main(){
    memset(s,0,sizeof(s));
 
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++) s[i]++;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++) s[i]++;
    
    int ans = 0;
    for(int i=0;i<=100;i++)
        if(s[i]==2)ans++;
if(ans == 0) ans ++;
    printf("%d\n",ans-1 );
    return 0;
}

Measured memory_bytes: 256