akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    map<int,int> mpd,mpt;
    int n,m;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        mpd[d[i]]++;
    }
    cin >> m;
    vector<int> t(m);
    for (int i = 0; i < m; ++i) {
        cin >> t[i];
        mpt[t[i]]++;
    }
    if(m > n){
        cout << "NO" << endl;
        return 0;
    }
    for(auto x:mpt){
        int f = x.first,s = x.second;
        if(mpd[f] < s){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

int main() {
  int N, A, B, P1, P2;
  cin >> N >> A >> B;
  P1 = A * N;
  P2 = B;
  if (P1 > P2) {
    cout << P2 << endl;
  }
  else {
    cout << P1 << endl;
  }
}

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

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

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

int main()
{
    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= d; j++)
        {
            if (j / 10 <= 1 || j % 10 <= 1)
            {
                continue;
            }
            if (i == (j / 10) * (j % 10))
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
if(c>a and c-a<=d):
 print("Yes\n")
elif(a>=c and a-c<=d):
 print("Yes\n")
elif(c>a and c-b<=d and b-a<=d):
 print("Yes\n")
elif(a>c and a-b<=d and b-c<=d):
 print("Yes\n")
else:
 print("No\n")


Measured memory_bytes: 3060
#include <stdio.h>


// I/O
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
//

// Union Find
typedef struct UnionFind {
    int parent[100000];
    int rank[100000];
    int size[100000];
} UnionFind;

void uf_init(UnionFind *UF) {
    const int N = 100000;
    for(int i = 0; i < N; ++i) {
        UF->parent[i] = i;
        UF->rank[i] = 0;
        UF->size[i] = 1;
    }
}

#define uf_same(UF, x, y) (uf_find((UF), (x)) == uf_find((UF), (y)))

int uf_find(UnionFind *UF, int x) {
    if(x == UF->parent[x]) return x;
    else return UF->parent[x] = uf_find(UF, UF->parent[x]);
}

void uf_unite(UnionFind *UF, int x, int y) {
    x = uf_find(UF, x), y = uf_find(UF, y);
    if(x == y) return;
    if(UF->rank[x] < UF->rank[y]) UF->parent[x] = y;
    else {
        UF->parent[y] = x;
        if(UF->rank[x] == UF->rank[y]) UF->rank[x]++;
        int tmp = x, x = y, y = tmp;
    }
    UF->size[y] += UF->size[x];
    UF->size[x] = 0;
}
//


int main(int argc, char **argv) {
    int n = get_uint();
    int m = get_uint();
    UnionFind UF;
    uf_init(&UF);
    for(int i = 0; i < m; ++i) {
        int s = get_uint();
        int t = get_uint();
        uf_unite(&UF, s, t);
    }
    int q = get_uint();
    for(int i = 0; i < q; ++i) {
        int s = get_uint();
        int t = get_uint();
        puts(uf_same(&UF, s, t) ? "yes" : "no");
    }
    return 0;
}



Measured memory_bytes: 2832
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int h, w; cin >> h >> w;
    string a[10];
    REP(i, h) {
        cin >> a[i];
    }
    REP(i, h) {
        REP(j, w) {
            if (((i == h - 1) && (j == w - 1))) {
                // 最初のマス、最後のマスについては二方向に '#' がある場合はNG
                if ((a[i-1][j] == '#') && (a[i][j-1] == '#')) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            } else if ((a[i][j] == '#') && (a[i+1][j] != '#') && (a[i][j+1] != '#')) {
                // 終点以外のすべての通過マスについて、右も下も '.' だとNG
                cout << "Impossible" << endl;
                return 0;
            } else {
                // 三方向に '#' がある場合はNG
                int c = 0;
                if ((0 < i) && (a[i-1][j] == '#')) {
                    c++;
                }
                if ((i < h - 1) && (a[i+1][j] == '#')) {
                    c++;
                }
                if ((0 < j) && (a[i][j-1] == '#')) {
                    c++;
                }
                if ((j < w - 1) && (a[i][j+1] == '#')) {
                    c++;
                }
                if (c > 2) {
                    cout << "Impossible" << endl;
                    return 0;
                }

                // 最初のマス、最後のマスについては二方向に '#' がある場合はNG
                if ((i == 0) && (j == 0) && (a[i+1][j] == '#') && (a[i][j+1] == '#')) {
                    cout << "Impossible" << endl;
                    return 0;
                }
                if ((i == h-1) && (j == w-1) && (a[i-1][j] == '#') && (a[i][j-1] == '#')) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    rep(i,n){
        if (a[i] == b[n-1]) cout << b[n-2] << endl;
        else cout << b[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int fi; cin >> fi;
    int max_ele = fi;
    int cnt = 1;
    rep(i, n-1) {
        int tmp; cin >> tmp;
        if (tmp <= max_ele) cnt++;
        chmin(max_ele, tmp);
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

int d[10],d2[10],num[10];

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int n2 = n;
    int m = 0;
    while(n2){
        int dig = n2%10;
        num[m++] = dig;
        n2/=10;
    }
    for(int i = 0; i<k; i++){
        int di;
        scanf("%d",&di);
        d[di] = 1;
    }
    int fd = 0;
    for(int i = 0; i<10; i++){
        if(!d[i]){
            fd = i;
            break;
        }
    }
    for(int i = 0; i<10; i++){
        d2[i] = -1;
        for(int j = i+1; j<10; j++){
            if(!d[j]){
                d2[i] = j;
                break;
            }
        }
    }
    for(int i = m-1; i>=0; i--){
        if(d[num[i]]){
            int f = i;
            while(f<m&&d2[num[i]]==-1)
                f++;
            if(f==m){
                num[m] = d2[0];
                for(int i = 0; i<m; i++)
                    num[i] = fd;
                m++;
            }else{
                num[f] = d2[num[i]];
                for(int j = f-1; j>=0; j--)
                    num[j] = fd;
            }
            break;
        }
    }
    for(int i = m-1; i>=0; i--)
        printf("%d",num[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  int N=s.size();
  int a=0;
  for(int i=0;i<N;i++){
    if(s.at(i)!=t.at(i)){
      a=1;
    }
  }  
  if(a==1){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}








Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
a.sort()
def binarysearch(x):
  ok=-1
  ng=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>=x:
      ng=mid
    else:
      ok=mid
  return ok
ans=0
for i in range(-1,10**5+2):
  ans=max(ans,binarysearch(i+2)-binarysearch(i-1))
print(ans)

Measured memory_bytes: 13964
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
overpower = 0
for i in range(n):
    if a[i] >= overpower:
        ans += overpower
        enemy = a[i] - overpower
    else:
        ans += a[i]
        enemy = 0
    overpower = 0
    
    if enemy >= b[i]:
        ans += b[i]
    else:
        ans += enemy
        overpower = b[i]-enemy

if a[-1]>=overpower:
    print(ans+overpower)
else:
    print(ans+a[-1])  


Measured memory_bytes: 18476
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define int long long

using namespace std;
const int inf = 1e18;
const double MOD = 0.00000001;

signed main(){
    int n;
    cin >> n;
    vector<pair<double,double> > v(n);
    for(int i = 0;i<n;i++){
        cin >> v[i].first;
        cin >> v[i].second;
    }
    int cnt = 1;
    int cnt1 = 1;
    for(int  i= 1;i<=n;i++) cnt *= i;
    cnt1 =cnt;
    cnt *= (n-1)*2;
    cnt /= n*(n-1);
    double res = 0;
    for(int i = 0;i<n;i++){
        for(int z = i+1;z<n;z++){
            res += cnt*sqrt((v[i].first-v[z].first)*(v[i].first-v[z].first) + (v[i].second-v[z].second)*(v[i].second-v[z].second));
        }
    }
    cout << fixed << setprecision(10) << res/cnt1;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int k; cin >> k;
  string s; cin >> s;
  int size = (int)s.size();

  if(size <= k) { cout << s << endl; }
  else {
    for(int i=0;i<k;i++) { cout << s[i]; }
    cout << "...\n";
  }

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[200010];

bool ok(int k) {
	map<int, int> mp;
	for (int i = 1; i <= n; i++) {
		if (a[i - 1] < a[i])continue;
		if (k == 1)return false;
		auto p = mp.upper_bound(a[i]);
		while (p != mp.end()) {
			auto q = p;
			p++;
			mp.erase(q);
		}
		int x = a[i];
		while (1) {
			if (mp[x] != k - 1) {
				mp[x]++;
				break;
			}
			if (x == 1) return false;
			mp[x] = 0;
			x--;
		}
	}
	return true;
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	int mi = 0, ma = n;
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (ok(md))ma = md;
		else mi = md;
	}
	cout << ma << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 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 MOD 1000000007

int a[200005];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n) scanf("%d", &a[i]);
	if (a[n - 1] > n - 1) {
		cout << -1 << endl;
		return 0;
	}
	LL ret = a[n-1];
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] > i) {
			cout << -1 << endl;
			return 0;
		}
		if (a[i] < a[i + 1] - 1) {
			cout << -1 << endl;
			return 0;
		}
		if (a[i] != a[i + 1] - 1) {
			ret += a[i];
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    int a=s.size();
    for(int i=0;i<a;i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int h[n+1];
    int c[n+1] = {0};
    int x = 0;
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(i == 0)c[i] = 0;
        else{
             if(h[i] <= h[i-1])c[i] += c[i-1]+1;
             else c[i] = 0;
        }
    }
    int mx = -1;
    for(int i = 0; i < n; i++){
        mx = max(mx,c[i]);
    }
    cout << mx << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define dbg(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<endl;
typedef vector<int> VI;
typedef long long ll;
typedef pair<double,int> PII;
const ll p=998244353;
const ll mod=1e9+7;
const int maxn=1e5+100;
map<ll,int> mp;

struct node
{
    int to,next;
}e[maxn*2];

int tol=0;
int head[maxn];
void add(int u,int v)
{
    e[++tol].to=v,e[tol].next=head[u],head[u]=tol;
}
ll dfs(int u,int f)
{
    ll ans=1;
    for(int i=head[u];i;i=e[i].next)
    {
        int v=e[i].to;
        if(v==f) continue;
        ans=(ans+dfs(v,u)*mod%p)%p;
    }
    mp[ans]++;
    return ans;
}


int main()
{
    int n;
    scanf("%d",&n);
    rep(i,1,n)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v),add(v,u);
    }
    mp.clear();
    dfs(1,0);
    ll ans=0;
    map<ll,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++) ans+=1ll*(it->se)*(it->se-1)/2;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 19236
N=int(input())
T=list(map(int, input().split()))
M=int(input())
PX=[list(map(int, input().split())) for _ in range(M)]
Tsum=sum(T)
for i in range(M):
    print(Tsum-T[PX[i][0]-1]+PX[i][1])


Measured memory_bytes: 3060
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

int main() {
	int n;
	cin >> n;
	vector<int> a = vector<int>(n, 0);
	rup(i, 0, n) {
		cin >> a[i];
		a[i]--;
	}
	vector<bool> already = vector<bool>(n, 0);

	int search = a[0];
	already[0] = true;
	int count = 1;
	while (1) {
		int next;

		if (search == 1) {
			cout << count;
			break;
		}
		else {
			if (!already[search]) {
				already[search] = true;
				next = a[search];
				count++;
			}
			else {
				cout << -1;
				break;
			}
		}
		search = next;
	}

	return 0;
}





Measured memory_bytes: 768
#include<stdio.h>

int main(void)

{
int S,s,m,h;

scanf("%d",&S);

h =0;
s =0;
m =0;

h=S/3600;
m=S%3600/60;
s=S%3600%60;
printf("%d:%d:%d\n",h,m,s);

return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  ll sum = 0;
  for(int i=1; i<=n; i++){
    if(i%3!=0&&i%5!=0){
      sum+=i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}




int main(){
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	
	int ans=0;
	for(int p=0; p<=a; p++){
	for(int q=0; q<=b; q++){
	for(int r=0; r<=c; r++){
		if(500*p + 100*q + 50*r == x) ans+=1;
	}}}
	
	cout<<ans<<endl;
	return 0;
}




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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  vector<vector<int>> C(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &C[i][j]);
    }
  }
  vector<int> A(3), B(3);
  bool ok = true;
  for (int i = -100; i <= 100; ++i) {
    A[0] = i;
    for (int j = 0; j < 3; ++j) {
      B[j] = C[0][j] - A[0];
    }
    for (int j = 1; j < 3; ++j) {
      A[j] = C[j][0] - B[0];
    }
    ok = true;
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (A[j] + B[k] != C[j][k]) {
          ok = false;
          break;
        }
      }
    }
    if (ok) { break; }
  }
  printf("%s\n", ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int arr[n];
        int l[n], r[n];
        vector<pair<int, int>> v;
        for(int i=0; n>i; i++){
            cin >> arr[i] >> l[i] >> r[i];
            v.push_back({abs(l[i]-r[i]), i});
        }
        int ans = 0;
        set<int> st, st2;
        for(int i=1; n>=i; i++){
            st.insert(i);
            st2.insert(i);
        }
        sort(v.rbegin(), v.rend());
        for(int ii=0; n>ii; ii++){
            int id = v[ii].second;
            if(l[id] > r[id]){
                auto it = st.upper_bound(arr[id]);
                if(it != st.begin()){
                    it--;
                    ans += l[id];
                    st.erase(*it);
                }else{
                    ans += r[id];
                }
            }else{
                int temp = arr[id] + 1;
                auto it = st2.lower_bound(temp);
                if(it != st2.end()){
                    ans += r[id];
                    st2.erase(*it);
                }else{
                    ans += l[id];
                }
            }
        }
        cout << ans << endl;
        
    }
}






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

#define MAX 200010
long long mod = 1000000007;
long long inv[MAX],fact[MAX],fi[MAX];

void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
}

void factinv(){
	int i;
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]%mod*inv[i]%mod)%mod;
	}
}

long long comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return (fact[n]%mod*fi[k]%mod*fi[n-k]%mod)%mod;
	}
}

