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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for (int i = 0; i < N - 2; i++)
  {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C')
    {
      cnt++;
      i += 2;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int x;
    cin >> x;
    Int moto = 100, ans = 0;
    while (moto < x) {
        ans++;
        moto += (moto / 100);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
int ensyu,kensu,maxsa=0,i,k,first,before=0,now,ans;
(void)scanf("%d %d",&ensyu,&kensu);
for(i=0;i<kensu;i++){
    (void)scanf("%d",&now);
    if(i==0)
    first=now;
    if(maxsa<(now-before))
    maxsa=(now-before);
    before=now;
}
if(first+ensyu-now>maxsa)
maxsa=first+ensyu-now;

ans=ensyu-maxsa;
printf("%d\n",ans);
return 0;
}

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    if(a - k < 0){
        ll x = abs(a - k);
        a = 0;        
        if(b - x < 0){
            b = 0;
        }else{
            b -= x;
        }
        
    }else{
        a -= k;
    }
    
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <string>
#include <utility>

int main(int argc,char* argv[]){
  int n;
  int q;
  
  std::cin >> n >> q;

  std::queue<std::pair<std::string, int> > queue;

  for(int i = 0; i < n; i++){
    std::pair<std::string, int> p;
    std::cin >> p.first >> p.second;
    queue.push(p);
  }
  
  int time = 0;
  while(!queue.empty()){
    std::pair<std::string, int> pair = queue.front();
    queue.pop();
    
    int diff = std::min(q, pair.second);
    pair.second -= diff;
    time += diff;

    if(pair.second == 0){
      std::cout << pair.first << " " << time << std::endl;
    }else{
      queue.push(pair);
    }
  }
  
  

  return 0;
  
}

Measured memory_bytes: 4404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int ans = 0;
  int N,M; cin >> N >> M;
  vector<int> P(N);
  rep(i,N) {
    cin >> P[i];
    P[i]--;
  }
  int x, y;
  vector<vector<int>> graph(N);
  rep(i,M){
    cin >> x >> y; x--; y--;
    graph[x].pb(y);
    graph[y].pb(x);
  }
  vector<bool> chked(N,false);
  rep(i,N){
    if(chked[i]) continue;
    chked[i] = true;
    queue<int> q;
    map<int,int> mp;
    q.push(i);
    mp[i]++; mp[P[i]]++;
    while(!q.empty()){
      int now = q.front(); q.pop();
      rep(i,(int)graph[now].size()){
        if(chked[graph[now][i]]) continue;
        chked[graph[now][i]] = true;
        q.push(graph[now][i]);
        mp[graph[now][i]]++; mp[P[graph[now][i]]]++;
      }
    }
    for(auto m:mp){
      // cout << i << " " << m.second << endl;
      if(m.second == 2) ans++;
    }
  }

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


Measured memory_bytes: 10752
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact();
    int N, M;
    cin >> N >> M;
    int ans = 0;
    int r = 1;
    rep(i, N + 1) {
        int r1 = M - i;
        int r2 = N - i;
        int tmp1 = Mul(P(M, i),  square(P(r1, r2)));
        int tmp2 = Mul(tmp1, C(N, i));
        ans = (ans + tmp2 * r + mod) % mod;
        //cout << i << " " << ans << endl;
        r *= -1;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  if (a == 1 && b == 2) cout << 3 << endl;
  else if (a == 1 && b == 3) cout << 2 << endl;
  else cout << 1 << endl;
  return 0;
}

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

const int maxn = 2e5 + 100;
int a[maxn];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >> n;
    for(int i = 0;i < n;i++) cin >> a[i];
    long long ans = 0;
    for(int i = 1;i < n;i++){
        if(a[i] >= a[i-1]) continue;
        ans += a[i-1] - a[i];
        a[i] = a[i-1];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4564
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

ll value[200010];
vector<ll> g[200010];
ll ans[200010];

void dfs(ll tmp,ll pre,ll sum){
  sum+=value[tmp];
  ans[tmp]=sum;
  for(auto c:g[tmp]){
    if(c==pre) continue;
    dfs(c,tmp,sum);
  }
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,q;
  cin>>n>>q;
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i,200010) value[i]=0;
  rep(i,q){
    ll a,b;
    cin>>a>>b;
    a--;
    value[a]+=b;
  }
  dfs(0,-1,0);
  rep(i,n){
    cout<<ans[i]<<' ';
  }
  cout<<endl;
}

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

const int N = 200 * 1000 + 5;

int a[N];
int cnt[N];
int b[N];

int main() {
	int n, q, ans = 0;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i; j > i - cnt[i]; j--) {
			if (j >= 1) {
				b[j]++;
				if (b[j] == 1) {
					ans++;
				}
			}
			else {
				b[1]++;
				if (b[1] == 0) {
					ans++;
				}
			}

		}
	}
//	cout << n - ans << endl;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		b[max(1, a[x] - cnt[a[x]] + 1)]--;
		if (b[max(1, a[x] - cnt[a[x]] + 1)] == 0) {
			ans--;
		}
		cnt[a[x]]--;
		a[x] = y;
		cnt[y]++;
		b[max(1, y - cnt[y] + 1)]++;
		if (b[max(1, y - cnt[y] + 1)] == 1) {
			ans++;
		}
		//for (int j = 1; j <= n; j++) {
		//	cout << "73 " << j << " " << cnt[j] << " " << b[j] << endl;
		//}
		cout << n - ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val (n, i) = sc.intList()
        println(n - i + 1)
    }
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

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

