akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 8;

const LL inf = 1e18;
int n, a, b, T[M];
LL dp[M], D[2 * M];

void add(int v, int w)
{
  v += M;
  D[v] += w;
  while (v > 1)
  {
    v /= 2;
    D[v] = D[2 * v] + D[2 * v + 1];
  }
}

int sum(int p, int k)
{
  p += M;
  k += M;
  int res = D[p];
  if (p != k)
  {
    res += D[k];
  }
  while (p / 2 != k / 2)
  {
    if (p % 2 == 0)
    {
      res += D[p + 1];
    }
    if (k % 2 == 1)
    {
      res += D[k - 1];
    }
    p /= 2;
    k /= 2;
  }
  return res;
}

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(NULL);
	scanf("%d%d%d", &n, &a, &b);
	FOR(i, 1, n)
	{
		scanf("%d", T + i);
	}
	
	dp[1] = 0;
	T[n + 1] = n + 1;
	FOR(i, 2, n + 1)
	{
		dp[i] = inf;
		LL tmp = 0;
		int ile = 0;
		FORD(j, i - 1, 0)
		{
			if (T[j] < T[i])
			{
				int mn = sum(0, T[j]);
				mini(dp[i], dp[j] + tmp + (LL)mn * b + (LL)min(a, b) * (ile - mn));
				debug(i, j, dp[i], dp[j], tmp, mn, b, min(a, b), (ile - mn));
			}
			add(T[j], 1);
			if (T[j] > T[i])
			{
				tmp += a;
			}
			else
			{
				ile++;
			}
		}
		FOR(j, 0, i - 1)
		{
			add(T[j], -1);
		}
	}
	
	printf("%lld\n", dp[n + 1]);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
    #include<stdio.h>
    using namespace std;
    int main(){
    	int A,B,N;
    	scanf("%d %d",&A,&B);
    	N=A+B;
    	if(N>=24)
    	printf("%d",N-24);
    	else
    	printf("%d",N);
    	return 0;
    }

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	int n,f=0;cin>>n;
	vector<pair<int, int>>a(n);
	for(int i=0;i<n;i++)
		cin>>a[i].first>>a[i].second;
	for(int i=0;i<n-2;i++){
		if(a[i].first==a[i].second&&a[i+1].first==a[i+1].second&&a[i+2].first==a[i+2].second){
			f=1;break;
		}
	}
	if(f)cout<<"Yes";
	else cout<<"No";
   return 0;
} 

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h> 
 
int main(){
  int x,y,z,n,i,r;
 
  do{
    scanf("%d %d %d",&x,&y,&z);
    if(x==0&&y==0&&z==0) break;
    x*=x; y*=y; z*=z;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&r);
      if(sqrt(x+z)/2<r||sqrt(x+y)/2<r||sqrt(y+z)/2<r){
    printf("OK\n");
      }else{
    printf("NA\n");
      }
    }
  }while(1);
  return 0;
}

Measured memory_bytes: 580
using System;

namespace abc134B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C;
            C = 2 * B + 1;
            int D = A / C;
            int E = A % C;
            if (E == 0)
                D = D + 0;
            else
                D = D + 1;
            Console.WriteLine(D.ToString());

        }
    }
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(12);
    cout << fixed;
    cin.tie(0);

    int n;
    cin >> n;
    map<string, int> dupa;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        dupa[s]++;
    }
    cout << "AC x " << dupa["AC"] << endl;
    cout << "WA x " << dupa["WA"] << endl;
    cout << "TLE x " << dupa["TLE"] << endl;
    cout << "RE x " << dupa["RE"] << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
const int N=25;
int n,m,c,b[N],ans;
/**/
int main()
{
	// freopen("test.in","r",stdin);
	// freopen("test.out","w",stdout);
	read(n);read(m);read(c);
	for(int i=1;i<=m;i++) read(b[i]);
	for(int i=1;i<=n;i++)
	{
		int sum=c;
		for(int j=1;j<=m;j++)
		{
			sum+=(Rem()*b[j]);
		}
		if(sum>0) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = scan.nextInt();
		String s = scan.next();

		if(3200 <= a) {
			System.out.println(s);
		}else {
			System.out.println("red");
		}

	}
}