int main(){
	int y,k=0,l=0,i;
	long long x=0,n;
	cin >> n;
	vector <int> a(n+1);
	vector <long long> b(n+1);
	
	inverse();
	factinv();
	
	for(i=0;i<=n;i++){
	cin >> a[i];
	x += a[i];
	}
	y = x - (n*(n+1))/2;
	for(i=0;i<=n;i++){
		if(a[i] == y){
			k = i+1;
			l += i+1;
		}
	}
	l = l-k;
	for(i=0;i<=n;i++){
		b[i] = (mod + comb(n+1,i+1) - comb(n-k+l,i))%mod;
			cout << b[i]%1000000007 << endl;
	}
}

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

using namespace std;

int main(void) {
	int e;
	while(1) {
		cin >> e;
		if(e == 0) {
			break;
		}
		
		int tmpx, tmpy, tmpz, tmpe;
		tmpe = e;
		for(tmpz = 0; pow(tmpz, 3) <= tmpe; tmpz++){}
		tmpz--;
		tmpe = tmpe - pow(tmpz, 3);
		if(tmpe == 0){
			tmpy = 0; tmpx = 0;
		}else{
			for(tmpy = 0; pow(tmpy, 2) <= tmpe; tmpy++){}
			tmpy--;
			tmpe = tmpe - pow(tmpy, 2);
			if(tmpe == 0){
				tmpx = 0;
			}else{
				tmpx = tmpe;
			}
		}
		int tmpm = tmpx + tmpy + tmpz;
		//cout << tmpz << " ! " << endl;

		int tmp;
		for(int z = 0; z <= tmpz + 1; z++) {
			for(int y = tmpy; y <= min(tmpm - z, int(pow(e - pow(z, 3), 1.0 / 2.0))); y++) {
				int x = e - pow(y, 2) - pow(z, 3);
				tmp = x + y + z;
				if(tmp < tmpm) {
					tmpm = tmp;
				}
			}
		}

		cout << tmpm << endl;
	}
	return 0;
}

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