#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 ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n);
  REP(i, n) cin >> x[i];

  ll ans = INF;
  REP(i, 101) {
    ll tmp = 0;
    REP(j, n) { tmp += (i - x[j]) * (i - x[j]); }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
P=0
R=0
S=0
pp = 0
rr = 0
ss = 0 

for i in t:
    if i == 'r':
        P+=1
    elif i =='s':
        R+=1
    else:
        S+=1
# for i,j in zip(t,t[b:]):
#     print(i,j)
#     if i == j and i == 'r':
#         pp+=1
#     elif i == j and i == 's':
#         rr +=1
#     elif i == j and i =='p':
#         ss+=1
def cal(x):
    return -((-x)//2)
# ans  = p*(P-pp//2) + r*(R-rr//2) + s*(S-ss//2)
# print(ans)

PP =[]
RR = []
SS = []
# print(P,R,S)
for i in range(b):
    A = 0
    PPP = 1
    RRR=1
    SSS = 1

    for j in range(i+b,a,b):
        # print(t[j-b] , t[j])
        if t[j-b] == t[j]:
            if t[j] == 'r':
                PPP+=1
            elif t[j] =='s':
                RRR +=1
            elif t[j] == 'p':
                SSS+=1
        else:
            # print(PPP,RRR,SSS)
            P-=PPP//2
            R-=RRR//2
            S-=SSS//2
            PPP = 1
            RRR=1
            SSS = 1

    else:
        P-=PPP//2
        R-=RRR//2
        S-=SSS//2
        PPP = 1
        RRR=1
        SSS = 1


ans  = p*(P) + r*(R) + s*(S)
# print(P,R,S)
print(ans)





Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    double a,b,C,S,l,h,c;
    double PI = acos(-1);
    scanf("%lf%lf%lf",&a,&b,&C);
    S = 0.5*a*b*sin(C*PI/180);
    l =a+b+sqrt(a*a+b*b-2*a*b*cos(C*PI/180));
    c = sqrt(a*a+b*b-2*a*b*cos(C*PI/180));
    h = 2*S/a;
    printf("%lf\n",S);
    printf("%lf\n",l);
    printf("%lf\n",h);
}


Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
int main()
{int num[5];
 for(int i=0;i<5;i++){
 cin>>num[i];
}
for(int i=0;i<5;i++)
{
 if(num[i]==0)
    cout<<i+1;
 }
 return 0;
}


Measured memory_bytes: 3608
import sys

#+++++
		
def main():
	n = int(input())
	
	ttt=[0]*n
	for i in range(n):
		ttt[i]=[]
	
	for i in range(n-1):
		a, b = map(int, input().split())
		ttt[a-1].append([b-1, i])
		ttt[b-1].append([a-1, i])
	
	bb=max([len(t) for t in ttt])	
	print(bb)
	
	ret_ll=[0]*(n-1)
	ss_stack=[(0,-1, bb+100)]
	#state, parent, parent_path_color
	
	while len(ss_stack) > 0:
		st, parent, pp_color = ss_stack.pop()
		
		current_color=1
		if current_color==pp_color:
			current_color+=1
		for i, [path_to, idx] in enumerate(ttt[st]):
			if path_to == parent:
				continue
			
			c_color = current_color
			current_color+=1
			if current_color==pp_color:
				current_color+=1
			
			ret_ll[idx] = c_color
			ss_stack.append([path_to, st, c_color])
			
	for ret in ret_ll:
		print(ret)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 45084
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,w,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	cin >> h >> w;
	vector<string>	s(h);
	vector<vector<ll>>		lh(h+1 , vector<ll>(w+1)),lw(h+1, vector<ll>(w+1));
	for(i=0;i<h;i++) cin >> s[i];

	for(i=0;i<h;i++) for(j=0;j<w;j++) {
		if (s[i][j]=='.') lw[i+1][j+1] = lw[i+1][j] + 1;
	}
	/*
	cout << "lw";
	for(i=0;i<=h;i++) {
		cout << endl;
		for(j=0;j<=w;j++) cout << lw[i][j] << ' ';
	}
	cout << endl;
	*/
	for(i=1;i<=h;i++) for(j=w-1;j>0;j--) {
		if ((lw[i][j]!=0)&&(lw[i][j+1]!=0)) lw[i][j] = lw[i][j+1];
	}
	/*
	cout << "lw";
	for(i=0;i<=h;i++) {
		cout << endl;
		for(j=0;j<=w;j++) cout << lw[i][j] << ' ';
	}
	cout << endl;
	*/
	for(j=0;j<w;j++) for(i=0;i<h;i++) {
		if (s[i][j]=='.') lh[i+1][j+1] = lh[i][j+1] + 1;
	}
	/*
	cout << "lh";
	for(i=0;i<=h;i++) {
		cout << endl;
		for(j=0;j<=w;j++) cout << lh[i][j] << ' ';
	}
	cout << endl;
	*/
	for(j=1;j<=w;j++) for(i=h-1;i>0;i--) {
		if ((lh[i][j]!=0)&&(lh[i+1][j]!=0)) lh[i][j] = lh[i+1][j];
	}
	/*
	cout << "lh";
	for(i=0;i<=h;i++) {
		cout << endl;
		for(j=0;j<=w;j++) cout << lh[i][j] << ' ';
	}
	cout << endl;
	*/
	for(i=1;i<=h;i++) for(j=1;j<=w;j++) {
		a = lw[i][j] + lh[i][j] - 1;
		ans = max(ans , a);
	}
	cout << ans << endl;




	return 0;
}