Measured memory_bytes: 21844
n = gets.to_i
h = gets.chomp.split(' ').map(&:to_i)

max = 0
count = 0

(n-1).times do |i|
  if h[i] >= h[i+1]
    count += 1
  else
    if max <= count
      max = count
    end
    count = 0
  end
end

if max <= count
  max = count
end

print max

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

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n+x-1)/x*t << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


class segtree{
public:
    segtree(ll size, vector<ll> &v){
        n = 1;
        while(n < size){n *= 2;}
        data = vector<ll>(2*n-1, INIT_VAL);
        build(v);
    }
    void build(vector<ll> &v){
        for(int i = 0; i < v.size(); i++){
            data[n-1+i] = v[i];
        }
        for(int i = n-2; i >= 0; i--){
            data[i] = data[2*i+1]|data[2*i+2];
        }
    }
    void update(ll k, ll a){
        k += n-1;
        data[k] = a;
        while(k>0){
            k = (k-1)/2;
            data[k] = data[2*k+1]|data[2*k+2];
        }
    }
    ll getSize(){return n;}
    ll getData(ll x){return data[n-1+x];}
    ll query(ll a, ll b, ll k, ll l, ll r){
        if(r <= a || b <= l){return INIT_VAL;}
        if(a <= l && r <= b){return data[k];}
        else{
            ll vl = query(a, b, 2*k+1, l, (l+r)/2);
            ll vr = query(a, b, 2*k+2, (l+r)/2, r);
            return vl|vr;
        }
    }
    void printAllTree(){
        ll cnt = 0;
        ll br = 1;
        for(int i = 0; i < data.size(); i++){
            cout << data[i] << " ";
            cnt++;
            if(cnt == br){
                cout << endl;
                cnt = 0;
                br *= 2;
            }
        }
    }
private:
    ll n;
    vector<ll> data;
    ll INIT_VAL = 0;
};

int main(){
    ll n, q;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;
    ll init_val = 0;
    vector<ll> a(n, init_val);
    for(int i = 0; i < n; i++){
        a[i] = 1LL<<(s[i]-'a');
    }
    segtree st(n, a);

    for(int i = 0; i < q; i++){
        ll ta, tb, tc;
        char ctc;
        cin >> ta ;
        if(ta==1){
            cin >> tb >> ctc;
            tb--;
            ll tc2 = 1LL<<(ctc-'a');
            st.update(tb, tc2);
        }else{
            cin >> tb >> tc;
            tb--; tc--;
            ll ret = st.query(tb, tc+1, 0, 0, st.getSize());
            ll cnt = 0;
            for(int j = 0; j < 40; j++){
                if(ret & (1LL<<j)){cnt++;}
            }
            cout << cnt << endl;
        }
    }
    return 0;

}


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