int selectionSort(int A[],int N){
  int sw = 0;
  for(int i=0; i<N; i++){
    int minj = i;
    for(int j=i; j<N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    if(minj != i){
      swap(A[i],A[minj]);
      sw++;
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for(int i=0; i<N; i++) cin >> A[i];
  sw = selectionSort(A,N);
  
  for(int i=0; i<N; i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
}


Measured memory_bytes: 3116
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return ((((a + m) % m + (b + m) % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return ((((a + m) % m * (b + m) % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

ll fp(ll x, ll y)
{
	ll res = 1;
	while (y)
	{
		if (y & 1)
			res = mul(res, x, MOD);
		y /= 2;
		x = mul(x, x, MOD);
	}
	return res % MOD;
}

ll nCr(ll n, ll r)
{
	if (n < r)
		return 0;
	ll ans = 1;
	if (r * 2 > n)
		r = n - r;
	for (ll i = 1; i <= r; i++)
		ans = mul(ans, mul(n - i + 1ll, fp(i, MOD - 2), MOD), MOD);
	return ans;
}

void solve()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = fp(2ll, n);
	ans = add(ans, MOD - 1ll, MOD);
	ans = add(ans, MOD - nCr(n, a), MOD);
	ans = add(ans, MOD - nCr(n, b), MOD);
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;

typedef pair<int, int> pi;
pair <int, int>p;
pair <int, int> po;
int n, m, c;
char ma[1001][1001];
int x, y;
int te[1001][1001];
int xw[4] = { 1, 0, -1, 0 };
int yw[4] = { 0, 1, 0, -1 };
char name[10] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
int nat = 0;
int na;
int op = 10000;
int main()
{
	queue<pi> q;
	cin >> n >> m >> na;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 < m; i2++){
			cin >> ma[i][i2];
			te[i][i2] = op;
			if (ma[i][i2] == 'S'){
				p.first = i;
				p.second = i2;
			}
		}
	}

	int count;

	count = 0;
	q.push(p);

	te[p.first][p.second] = 0;
	while (!q.empty()){
		p = q.front();
		po = p;
		q.pop();

		for (int i = 0; i < 4; i++){
			x = p.first + xw[i];
			y = p.second + yw[i];
			if (0 <= x && x < n && 0 <= y && y < m && ma[x][y] != 'X' && te[x][y] == op){

				if (ma[x][y] == name[nat]){
					po.first = x;
					po.second = y;
					while (!q.empty()){ q.pop(); }
					q.push(po);
					count += te[p.first][p.second] + 1;
					nat++;
					if (nat == na){ cout << count << endl; return 0; }
					for (int i2 = 0; i2 <= n; i2++){
						for (int i3 = 0; i3 <= m; i3++){
							te[i2][i3] = op;
						}
					}
					te[x][y] = 0;
					break;
				}
				else{
					po.first = x;
					po.second = y;
					q.push(po);
					po = p;
					te[x][y] = te[p.first][p.second] + 1;
				}
			}
		}
	}
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vector<string> s(n);
  rep(i, n) {
    cin >> s[i];
  }

  REP(i, n) {
    bool flag = false;

    if (s[i][0] != s[i - 1][s[i - 1].size() - 1]) {
      flag = true;
    } else {
      rep(j, i) {
        if (s[i] == s[j]) {
          flag = true;
          break;
        }
      }
    }

    if (flag) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2) {
      n--;
      result *= x;
      result %= mod;
    } else {
      n /= 2;
      x *= x;
      x %= mod;
    }
  }
  return result;
}

ll Inv(ll x) {
  return Pow(x, mod - 2);
}

const int maxn = 3 * 100 * 1000 + 2;
ll fact[maxn];

ll C(int n, int k) {
  ll result = fact[n];
  result = result * Inv(fact[k]) % mod;
  result = result * Inv(fact[n - k]) % mod;
  return result;
}

int main()
{
  ll n, A, B, k;
  cin >> n >> A >> B >> k;

  fact[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    fact[i] = fact[i - 1] * i % mod;
  }

  ll result = 0;
  for (ll x = 0; x <= n; ++x) {
    if (k - x * A < 0) continue;
    if ((k - x * A) % B != 0) continue;
    ll y = (k - x * A) / B;
    if (y > n) continue;

    result += C(n, x) * C(n, y);
    result %= mod;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 2560
#include"bits/stdc++.h"
// #include "prettyprint.hpp"

using namespace std;

typedef long long ll;


#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, n) for(ll i=n; i>=0; i--)
#define reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()

int main(){
	int H,N;

	cin >> H >> N;

	vector<ll> A(N);
	vector<ll> B(N);

	rep(i,N) cin >> A[i] >> B[i];

	vector<ll> dp(H+10000);

	ll max_A = 0;

	rep(i,N) max_A = max(A[i],max_A);

	ll ans = 1000000000000;

	reps(i,1,H+max_A+1){
		ll temp = 100000000000;
		rep(j,N){
			if(i>A[j]){
				temp = min(dp[i-A[j]] + B[j], temp);
			}

			else{
				temp = min(B[j],temp);
			}
		}
		dp[i] = temp;

		if(i>=H && i<= H+max_A){
			ans = min(ans,dp[i]);
		}
	}

	cout << ans << endl;

	return 0;

}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	VI table;
	REP (i, 1, 1000) {
		if (i == 1) {
			table.pb(i);
		} else {
			table.pb(table[i - 2] + i);
		}
	}
	int a, b;
	cin >> a >> b;
	int ans = -1;
	rep (i, table.size() - 1) {
		int c = table[i] - a;
		int d = table[i + 1] - b;
		if (c == d) {
			ans = c;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}




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

using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int H, W;
 
struct Dinic {
    struct Edge {
        int to, rev;
        ll c, f;
    };
    vi lvl, ptr, q;
    vector<vector<Edge>> adj;
    Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
    void addEdge(int a, int b, ll c, int rcap = 0) {
        adj[a].push_back({b, sz(adj[b]), c, 0});
        adj[b].push_back({a, sz(adj[a]) - 1, rcap, 0});
    }
    ll dfs(int v, int t, ll f) {
        if (v == t || !f) return f;
        for (int& i = ptr[v]; i < sz(adj[v]); i++) {
            Edge& e = adj[v][i];
            if (lvl[e.to] == lvl[v] + 1)
                if (ll p = dfs(e.to, t, min(f, e.c - e.f))) {
                    e.f += p, adj[e.to][e.rev].f -= p;
                    return p;
                }
        }
        return 0;
    }
    ll calc(int s, int t) {
        ll flow = 0; q[0] = s;
        rep(L,0,31) do { // 'int L=30' maybe faster for random data
            lvl = ptr = vi(sz(q));
            int qi = 0, qe = lvl[s] = 1;
            while (qi < qe && !lvl[t]) {
                int v = q[qi++];
                trav(e, adj[v])
                    if (!lvl[e.to] && (e.c - e.f) >> (30 - L))
                        q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
            }
            while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
        } while (lvl[t]);
        return flow;
    }
};

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> H >> W;
    Dinic d(H + W + 2);
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            if (s[j] == 'o')
                d.addEdge (i, H + j, 1, 1);
            if (s[j] == 'S')
            {
                d.addEdge (H + W, i, 1e9);
                d.addEdge (H + W, H + j, 1e9);
            }
            if (s[j] == 'T')
            {
                d.addEdge (i, H + W + 1, 1e9);
                d.addEdge (H + j, H + W + 1, 1e9);
            }
        }
    }

    ll ans = d.calc (H + W, H + W + 1);
    if (ans > 1e8)
        cout << "-1\n";
    else
        cout << ans << "\n";
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int c[N];
int main() {
	int k, n;
	scanf("%d %d", &k, &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &c[i]);
	int ans = c[n] - c[1];
	for (int i = 2; i <= n; i++)
	{
		ans = min(ans, k - c[i] + c[i - 1]);
	}
	printf("%d", ans);
}

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

string z,x;
int dp[3005][3005];
vector <char> asd;
char lcs[3005+1]; 

void LCSS( string X,string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   lcs[index]; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<<lcs;
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>z>>x;
	LCSS(z,x,z.size(),x.size());
//	jalan(z.size(),x.size());
//	for(int q=asd.size()-1;q>=0;q--)
//	{
//		cout<<asd[q];
//	}
//	cout<<endl;
//	cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include <stdio.h>

int main(void)
{
        int i;
        int r;
        int D;
        int x;

        scanf("%d %d %d",&r,&D,&x);

        for(i=1;i<=10;i++){
                x=r*x-D;
                printf("%d\n",x);
        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int light = 0;
  int count = 0;
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    count++;
    light = A.at(light)-1;
    if (light == 1){
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3788
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int m1 = scn.nextInt();
		int d1 = scn.nextInt();
      	int m2 = scn.nextInt();
      	int d2 = scn.nextInt();
      	int ans = 0;
      	if(d2==1) ans = 1;
      	System.out.println(ans);
	}
}

Measured memory_bytes: 35828
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            while (sc.hasNext()) {
                String[] strs = sc.nextLine().split(" ");
                int a = Integer.parseInt(strs[0]);
                int b = Integer.parseInt(strs[1]);
                int c = Integer.parseInt(strs[2]);
                int sum = a+b+c;
                int m = Math.max(a, Math.max(b,c));
                System.out.println((((m*3-sum)%2 == 0)?(m*3-sum)/2:(m*3 + 3-sum)/2));
            }
        }
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	int n;
	cin >> n;
	int number = 1;
	int maxer = 0;
	for (int i = 1; i <= n; i++) {
		int a = i;
		int cnt = 0;
		while (true) {
			if (a == 0) break;
			if (a % 2 == 0) {
				a /= 2;
				cnt++;
			}
			else {
				break;
			}
		}
		if (maxer < cnt) {
			maxer = cnt;
			number = i;
		}
	}
	cout << number << endl;
}



Measured memory_bytes: 256
#C - Traveling Salesman around Lake WA(ヒント)
K,N = map(int,input().split())
A = list(map(int, input().split()))

A[N+1:] = [A[0] + K]#Aを二回繰り返して円を表現

distance_list = []
for i in range(N):
    distance = abs(A[i] - A[i+1])
    distance_list.append(distance)
distance_list.remove(max(distance_list))
print(sum(distance_list))

Measured memory_bytes: 32368
s = input()
s1 = int(s[:2])
s2 = int(s[2:])

if 1 <= s1 <= 12 and 1 <= s2 <= 12:
    print("AMBIGUOUS")

elif 1 <= s2 <= 12:
    print("YYMM")

elif 1 <= s1 <= 12:
    print("MMYY")

else:
    print("NA")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// int		cmpstr(const void *s1, const void *s2)
// {
// 	while (*(char **)s1 && *(char **)s2 && *(char **)s1 == *(char **)s2)
// 	{
// 		*(char **)s1 += 1;
// 		*(char **)s2 += 1;
// 	}
// 	return (*(char **)s1 - *(char **)s2);
// }

int		cmpstr(const void *s1, const void *s2)
{
	return (strcmp(*(char **)s1, *(char **)s2));
}

int		main()
{
	int		N;
	char	**str;
	int		count = 1;
	char	prev[11];

	scanf("%d\n", &N);
	str = (char **)malloc(sizeof(char *) * (N + 1));
	for (int i = 0; i < N; i++)
	{
		str[i] = (char *)malloc(sizeof(char) * 11);
		scanf("%s\n", str[i]);
	}
	// printf("s = %s s = %s\n", str[0], str[1]);
	qsort((void *)str, N, sizeof(char *), cmpstr);
	// printf("s = %s s = %s\n", str[0], str[1]);
	strcpy(prev, str[0]);
	for (int i = 1; i < N; i++)
	{
		if (strcmp(prev, str[i]))
			count++;
		// printf("%s %s\n", prev, str[i]);
		strcpy(prev, str[i]);
	}
	printf("%d\n", count);
	return (0);
}


Measured memory_bytes: 10716
#include<bits/stdc++.h>
#define debug puts("&&&&&&")
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const int mod=1e9+7;
int n,k;
int u[maxn],v[maxn];
LL next[maxn],cnt,temp;
LL cnt1;
vector<int> ma[maxn];
void dfs(int f,int t,int deep) {
    cnt1++;
    if(deep==0){
        return;
    }
    for(int i=0;i<ma[f].size();i++) {
        if(ma[f][i] != t) {
            dfs(ma[f][i],f,deep-1);
        }
    }
}
int main() {
    while(read(n) != EOF) {
        read(k);
        for(int i=0;i<=n;i++) {
            ma[i].clear();
        }
        cnt=0;
        temp=0;
        LL ans=0;
        for(int i=1;i<=n-1;i++) {
            read(u[i]);
            read(v[i]);
            ma[u[i]].push_back(v[i]);
            ma[v[i]].push_back(u[i]);
        }
        if(k%2==1) {
            for(int i=1;i<=n-1;i++) {
                cnt=0;
                cnt1=0;
                dfs(u[i],v[i],k/2);
                dfs(v[i],u[i],k/2);
                cnt+=cnt1;
                ans=max(ans,cnt);
            }
        }
        else {
            for(int i=1;i<=n;i++) {
                cnt=0;
                cnt1=0;
                dfs(i,0,k/2);
                cnt+=cnt1;
                ans=max(ans,cnt);
            }
        }
        printf("%d\n",n-ans);
    }
}


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

int main(){
	int n, k;
	int sum=0;
	cin >> n >> k;
	vector<int> vec(n);
	for(int i=0; i<n; i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for(int i=0; i<k; i++){
		sum += vec.at(i);
	}
	cout << sum << endl;
}


Measured memory_bytes: 3612
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    string s;
    cin>>s;
    int k;
    cin>>k;
    int n = s.size();
    ll dp[n+1][k+1][2]={};
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
            dp[i+1][j][1] += dp[i][j][1]; // 確定 -> 確定
            if(s[i]=='0') dp[i+1][j][0] += dp[i][j][0]; // 0 未確定->未確定
            if(s[i]!='0') dp[i+1][j][1] += dp[i][j][0]; // 0　未確定->確定
            for(int h=1;h<=9;h++){
                if(j+1<=k && s[i]==('0'+h)) dp[i+1][j+1][0] += dp[i][j][0]; //0以外 未確定->未確定
                if(j+1<=k){
                    dp[i+1][j+1][1] += dp[i][j][1]; // 0以外 確定 ->　確定
                    if('0'+h < s[i]) dp[i+1][j+1][1] += dp[i][j][0]; // 0以外 未確定 -> 確定
                }
            }
        }
    }
    ll ans = dp[n][k][0] + dp[n][k][1];
    cout << ans << endl;


}


// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vi a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 0;
    rep(i, n-1) {
        sum -= a[i];
        ll r = a[i] * (sum % mod);
        r %= mod;
        ans += r;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <string>
using namespace std;

int main()
{
    string s;
    int k;
    cin >> s;
    cin >> k;
    for(int i = 0; i < s.size(); ++i)
    {
        if(s[i] > 'a')
        {
            int pos = s[i] - 'a';
            if(k >= 26 - pos)
            {
                k -= (26 - pos);
                s[i] = 'a';
            }
        }
    }
    k %= 26;
    int n = s.size();
    s[n-1] = (s[n-1] - 'a' + k) % 26 + 'a';
    cout << s << endl;
    return 0;
}


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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int sum[2000];
    for(int i=1;i<=n-1;i++){
        sum[i]=0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int min_dis;
            min_dis=min(j-i,abs(x-i)+1+abs(j-y));
            sum[min_dis]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<sum[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256