akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

string S[2];
string encoded_dominoes;

void encode() {
    encoded_dominoes = "";
    for (int i = 0; i < S[0].size(); ++i) {
        if (S[0][i] == S[1][i])
            encoded_dominoes += "X";
        else if (S[0][i] == S[0][i + 1] && S[1][i] == S[1][i + 1]) {
            encoded_dominoes += "Y";
            ++i;
        }
    }
}

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

    cin >> S[0];
    cin >> S[1];

    encode();

    long long res;
    if (encoded_dominoes[0] == 'X')
        res = 3;
    else
        res = 6;

    for (int i = 1; i < encoded_dominoes.size(); ++i) {
        if (encoded_dominoes[i] == 'X')
            if (encoded_dominoes[i - 1] == 'X')
                res *= 2;
            else
                res *= 1;
        else if (encoded_dominoes[i] == 'Y')
            if (encoded_dominoes[i - 1] == 'X')
                res *= 2;
            else
                res *= 3;

        res %= 1000000007;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 long long N, A[87], CurrentMoney = 1000;
 int main() {
 cin >> N;
 for (int i = 1; i <= N; i++) cin >> A[i];
 for (int i = 1; i <= N - 1; i++) {
 long long Stocks = 0;
 if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
 CurrentMoney += (A[i + 1] - A[i]) * Stocks;
 }
 cout << CurrentMoney << endl;
 }

Measured memory_bytes: 3600
from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def lcm(x, y):
    return x * y // gcd(x, y)


def main():
    input = stdin.buffer.readline
    a, b, c, d = map(int, input().split())
    l = lcm(c, d)
    ans = 0
    ans += (l - (l // c + l // d - 1)) * (b // l - (a - 1)//l)
    tmp_b = b % l
    ans += tmp_b - (tmp_b // c + tmp_b // d)
    tmp_a = (a - 1) % l
    ans -= tmp_a - (tmp_a // c + tmp_a // d)
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

int main() {
    
    int t, a=0, w=0, tl=0, r=0;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        if(s=="AC") ++a;
        else if(s=="WA") ++w;
        else if(s=="TLE") ++tl;
        else if(s=="RE") ++r;
    }
    
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << tl << endl;
    cout << "RE x " << r << endl;
    
    
    
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> a;
//ベクターnを構成
  for(auto p : n){
    a.push_back(p-'0');
  }
  /*
  for (int i = 0; i < n.length(); i++){
    cout << a[i];
  }
  cout << endl;
  */
  int dp[105][3][5] = {0}; //今調べている桁をi、未満フラグをsmaller、0以外が出た個数をm
  dp[0][0][0] = 1;
  dp[0][0][1] = 0;
  dp[0][1][0] = 0;
  dp[0][1][1] = 0;

  for (int i = 0; i < n.length(); i++){
    for (int j = 0; j < 2; j++){
      for(int m = 0; m <= k; m++){
        int tmp;
        if(j == 1){
          tmp = 9;
        }else{
          tmp = a[i];
        }
        for (int x = 0; x <= tmp; x++){
          //未満か
          //cout << x << " ";
          /*
          if (j == 1){
            dp[i + 1][j][m] += dp[i][j][m];
          }else if(x == a[i] && j == 0){
            //dp[i + 1][j][m] += dp[i][j][m];
          }else if(x < a[i] && j == 0){
            dp[i + 1][1][m] += dp[i][0][m];
          }
          //既に0以外がいくつ出たか
          if(x == 0){
            dp[i + 1][j][m] += dp[i][j][m];
          }else if (x != 0){
            dp[i + 1][j][m + 1] += dp[i][j][m];
          }
          */
          //dp[i + 1][j || x < a[i]][m || x != 0] += dp[i][j][m];
          dp[i + 1][j || x < a[i]][m + (x != 0)] += dp[i][j][m];
        }
        
      }
    }
  }
  /*
  for (int i = 0; i<=n.length(); i++){
    for (int j = 0; j < 2; j++){
      for (int m = 0; m <= k; m++){
        cout << dp[i][j][m] << " ";
      }
      cout << " ";
    }
    cout << endl;
  }
  */
  cout << dp[n.length()][0][k] + dp[n.length()][1][k] << "\n";


  return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
b = 0
if y % 2 != 0:
  print("No")
  quit()
else:
  while x >= 0:
    c = x * 2 + b * 4
    if c == y:
      print("Yes")
      quit()
    x -=1
    b +=1
print("No")

Measured memory_bytes: 9184
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= putStrLn

solve :: [Int] -> String
solve xs = if sort xs == [5,5,7] then "YES" else "NO"

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G ((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;
map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
	d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L a,L i){for(a=M(i++)+G-M(i);i<1e5;i+=i&-i)B[i]+=a;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f])-M(O[a])+G+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
	for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;
	for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33388
# -*= coding: utf-8 -*-
K, N = map(int, input().split())
A = list(map(int, input().split()))

d = [0] * N
for i in range(len(A)):
  if i == 0:
    d[0] = A[0] + (K - A[N-1]) if A[0] + (K - A[N-1]) <= A[N-1] else A[N-1]
    continue
  
  d[i] = A[i] - A[i-1]

d_max = max(d)

print(K - d_max)

Measured memory_bytes: 100068
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807
#define LLMIN       -9223372036854775808
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;

using namespace std;
int N;
vector<LL> A;
vector<LL> front;
vector<LL> back;

int main(void){
    cin>>N;
    REP(i,3*N){
        LL a;cin>>a;A.pb(a);
    }
    priority_queue<LL,vector<LL>,greater<LL> > pq1;
    LL sum1=0;
    REP(i,N){
        sum1+=A[i];
        pq1.push(A[i]);
    }
    REP(i,N+1){
        front.pb(sum1);
        sum1+=A[i+N];
        pq1.push(A[i+N]);
        sum1-=pq1.top();
        pq1.pop();
    }
    priority_queue<LL> pq2;
    LL sum2=0;
    FOR(i,2*N,3*N){
        sum2+=A[i];
        pq2.push(A[i]);
    }
    for(int i=2*N-1;N-1<=i;i--){
        back.pb(sum2);
        sum2+=A[i];
        pq2.push(A[i]);
        sum2-=pq2.top();
        pq2.pop();
    }
    reverse(ALL(back));
    LL ans=front[0]-back[0];
    REP(i,N+1){
        // printf("f[%d]=%lld b[%d]=%lld\n",i,front[i],i,back[i]);
        ans=max(ans,front[i]-back[i]);
    }
    cout<<ans<<endl;
     return 0;
}

Measured memory_bytes: 8556
using System;

class Program
{
    static void Main()
    {
        int input = -1;
        int smallest = 1000000;
        int x = 0;
        int threez = 0;
        
        input = int.Parse(Console.ReadLine());
        while(input != 0) {
            smallest = 1000000;
            for(int z = 0; z * z * z <= input; z++) {
                threez = z * z * z;
                for(int y = 0; y * y <= input - threez; y++) {
                    x = input - threez - y * y;
                    if (x + y + z < smallest) {
                        smallest = x + y + z;
                    }
                }
            }
            Console.WriteLine(smallest);
            input = int.Parse(Console.ReadLine());
        }
    }
}

Measured memory_bytes: 5764
// ==   ||
// 			||
//	*	  ||	
//	*		||
//      ||
// ==   ||
//
//
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

string S;
int cnt[30];

int N;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> N >> S;
	for (int i = 0; i < N; i++)
		cnt[S[i] - 'a']++;
	int ans = 1;
	for (int i = 0; i < 26; i++)
		ans = 1LL * ans * (cnt[i] + 1) % MO;
	ans = (ans - 1 + MO) % MO;
	cout << ans << "\n";
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,c,d; cin >> a >> b >> c >> d;
    
    cout << max({a*c, a*d, b*c, b*d}) << "\n";



    

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
using ll = long long;
int main(){
    int n , m,c;
    c =0;
    ll k;
    cin >> n >> m >>k;
    vector<ll> a(n+1);
    vector<ll> b(m+1);
    rep(i,n){
        cin >> a[i+1];
    }
    rep(i,m){
        cin >> b[i+1];
    }
    vector<ll> A(n+1);
    vector<ll> B(m+1);
    rep(i,n){
        A[i+1]=A[i]+a[i+1];
    }
    rep(i,m){
        B[i+1]=B[i]+b[i+1];
    }
    int x=m+1;
    rep(i,n+1){
        if(A[i]>k){
            break;
        }
        rep(j,x){
            if(B[x-1]+A[i]<=k){
                c = max(c,i+x-1);
                break;
            }
            else if(A[i]+B[x-1-j]<=k){
                c=max(c,i+x-j-1);
                x=x-j;
                break;
            }
        }
    
    }
    cout << c << endl;
}

Measured memory_bytes: 9512
#include "iostream"

using namespace std;

void sentaku(int a[100], char k[100][2], int num ) {

	for (int i = 0; i < num; i++) {
		int minj = i;
		int s = 0;
		for (int j = i; j < num; j++) {
			if (a[j] < a[minj]) {
				minj = j;
				s = 1;
			}
		}
		if (s == 1) {
			int b = a[i];
			a[i] = a[minj];
			a[minj] = b;

			char l = k[i][0];
			k[i][0] = k[minj][0];
			k[minj][0] = l;
			
			l = k[i][1];
			k[i][1] = k[minj][1];
			k[minj][1] = l;
		}
	}


	for (int i = 0; i < num; i++) {
		cout << k[i][0] << k[i][1];
		if (i < num - 1) cout << " ";

	}
	cout << endl;

}

void baburu(int a[100], char k[100][2], int num) {

	int frag = 1;
	while (frag == 1) {
		frag = 0;
		for (int j = num - 1; j > 0; j--) {
			if (a[j] < a[j - 1]) {
				int b = a[j];
				a[j] = a[j - 1];
				a[j - 1] = b;

				char l = k[j][0];
				k[j][0] = k[j-1][0];
				k[j-1][0] = l;

				l = k[j][1];
				k[j][1] = k[j-1][1];
				k[j-1][1] = l;

				frag = 1;
			}
		}
	}

	for (int i = 0; i < num; i++) {
		cout << k[i][0] << k[i][1];
		if (i < num - 1) cout << " ";

	}
	cout << endl;

}

int main() {

	int num;
	char ka[100][2], kb[100][2];
	int a[100], b[100];

	cin >> num;

	for (int i = 0; i < num; i++) {
		cin >> ka[i];
		a[i] = ka[i][1] - '0';

		kb[i][0] = ka[i][0];
		kb[i][1] = ka[i][1];
		b[i] = a[i];
	}

	baburu(b, kb, num);
	cout << "Stable" << endl;
	sentaku(a, ka, num);
	
	int s = 0;

	for (int i = 0; i < num; i++) {
		if (ka[i][0] != kb[i][0]) {
			s = 1;
			cout << "Not stable" << endl;
			break;
		}
	}
	if (s == 0) cout << "Stable" << endl;

	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
using namespace std;



int main()
{
    
    long long a, b, x;
    cin >> a >> b >> x;
     
    long long ans = b / x - a / x;

    if((a % x) == 0) ans++;

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

Measured memory_bytes: 256
n=int(input())
a=[-1]+[int(input()) for _ in range(n)]
for i,j in zip(a[:n],a[1:]):
  if i<j-1:
    print(-1)
    exit()
ans=0
for i,j in zip(a[1:n],a[2:]):
  if j-i==1:ans+=1
  else:ans+=j
print(ans)

Measured memory_bytes: 95540
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;

signed main()
{
    int p, q, r;
    cin >> p >> q >> r;
    vector<int> v;
    v.push_back(p);
    v.push_back(q);
    v.push_back(r);
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << "\n";
}

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

#define MAX_N 10000000
#define INF 10000000

long long H, W, V, T, X, Y, P, Q;

int main() {
	cin >> W >> H >> V >> T >> X >> Y >> P >> Q;
	long long K = V*T;
	long long x[4] = { P,2 * W - P,P,2 * W - P };
	long long y[4] = { Q,Q,2 * H - Q,2 * H - Q };
	long long res = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = -(MAX_N); j <= MAX_N; j++) {
			long long X1 = x[i] + (2 * W*j);
			if (abs(X1) >= 2000000000) { continue; }
			long long XD = (X1 - X)*(X1 - X);
			if (XD <= K*K) {
				long double YD = sqrtl(1.0*(K*K - XD));
				long double LY = Y - YD, RY = Y + YD;
				long double LS = LY - y[i];
				long double RS = RY - y[i];
				LS /= (2 * H); RS /= (2 * H);
				long long P = (long long)(LS + INF + 0.999999999) - INF;
				long long Q = (long long)(RS + INF) - INF;
				res += Q - P + 1;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [0 for n in range(N)]
inf = 10**10
for i in range(1, N):
	dp[i] = inf
	for k in range(max(0, i-K), i):
		dp[i] = min(dp[i], dp[k] + abs(H[i] - H[k]))
# print(dp)
print(dp[N-1])

Measured memory_bytes: 56544
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n)-1;i>=(j);i--)
using ll=long long;
using namespace std;
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 ll INF=1LL<<60;

int n;
vector<int> a(100100);


int main(){
    cin>>n;
    rep(i,0,n) cin>>a[i];

    int cnt=0;
    int flag;
    if(a[0]==a[1]) flag=0;
    else if(a[0]>a[1]) flag=1;
    else if(a[0]<a[1]) flag=2;

    int ans=1;
    rep(i,1,n-1){
        if(flag==0){
            if(a[i]>a[i+1]) flag=1;
            else if(a[i]<a[i+1]) flag=2;
        }
        else if(flag==1){
            if(a[i]<a[i+1]){
                ans++;
                flag=0;
            }
        }
        else if(flag==2){
            if(a[i]>a[i+1]){
                ans++;
                flag=0;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define INF (1 << 30)
#define pb push_back
#define mk make_pair

int N, M;
pii esum[1000];
vector<int> G[1000];
bool used[1000];
bool elist[1000][1000];
int color[1000];
int ab[1000][2];
bool dp[1000][1000];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        elist[a][b] = true;
        elist[b][a] = true;
    }
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            if(!elist[i][j]){
                G[i].pb(j);
                G[j].pb(i);
            }
        }
    }
    int cnt = 0;
    memset(color, -1, sizeof(color));
    for(int i = 0; i < N; i++){
        if(color[i] < 0){
            queue<pii > que;
            que.push(mk(i, 0));
            color[i] = 0;
            while(que.size()){
                int cur = que.front().first;
                int now = que.front().second;
                ab[cnt][now]++;
                que.pop();
                for(int j = 0; j < (int)G[cur].size(); j++){
                    int to = G[cur][j];
                    if(color[to] < 0){
                        color[to] = (now^1);
                        que.push(mk(to, color[to]));
                    }
                    else {
                        if(color[to] == now){
                            printf("-1\n");
                            return 0;
                        }
                    }
                }
            }
            cnt++;
        }
    }
    dp[0][0] = true;
    for(int i = 0; i < cnt; i++){
        for(int j = 0; j <= N; j++){
            if(j - ab[i][0] >= 0){
                dp[i + 1][j] |= dp[i][j - ab[i][0]];
            }
            if(j - ab[i][1] >= 0){
                dp[i + 1][j] |= dp[i][j - ab[i][1]];
            }
        }
    }
    int ans = INF;
    for(int i = 0; i <= N; i++){
        if(dp[cnt][i]){
            int res = i * (i - 1) / 2 + (N - i) * (N - 1 - i) / 2;
            ans = min(ans, res);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    set<string> S;
    int n; cin >> n;
    char last;
    string ret; cin >> ret;
    S.emplace(ret);
    last = ret.back();
    for(int i = 1; i < n; ++i) {
        cin >> ret;
        if(ret[0] != last || S.find(ret) != S.end()) return !printf("No");
        last = ret.back();
        S.emplace(ret);
    }
    puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////


void solve(){
    ll n,m;
    cin >> n >> m;
    Vi mods(n),sum(n+1);
    rp(i,n){
        cin >> mods.at(i);
        mods.at(i)%=m;
    }
    sum[0]=0;
    rp(i,n){
        sum[i+1]=sum[i]+mods[i];
        sum[i+1]%=m;
    }
    sort(all(sum));
    ll ans=0;
    ll ctr=1;
    rp(i,n){
        if(sum[i]==sum[i+1]){
            ctr++;
        }
        else{
            ans += ctr*(ctr-1)/2;
            ctr=1;
        }
    }
    ans+=ctr*(ctr-1)/2;
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main() {
    
    int t;
    t=1;
   // cin >> t;
    while(t--){
        int n,w;
        cin >> n >> w;
        
        ll weights[n+1];
        ll values[n+1];
        
        for(int i=1;i<=n;i++){
            cin >> weights[i] >> values[i];
        }
        
        ll dp[n+1][w+1];
        memset(dp,0,sizeof(dp));
       
        for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
                if(j<weights[i]){
                    dp[i][j] = dp[i-1][j];
                }else{
                    dp[i][j] = max(dp[i-1][j],values[i]+dp[i-1][j-weights[i]]);
                }
            }
        }
        cout << dp[n][w] << endl;
         

    }
    return 0;

}

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

int main()
{
	int N, M;
	cin >> N >> M;

	vector<string> imgN(N);
	vector<string> imgM(M);

	for (int i = 0; i < N; i++)
		cin >> imgN[i];

	for (int i = 0; i < M; i++)
		cin >> imgM[i];

	bool result;
	for (int i = 0; i + M <= N; i++) {
		for (int j = 0; j + M <= N; j++) {
			result = true;
			for (int w = 0; w < M && result; w++) {
				for (int h = 0; h < M && result; h++) {
					if (imgN[j + h][i + w] != imgM[h][w]) {
						result = false;
					}
				}
			}
			if(result)
				goto END_HANDLE;
		}
	}
END_HANDLE:

	cout << (result ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int l1=s1.length(),l2=s2.length();
	if(l1!=l2) {cout<<"No";return 0;}
	for(int i=0;i<l1;i++)
	{
		for(int j=0;j<l1;j++)
		{
			if(s1[(i+j)%l1]!=s2[j]) break;
			if(j==l1-1) {cout<<"Yes";return 0;}
		}
	}
	cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
	cin>>a;
	for(int s=1;s<=32;s++)
	{
		for(int v=2;v<=10;v++)
		{
			if(pow(s,v)<=a)b=max(b,(long long)pow(s,v));
		}
	}
	cout<<b<<endl;
}

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

long long ans;
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++) {
   	if (s[i] == 'A' && s[i +1] == 'B' && s[i+2] == 'C' ) 
    	ans++;
  }
  	cout << ans;
 	return 0; 
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long C = scan.nextLong();
        long K = scan.nextLong();
        long[] l = new long[N];
        for (int i = 0; i < N; i++) {
            l[i] = scan.nextLong();
        }
        Arrays.sort(l);
        long[] r = new long[N];
        for (int i = 0; i < N; i++) {
            r[i] = l[i] + K;
        }
        int answer = 0;
        for (int i = 0; i < N;) {
            int current = i;
            int number_of_people = 0;
            for (int j = current; j < N; j++) {
                if (r[current] < l[j]) {
                    break;
                }
                number_of_people += 1;
                i = j + 1;
                if (number_of_people == C) {
                    break;
                }
            }
            answer += 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 50100
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#define mod 1000000007
using namespace std; 

int main(){
	int n,m; cin >> n >> m;
	int a=0;
	for (int i=0;i<m;i++){
		int s; cin >> s;
		a+=s;
	}
	if (n<a){
		cout << "-1" << "\n";
	}
	else{
		cout << n-a << "\n";
	}
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    int r;cin >> r;
    cout << r * r;
}


Measured memory_bytes: 892
s = input()
# s = 'RRRLLL'
n = len(s)
index = []

a = 'R'
for i in range(n):
    if a == 'R' and s[i] == 'L':
        index += [(i - 1)]
        a = 'L'
    elif a == 'L' and s[i] == 'R':
        index += [-(i - 1)]
        a = 'R'
m = len(index)

ans = [0] * n
j = 0
r = 0
while True:
    if j == m - 1:
        l = n
        if (index[j] - r) % 2 == 1:
            ans[index[j]] = (l - r) // 2
            ans[index[j]+1] = (l - r) - (l - r) // 2 
        else:
            ans[index[j]+1] = (l - r) // 2
            ans[index[j]] = (l - r) - (l - r) // 2
        break 
    l = -index[j+1] + 1
    if (index[j] - r) % 2 == 1:
        ans[index[j]] = (l - r) // 2
        ans[index[j]+1] = (l - r) - (l - r) // 2 
    else:
        ans[index[j]+1] = (l - r) // 2
        ans[index[j]] = (l - r) - (l - r) // 2
    r = l
    j += 2

ans = map(str, ans)
print(' '.join(ans))

Measured memory_bytes: 14324
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;

vector<ll> findDivs(ll n)
{
  vector<ll>divs;
  for(ll i = 1; i * i <= n ; i++)
  {
    if(n % i == 0)
    {
      ll x = n / i;
      if(i != 1)
        divs.push_back(i);
      if(x != i)
        divs.push_back(x);
    }
  }
  return divs;
}
ll solve(ll n)
{
  set<ll>ans;
  for(auto &c : findDivs(n - 1))
    ans.insert(c);
  for(auto &c : findDivs(n))
  {
    ll y = n;
    while(n % c == 0)
      n /= c;
    if(n % c == 1)
      ans.insert(c);
    n = y;
  }
  return ans.size();
}

int main()
{
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  cout << solve(n) << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int ans=0;
const int maxn=200500;
typedef long long ll;
ll a[maxn],s[maxn];
int n;
const ll inf=1e18;
int main(){
    scanf("%d",&n);
    rep(i,1,n) scanf("%lld",&a[i]);
    rep(i,1,n) s[i]=s[i-1]+a[i];
    ll ans=inf;
    rep(i,1,n){
        ll p=s[n]-s[i];
        if (p==s[i]) {
            ans=min(ans,0ll);
            break;
        }
        if (s[i]>p) {
            ans=min(ans,s[i]-p);
            break;
        }
        else ans=min(ans,p-s[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

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

using namespace std;

int a[100001];

int gcd(int a, int b) {
    return a == 0 ? b : gcd(b % a, a);
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int l = 0, r = n - 1;
    while (r - l > 3) {
        int m = (l + r) / 2;
        int g1 = a[0], g2 = a[m + 1];
        for (int i = 1; i < m + 1; ++i) {
            g1 = gcd(g1, a[i]);
        }
        for (int i = m + 1; i <= r; ++i) {
            g2 = gcd(g2, a[i]);
        }
        if (g1 < g2) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    int answer = 0;
    for (int j = l; j <= r; ++j) {
        int g = a[0];
        if (j == 0) {
            g = a[1];
        }
        for (int i = 0; i < n; ++i) {
            if (i != j) g = gcd(g, a[i]);
        }
        answer = max(answer, g);
    }
    cout << answer << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long L, R; cin >> L >> R;

    if (R - L >= 2019) cout << 0 << endl;
    else {
        long long ans = INF;
        for (long long i = L; i < R; ++i) {
            for (long long j = i+1; j <= R; ++j) {
                ans = min(ans, (i * j) % 2019);
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        int mimin = 1000000000;
        for(int j = 1; j <= k; j++){
            if(i-j < 0) break;
            mimin = min(mimin, dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i] = mimin;
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct coo{
	int x;
	int y;
	int h;
}c[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;
		cin>>c[i].y;
		cin>>c[i].h;
	}
	int ch;
	int p=0;
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int f=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					f=1;
					break;
				}
			}
			if(!f)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> compte(n);
    for(int c=0;c<n-1;c++) {
        int z;
        cin>>z;
        z--;
        compte[z]++;
    }
    for(int c=0;c<n;c++) cout<<compte[c]<<endl;
}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    cin >> num;
    long water[100010];
    long sum=0;

    for(int i=1;i<num;i++){
        cin >> water[i];
        if(i%2==1){
            sum += water[i];
        }else{
            sum -= water[i];
        }
    }
    //a-num がsum

    cin >> water[num];

    long mountain[100010];
    mountain[1]=water[num]+sum;
    cout << mountain[1] << " ";

    for(int i=2;i<num;i++){
        mountain[i]=(water[i-1]-mountain[i-1]/2)*2;
        cout << mountain[i] <<" ";
    }
    mountain[num]=(water[num-1]-mountain[num-1]/2)*2;
    cout << mountain[num]<<endl;

    return 0;



}

Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
using namespace std; 
int a,b,c,d,sum1=0,x=0,sum2=0;
int main(){
	cin>>a>>b>>c>>d;
	sum1=abs(a-b);
	sum2=abs(b-c);
	x=x+abs(a-c);
	if(x<=d){
		cout<<"Yes"	;
	}
	else if(sum1<=d && sum2<=d){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	

}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    string s;
    cin >> s;

    int i = 0;
    int cont = 0;
    while (i < s.size()) {
        if (s[i] == 'A') {
            cont++;
            i++;
        } else if (s[i] == 'B' && s[i+1] == 'C') {
            ans += cont;
            i += 2;
        } else if (s[i] != 'A') {
            cont = 0;
            i++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int           int64_t
#define double        long double
#define nitro         ios_base::sync_with_stdio(false);cin.tie(0);
#define vi            vector<int64_t>
#define pub           push_back
#define puf           push_front
#define pob           pop_back
#define pof           pop_front
#define fi            first
#define se            second
#define PI            3.1415926535897932384626433832795
#define linp(a)       for(auto& x : a) cin>> x
#define endl          '\n'
#define gap           ' '
#define min3(a,b,c)   min(a, min(b, c))
#define max3(a,b,c)   max(a, max(b, c))
#define MOD           10000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int h,m,H,M;cin>>h>>m>>H>>M;
    double angle=H*30-(5.5)*M;
    angle*=PI/180;
    double x=(h*h)+(m*m)-(2*h*m)*cos(angle);
    cout<<fixed<<setprecision(15)<<sqrt(x);
    return 0;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S;
    cin >> S;
    for (u32 i = 0; i < S.size(); i++) cout << "x";
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
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,greater<int>());
    int x=1e9+1;
    int ans;
    for(int i=1;i<N;i++){
        if(x>abs(a[0]/2-a[i])){
            x=abs(a[0]/2-a[i]);
            ans=a[i];
        }
    }
    cout << a[0] << ' ' << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i <= n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
  string s;
  int counter=0;
  ll sum_of_digits=0;
  ll digits = 1;
  int mods[2019]={};
  cin >> s;
  reverse(all(s));
  for (char i:s){
    int n = int(i-'0');
    sum_of_digits+=n*digits;
    mods[sum_of_digits%2019]+=1;
    digits*=10;
    digits%=2019;
  }
  int res = mods[0];
  for (int i=0;i<2019;i++){
    int n = mods[i];
    if(n>1){
      res += n*(n-1)/2;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3720
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+j*100+k*50==x:
        ans+=1

print(ans)        

Measured memory_bytes: 39536
import math

n = int(input()) - 1
l = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    time = l[i][0] + l[i][1]

    for j in range(i + 1, n):
        if time <= l[j][1]:
            time = l[j][1]
        elif time % l[j][2] != 0:
            time += l[j][2] - (time % l[j][2])
        
        time += l[j][0]
    
    print(time)

print(0)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

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

	int n;
	cin >> n;
	vector<Pll> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i].second >> w[i].first;
	}
	sort(w.begin(), w.end());
	ll now = 0;
	for (int i = 0; i < n; i++) {
		int a = w[i].second;
		int b = w[i].first;

		now += a;
		if (now > b) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007


int main(){
int N;
  cin >>N;
  lli sum;
  lli mini=MAX_INF;
  lli X[N];
  rep(i, N)
    cin >> X[i];
  rep(j, 100){
  sum=0;
    rep(i, N){
    sum+=(X[i]-(j+1))*(X[i]-(j+1));
    }
    mini=min(mini,sum);
  }
  cout << mini << endl;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

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

    string S;
    std::cin >> S;

    bool fc = false;

    for(const char &c : S){
        if(c == 'C'){fc = true;}
        if(c == 'F' && fc){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    println(problem159a(n, m))
}

fun problem159a(n: Int, m: Int): Int {
    return n * (n - 1) / 2 + m * (m - 1) / 2
}

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

class Dinic{
    struct edge{
        int to;
        int rev;
        int cap;
    };
    int n;
    vector<int> level,itr;
    vector<vector<edge>> G;

    void bfs(int s){
        level.assign(n,-1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(auto &e : G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f){
        if(v == t){
            return f;
        }
        for(int& i=itr[v]; i<G[v].size(); i++){
            edge& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    public:

    Dinic(int num){
        n = num;
        G.assign(n,vector<edge>());
    }

    void add_edge(int to, int from, int cap){
        G[from].emplace_back((edge){to, G[to].size(), cap});
        G[to].emplace_back((edge){from, G[from].size()-1, 0});
    }

    int run(int s, int t){
        int ret = 0, f;
        while(bfs(s), level[t]>= 0){
            itr.assign(n,0);
            while((f = dfs(s,t,INT_MAX)) > 0){
                ret += f;
            }
        }
        return ret;
    }
};

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

    Dinic solver(2*n+2);
    vector<pair<int,int>> red(n);
    for(int i=0; i<n; i++){
        cin >> red[i].first >> red[i].second;
        solver.add_edge(i+1,0,1);
    }

    for(int i=0; i<n; i++){
        int c,d;
        cin >> c >> d;
        solver.add_edge(2*n+1, n+i+1, 1);
        for(int j=0; j<n; j++){
            if(red[j].first < c && red[j].second < d){
                solver.add_edge(n+i+1,j+1,1);
            }
        }
    }

    cout << solver.run(0,2*n+1) << endl;
}

Measured memory_bytes: 384
s = input()
n = len(s) + 1
A = [0] * n

for i in range(n-1):
    if s[i] == '<':
        A[i+1] = A[i]+1
        
for i in range(n-2, -1, -1):
    if s[i] == '>':
        A[i] = max(A[i], A[i+1]+1)
print(sum(A))

Measured memory_bytes: 23336
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>

int main()
{
	int H, N;
	std::cin >> H >> N;

	int sum = 0;
	std::vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> A[i];

		sum += A[i];
	}

	if (sum < H) {
		std::cout << "No";
	}
	else {
		std::cout << "Yes";
	}



	return 0;
}

Measured memory_bytes: 640
gyou,retu=map(int,input().split())
l=[input() for _ in range(gyou)]
d=[(0,1),(1,0),(-1,0),(0,-1)]
for g in range(gyou):
  for r in range(retu):
    if l[g][r]=="#":
      k=0
      for x,y in d:
        try:
          if l[g+x][r+y]=="#" and g+x>=0 and r+y>=0:
            k+=1
        except IndexError:
          pass
      if k==0:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

const int MOD = 1000000007;
int n, l;
int x[5010], a[5010];

int dp[5010][5010];

signed main(){
    while(cin >> n >> l){
        rep(i, n) cin >> x[i], ++x[i];
        rep(i, n) cin >> a[i], a[i] ? 0 : a[i] = l;
        memset(dp, 0, sizeof dp);
        for(int i = 0; i <= l; ++i) dp[0][i] = 1;
        for(int i = 1; i <= n; ++i){
            int a = ::a[i-1], x = ::x[i-1];
            for(int j = x; j <= l; ++j){
                if(j == x){
                    dp[i][j] = dp[i-1][j-1];
                } else {
                    if((j-x)%a == 0){
                        dp[i][j] += dp[i-1][j-1];
                    }
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] %= MOD;
                }
            }
        }

        // for(int i = 0; i <= n; ++i){
        //     for(int j = 0; j <= l; ++j){
        //         cout << dp[i][j] << ' ';
        //     }
        //     cout << endl;
        // }

        cout << dp[n][l] << endl;
    }
}

Measured memory_bytes: 199204
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int h1 = sc.nextInt();
    int m1 = sc.nextInt();
    int h2 = sc.nextInt();
    int m2 = sc.nextInt();
    int k = sc.nextInt();
    
    int ans = h2 * 60 + m2 - k - h1*60 - m1;
    System.out.println(ans);
  }
}

Measured memory_bytes: 35708
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const map<T, S> m) { for (pair<T, S> p: m) s << p << endl; return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

int count(int a, int b) {
  if (a <= b && b < 4 * a) return 0;
  else if (a < b) {
    return -1 + count(4 * a, b);
  } else {
    return 1 + count(a, 4 * b);
  }
}
signed main() {
  int N; cin >> N;
  VI A(N);
  REP (i, N) cin >> A[i];
  VVVI dp(2, VVI(N, VI(16)));
  REP (k, 2) {
    REP (x, 16) {
      dp[0][N - 1][x] = dp[1][N - 1][x] = x;
    }
  }
  REP (k, 2) {
    for (int i = N - 2; i >= 0; i--) {
      int dif = count(A[i], A[i + 1]);
      REP (x, 16) {
        int tmp = max(0LL, x + dif);
        dp[k][i][x] = dp[k][i + 1][min(15LL, tmp)] + x + max(0LL, tmp - 15) * (N - i - 1);
      }
    }
    reverse(ALL(A));
  }
  dump(dp[0], dp[1]);
  int ans = 1e18;
  REP (i, N) {
    int tmp = i + (dp[0][i][0] + (i == 0 ? 0 : dp[1][N - i][0])) * 2;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 100224
#include<stdio.h>

int A[20], n, j;
void solve(int, int);

main(){
  int i, q, M[200];
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i = 0;i < q;i++){
    j = 0;
    scanf("%d", &M[i]);
    solve(0,M[i]);
    if(j == 0){
      printf("no\n");
    }
  }
  return 0;
}

void solve(int p, int t){
  if(p < n && j == 0 && t > 0){
    if(t == A[p]){
      printf("yes\n");
      j++;
      return;
    }
    solve(p+1, t-A[p]);
    solve(p+1, t);
  }
}

Measured memory_bytes: 580