Measured memory_bytes: 73900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using Pa = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    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 {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // 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;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};


/*
for i in [r1:r2] for j in [c1:c2]
    ans += (i+j)_C_(i)

f(N,M)が求まれば
f(R2,C2)-f(R1-1,C2)-f(R2,C1-1)+f(R1-1,C1-1)
(i)_C_(i)+(i+1)_C_(i)+(i+2)_C_(i)+...+(i+j)_C_(i)+...+(i+M)_C_(i) = (i+M+1)_C_(M)
(i)_C_(0)+(i+1)_C_(1)+(i+2)_C_(2)+...+(i+j)_C_(j)+...+(i+M)_C_(M)
(i+j)_C_(j) = (i+j-1)_C_(j-1)+(i+j-1)_C_(j)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
*/

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R1,R2,C1,C2;
    cin >> R1 >> C1 >> R2 >> C2;
    combination C(R2+C2+1);
    mint ans = 0;

    auto f = [&](int N,int M){
        mint res = 0;
        for(int i=0;i<=N;i++) res += C.comb(i+M+1,M);
        return res;
    };
    cout << f(R2,C2)-f(R1-1,C2)-f(R2,C1-1)+f(R1-1,C1-1) << "\n";
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  vector<ll> L(N, 0);
  vector<ll> R(N, 0);
  map<ll, ll> mp;
  REPLL(i, N){
    ll A; cin >> A;
    L[i] = i + A;
    R[i] = i - A;
    if(i > 0) mp[R[i]]++;
  }
  ll ans = 0;
  REP(i, N-1){
    if(mp.find(L[i]) != mp.end()){
      ans += mp[L[i]];
    }
    mp[R[i+1]]--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 17900
#include<bits/stdc++.h>
#define eps 1e-9
using namespace std;
struct obj{
  double x, y ,z;
  obj operator+(const obj& a)const{
    obj b;
    b.x = x + a.x;
    b.y = y + a.y;
    b.z = z + a.z;
    return b; 
  }
  obj operator-(const obj& a)const{
    obj b;
    b.x = x - a.x;
    b.y = y - a.y;
    b.z = z - a.z;
    return b; 
  }
};
struct obstacle{
  obj c;
  long long int r, l;
};
typedef pair<obj, obj> line;

double abs(obj b){
  return sqrt(b.x*b.x + b.y*b.y + b.z*b.z);
}

double cross(obj a, obj b){
  double x, y, z;
  x = a.y*b.z - a.z*b.y;
  y = a.z*b.x - a.x*b.z;
  z = a.x*b.y - a.y*b.x;
  return sqrt(x*x + y*y + z*z);
}

double dot(obj a, obj b){
  return a.x*b.x + a.y*b.y + a.z*b.z;
}

double dis(line l, obj p){
  double area = cross(l.second - l.first, p - l.first)/2.0;
  double res = (2.0*area)/abs(l.second - l.first);
  double cosa = dot(l.second - l.first, p - l.first) /
    (abs(l.second - l.first)*abs(p - l.first));
  double cosb = dot(l.first - l.second, p - l.second) /
    (abs(l.first - l.second)*abs(p - l.second));
  if(cosa < 0) return abs(p - l.first);
  if(cosb < 0) return abs(p - l.second);
  return res;
}

int main(int argc, char *argv[]){
  int n, q;
  cin >> n >> q;
  obstacle p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i].c.x >> p[i].c.y >> p[i].c.z >> p[i].r >> p[i].l;
  }
  obj s, d;
  for (int i = 0; i < q; i++) {
    long long int ans = 0;
    cin >> s.x >> s.y >> s.z >> d.x >> d.y >> d.z;
    line l = line(s, d);
    for (int j = 0; j < n; j++) {
      double d = dis(l, p[j].c);
      if(d <= p[j].r + eps){
        ans += p[j].l;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
const ll MOD=1e9+7;
const int MAX=1e5;
const ll INF=(1ll<<62)-1;
signed main(){
    int A,B,C,D; cin>>A>>B>>C>>D;
    bool flag=1;
    while(1){
        if(flag){
            C-=B;
            if(C<=0){
                cout<<"Yes"<<endl;
                break;
            }
        }
        else{
            A-=D;
            if(A<=0){
                cout<<"No"<<endl;
                break;
            }
        }
        flag=!flag;
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;


int main(){
  ll N,ans=0;
  cin>>N;
  
  ll H[N+1],DP[N+1];
  RREP(i,N){
    cin>>H[i];
    DP[i]=0;
  }
  DP[0]=0;
  H[0]=H[1];
  
  for(int i=2; i<=N; ++i){
    DP[i]=min(DP[i-1]+abs(H[i]-H[i-1]),DP[i-2]+abs(H[i]-H[i-2]));
  }
  
  cout<<DP[N]<<endl;
  return 0;
}

Measured memory_bytes: 1792
# A
H1,M1,H2,M2,K = map(int,input().split())
if H2 >= H1:
    h = (H2-H1)*60 + M2- M1 - K
    print(h)
else:
    h = (24-H1+ H2)*60 + M2- M1 - K
    print(h)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second

void solve(){
    int n; cin>>n;
    vector<int> v(n);
    ll x_or=0;
    for(int i=0;i<n;++i){
        cin>>v[i];
        x_or ^= v[i];
    }
    for(int i=0;i<n;i++){
        cout<<(v[i]^x_or)<<" ";
    }
}
int main() {
    // int t; cin>>t;
    // while(t--){
        solve();
        // cout<<endl;
    // }
}

Measured memory_bytes: 4024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}
		for (int j = 0;j < H;j++) {
			for (int i = 0; i < W; i++) {
				if (j == 0 || j == H - 1) {
					cout << "#";
				}
				else {
					if (i == 0 || i == W - 1) {
						cout << "#";
					}
					else {
						cout << ".";
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3104
import sys


class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]


input = sys.stdin.readline
N, M, K = map(int, input().split())
F = [[] for _ in [0]*N]
B = [[] for _ in [0]*N]

uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a].append(b)
    F[b].append(a)
    uf.unite(a, b)

for _ in range(K):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    B[a].append(b)
    B[b].append(a)

for i in range(N):
    ans = uf.size(i) - 1
    ans -= len(F[i])
    for b in B[i]:
        if uf.same(i, b):
            ans -= 1
    print(ans, end=' ')


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

namespace ABC123 {
	class ABC123_B {
		static void Main(string[] args) {
			var AtoE = new double[5];
			double minOnesPlace = 10;
			for(int i=0; i<5; i++) {
				AtoE[i] = double.Parse(Console.ReadLine());
				if((minOnesPlace > AtoE[i] % 10) && (AtoE[i] %10) != 0) {
					minOnesPlace = AtoE[i] % 10;
				}
			}
			double sum = AtoE.Select(n => Math.Ceiling(n/10) *10).Sum();
			sum -= 10 - minOnesPlace;
			Console.WriteLine(sum);
		}
	}
}


Measured memory_bytes: 13268
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))

ans=-1
ansT=-1000000000

for i in range(N):
  if abs(ansT-A)>(abs(T-H[i]*0.006-A)):
    ans=i+1
    ansT=T-H[i]*0.006

print(ans)

Measured memory_bytes: 3064
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[];j=0
 for l in L:
  while j-len(R)and R[j]<l:T+=[R[j]];j+=1
  T+=[l]
 while j-len(R):T+=[R[j]];j+=1
 return T
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a,b);
  }

  int res = 0;
  rep(i,n) if(uf.find(i) == i) res++;
  res--;
  cout << res << endl;
  /*rep(i,n)
 	for(int j = i+1; j < n; ++j) {
      if(uf.same(i,j) == 0)
	    res++;
	}
  res -= m;
  */
  return 0;
}



Measured memory_bytes: 3740
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int lcs(string x, string y) {
    static int c[1001][1001];
    int m = x.size();
    int n = y.size();
    int max1 = 0;
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 0; i <= m; i++)c[i][0] = 0;
    for (int j = 1; j <= n; j++)c[0][j] = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (x[i] == y[j])c[i][j] = c[i - 1][j - 1] + 1;
            else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            max1 = max(max1, c[i][j]);
 
        }
    }
    return max1;
}
 
