akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
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 VI vector<int>
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x){return mrand()%x;}
clock_t ac; double TLE(){return (double)(clock()-ac)/CLOCKS_PER_SEC;}
void DBG() {cerr << "]" << endl;}
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h);
if(sizeof...(t)) cerr << ", ";
DBG(t...);}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
int maxvalue(int s){
  int len = s/3.0;
  s-=len;
  if(len==0)len=1.0;
  int breadth = s/2.0;
  int height = s-breadth;
  if(breadth==0) breadth=1.0;
  return len*breadth*height;
}

int main(){
 ios::sync_with_stdio(0);
 cin.tie(0);
 double n;
 cin>>n;
 double res= n/3;
 cout<<fixed<<setprecision(6)<<res*res*res<<"\n";
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

int main(){
    int n;
    cin>>n;
    set<string>s;
    while(n--){
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;
    return 0;
}

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

#define ff first
#define ss second

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int main() {

	int n; cin >> n;
	vector<pair<long long , long long >> a(n);
	for (int i = 0; i < n; i++) cin >> a[i].ff, a[i].ss = i;
	sort(a.begin(), a.end(), greater<pair<long long , long long >>());

	vector<vector<long long >> dp(n, vector<long long >(n + 1, 0));

	dp[0] = {a[0].ff * abs(a[0].ss - n + 1), a[0].ff * abs(a[0].ss)};
	for (int i = 1; i <= n - 1; i++) {
		for (int j = 0; j <= i + 1; j++) {
			if (j == 0) dp[i][j] = dp[i - 1][j] + a[i].ff * abs(a[i].ss - n + 1 + i - j);
			else if (j <= i) dp[i][j] = max(dp[i - 1][j - 1] + a[i].ff * abs(a[i].ss - j + 1), dp[i - 1][j] + a[i].ff * abs(a[i].ss - n + 1 + i - j));
			else dp[i][j] = dp[i - 1][j - 1] + a[i].ff * abs(a[i].ss - j + 1);
		}
	}

	cout << *max_element(dp[n - 1].begin(), dp[n - 1].end());

	return 0;
}

Measured memory_bytes: 34396
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, V;
int a[1010], b[1010], c[1010], d[1010];

signed main() {
    cin >> N >> V;
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];
    rep(i,0,N) cin >> c[i];
    rep(i,0,N) cin >> d[i];

    vector<int> va, vb;
    rep(i,0,N) rep(j,0,N) va.push_back(a[i] + b[j]);
    rep(i,0,N) rep(j,0,N) vb.push_back(c[i] + d[j]);

    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());

    int S = va.size(), T = vb.size();
    int cur = 0, ans = 0;
    rep(i,0,S) {
        int ub = upper_bound(vb.begin(), vb.end(), V-va[i]) - vb.begin();
        int lb = lower_bound(vb.begin(), vb.end(), V-va[i]) - vb.begin();
        ans += (ub - lb);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23096
#include<bits/stdc++.h>
#define ci const int&
#define C(x,y) (1ll*fac[x]*invf[y]%mod*invf[x-y]%mod)
using namespace std;
const int mod=1e9+7;
int n,m,l,r,S,fac[600010],invf[600010];
int POW(int x,int y){
	int tot=1;
	while(y)y&1?tot=1ll*tot*x%mod:0,x=1ll*x*x%mod,y>>=1;
	return tot;
}
int Calc(ci s,ci ri,ci li){
	S=s-ri*m;
	if(S<0)return 0;
	int ans=0;
	for(int i=0,op=1;i<=n-m&&S>=0;++i,op=-op,S-=li)ans=(ans+1ll*op*C(S+n,n)*C(n-m,i)%mod+mod)%mod;
	return 1ll*ans*C(n,m)%mod;
}
int Solve(ci s){
	int ans=0;
	for(int i=0;i<=s/m;++i)ans=(ans+1ll*(Calc(s,i,i)-Calc(s,i+1,i)+mod)%mod)%mod;
	return (C(s+n,n)-ans+mod)%mod;
}
int main(){
	scanf("%d%d%d%d",&n,&m,&l,&r),fac[0]=1;
	for(int i=1;i<=n+r;++i)fac[i]=1ll*fac[i-1]*i%mod;
	invf[n+r]=POW(fac[n+r],mod-2);
	for(int i=n+r-1;i>=0;--i)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	printf("%d",(Solve(r)-Solve(l-1)+mod)%mod);
	return 0;
}

Measured memory_bytes: 4992
n=int(input())
adj=[None]
for i in range(n):
    adj_i=list(map(int,input().split()[2:]))
    adj.append(adj_i)
sndf=[None]
for i in range(1,n+1):
    sndf.append([False,i])
path=[]
time=0
def dfs(u):
    global time
    sndf[u][0]=True
    time+=1
    sndf[u].append(time)
    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    time+=1
    sndf[u].append(time)
for i in range(1,n+1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:])

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

int main(){
  int n, j, a[200000], count[200000];
  
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
    count[i] = 0;
  }
  
  for(int i=0; i<n; i++){
  	j = a[i] - 1;
    count[j]++;
  }
  
  for(int i=0; i<n; i++){
  	cout << count[i] << endl;
  }
}