############### TESTCASE ###############
test = ""
#test = \
"""
4 2001
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
################# MAIN ################# 

k, x = map(int, input2().split())
if k * 500 - x >= 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2e5+5;
int n,a[maxn],q[maxn];
char s[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	go(i,n+1,1) a[i]=s[i] == 'S';
	int tl=0;
	go(i,n+1,1){
		if(tl > 0 && q[tl] == 1 && a[i] == 0) tl--;
		else q[++tl]=a[i];
	}
	printf("%d",tl);
	return 0;
}//Faze


Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    rep(i, S.size()) {
        if(S[i] != T[i])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	int x, dist;
	dist = 0;
	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x * x < (x - K) * (x - K)) {
			dist += 2*x;
		}
		else if(x < K){
			dist += 2*(K - x);
		}
		else {
			dist += 2*(x - K);
		}
	}
	cout << dist << endl;
}

Measured memory_bytes: 256
N, X, M = map(int, input().split())
cnt = [0] * M
cnt[X] = 1
start = -1
seq = [X]
for i in range(1, N):
    X = X * X % M
    if cnt[X] > 0:
        start = X
        break
    seq.append(X)
    cnt[X] += 1

if start < 0:
    print(sum(seq))
    exit()

cycle_start_idx = seq.index(start)
header = seq[:cycle_start_idx]
cycle = seq[cycle_start_idx:]
in_cycle_N = N - len(header)
q, r = divmod(in_cycle_N, len(cycle))
ans = sum(header) + sum(cycle) * q + sum(cycle[:r])
print(ans)


Measured memory_bytes: 12424
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	REP(i, N) {
		cout << S[i] << T[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll A[17];
ll t;
ll x, y;
ll ret = 0;
ll state[17][17];
ll human[17];

void input() {
  REP(i, 17) {
    REP(j, 17) {
      state[i][j] = -1;
    }
  }

  IN(N);
  FOR(i, 1, N+1) {
    IN(A[i]);
    REP(j, A[i]) {
      IN(x);
      IN(y);
      state[i][x] = y; // iさんはxさんをyだと言った
    }
  }
}

void solve() {
  FORR(b, (1<<N) - 1, 0) {
    REP(i, N) {
      human[i+1] = (b>>i) & 1;
      // DEBUG(human[i+1]);
    }
    bool ok = true;
    FOR(i, 1, N+1) {
      if (human[i] == 0) {
        continue;
      } else {
        //iさんが正直者
        FOR(j, 1, 16) {
          //iさんのjさんへの発言を確認
          if (state[i][j] != -1) {
            if (state[i][j] != human[j]) {
              // DEBUG("BURN!!");
              // DEBUG(i);
              // DEBUG("さんは");
              // DEBUG(j);
              // DEBUG("さんを");
              // DEBUG(state[i][j]);
              // DEBUG("だと言ったが");
              // DEBUG(human[j]);
              // DEBUG("だ|");
              //正直者の発言の整合性が取れない
              ok = false;
            }
          }
        }
      }
    }
    if (ok) {
      // 全ての正直者の発言の整合性が取れた
      ll num = 0;
      REP(i, 17) {
        num += human[i];
      }
      ret = CHMAX(ret, num);
    }
    // LN();
  }
  
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool check=false;
	rep(i,b)if(a*i%b==c){check=true;break;}
	if(check)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll h,w,k;cin>>h>>w>>k;
  vector<string>s(h);
  auto ret=make_v(h,w,0LL);
  rep(i,0,h)cin>>s[i];
  ll cnt=0;
  rep(i,0,h){
    ll num=0;
    rep(j,0,w)if(s[i][j]=='#')num++;
    if(num!=0){
      ll num2=0;
      rep(j,0,w){
        if(s[i][j]=='#'){
          num2++;cnt++;
        }
        if(num2!=0)ret[i][j]=cnt;
      }
      rrep(j,0,w)if(ret[i][j]==0)ret[i][j]=ret[i][j+1];
    }
  }
  rep(i,1,h)rep(j,0,w)if(ret[i][j]==0)ret[i][j]=ret[i-1][j];
  rrep(i,0,h-1)rep(j,0,w)if(ret[i][j]==0)ret[i][j]=ret[i+1][j];
  debug(ret,h,w);
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int sum = a + b + c;
  int ma = max(a,b);
  ma = max(ma,c);
  int goal;
  while(1) {
    if(sum % 3 == 0) {
      if(sum / 3 >= ma) {
        goal = sum / 3;
        break;
      }
      else sum += 6;
    }
    else if(sum % 3 == 1) sum += 2;
    else sum += 4;
  }
  int ans = 0;
  ans += goal - a;
  ans += goal - b;
  ans += goal - c;
  cout << ans / 2 << endl;
}

Measured memory_bytes: 256
N = int(input())
xc, yc, tc = 0, 0, 0
ans = 'Yes'
for i in range(N):
  t, x, y = map(int, input().split())
  if (t - tc - abs(x-xc) - abs(y-yc)) % 2 == 0 and t - tc - abs(x-xc) - abs(y-yc) >= 0:
    xc, yc, tc = x, y, t
  else:
    ans = 'No'
    break
print(ans)
  

Measured memory_bytes: 9040
def list_input():
    return list(map(int,input().split()))
def map_input():
    return map(int,input().split())
def map_string():
    return input().split()
    
def solve(b):
	res = [0]*(len(b))
	m = max(b)
	#n-i-2+1 for 1s
	#n-i-2+1 for 2s
	#n-i-2+3 for 3s
	#n-i-2+m for ms
	c = []
	for i in range(len(b)):
		if b[i] == m:
			ind = len(b)-i-2+m
			if(ind < 0 or ind >= len(b)):
				print(-1)
				exit()
			res[ind] = m
		else:
			c.append(b[i])		
	if(c):
		bitch = solve(c)
		j = 0
		for i in bitch:
			while res[j] != 0:
				j += 1
			res[j] = i
	return res			


n = int(input())    
a = list_input()
ans = solve(a)      
for i in ans:
	print(i)

Measured memory_bytes: 3064
import java.io.*
import java.util.*

fun solve(N: Long, T: Long, c: LongArray, t: LongArray){
    val ans = (0 until N.toInt()).map{ c[it] to t[it] }.filter{ it.second <= T }.minBy{ it.first }?.first
    println(ans?: "TLE")
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val T = sc.next().toLong()
    val c = LongArray(N.toInt())
    val t = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        c[i] = sc.next().toLong()
        t[i] = sc.next().toLong()
    }
    solve(N, T, c, t)
}



Measured memory_bytes: 31492
#include<stdio.h>
int main(){
	int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 
            15, 2, 2, 5, 4, 1, 4, 1, 51};
	int i;
	scanf("%d", &i);
	printf("%d", array[i-1]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int d, r;
	int w = 0;
	double  x = 0, y = 0;
	char n;
	 

	 while(1){

	 	cin >> d >> n >> r;
	 	
	 	if(d == 0 && n == ',' && r == 0) break;
	 	
	 	x += d * sin(w * M_PI / 180);
	 	y += d * cos(w * M_PI / 180);
	 	w += r;
	 	
	 
	 	
	 }
	 
	 cout << (int)x << endl << (int)y << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	cin >> n >> m;
	vll h(n);
	for (ll i = 0; i < n; i++) cin >> h[i];
	vector<vll> nx(n, vll(0));
	for (ll i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		nx[a].push_back(b);
		nx[b].push_back(a);
	}

	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		if (nx[i].size() == 0) ans++;
		for (ll j = 0; j < nx[i].size(); j++) {
			if (h[i] <= h[nx[i][j]]) break;
			if (j == nx[i].size() - 1) ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 9860
n,m=gets.split.map(&:to_i)
rd=[]
i=1#iが都市
j=0
while line= gets
  rd<< line.split.map(&:to_i)
end
while i<=n
  num=0
  while j<m
    if rd[j].any?{|n| n==i}
      num+=1
    end
    j+=1
  end
  puts num
  i+=1
  j=0
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll X, K, D;
    cin >> X >> K >> D;
    ll a = abs(X) / D;
    if(K <= a){
        cout << abs(X) - K*D << endl;
        return 0;
    }
    if((K-a)%2 == 0){
        cout << abs(X) - a*D << endl;
        return 0;
    }
    cout << abs(abs(X) - (a+1)*D) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF ((ll)1<<31)-1
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,p;
vector<P> vec;
void func(int m){
	for(int i=2;i<=sqrt(m);i++){
		int cnt=0;
		while(m%i==0){
			cnt++;
			m/=i;
		}
		if(cnt)vec.push_back({i,cnt});
	}
	if(m!=1)vec.push_back({m,1});
}
signed main(){
	cin>>n>>p;
	func(p);
	int ans=1;
	for(P p:vec){
		ans*=(int)pow(p.first,p.second/n);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int x,a,b;
int main(){
	cin>>x>>a>>b;
	if(b-a<=0)cout<<"delicious"<<endl;
	else if(b-a<=x)cout<<"safe"<<endl;
	else if(b-a>x)cout<<"dangerous"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  string S;
  cin >> S;
  ll N = 753;

  ll ans = INF;

  REP(i, S.length() - 2) {
    ll Nnow = stoi(S.substr(i, 3));
    ans = min(ans, abs(Nnow - N));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>i;
int u,y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b=0,c,d=0,e=0,f=-1,g=0;
  string s,w;
  cin >>s>>w;
  if(s[0]==w[0]) d++;
  if(s[1]==w[1]) d++;
  if(s[2]==w[2]) d++;
  cout <<d<<'\n';
  return (0);
}


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

int main(){
int a,b,c;
while(scanf("%d",&c),c){
	a=b=0;
	for(int d=0;d<c;d++){
	int e,f;
	scanf("%d%d",&e,&f);
	if(e>f)a+=e+f;
	else if(e<f)b+=e+f;
	else {a+=e;b+=f;}
}
printf("%d %d\n",a,b);
}
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

int main(){
    int x;
    cin >> x;

    const int max = 100004;
    int l[max];
    for(int i = 0; i < max; i++){
        l[i] = i;
    }
    for(int i = 0; i < max; i++){
        if(l[i] == -1) continue;
        if(i == 0 || i == 1){
            l[i] = -1;
            continue;
        }
        for(int j = i + 1; j < max; j++){
            if(l[j] == -1) continue;
            if(l[j]%l[i]==0) l[j] = -1;
        }
    }

    for(int i = x; i < max; i++){
        if(l[i] != -1){
            cout << l[i] << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
//#define INF 1000000007
#define ARRAY_MAX 100005
const ll INF = 1e17;

struct SegmentTree{

    int N;
    vector<int> node;
    const int INF = INT_MAX;

    void init(int siz){
        N = 1;
        while(N < siz){
            N *= 2;
        }
        node.resize(2*N-1,INF);
    }

    void build(vector<int>& dat){
        for(int i = 0;i < dat.size();i++){
            node[i+N-1] = dat[i];
        }
        for(int i = N-2;i >= 0;i--){
            node[i] = min(node[2*i+1],node[2*i]+2);
        }
    }

    void update(int k,int x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;//親
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }

    int getMin(int a,int b,int k,int l,int r){
        if(r <= a || b <= l){
            return INF;
        }
        if(a <= l && r <= b){
            return node[k];
        }
        int vl = getMin(a,b,k*2+1,l,(l+r)/2);
        int vr = getMin(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }

    int getMin(int a,int b){
        return getMin(a,b,0,0,N);
    }
};

int main(){

    SegmentTree segt;
    int n,q;
    cin >> n >> q;
    segt.init(n);
    REP(i,q){
        int comp,x,y;
        cin >> comp >> x >> y;
        if(comp == 1){
            cout << segt.getMin(x,y+1) << endl;
        }else{
            segt.update(x,y);
        }
    }



    return 0;
}


Measured memory_bytes: 3912
//============================================================================
// Name        : svdzva.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	for(int i = 1;i<10;i++){
		for(int j = 1;j<10;j++){
			cout << i <<"x"<< j <<"="<<i*j<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
  using namespace std;
  int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int sa;
    sa = B/K-A/K;
    if(sa > 0 || A % K == 0){
      cout << "OK" << endl;
    }
    else{
      cout << "NG" << endl;
    }
  }

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String word = input.readLine();
        boolean [] state  = new boolean[26];

        for (int i = 0; i < word.length(); i++) {
            if (state[word.charAt(i) - 'a']){
                System.out.println("no");
                return;
            }
            state[word.charAt(i) - 'a'] = true;
        }
        System.out.println("yes");
    }
}


Measured memory_bytes: 21076
#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)
EPS = 0.00001

while true
  q = gets.to_f
  break if q < 0
  x = q / 2
  while (x**3 - q).abs >= EPS * q
    x -= (x**3 - q) / 3.0 / x / x
  end
  puts x
end

Measured memory_bytes: 6208
#include<iostream>
#include<cstring>

using namespace std;


int main( )
{
	char s[100];
	cin >> s;
	char ss[] = "FESTIVAL";
	int len = strlen(s);
	int end;
	int j;
	for(j = 1; j <= 8; j++)
		if(s[len - j] != ss[8 - j]) break;
//	cout << j << endl;
	if(j == 9){
		for(int j = 0; j < len - 8; j++)
			cout << s[j];
		cout << endl;
	}else
		cout <<s << endl;
	
		 
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    int a, b;
    cin >> a >> b;
    cout << 100 << " " << 100 << endl;
    char matrix[100][100];
    for (int i=0; i < 50; i++) for (int j=0; j < 100; j++) matrix[i][j] = '#';
    for (int i=50; i < 100; i++) for (int j=0; j < 100; j++) matrix[i][j] = '.';
    a--;
    int u = 0, v = 0;
    while (a){
        if (v == 100){
            v -= 100;
            u += 2;
        }
        matrix[u][v] = '.';
        v += 2;
        a--;
    }
    b--;
    u = 51, v = 0;
    while (b){
        if (v == 100){
            v -= 100;
            u += 2;
        }
        matrix[u][v] = '#';
        v += 2;
        b--;
    }
    for (int i=0; i < 100; i++){
        for (int j=0; j < 100; j++) cout << matrix[i][j];
        cout << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long; 

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

    int n, x;
    cin >> n >> x;
    // int even[n], odd[n];
    long long pre, cur;
    // cin >> even[0];
    cin >> pre;
    long long total = 0;
    if (pre > x) {
        total += pre - x;
        pre = x;
    }
    for (int i = 1; i < n; ++i) {
        cin >> cur;
        long long diff = pre + cur - x;
        if (diff > 0) {
            total += diff;
            cur -= min(cur, diff);
            // if (cur >= x) {
            //     cur -= diff;
            // } else {
            //     cur = 0;
            // }
        }
        pre = cur;
    }

    printf("%lld\n", total);
    // cout << total << '\n';
    // odd[0] = even[0];
    // ll even_op = 0;
    // ll odd_op = 0;
    // for (int i = 1; i < n; ++i) {
    //     cin >> even[i];
    //     odd[i] = even[i];
    //
    //     int even_idx = (i % 2 == 0)? i : i - 1;
    //     int odd_idx = (i % 2 == 0)? i - 1: i;
    //     bool op = false;
    //     ll even_rem = ll(even[even_idx] + even[odd_idx] - x);
    //     if (even_rem > 0) {
    //         op = true;
    //         even_op += even_rem;
    //         if (even[even_idx] >= even_rem) {
    //             even[even_idx] -= even_rem;
    //         } else {
    //             even[odd_idx] -= even_rem - even[even_idx];
    //             even[even_idx] = 0;
    //         }
    //     }
    //
    //     ll odd_rem = ll(odd[even_idx] + odd[odd_idx] - x);
    //     if (odd_rem > 0) {
    //         op = true;
    //         odd_op += odd_rem;
    //         if (odd[odd_idx] >= odd_rem) {
    //             odd[odd_idx] -= odd_rem;
    //         } else {
    //             odd[even_idx] -= odd_rem - odd[odd_idx];
    //             odd[odd_idx] = 0;
    //         }
    //     }
    //
    //     if (!op) {
    //         if (even_op > odd_op) {
    //             even_op = odd_op;
    //         } else {
    //             odd_op = even_op;
    //         }
    //     }
    //
    // }
    //
    // cout << min(even_op, odd_op) << '\n';

    return 0;
}


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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n";

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	int ans1 = a+a-1;
	int ans2 = b+b-1;
	int ans3 = a+b;
	
	int sum = max(ans1, max(ans2, ans3));
	
	cout << sum << "\n";
	
	return 0;
}


Measured memory_bytes: 256
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;

typedef struct datum_name {
	int x;
	int y;
	int whosay;
	bool operator==(const datum_name& data) const
	{
		return (x == data.x && y == data.y);
	}
} datum;


bool cmp_who(const datum& left, const datum& right) {
	return left.whosay < right.whosay;
}


int main()
{
	int N;
	string S, T;
	cin >> N;
	cin >> S >> T;
	string ans;
	ans.resize(2 * N);
	for (int i = 0; i < N; i++) {
		ans[i * 2] = S[i];
		ans[i * 2 + 1]=T[i];
	}
	cout << ans << endl;
	return 0;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

A.sort()
A.reverse()

all = sum(A)

k = 1 / (4 * M)
#print(k)

for c in range(M):
    if A[c] < k * all:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
# coding: utf-8
# Your code here!
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

N,M=map(int,input().split())

linked=[[] for i in range(N)]

for _ in range(M):
    x,y=map(int,input().split())
    linked[x-1].append(y-1)



def saiki(num):
    if visited[num]==1:
        return dp[num]
    
    visited[num]=1
    value=0
    if linked[num]:
        for item in linked[num]:
            value=max(value,saiki(item)+1)
    dp[num]=value
    return value

dp=[0]*N
visited=[0]*N
ans=0
for i in range(N):
    ans=max(ans,saiki(i))

print(ans)

Measured memory_bytes: 61772
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[100009],g[100009];
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(b=1; b<=a; b++) cin>>f[b];
    for(b=1; b<=a; b++) f[b]*=2;
    for(b=a; b>=1; b--){
        if((a-b)%2==0) c+=f[b]; else c-=f[b];
    }
    c/=2;
    cout<<c<<" ";
    g[1]=c;
    for(b=2; b<=a; b++){
        cout<<f[b-1]-g[b-1]<<" ";
        g[b]=f[b-1]-g[b-1];
    }
    return 0;
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vvi a;
	for(string s;getline(cin,s);){
		replace(allof(s),',',' ');
		istringstream iss(s);
		a.push_back(vi());
		for(string s2;iss>>s2;)
			a.back().push_back(atoi(s2.c_str()));
	}
	
	vvi dp(a.size());
	rep(i,dp.size())
		dp[i].resize(a[i].size());
	
	dp[0][0]=a[0][0];
	repi(i,1,a.size()/2+1){
		dp[i][0]=dp[i-1][0]+a[i][0];
		dp[i][i]=dp[i-1][i-1]+a[i][i];
		repi(j,1,i)
			dp[i][j]=max(dp[i-1][j-1],dp[i-1][j])+a[i][j];
	}
	repi(i,a.size()/2+1,a.size()){
		rep(j,a.size()-i)
			dp[i][j]=max(dp[i-1][j],dp[i-1][j+1])+a[i][j];
	}
	
	cout<<dp.back()[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
G = [[float('inf')]*N for i in range(N)]
G2 = [[float('inf')]*N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c
    G2[a-1][b-1] = c
    G2[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            if G[i][j] > G[i][k] + G[k][j]:
                G[i][j] = G[i][k] + G[k][j]

not_change = set()
for i in range(N):
    for j in range(N):
        if G[i][j] == G2[i][j]:
            not_change.add((i, j))

print(M - len(not_change)//2)



Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    do {
        n /= k;
        ans++;
    } while (n);
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N,M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for(int i=0;i<M;i++){
        int l,r,d;
        cin >> l >> r >> d;
        if(uf.root(l)==uf.root(r)){
            if(uf.diff(l,r)!=d){
                cout << "No" << endl;
                return 0;
            }
        }
        uf.merge(l,r,d);
    }
    cout << "Yes" << endl;
}

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

def main():
    N, Y = map(int, input().split())
    ans = "-1 -1 -1"
    for i in range(N+1):
        for j in range(N+1-i):
            if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
                ans = "{} {} {}".format(i, j, N-i-j)
                break
        if ans != "-1 -1 -1":
            break
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();

  
  vector<int> r(N);     //右のR
  vector<int> l(N);     //左のL  //自分含める
  for(int i=0;i<N;i++){
    r.at(i)=0;
    l.at(i)=0;
  }                           //とりあえず全部0
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      r.at(0)++;
    }
    else{
      break;
    }
  }
  
  
  
  
  for(int i=1;i<N;i++){
    if(r.at(i-1)>1){   //2以上
      r.at(i)=r.at(i-1)-1;
    }
    else if(r.at(i-1)==0){
      if(S.at(i)=='R'){
        for(int j=i;j<N;j++){
          if(S.at(j)=='R'){
            r.at(i)++;
          }
          else{
            break;
          }
        }
      }
    }
  }
  
  
  reverse(S.begin(),S.end());
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='L'){
      l.at(0)++;
    }
    else{
      break;
    }
  }
  
  for(int i=1;i<N;i++){
    if(l.at(i-1)>1){   //2以上
      l.at(i)=l.at(i-1)-1;
    }
    else if(l.at(i-1)==0){
      if(S.at(i)=='L'){
        for(int j=i;j<N;j++){
          if(S.at(j)=='L'){
            l.at(i)++;
          }
          else{
            break;
          }
        }
      }
    }
  }
  
  reverse(S.begin(),S.end());
  reverse(l.begin(),l.end());
  
  
  vector<int> n(N);     //人数用のハコ
  for(int i=0;i<N;i++){
    n.at(i)=0;
  }      //とりあえず全部0
  
  vector<int> s(N);    //偶奇判定用、偶数1奇数0
  s.at(0)=0;
  for(int i=0;i<N-1;i++){
    if(s.at(i) == 0){
      s.at(i+1)=1;
    }
    else{
      s.at(i+1)=0;
    }
  }
  
  for(int i=0;i<N;i++){
    if(r.at(i)!=0){//R
      if(s.at(r.at(i)) == 0){//r.at(i)正偶数
        n.at(i + r.at(i))++;
      }
      else{//r.at(i)奇数
        n.at(i + r.at(i) -1)++;
      }
    }
    else{//L
      if(s.at(l.at(i)) == 0){//l.at(i)正偶数
        n.at(i - l.at(i))++;
      }
      else{//l.at(i)奇数
        n.at(i - l.at(i) +1)++;
      }
    }
  }
  
 
  
  for(int i=0;i<N-1;i++){
    cout << n.at(i) << " ";
  }
  cout << n.at(N-1) << endl;
}



Measured memory_bytes: 2176
import itertools

def num_days(month):
    if month == 2:
        return 28
    elif month in [4, 6, 9, 11]:
        return 30
    else:
        return 31

a, b = tuple(map(lambda x: int(x), input().split()))

num_takahashi = 0

for i, j in itertools.product(range(1, a), range(1, num_days(a))):
    if i == j:
        num_takahashi += 1

for d in range(1, b + 1):
    if a == d:
        num_takahashi += 1

print(num_takahashi)


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken()), w = Integer.parseInt(st.nextToken());
        int[][] dp = new int[n + 1][100001]; int sum = 0; Arrays.fill(dp[0], 1000000000);

        for (int i = 1; i <= n; i++) {
            st = new StringTokenizer(br.readLine());
            int weight = Integer.parseInt(st.nextToken()), v = Integer.parseInt(st.nextToken()); sum += v;
            Arrays.fill(dp[i], 1000000000); dp[i][v] = weight;

            for (int j = 1; j <= sum; j++) {
                dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]);

                if (j >= v)
                    dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - v] + weight);
            }
        }

        int ind = sum;

        while (ind > 0 && (dp[n][ind] > w || dp[n][ind] == 0))
            ind--;

        System.out.println(ind);
    }
}


Measured memory_bytes: 81424