int main() {
    string s1, s2;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7000
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[10];
signed main(){
  int n, ans = 0;
  rep(i,3)cin >> a[i];cin >> n;
  rep(i,n+1)rep(j,n+1){
    int sum = a[0]*i + a[1]*j;
    if(n < sum)continue;
    if((sum-n)%a[2] == 0)ans++;
  }
  cout << ans << endl;
  return 0;
}






Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func check(N int) int {
	for i := 0; i < 500; i++ {
		if i*(i-1)/2 == N {
			return i
		}
	}
	return -1
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	n := check(N)
	if n == -1 {
		out("No")
		return
	}
	m := make([][]int, n)
	cnt := 1
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			// out(m)
			m[i][j] = cnt
			m[j][i] = cnt
			cnt++
		}
	}
	out("Yes")
	out(n)
	for i := 0; i < n; i++ {
		fmt.Print(n-1, " ")
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			fmt.Print(m[i][j], " ")
		}
		out()
	}
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	char a[101],b[101];
	cin>>n;
	cin>>a>>b;
	F(n){
		cout<<a[i]<<b[i];
	}
	cout<<endl;
return 0;
}


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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n; cin>>n;
    set<ll> vst;
    if(n>2) vst.insert(n-1);
    vst.insert(n);
    for(ll i=2;i*i<=(n-1);i++){
        if((n-1)%i==0){
            vst.insert(i);
            vst.insert(n/i);
        }
    }
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll nn=n;
            while(nn%i==0) nn/=i;
            if((nn-1)%i==0) vst.insert(i);
        }
    }
    cout<<vst.size();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int N;