Measured memory_bytes: 5092
#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    ass.sort()
    return ass

n = int(input())
d = divisor(n-1)
#print(d)
ans = len(d)-1
d2 = divisor(n)
#print(d2)
for k in d2:
    if k == 1:
        continue
    s = n
    while s%k == 0:
        if s%k == 0:
            s = s//k
    s = s%k
    if s == 1:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <set>
using namespace std;


int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int minv = min(x, k-x)*2;
        ans += minv;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*input
2 3 3

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false); // 🏁 👀 💕
  cin.tie(NULL);
  
  ll a, b, k;
  cin >> a >> b >> k;
  ll mn = min(a, k);
  a -= mn;
  k -= mn;
  mn = min({b, k});
  b -= mn;
  cout << a << " " << b << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
#define  rep(i, k)  for(int i = 0; i < k; i++)

int main()
{
	string s;
	cin >> s;
	int n;
	n = s.size();
	vector <int> S(n);
	rep(i, n)  S[i] = s[i] - '0';

	ll sum = 0;

	for (int bit = 0; bit < (1 << (n - 1)); bit++) {
		ll tmp = S[0];
		for (int i = 0; i < n - 1; i++) {
			if (bit & (1 << i)) {
				sum += tmp;
				tmp = S[i + 1];
			}
			else {
				tmp = tmp * 10 + S[i + 1];
			}
		}
		sum += tmp;

	}
	cout << sum << endl;
}

Measured memory_bytes: 256
// ABC 153-F
// 2020.1.26 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define MAX 200005
typedef struct { int X, H; } T;
T a[MAX]; int N;

void Usort(T *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	int tt1[1 << B], tt2[1 << B];
	T *tmp = malloc(n * sizeof(T));
	
	for (k = 0; k < 4; ++k) {
		memset(tt1, 0, sizeof(tt1)), memset(tt2, 0, sizeof(tt2));
		for (i = 0; i < n; ++i)	tt1[a[i].X >> k * B & BMSK]++;
		for (i = 1; i < (1 << B); ++i) tt1[i] += tt1[i-1];
		i = n; while (i--) tmp[--tt1[a[i].X >> k * B & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) tt2[tmp[i].X >> k * B & BMSK]++;
		for (i = 1; i < (1 << B); ++i) tt2[i] += tt2[i-1];
		i = n; while (i--) a[--tt2[tmp[i].X >> k * B & BMSK]] = tmp[i];
	}
	free(tmp);
}

// 見つからなければ、一つ小さい要素を返す
int bs(int l, int x) {
	int m, r = N+1;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m].X <= x) l = m + 1; else r = m;
    }
	return l-1;
}

ll imos[MAX];