ll inf = 1e9+7;
string S,T;

int main(){
	cin >> N;
	cin >> S;
	cin >> T;
	S += '0';
	T += '0';
	ll ans = 1;
	bool ty = true;//tate
	int i=0;
	while(i<N){
		if(i==0){
			if(S[i]!=S[i+1]){
				ans *= 3;
				i++;
			}else{
				ans *= 6;
				i += 2;
				ty = false;
			}
		}else{
			if(ty){
				(ans *= 2)%inf;
				if(S[i]!=S[i+1]) i++;
				else {
					i += 2;
					ty = false;
				}
			}else{
				if(S[i]!=S[i+1]){
					i++;
					ty = true;
				}else{
					(ans *= 3)%inf;
					i += 2;
				}
			}
		}
	}
	cout << ans%inf << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,K,i;
	cin>>N>>K;
	vector<LL> A(N);
	for (i=0;i<N;i++){
		cin>>A[i];
	}
	vector<LL> B;
	for (i=K;i<N;i++){
		B.push_back(A[i]);
	}
	for (i=0;i<B.size();i++){
		if (A[i]<B[i]){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

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

int main(){
  int n,m;
  int p[1001];
  int s[1001000];
  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    for(int i=0;i<n;i++)cin >> p[i];
    p[n] = 0;

    for(int i=0;i<=n;i++)
      for(int j=0;j<=n;j++)s[i*(n+1)+j] = p[i] + p[j];

    int N = (n+1)*(n+1);
    sort(s,s+N);
      
    int ans = 0;
    for(int i=0;i<N;i++){
      int hoge = upper_bound(s,s+N,m-s[i]) - s;
      //cout << s[i] << " " << s[hoge-1] << endl;
      if(hoge == 0)break;
      else if(hoge == N)ans = max(ans,s[i]);
      else ans = max(ans,s[i] + s[hoge-1] );
    }

    cout << ans << endl;
  }
}
	  

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
  ll n;cin>>n;
  ll a[n+3],b[n+3],c[n+3];
  ll dp[n+3][4];
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
  dp[1][1]=a[1];dp[1][2]=b[1];dp[1][3]=c[1];

  for(int i=2;i<=n;i++)
  {
    dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
    dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
    dp[i][3]=c[i]+max(dp[i-1][2],dp[i-1][1]);

    //cout<<dp[i][1]<<" "<<dp[i][2]<<" "<<dp[i][3]<<endl;
  } 
  cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
}

Measured memory_bytes: 5888
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def make_combination_list():
    cmb = [0] * 4001
    count = minus = n = s = 0

    for i in range(1001):
        count += (i+1) * (i+2) // 2
        cmb[i] = cmb[4000-i] = count

    for i in range(1001, 2001):
        count += (i+1) * (i+2) // 2
        n += 1
        s += n
        minus += 4 * s
        cmb[i] = cmb[4000-i] = count - minus

    return cmb


def main():
    ans = make_combination_list()
    for line in stdin:
        print(ans[int(line)])


if __name__ == '__main__':
    main()

Measured memory_bytes: 4336
def main():
    A, B, C, X, Y = map(int, input().split())
    ans = 0
    if A + B <= C * 2:
        print(A * X + B * Y)
    else:
        if X < Y:
            ans += C * X * 2
            if B <= C * 2:
                ans += B * (Y - X)
            else:
                ans += C * (Y - X) * 2
        elif X > Y:
            ans += C * Y * 2
            if A <= C * 2:
                ans += A * (X - Y)
            else:
                ans += C * (X - Y) * 2
        else:
            ans += C * (X + Y)
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include "math.h"
using namespace std;
int main() {
    long int N,D;
    cin >> N >> D;
    long int x,y;
    long double dis;
    long int counter = 0;
    for(int i = 0;i<N;i++){
        cin >> x >> y;
        dis = sqrt(x*x+y*y);
        if(dis<=D){
            counter++;
        }
    }
    cout << counter;
    return 0;
}

Measured memory_bytes: 3196
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 1000000007
	limit = 10**18
	ans = 0
	start = {}
	def pre_sum(arr):
		ans = [arr[0]]
		for i in range(1,len(arr)):
			ans.append(ans[-1]+ arr[i])
		return ans
	for test in range(tests):
		n = inp()
		a = inlt()
		ans = 0
		dp = [[sys.maxsize for j in range(n)] for i in range(n)]
		pre = pre_sum(a)
		# print(pre)
		for i in range(n-1,-1,-1):
			dp[i][i] = 0
			for j in range(i+1,n,1):
				for k in range(i+1,j+1):
					dp[i][j] = min(dp[i][j] , dp[i][k-1] + dp[k][j] + pre[j] -pre[i] + a[i])
		# print(dp)
		print(dp[0][-1])



		
		


if __name__== "__main__":
	main()

Measured memory_bytes: 80464
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Stone Monument
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            int diff = b - a;

            int height = 0;

            for(int i = 1; i < diff; i++)
            {
                height += i;
            }

            Console.WriteLine(height - a);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
n = int(input())
h_list = list(map(int, input().split()))

ans = "Yes"
now = 10 ** 9 + 1

for i in range(n - 1, -1, -1):
	for j in range(2):
		tmp = h_list[i] - j
		if tmp <= now:
			now = tmp
			break
		if j == 1:
		  ans = "No"
		
print(ans)

Measured memory_bytes: 14396
#C問題
#考え方：平方根に近いところを探す。
#平方根を切り上げた値からスタート。割り切れた時点で終了。
#TLEになった。原因として考えられるのは何か？ものすごい大きな数の時にうまくいかない？
#素数の時に厳しい。
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

N = int(input())
lis_1 = make_divisors(N)
A = getNearestValue(lis_1,math.sqrt(N))
B = int(N/A)

print(A+B-2)

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<ll> a(n), x(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    x.at(a.at(i))++;
  }
  
  vector<ll> y(n + 1);
  ll keep = 0;
  for (int i = 1; i <= n; i++) {
    y.at(i) = x.at(i) * (x.at(i) - 1) / 2;
    keep += y.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    ll keep2 = keep;
    keep2 -= y.at(a.at(i));
    keep2 += (x.at(a.at(i)) - 1) * (x.at(a.at(i)) - 2) / 2;
    cout << keep2 << '\n';
  }
}