int main()
{
	int i, j, A, D;
	ll h, t, ans;
	
	N = in(), D = in(), A = in();
	for (i = 1; i <= N; ++i) a[i].X = in(), a[i].H = in();
	Usort(a+1, N);

	if ((ll)D*2 > a[N].X) D = a[N].X; else D *= 2;
	
	ans = 0;
	for (i = 1; i <= N; ++i) {
		imos[i] += imos[i-1];
		h = a[i].H - imos[i];
		if (h > 0) {
			t = (h-1)/A + 1;
			ans += t, t *= A;
			j = bs(i, a[i].X + D);
			imos[i] += t, imos[j+1] -= t;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int h[n], hm[n];
    int minh;
    for (int i = 0; i<n;i++) {
        cin>>h[i];
    }
    
    for (int i = 0; i<n-1;i++) {
        if(i==0)
        {
            hm[i+1]=abs(h[i]-h[i+1]);
            hm[i+2]=abs(h[i]-h[i+2]);
            minh=min(hm[i+1], hm[i+2]);
        }
        else if(i==n-2)
        {
            hm[i+1]=min(abs(h[i]-h[i+1])+hm[i], hm[i+1]);
            minh=hm[i+1];
        }
        else
        {
            hm[i+1]=min(abs(h[i]-h[i+1])+hm[i], hm[i+1]);
            hm[i+2]=abs(h[i]-h[i+2])+hm[i];
            minh=min(hm[i+1], hm[i+2]);
        }
    }
    cout << minh;
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

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

/* 最大公約数 */
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

/* 最小公倍数 */
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;  // Be careful not to overflow
}

int f(int x) {
  int res = 0;
  while (x % 2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}

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

  lint n, m;
  cin >> n >> m;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 1) {
      cout << 0 << endl;
      return 0;
    }
    a[i] /= 2;
  }

  int t = f(a[0]);
  for (int i = 0; i < n; i++) {
    if (f(a[i]) != t) {
      cout << 0 << endl;
      return 0;
    }
    a[i] >>= t;
  }
  m >>= t;

  lint l = 1;
  for (int i = 0; i < n; i++) {
    l = lcm(l, a[i]);
    if (l > m) {
      cout << 0 << endl;
      return 0;
    }
  }

  m /= l;
  int ans = (m + 1) / 2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
n=int(input())
s=[]
for i in range(n):
    s.append(input())
print('AC x {}'.format(s.count('AC')))
print('WA x {}'.format(s.count('WA')))
print('TLE x {}'.format(s.count('TLE')))
print('RE x {}'.format(s.count('RE')))

Measured memory_bytes: 16324
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        int takahasi = Integer.parseInt(str[0]);
        int aoki = Integer.parseInt(str[2]);
        while(true){
            aoki = aoki - Integer.parseInt(str[1]);
            if (aoki <= 0){
                System.out.println("Yes");
                break;
            }
            takahasi = takahasi - Integer.parseInt(str[3]);
            if (takahasi <= 0){
                System.out.println("No");
                break;
            }
        }
    }
}


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