Measured memory_bytes: 7296
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <tuple>
#include <map>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin, s);
    for(int i = 0; i < s.size() - 1; ++i){
        if(s.at(i) == s.at(i + 1)){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}

int main(){
    int N,M;
    cin >> N >> M;
    string S[2002],T[2002];

    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    for(int i = 0; i < M; i++){
        cin >> T[i];
    }

    vector<vector<ll>> dp(N+1,vector<ll> (M+1));
    dp[0][0] = 1;
    for(int i = 0; i < N+1; i++){
        for(int j = 0; j < M+1; j++){
            if(i) dp[i][j] += dp[i-1][j];
            if(j) dp[i][j] += dp[i][j-1];
            if(i && j && S[i-1] != T[j-1]) dp[i][j] += MOD - dp[i-1][j-1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[N][M] << endl;
}




Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

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

    string ans = "";

    for(int i=0; i < n; i++)
    {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N;
    std::cin >> N;
    std::map<std::string, int> mp;
    std::string input;
    int max_num = 0;
    for(int i = 0; i < N; i++){
        std::cin >> input;
        mp[input]++;
        if(max_num < mp[input]) max_num = mp[input];
    }

    std::map<std::string, std::string> output;
    for(auto const& entry: mp){
        if(max_num != entry.second) continue;
        output[entry.first] = entry.first;
    }

    for(auto const& entry: output){
        std::cout << entry.first << std::endl;
    }


    return 0;
}

Measured memory_bytes: 39680
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, n;
	cin >> h >> w >> n;
	cout << min(ceil(n * 1.0 / h), ceil(n * 1.0 / w));
}

Measured memory_bytes: 256