int main(){
    int x,y,z;
    cin >> x >> y >> z;

    if(x==y){
        if(y==z){cout<<"No";}
        else{cout<<"Yes";}
    }
    else{
        if(x==z){cout<<"Yes";}
        else if(y==z){cout<<"Yes";}
        else{cout<<"No";}
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef unsigned long long int ll;

int main()
{
	const ll MAX_N = 1000000000000000000;
	ll n;
	cin>>n;
	ll left,right;
	cin>>left>>right;
	for(int i = 1; i < n; i++){
		ll t,a;
		cin>>t>>a;
		ll j,leftJ,rightJ;
		if( left % t == 0){
			leftJ = left / t;
		}else{
			leftJ = (left / t) + 1;
		}
		if( right % a == 0){
			rightJ = right /a;
		}else{
			rightJ = (right / a) + 1;
		}
		j = max(leftJ,rightJ);
		for( ; j*max(a,t) <= MAX_N; j++){
			if( j*a >= right && j*t >= left){
				left = j*t;
				right = j*a;
				break;
			}
		}
	}
	cout<<left+right<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main()
{
    int h, w, k;

    char buf[10];
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d %d", &h, &w, &k);

    char c[h][w];  // c_ij

    //printf("%d %d %d\n", h, w, k);
    for(int i=0; i<h; i++){
        fgets(buf, sizeof(buf), stdin);
        for(int j=0; j<w; j++){
            c[i][j] = buf[j];
        }
    }

    //printf("\n");
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            //printf("%c", c[i][j]);
        }
        //printf("\n");
    }

    int pattern = 0;
    for(int i=0; i<(1<<h); i++){
        for(int j=0; j<(1<<w); j++){

            int count = 0;
            for(int a=0; a<h; a++){
                for(int b=0; b<w; b++){
                    int p = (i >> a) & 1;
                    int q = (j >> b) & 1;
                    if( p != 1 && q != 1 && c[a][b] == '#' ){
                        count++;
                    }
                }
            }
            if(count == k){
                pattern++;
            }
        }
    }

    printf("%d\n", pattern);

    return 0;
}


Measured memory_bytes: 1772
#include<stdio.h>
#include<algorithm>
#include<utility>
#include<iostream>
using namespace std;
int main(){
    const int INF=(1<<29);
    int i,j,h,n,a[1010],b[1010],dp[1010][10010];
    scanf("%d %d\n",&h,&n);
    for(i=0;i<=n;i++){
        scanf("%d %d\n",&a[i],&b[i]);
    }
    for(i=0;i<=n;i++){
        for(j=0;j<=h;j++){
            dp[i][j]=INF;
        }
    }
  dp[0][0]=0;
    for(i=0;i<n;i++){
        for(j=0;j<=h;j++){
            if(j+a[i]>=h){
                if(dp[i][h]>dp[i][j]+b[i]){
                dp[i][h]=dp[i][j]+b[i];
                }
                if(dp[i+1][j]>dp[i][j]){
                dp[i+1][j]=dp[i][j];
                }
            }
            else{
            if(dp[i][j+a[i]]>dp[i][j]+b[i]){
                dp[i][j+a[i]]=dp[i][j]+b[i];
            }
            if(dp[i+1][j]>dp[i][j]){
                dp[i+1][j]=dp[i][j];
            }
            }
        }
    }
    printf("%d\n",dp[n][h]);
    return 0;
}

Measured memory_bytes: 39552
import sys
input=sys.stdin.readline
D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
    sub=list(map(int,input().split()))
    s.append(sub)

last=[-1]*26

t=[]

for i in range(D):
    m=-10**9
    change=-1
    for j in range(26):
        temp=0
        temp+=s[i][j]
        for k in range(26):
            if k!=j:
                temp-=c[k]+(i-last[k])
        if temp>m:
            m=temp
            change=j
    t.append(change+1)

m=100000
import random
for _ in range(m):
    h=0
    d=random.randint(1,D)
    q=random.randint(1,26)
    h+=s[d-1][q-1]-s[d-1][t[d-1]-1]
    o=t[d-1]

    pre=1
    for i in range(d-2,-1,-1):
        if t[i]==o:
            break
        pre+=1
    post=1
    for j in range(d,D):
        if t[j]==o:
            break
        post+=1
    h-=c[o-1]*pre*post

    pre = 1
    for i in range(d - 2, -1, -1):
        if t[i] == q:
            break
        pre += 1
    post = 1
    for j in range(d, D):
        if t[j] == q:
            break
        post += 1
    h += c[q - 1] * pre * post

    if h>0:
        t[d-1]=q

for i in t:
    print(i)

Measured memory_bytes: 81316
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))

    ans = 0
    j = m
    for i,item in enumerate(a):
        if k<item:  break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)
    print(ans)
    return

if __name__=='__main__':
    Main()

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

int main (){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i] ;
    }
    sort(a,a+N);
    cout << a[N-1]-a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())

List = [a,b,c]
List.sort()

if(abs(a-c) <= d):
    print('Yes')
elif(List[1] - List[0] <= d and List[2] - List[1] <= d):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
using P = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

const int mod = 1e9+7;

int main(){
  int A, B, C;
  cin >> A >> B >> C;

  if(A==B && A != C){
    cout << "Yes" << endl;
    return 0;
  }
  if(B==C && C!=A){
    cout << "Yes" << endl;
    return 0;
  }
  if(A==C && B!=A){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
            string[] data;
            int H, W;
            while(true){

                data = Console.ReadLine().Split();
                if (int.Parse(data[0])== 0 && int.Parse(data[1]) == 0)
                {
                    break;
                }

                for (H = int.Parse(data[0]); H > 0; H--)
                {
                    for (W = int.Parse(data[1]); W > 0; W--)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
	}
}

Measured memory_bytes: 8832
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn trans (dp: &mut Vec<bool>, a: usize) {
    for i in (a..dp.len()).rev() {
        dp[i] |= dp[i - a];
    }
}

fn calc (x: &Vec<usize>, l: usize, r: usize, mut dp: &mut Vec<bool>) -> usize {
    if l + 1 == r {
        let k = dp.iter().rposition(|&x| x).unwrap();
        return if x[l] + k >= dp.len() {0} else {1};
    }
    let save = dp.clone();
    let m = (l + r) / 2;
    for &a in &x[l..m] {
        trans (&mut dp, a);
    }
    let front = calc (x, m, r, &mut dp);
    dp.clone_from (&save);
    for &a in &x[m..r] {
        trans (&mut dp, a);
    }
    front + calc (x, l, m, &mut dp)
}

fn run() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    let mut dp = vec![false; k];
    dp[0] = true;
    let ans = calc (&a, 0, n, &mut dp);
    println! ("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if(H==0&&W==0) {
				break;
			}

			for(int i=0;i<H;i++) {
				for(int j=0;j<W;j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}

		sc.close();
	}
}


Measured memory_bytes: 33140
#include <iostream>
#include <bitset>

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

int main() {
	int N, K; cin >> N >> K;
	int l[51], b[51];
	rep(i, 0, 51) b[i] = 0;

	rep(i, 1, N + 1) {
		cin >> l[i];
		b[l[i]]++;
	}

	int count = 0;
	int length = 0;
	for (int i = 50; i >= 0; i--) {
		for (int j = 0; j < b[i]; j++) {
			length += i;
			count++;
			if (count == K)break;
		}
		if (count == K)break;
	}
	cout << length << endl;

	return 0;
}

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


int main()
{
	int s, m ,h,S;
	cin >> S;
	h = S / 3600;
	m = S % 3600/60;
	s = S % 3600 % 60;
	cout << h << ":" << m << ":" <<s <<endl;
	return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator++() { return *this += mint(1); }
    mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator--() { return *this -= mint(1); }
    mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint& a) const { mint res(*this); return res+=a; }
    mint operator-(const mint& a) const { mint res(*this); return res-=a; }
    mint operator*(const mint& a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const {
        mint res = mint(1),a(*this);
        while(t > 0) {
            if(t&1) res *= a;
            t >>= 1;
            a *= a;
        }
        return res;
    }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { mint res(*this); return res/=a; }
};
ostream& operator<<(ostream& os,const mint& m) { return os << m.x; }

mint dp[2][100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,K;
    cin >> n >> K;
    vi a(n);
    cin >> a;
    dp[0][0] = 1;
    rep(i,n) {
        memset(dp[1],0, sizeof(dp[1]));
        rep(j,K+1) {
            int mx = min(a[i],K-j);
            dp[1][j] += dp[0][j];
            dp[1][j+mx+1] -= dp[0][j];
        }
        rep(j,K) dp[1][j+1] += dp[1][j];
        swap(dp[0],dp[1]);
    }
    cout << dp[0][K] << endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int n=gi();
        int[] L=new int[n];
        for (int i=0; i<n;i++) {
        	L[i]=gi();
        }
        Arrays.parallelSort(L);
        int s=0;
        for (int i=0; i<n-1;i++) {
        	s+=L[i];
        }
	    //System.out.println(i);

        if (s>L[n-1]) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

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

	vector<vector<long long> > ab2vec(26);

	for(long long i=0;i<s.size();i++)
	{
		ab2vec[s[i]-'a'].push_back(i);
	}


	long long loop=0,ans=-1;
	for(long long i=0;i<t.size();i++)
	{
		long long now=t[i]-'a';

		if(ab2vec[now].size()==0)
		{
			cout << -1 << endl;
			return 0;
		}

		if(ans>=ab2vec[now][ab2vec[now].size()-1])
		{
			loop++;
			ans=ab2vec[now][0];
		}
		else
		{
			auto itr=lower_bound(ab2vec[now].begin(),ab2vec[now].end(),ans+1);
			ans=*itr;
		}

//		cout << t[i] << " : " <<  loop << " : " << ans << endl;

	}

	cout << loop*s.size()+ans+1 << endl;
}


Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
	int flag=0, n;
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> arr[i];
		if(arr[i]%2 == 0)
		{
			if(arr[i]%3 ==0 || arr[i]%5 ==0)
			{
				continue;
			}
			else
			{
				flag = 1;
			}
		}
	}
	if(flag)
	{
		cout << "DENIED" << endl;
	}
	else
	{
		cout << "APPROVED" << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <time.h>

using namespace std;
typedef long long ll;

ll A, B = 0;

int main(){
    clock_t start = clock();
    cin >> A >> B;

    ll total = 0;

    switch ((A - 1) % 4)
    {
        case 0:
            total = A - 1;
            break;
        case 1:
            total = 1;
            break;
        case 2:
            total = A ;
            break;
        case 3:
            total = 0;
            break;
    }

    switch (B % 4)
    {
        case 0:
            total = total ^ B;
            break;
        case 1:
            total = total ^ 1;
            break;
        case 2:
            total = total ^ (B + 1);
            break;
        case 3:
            total = total ^ 0;
            break;
    }

    cout << total << endl;

}

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


int main(){
  int n;
  cin >> n;
  vector<int> va(n),co(n);
  for(int i=0;i<n;i++){
    cin >> va[i];
  }
  for(int i=0;i<n;i++){
    cin >> co[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(va[i]>co[i])
      ans+=va[i]-co[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let x:i32 = read();

    println!("{}",
        match x {
            3 => "YES",
            5 => "YES",
            7 => "YES",
            _ => "NO",
        }
    );

}


Measured memory_bytes: 4352
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if a1>b1 and a2>b2:
    print(0)
elif b1>a1 and b2>a2:
    print(0)
elif a1*t1+a2*t2==b1*t1+b2*t2:
    print("infinity")
else:
    ans=-1
    num2=-1
    num3=-1
    if a1*t1+a2*t2>b1*t1+b2*t2:
        if a1>b1:
            ans=0
        else:
            num2=(b1-a1)*t1
            num3=((a1-b1)*t1)+((a2-b2)*t2)
            if num2//num3==num2/num3:
                ans=(num2//num3)*2
            else:
                ans=(num2//num3)*2+1
    else:
        if b1>a1:
            ans=0
        else:
            num2=(a1-b1)*t1
            num3=((b1-a1)*t1)+((b2-a2)*t2)
            if num2//num3==num2/num3:
                ans=(num2//num3)*2
            else:
                ans=(num2//num3)*2+1
    print(ans)


Measured memory_bytes: 9252
#include <stdio.h>
int gcd(int p,int q){
  if(p%q==0)
    return q;
  return gcd(q,p%q);
}

int main(void){
  int k;
  scanf("%d",&k);
  int a,b,c;
  int n;
  int sum=0;
  
  for(a=1;a<=k;a++){
    for(b=1;b<=k;b++){
      for(c=1;c<=k;c++){
        n=gcd(gcd(a,b),c);
        sum=sum+n;
      }
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = Integer.parseInt(sc.next());
			int nmin = Integer.parseInt(sc.next());
			int nmax = Integer.parseInt(sc.next());
			if (m == 0 && nmin == 0 && nmax == 0)
				return;
			int[]p = new int[m];
			for (int i = 0; i < m; i++)
				p[i] = Integer.parseInt(sc.next());
			int diff = Integer.MIN_VALUE;
			int index = 0;
			for (int i = nmin - 1; i < nmax; i++) {
				if (diff <= p[i] - p[i + 1]) {
					index = i;
					diff = p[i] - p[i + 1];
				}
			}
			System.out.println(index + 1);
		}
	}
}


Measured memory_bytes: 47304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; string S; cin >> N >> S;
    string ans;
    for (int i = 0; i < S.size(); i++) {
        ans += (S[i] - 'A' + N) % 26 + 'A';
    }
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

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

#define mod 1000000007
using ll=long long;

ll modpow(ll n,ll m=mod-2){
  ll r=1;
  while(m){
    r=r*((m%2)?n:1)%mod,n=n*n%mod,m>>=1;
  }
  return r;
}

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

	ll ans = modpow(10,n);
	ans=ans+modpow(8,n);
	ans=ans%mod;
	ans=ans-modpow(9,n)*2;
    ans=ans%mod;

	//これだとオーバーフローする
	//ll ans = modpow(10,n)+modpow(8,n)-modpow(9,n)-modpow(9,n);

	ans=(ans+mod)%mod;
	cout << ans << endl;
}


Measured memory_bytes: 3604
n, k = gets.split.map(&:to_i)
p = gets.split.map{ |p_i| (p_i.to_i * 1.0 + 1.0) / 2.0 }
p_0 = p.slice!(0..(k-1))
l = []
l[0] = p_0.inject(:+)
(1..(n-k)).each do |idx|
  p_0 << p.shift
  l[idx] = l[idx-1] - p_0[idx-1] + p_0[-1]
end
puts l.max

Measured memory_bytes: 17944
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const double EPS = 1e-10;
const int INF = 1001001001;

int main()
{
	int x, y, z;
	while(scanf("%d%d%d", &x, &y, &z), x){
		int dice[4];
		rep(i, x)
			scanf("%d", &dice[i]);
		
		pii event[51];
		fill(event, event+y+1, pii(0, 0));
		rep(i, z){
			int n, e, a;
			scanf("%d%d%d", &n, &e, &a);
			event[n] = pii(e, a);
		}
		
		double prob[51][5001];
		rep(i, y+1)
			fill(prob[i], prob[i]+5001, 0.0);
		prob[0][0] = 1.0;
		rep(i, y) rep(j, 5001) {
			rep(k, x){
				int next = min(y, i+dice[k]);
				int money = j;
				if(event[next].first == 1)
					next = min(y, next+event[next].second);
				else if(event[next].first == 2)
					money += event[next].second;
				else
					money = max(0, money-event[next].second);
				prob[next][money] += prob[i][j] / x;
			}
		}
		
		double ans = 0.0;
		rep(i, 5001)
			ans += prob[y][i] * i;
		printf("%d\n", (int)(ans+EPS));
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

  for (int i{}; i < N; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int alice{}, bob{};
  for (int i{}; i < N; ++i) {
    if (i % 2 == 0)
      alice += a[i];
    else
      bob += a[i];
  }

  cout << alice - bob << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n,l;
    cin>>n>>l;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    
    rep(i,0,n-1){
        if(a[i]+a[i+1]>=l){
            cout<<"Possible"<<endl;
            for(int j=1;j<=i;j++) cout<<j<<endl;
            for(int j=n-1;j>=i+2;j--) cout<<j<<endl;
            cout<<i+1<<endl;
            return 0;
        }
    }
    
    cout<<"Impossible"<<endl;
}



Measured memory_bytes: 1152
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int Y, X;
vector<vector<char>> G;
vector<vector<bool>> seen;

pll dfs(int y, int x, ll &w, ll &b) {
    seen[y][x] = true;
    if (G[y][x] == '#')
        b++;
    else
        w++;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || ny < 0 || nx >= X || ny >= Y)
            continue;
        if (seen[ny][nx])
            continue;
        if (G[ny][nx] == G[y][x])
            continue;
        dfs(ny, nx, w, b);
    }
    return {w, b};
}

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

    cin >> Y >> X;
    G.resize(Y, vector<char>(X));
    rep(i, Y) {
        rep(j, X) { cin >> G[i][j]; }
    }

    seen.resize(Y, vector<bool>(X, false));
    ll ans = 0;
    rep(i, Y) {
        rep(j, X) {
            if (G[i][j] == '.')
                continue;
            if (seen[i][j])
                continue;
            else {
                ll w = 0, b = 0;
                pll p = dfs(i, j, w, b);
                ans += (p.first * p.second);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 18836
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int l=0,i;
  string s,res;
  cin >> s;
  for(i=0;i<s.size();i++)
    if(s.substr(i,1)=="x") l++;
  if(l>=8) res="NO";
  else res="YES";
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) cerr << "[(" << __LINE__ << ") " << (#__VA_ARGS__) << "]: " << __VA_ARGS__ << endl;
ll MOD = 1e9+7;

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

    ll l = 0, r = 0;
    for (int i=1; i<k; i++) {
        l += i;
    }
    for (int i=n; i>n-k; i--) {
        r += i;
    }
    int tn = n-k;

    ll ans = 0;
    while (k<=n+1) {
        ans += r-l+1;
        ans %= MOD;
        l += k;
        r += tn;
        k++;
        tn--;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3652
fn main() {
    use std::io::*;
    let mut reader = BufReader::new(stdin());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();

    let split:Vec<u32> = s.trim()
        .split(" ")
        .map(|x| x.parse::<u32>().unwrap())
        .collect();
    
    let x = split[0];
    let y = split[1];
    println!("{} {}",x * y, x * 2 + y * 2);
}


Measured memory_bytes: 5040
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {

        int sum = 0;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i = 0; i <= n; i++) {

            sum += i;

        }

        System.out.println(sum);

    } 
}

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

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

  long long score = 0;
  long long current_capacity = 0;
  for (int i = 0; i < n; i++)
  {
    score += std::min(a[i], b[i]);
    // std::cout << "score "<< score << std::endl;
    int left_power = std::max(b[i] - a[i], 0);
    // std::cout << "left power "<< left_power << std::endl;
    int next_num_enemy = std::min(left_power, a[i+1]);
    a[i+1]-= next_num_enemy;
    score+=next_num_enemy;
    // std::cout << "second score "<< score << std::endl;

    // num_enemy += std::min()
    // current_capacity += a[i];
    // int s = std::min((int)current_capacity, a[i]);
    // score+=s;
    // current_capacity = std::min((int)(b[i]-current_capacity), 0);
  }
  std::cout << score << std::endl;


}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> firstRow = Arrays.asList(br.readLine().split(" "));
            int N = Integer.parseInt(firstRow.get(0));
            int K = Integer.parseInt(firstRow.get(1));

            Set<String> haveCookie = new HashSet<>();
            for (int i = 0; i < K; i++) {
                br.readLine();
                List<String> tmpList = Arrays.asList(br.readLine().split(" "));
                for (String tmp : tmpList) {
                    haveCookie.add(tmp);
                }
            }

            int ans = N - haveCookie.size();
            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 26808
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int n = b/a;
    cout << min(c, n);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
vector<pii> g[125252];
const ll INF = 1ll<<60;
ll vp[125252], vn[125252];
bool used[125252];

void dfs(int p,ll bvp,ll bvn){
  // printf("%d : x+%lld, -x+%lld\n",p,bvp,bvn);
  vp[p] = bvp;
  vn[p] = bvn;
  used[p] = true;
  for(pii P : g[p]){
    int to = P.first;
    ll s = P.second;
    ll nvp = abs(bvn)==INF ? bvn : s-bvn;
    ll nvn = abs(bvp)==INF ? bvp : s-bvp;
    // printf("%d--%d : x+%lld, -x+%lld\n",p,to,nvp,nvn);
    if(used[to]){
      if(vp[to]==INF){
        vp[to] = nvp;
      }else if(nvp!=INF && vp[to]!=nvp){
        vp[to] = -INF;
      }
      if(vn[to]==INF){
        vn[to] = nvn;
      }else if(nvn!=INF && vn[to]!=nvn){
        vn[to] = -INF;
      }
    }else{
      dfs(to,nvp,nvn);
    }
  }
}

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int u,v,s;
    scanf("%d%d%d",&u,&v,&s);
    --u;--v;
    g[u].push_back(pii(v,s));
    g[v].push_back(pii(u,s));
  }
  REP(i,n)vp[i]=vn[i]=INF;
  dfs(0,0ll,INF);
  bool ok = true;
  REP(i,n)if(vp[i]==-INF || vn[i]==-INF)ok=false;
  if(!ok){
    puts("0");
    return 0;
  }
  ll lft = 1ll, rit = INF;
  REP(i,n){
    if(vp[i]!=INF && vn[i]!=INF){
      // y = x+vp = -x+vn > 0
      // 2x = vn-vp
      // x = (vn-vp)/2
      ll xup = vn[i]-vp[i];
      if(xup<=0 || xup%2==1){
        ok = false;
      }else{
        ll x = xup/2ll;
        if(x+vp[i]<=0){
          ok = false;
        }else{
          CHMAX(lft, x);
          CHMIN(rit, x);
        }
      }
    }else{
      // y = x+vp[i] >= 1
      // x >= 1-vp[i]
      if(vp[i]!=INF)CHMAX(lft,1ll-vp[i]);
      // y = -x+vn[i] >= 1
      // x-vn[i] <= -1
      // x <= vn[i]-1
      if(vn[i]!=INF)CHMIN(rit,vn[i]-1ll);
    }
  }
  ll ans = max(0ll, rit-lft+1);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 15872