akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();

        int[] route = { p, q, r };
        Arrays.sort(route);

        int ans = 0;
        ans += route[0];
        ans += route[1];

        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        outer: for (int i = 1 ; ; i++) {
            int x = sc.nextInt();
            switch(x) {
                case 0:
                    break outer;
                default:
                    System.out.printf("Case %d: %d\n", i, x);
            }
        }
    }
}


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

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  
  bool can = false;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      can = true;
      break;
    }
  }
  
  if(can){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>

int a[1123], n, k;
int tmp[1123];
bool test(int t){
	int num(0), sum1(0), sum2(0);
	for(int i(1); i <= n; ++i){
		if(a[i] % t != 0) tmp[++num] = a[i] % t, sum1 += tmp[num];
	}	
	std::sort(tmp + 1, tmp + num + 1);
	for(int i(num); i >= 2 && sum1 != sum2 && sum2 <= k; --i){
		sum1 -= tmp[i]; sum2 += (t - tmp[i]);
	}
	return sum2 <= k;
}

int main(){
	scanf("%d%d", &n, &k);
	int sum(0);
	for(int i(1); i <= n; ++i){
		scanf("%d", &a[i]); sum += a[i];
	}
	int Max = sum;
	for(int i(Max); i >= 1; --i){
		if(sum % i == 0 && test(i)){
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 128
N,L=map(int,input().split())
ans=0
f=0
min=10000
for i in range(1,N+1):
    tmp=L+i-1
    ans+=tmp
    if abs(tmp) < min:
        min = abs(tmp)
        if tmp < 0:
            f=1
if f == 0:
    ans-=min
else:
    ans+=min
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
        while(1){
                int h, w;
                scanf("%d %d", &h, &w);
                if(h+w==0) break;

                for(int i=0; i<h; i++){
                        for(int j=0; j<w; j++) putchar('#');
                        puts("");
                }
                puts("");
        }
        return 0;
}


Measured memory_bytes: 2056
from itertools import accumulate
n, k = map(int,input().split())
MOD = 10**9+7

a = [i for i in range(n+1)]
ac = list(accumulate(a))
sa = sum(a)
cnt = 0
for i in range(k, n+2):
    if i == n+1:
        cnt += 1
        break
    cnt += sa - ac[-i-1] - ac[i-1] + 1
print(cnt%MOD)

Measured memory_bytes: 27264
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

signed main() {
    int N; cin >> N;
    int ans=1;
    string S; cin >> S;
    rep(i,N-1){
        if(S[i]!=S[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    string S;
    cin >> S;
    int s = 0, t = 0, ans = 0;
    for(int i = 0; i < S.length(); i++) {
        if(S[i] == 'S') {
            s++;
        } else if(S[i] == 'T') {
            if(s) {
                s--;
            } else {
                t++;
            }
        }
    }
    ans = 2 * t;
    cout << ans << endl;
}

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

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

    bool flag = false;
    for(int i=0; i<n-2; i++){
        if(a[i][0]!=a[i][1]) continue;
        if(a[i+1][0]!=a[i+1][1]) continue;
        if(a[i+2][0]!=a[i+2][1]) continue;
        flag = true;
        break;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, K;
    cin>>N>>K;
    vector<int> as(N);
    rep(i, N) cin>>as[i];

    vector<bool> dp(K + 1);
    rep(i, K + 1) {
        if (i < as[0]) continue;
        rep(j, N) {
            if (i - as[j] < 0) continue;
            if (!dp[i - as[j]]) {
                dp[i] = true;
                break;
            }
        }
    }
    if (dp[K]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int c[510],s[510],f[510];
  int n,i,start=1,t=0,look;
  scanf("%d",&n);
  for(i=0;i<n-1;i++){
    scanf("%d %d %d",&c[i],&s[i],&f[i]);
  }
  for(start=1;start<=n;start++){
    t = 0;
    look = start;
    while(look <= n-1){
      while((t-s[look - 1]) % f[look - 1] != 0 || t-s[look-1] < 0){
      t++;
      }
    t += c[look-1];
    look++;
    }
    printf("%d\n",t);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
n, l = map(int,input().split())
sum1 = 0
num = 1000
for i in range(n):
  a = l+(i+1)-1
  sum1 += a
  if abs(a) < num:
    num1 = a
    num = abs(a)
if num1 == num:
  print(sum1-num)
else:
  print(sum1+num)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 14 08:52:34 2018
AGC028A
@author: maezawa
"""

n, m = list(map(int, input().split()))
s = input()
t = input()

def gcm(a,b):
    while b:
        a, b = b,a%b
    return a

lcm = n*m//gcm(n,m)
possible = True

for k in range(n):
    if k*m%n == 0:
        if k*m//n < m and s[k] != t[k*m//n]:
            possible = False
            #print(k, k*n//m, s[k], t[k*n//m])
            break
for k in range(m):
    if k*n%m == 0:
        if k*n//m < n and t[k] != s[k*n//m]:
            possible = False
            #print(k, k*m//n, t[k], s[k*m//n])
            break
                                
    
if possible:
    print(lcm)
else:
    print(-1)
        

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES

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

typedef long long ll;


int main()
{
    int n;
    cin >> n;
    int a[n-1];

    for (int i=0; i<n-1; i++) {
        cin >> a[i];
    }

    int subordinates[n-1] = {0};
    for (int j=0; j<n-1; j++) {
        subordinates[a[j]-1]++;
    }

    for (int k=0; k<n-1; k++) {
        cout << subordinates[k] << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 5184
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=Integer.parseInt(sc.nextLine());
		Map<String,Integer> keywords=new HashMap<>();
		for(int i=0;i<N;i++) {
			String key=sc.nextLine();
			if(keywords.containsKey(key)) {
				keywords.put(key,keywords.get(key)+1);
			}else {
				keywords.put(key, 1);
			}
		}
		N=Integer.parseInt(sc.nextLine());
		for(int i=0;i<N;i++) {
			String key=sc.nextLine();
			if(keywords.containsKey(key)) {
				keywords.put(key,keywords.get(key)-1);
			}
		}
		Integer max=keywords.values().stream().max(Integer::compare).get();
		System.out.println(max<0?0:max);
	}
}

Measured memory_bytes: 28368
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;


int main(){
  string S,T;
  cin >> S >> T;
  int ss = S.size();
  int ts = T.size();
  int ans = 1000000;
  rep(i,ss-ts+1){
    int provi = 0;
    rep(j,ts){
      if(S.at(i+j) != T.at(j)){
        provi++;
      }
    }
    ans = min(ans,provi);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;


ll n, a, b, c, d;

int main() {
	cin >> n >> a >> b >> c >> d;
	lp(n) {
		if ((n - i) % 2) {
			if ((a + c*i - (n - i - 1)*(d - c)/2 <= b&&b <= a + d*i + (n - i - 1)*(d - c)/2) || (a - c*i + (n - i - 1)*(d - c)/2 >= b&&b >= a - d*i - (n - i - 1)*(d - c)/2)) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from itertools import combinations

def main():
    n = int(input().strip())
    G = [[-1] * n for _ in range(n)]
    # H = [[0] * n for _ in range(n)]
    for i in range(n):
        m = int(input().strip())
        for j in range(m):
            x, y = list(map(int, input().strip().split()))
            G[i][x-1] = y
    # print(G)
    for i in reversed(range(n+1)):# n~0
        for c in combinations(range(n), i):
            # 正直者と正直者が指す人，がある特定の人を正直，真偽不明で指していたら矛盾
            cont = False
            # print("c: ", c)
            for p in c:
                for j in range(n):
                    if G[p][j] == -1:
                        continue
                    if (G[p][j] == 1) != (j in c):
                        cont = True
                    # print("p, j, cont: ", p, j, cont)
                    # print(c, j in c)
                    # print(G[p][j] == 1)
                    # print((G[p][j] == 1) != True)
                    # if (j in c and G[p][j] == 0):
                    #     print("cont: ", c)
                    #     cont = True
            if cont == False:
                print(i)
                return

if __name__ == '__main__':
    main()


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

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N)cin >>A[i];
    int a = 0;
	rep(i, N) {
		if (A[i] % 2 == 0) {
			if ((A[i] % 3 != 0) && (A[i] % 5 != 0))
				a++;
		}
	}

	if (a == 0)cout << "APPROVED";
	else cout << "DENIED";
		}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 100000;
long long int ans[maxn], v[maxn];
int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> v[i];
	ans[0] = 0, ans[1] = abs(v[1] - v[0]);
	for (int i = 2; i < n; i++)
		ans[i] = min(ans[i - 1] + abs(v[i] - v[i - 1]), ans[i - 2] + abs(v[i] - v[i - 2]));
	cout << ans[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int MX=1048576,MB=20;
typedef long long LL;
int n,q,a[MX];
int readch(){
	char c=getchar();
	while(c==' '||c=='\n') c=getchar();
	if(c=='D') return 1;
	if(c=='M') return 2;
	if(c=='C') return 3;
}
struct data{
	int c0,c1;
	LL pr;
	void init(){
		c0=c1=0;
		pr=0ll;
	}
};
data merge(data A,data B){
	data R;
	R.c0=A.c0+B.c0;
	R.c1=A.c1+B.c1;
	R.pr=A.pr+B.pr+(LL)A.c0*(LL)B.c1;
	return R;
}
vector < data > t[5000005];
int lp[5000005],rp[5000005],AD;
void init(int p,int l=0,int r=MX-1){
	if(!l && !r) AD=p;
	lp[p]=l;
	rp[p]=r;
	t[p].resize(r-l+1);
	if(l==r){
		t[p][0].c0=(a[l]==2);
		t[p][0].c1=(a[l]==3);
		t[p][0].pr=0ll;
	}
	else{
		int M=(l+r)>>1,i;
		init((p<<1),l,M);
		init((p<<1|1),M+1,r);
		for(i=l;i<=r;++i){
			t[p][i-l].c0=(a[i]==2);
			t[p][i-l].c1=(a[i]==3);
			t[p][i-l].pr=0ll;
		}
		for(i=M-1;i>=l;--i){
			t[p][i-l]=merge(t[p][i-l],t[p][i-l+1]);
		}
		for(i=M+2;i<=r;++i){
			t[p][i-l]=merge(t[p][i-l-1],t[p][i-l]);
		}
	}
}
LL qry(int l,int r){
	r=min(r,n-1);
	LL ret=0ll;
	int ln=__builtin_clz(l+AD^r+AD)-11;
	int p=(1<<ln)-1&(l+AD>>MB-ln+1);
	return merge(t[p][l-lp[p]],t[p][r-lp[p]]).pr;
}
LL solve(int L){
	int i,j,k;
	LL ret=0ll;
	for(i=0;i<n;++i){
		if(a[i]==1){
			ret+=qry(i+1,i+L-1);
		}
	}
	return ret;
}
int main(){
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		a[i]=readch();
	}
	init(1);
	scanf("%d",&q);
	while(q--){
		scanf("%d",&k);
		printf("%lld\n",solve(k));
	}
	return 0;
}

Measured memory_bytes: 519808
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 10;
int n, m;
string s;
ll ans, res, now;
int cnt[N];
int main()
{
	cin >> s;
	int len = s.size();
	mem(cnt, 0);
	cnt[0] = 1;
	res = 1;
	ans = 0;
	now = 0;
	per(i, len-1, 0)
	{
		now = (now + ll(s[i] - '0') * res) % 2019;
		ans += cnt[now]++;
		res = res * 10 % 2019;
	}
	pld(ans);
	return 0;
}


Measured memory_bytes: 4656
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
ll a[110],b[110];
ll dp[100005];
const int maxn=100005;
int main()
{
	ll n,w;
	cin>>n>>w;
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
    
    memset(dp,0x3f3f3f,sizeof(dp));
    dp[0]=0;
    ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=maxn;j>=b[i];j--){
			dp[j]=min(dp[j],dp[j-b[i]]+a[i]);
		}
	}
	
	for(ll i=0;i<maxn;i++){
		if(w>=dp[i])
			ans=max(ans,i);
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 4428
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;

ll gcd(ll a, ll b){
    ll q=a/b,r=a%b;
    if(r==0){
        return b;
    }else{
        return gcd(b,r);
    }
}

ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}

int main(){
    ll N,M;
    cin >> N >> M;
    
    string S,T;
    cin >> S >> T;

    
    ll L = lcm(N,M);
    
    for(ll n; n<N; n++){
        if((n*M)%N==0){
            ll m=(n*M)/N;
            if(S[n]!=T[m]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    
    cout<< L << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] ans = new int[13];
        for(int i=1;i<=7;i++) ans[i]=1;
        for(int i=8;i<=12;i+=2) ans[i]=1;
        ans[4]=2;
        ans[6]=2;
        ans[9]=2;
        ans[11]=2;
        ans[2]=3;
        String res = "No";
        if(ans[x]==ans[y]) res = "Yes";
        System.out.println(res);
    }
}


Measured memory_bytes: 21716
<?php
 
function input($func = null) {
    if ($func === null) {
        return trim(fgets(STDIN));
    } else {
        return $func(trim(fgets(STDIN)));
    }
}
function input_array($func = null) {
    if ($func === null) {
        return explode(' ', input());
    } else {
        return array_map(function($v) use ($func) {
            return $func($v);
        }, explode(' ', input()));
    }
}

list($t, $x) = input_array('intval');

echo $t / $x . "\n";

Measured memory_bytes: 4728
#include <stdio.h>

int main(void){
    // Your code here!
    int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    int slot[15] = {};
    int level[15] = {};
    int Np = 15;
    int N;
    int count = 0;
    
    scanf("%d\n",&N);
    
    for (int i = 1; i <= N; i++)
    {
        int res = i;
        for(int j = 0; j < Np && i >= prime[j]; j++)
        {
            for(int k = res; k % prime[j] == 0; k /= prime[j])
            {
                slot[j]++;
            }
        }
    }
    
    int Nclass[6] = {};
    for(int i = 0; i < Np; i++)
    {
        if(slot[i] < 2)
            level[i] = 0;
        else if(slot[i] < 4)
            level[i] = 1;
        else if(slot[i] < 14)
            level[i] = 2;
        else if(slot[i] < 24)
            level[i] = 3;
        else if(slot[i] < 74)
            level[i] = 4;
        else
            level[i] = 5;
            
        Nclass[level[i]]++;
    }
    
    // 75*1*1
    count += Nclass[5];
    // 25*3*1
    count += (Nclass[5]+Nclass[4]) * (Nclass[5]+Nclass[4]+Nclass[3]+Nclass[2]+Nclass[1]-1);
    // 15*5*1
    count += (Nclass[5]+Nclass[4]+Nclass[3]) * (Nclass[5]+Nclass[4]+Nclass[3]+Nclass[2]-1);
    // 5*5*3
    count += (Nclass[5]+Nclass[4]+Nclass[3]+Nclass[2])*(Nclass[5]+Nclass[4]+Nclass[3]+Nclass[2]-1)/2 * (Nclass[5]+Nclass[4]+Nclass[3]+Nclass[2]+Nclass[1]-2);
    /*
    for(int i=0; i < Np; i++)
        printf("%d, ", slot[i]);
    printf("\n");
    for(int i=0; i < Np; i++)
        printf("%d, ", level[i]);
    printf("\n");
    for(int i=5; i >= 0; i--)
        printf("%d, ", Nclass[i]);
    printf("\n");
    */
    printf("%d\n",count);
}


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

int main() {
  int N,Ans=0;
  cin>>N;
  vector<int> L(N);
  
  rep(i,N){cin >> L.at(i);}
  sort(L.begin(), L.end());
  for (int i = 0; i < N-2; i++){
    for (int j = i+1; j < N-1; j++){
      for (int k = j+1; k < N; k++){if(L.at(k)<L.at(i)+L.at(j)&&(L.at(k)-L.at(j))*(L.at(i)-L.at(j))!=0){Ans++;}
                                   }
                                   }
  }
  cout<<Ans<<endl;
}  

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	ll a, b, c, k;
	cin>>a>>b>>c>>k;
	if(k<=a+b)
		cout<<min(k, a)<<endl;
	else
		cout<<a-(k-(a+b))<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3588
A, B, C, D = list(map(int, input().split()))

# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
# 最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

a1 = A // C if (A // C) * C >= A else A // C + 1
a2 = (B // C + 1) if (B // C + 1) * C <= B else B // C
a = a2 - a1 + 1

b1 = A // D if (A // D) * D >= A else A // D + 1
b2 = (B // D + 1) if (B // D + 1) * D <= B else B // D
b = b2 - b1 + 1

E = lcm(C, D)
c1 = A // E if (A // E) * E >= A else A // E + 1
c2 = (B // E + 1) if (B // E + 1) * E <= B else B // E
c = c2 - c1 + 1

ans = (B - A + 1) - (a + b - c)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <float.h>
using namespace std;

#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>


const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> ii;


// Custom comparator
struct cmp {
    bool operator()(int a, int b) {
        return b < a;
    }
};


// Solution class
class Solution {
public:
    char sol(char c) {
        return c >= 'a' && c <= 'z' ? 'a' : 'A';
    }
};



// Run code
int main(int argc, char const *argv[])
{
    int n, k;
    scanf("%d%d", &n, &k);

    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &arr[i]);
    }

//    Solution* sol = new Solution();
//    cout<<sol->sol(n, k, arr);

    int res = 0;
    sort(arr.begin(), arr.end());
    for (int i = 0; i < k; i++)
        res += arr[i];

    cout<<res;
    return 0;
}


Measured memory_bytes: 3228
from itertools import combinations
N, M, X = map(int, input().split())

Books = []
for _ in range(N):
    Books.append(list(map(int, input().split())))

ans = 10**9
for i in range(1, N+1):
    for j in combinations(Books, i):
        understand = [0] * M
        cost = 0
        for book in j:
            cost += book[0]
            for p in range(M):
                understand[p] += book[p+1]
        if all(understand[p] >= X for p in range(M)):
            ans = min(ans, cost)

if ans == 10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9224
import bisect

A, B, Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for i in range(Q):
    x = int(input())
    b = bisect.bisect_right(s, x)
    d = bisect.bisect_right(t, x)
    ans = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            ans1 = abs(S-x) + abs(S-T)
            ans2 = abs(T-x) + abs(T-S)
            ans = min(ans, ans1, ans2)
    print(ans)

Measured memory_bytes: 17632
N = int(input())
A = []
x = []
y = []

for i in range(N):
    num = int(input())
    A.append(num)

    tmp_x = []
    tmp_y = []
    for j in range(num):
        input1, input2 = [int(k) for k in input().split()]
        tmp_x.append(input1)
        tmp_y.append(input2)

    x.append(tmp_x)
    y.append(tmp_y)

ans_list = []
# 2^N通りのパターンを試す
# iを2進数で表示した際に、
# N桁目（0始まり）の数字（0/1）は、人Nが正直者か不親切な人かを示す
for i in range(2 ** N):

# honestは正直者のリスト
    honest = []
    for j in range(N):
        if ((i >> j) & 1):
            honest.append(j)

# 正直者の証言に矛盾がないかをチェック
    flag = 1
    for j in honest:
        for k, l in zip(x[j], y[j]):
            if l == 1:
                if ((i >> (k-1)) & 1):
                    pass
                else:
                    flag = 0
            else:
                if not ((i >> (k-1)) & 1):
                    pass
                else:
                    flag = 0

    if flag == 1:
        ans_list.append(len(honest))

print(max(ans_list))

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  k = min(k, 100);
  for (int i = 0; i < k; i++) {
    vector<int> b(n + 1);
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      b[l]++;
      b[r + 1]--;
    }
    for (int j = 0; j < n; j++) {
      b[j + 1] += b[j];
      a[j] = b[j];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 4960
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
	int q,h,s,d;
	cin >> q >> h >> s >> d;
	int smin = min({q*4,h*2,s});
	int dmin = min(d,smin*2);
	int n;
	cin >> n;
	if(n%2 == 1){
		n /= 2;
		cout << dmin * n + smin << endl;
	}
	else{
		n /= 2;
		cout << dmin * n << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int n, ans=0;
    cin >> n;
    vector<int> h(n);
    rep(i,n)cin >> h.at(i);
    REP(i, *max_element(all(h))){
        if(h.at(0) >= i)ans++;
        REP(j, n-1) if(h.at(j-1) < i && h.at(j) >= i) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool is_hamming(int n) {
    while (true) {
        if (n % 5 != 0) break;
        n /= 5;
    }
    while (true) {
        if (n % 3 != 0) break;
        n /= 3;
    }
    while (true) {
        if (n % 2 != 0) break;
        n /= 2;
    }
    if (n == 1) return true;
    else return false;
}

int main() {
    int a, b;
    while (cin >> a) {
        if (a == 0) break;
        cin >> b;
        int count = 0;
        for (int i = a; i <= b; i++) {
            if (is_hamming(i)) count++;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 868
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a, b;
  cin >> a >> b;
  if (a <= 8 and b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,k,d[10];
signed main(){
	cin>>n>>k;
	rep(i,k)cin>>d[i];
	for(int i=n;;i++){
		string s=to_string(i);
		bool flag=false;
		rep(j,s.size()){
			rep(l,k){
				if(s[j]-'0'==d[l])flag=true;
			}
		}
		if(!flag){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int M = 1e5;
int N, V[maxn*5], W[maxn*5], Q, K;
LL D[600][maxn];
int main()
{
    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
        scanf("%d %d", &V[i], &W[i]);
    K = sqrt(N);
    for(int i = 1; i <= K; i++)
    {
        for(int j = 1; j <= M; j++)
        {
            D[i][j] = D[i>>1][j];
            if(j >= W[i])
                D[i][j] = max(D[i][j], D[i>>1][j-W[i]] + V[i]);
        }
    }
    scanf("%d", &Q);
    while(Q--)
    {
        int v, L;
        scanf("%d %d", &v, &L);
        vector<int> a;
        while(v > K)
        {
            a.push_back(v);
            v >>= 1;
        }
        LL ans = 0;
        for(int i = 0; i < (1 << a.size()); i++)
        {
            LL sum_V = 0, sum_W = 0;
            for(int j = 0; j < a.size(); j++)
            {
                if((i >> j) & 1)
                {
                    sum_V += V[a[j]];
                    sum_W += W[a[j]];
                }
            }
            if(sum_W <= L)
                ans = max(ans, D[v][L-sum_W] + sum_V);
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 405088
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N, M;
	cin >> N >> M;
	vvi town(N + 1);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		town[a].push_back(b);
		town[b].push_back(a);
	}

	for (int i = 1; i <= N; i++)
		cout << town[i].size() << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#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 N, L;
  cin >> N >> L;
  int max = 0;
  int m = L;
  for(int i = 0; i < N; i++){
    max += L + i;
    if(m * m > (L + i) * (L + i)) m = L + i;
  }
  cout << max - m << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    if(A == 1) A += 13;
    if(B == 1) B += 13;
    if(A < B) {
        cout << "Bob" << endl;
    } else if(A == B) {
        cout << "Draw" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	
	int soma = 0;
	
	char n[] = {"123456789"};
	
	while(true){
		char x[1000] = {0};
		scanf("%s", &x);
		
		if(x[0] == '0')
			return 0;
		
		soma = 0;
		
		for(int i = 0; i < 1000; i++){
		switch (x[i]){
			case '1':
				soma += 1;
				break;
			case '2':
				soma += 2;
				break;
			case '3':
				soma += 3;
				break;
			case '4':
				soma += 4;
				break;
			case '5':
				soma += 5;
				break;
			case '6':
				soma += 6;
				break;
			case '7':
				soma += 7;
				break;
			case '8':
				soma += 8;
				break;
			case '9':
				soma += 9;
				break;
		}
	}
		printf("%d\n",soma);
	}
  	return 0;
}

Measured memory_bytes: 964
import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            lv = links[v]
            for c in lv:
                for u in lv[c]:
                    if (u, c) in visited:
                        continue
                    q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) in visited:
                    continue
                q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))


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

int main(){
string S;
cin >> S ;
 
vector<string>data={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int answer;
for(int i=0;i<data.size();i++){
    if(S==data.at(i)){
     answer=7-i;
    }
}

  cout << answer << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
s = input()
c_dic = defaultdict(list)
for idx,i in   enumerate(s):
    c_dic[i].append(idx)
ans = len(c_dic['R'])*len(c_dic['G'])*len(c_dic['B'])
for i in range(0,n-1):
    for j in range(i+1,n):
        k = 2*j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9516
s = gets.chomp
t = gets.chomp

(s.size-t.size).downto(0) do |i|
    if /#{s[i, t.size].gsub('?','.')}/ === t
        s[i, t.size] = t
        puts s.gsub('?','a')
        exit
    end
end

puts "UNRESTORABLE"


Measured memory_bytes: 1788
import java.lang.Math

fun main(args: Array<String>)
{
    val s = readLine()!!.toCharArray()

    var cnt = 0
    for (i in 0..(s.size/2-1)) {
        val right = s.size - 1 - i
        if (s[i] != s[right]) cnt++
    }

    println(cnt)
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

string S;
ll N, K;

struct kukan {
    bool is_sakadachi;
    ll renzoku;
};

vector<kukan> kukans;
vector<ll> ruiseki;
vector<int> not_sakadachis_idxs;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> K >> S;

    char cur = '0';
    ll cnt = 0;
    REP(i, N) {
        if (i && cur != S[i]) {
            kukans.pb(kukan{cur == '1', cnt});
            cur = S[i];
            cnt = 0;
        } else if ( i == 0 ) {
            cur = S[i];
        }
        cnt++;
    }
    kukans.pb(kukan{cur == '1', cnt});

    ruiseki.resize(kukans.size()+1);
    REP(i, kukans.size()) {
        ruiseki[i+1] = ruiseki[i] + kukans[i].renzoku;
    }
    REP(i, kukans.size()) {
        if (!kukans[i].is_sakadachi) not_sakadachis_idxs.pb(i);
    }

    if (not_sakadachis_idxs.size() <= K) {
        cout << N << endl;
        return 0;
    }

    ll ans = 0;
    REP(st, not_sakadachis_idxs.size()-K+1) {
        ll ed = st + K - 1;
        ll tans = ruiseki[not_sakadachis_idxs[ed]+1] - ruiseki[not_sakadachis_idxs[st]];
        if (not_sakadachis_idxs[ed]+1 < kukans.size() && kukans[not_sakadachis_idxs[ed]+1].is_sakadachi) {
            tans += kukans[not_sakadachis_idxs[ed]+1].renzoku;
        }
        if (not_sakadachis_idxs[st]-1 >= 0 && kukans[not_sakadachis_idxs[st]-1].is_sakadachi) {
            tans += kukans[not_sakadachis_idxs[st] - 1].renzoku;
        }
        ans = max(tans, ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, a, b, c;
	vector<char>l;
	while (true){
		cin >> n;
		if (n == 0){
			break;
		}
		else{
			for (int i = 0; i < n; i++){
				cin >> a >> b >> c;
				if (a == 100 || b == 100 || c == 100){
					l.push_back('A');
				}
				else if (a + b >= 180){
					l.push_back('A');
				}
				else if (a + b + c >= 240){
					l.push_back('A');
				}
				else if (a + b + c >= 210){
					l.push_back('B');
				}
				else if (a + b + c >= 150 && a >= 80){
					l.push_back('B');
				}
				else if (a + b + c >= 150 && b >= 80){
					l.push_back('B');
				}
				else l.push_back('C');
				a = 0;
				b = 0;
				c = 0;
			}
		}
	}
	for (int i = 0; i != l.size(); i++)
	{
		cout << l[i] << endl;
	}
}

Measured memory_bytes: 3096
n,x,y=map(int,input().split())
d=[0]*(n-1)
 
for i in range(n-1):
	for j in range(i+1,n):
		d[min(j-i-1,abs(x-1-i)+abs(y-1-j))]+=1
		
for i in range(n-1):
	print(d[i])

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

int main() {
	string s; cin >> s;
	int gx, gy; cin >> gx >> gy;

	int xx, mode = 0, count = 0, tokubetu = 1;
	vector<int> idox, idoy;
	for (int i = 0; i <= s.size(); i++) {
		if (s[i] == 'T' || i == s.size()) {
			if (tokubetu) xx = count, tokubetu = 0;
			else if (mode == 0) idox.push_back(count);
			else idoy.push_back(count);
			mode ^= 1;
			count = 0;
		}
		else {
			count++;
		}
	}

	set<int> cangox = { 0 }, cangoy = { 0 };
	for (auto sa : idox) {
		set<int> res(cangox);
		cangox.clear();
		for (auto x : res) {
			cangox.insert(x + sa);
			cangox.insert(x - sa);
		}
	}

	for (auto sa : idoy) {
		set<int> res(cangoy);
		cangoy.clear();
		for (auto y : res) {
			cangoy.insert(y + sa);
			cangoy.insert(y - sa);
		}
	}

	if (cangox.count(gx - xx) && cangoy.count(gy)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

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


int main()
{
int H,W,h,w;
  cin>>H>>W>>h>>w;
  cout <<H*W-h*W-w*H+h*w<<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  cout<<(1000-n%1000)%1000<<endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	for (int i=0;i<sz(s);i++){
		if (s[i]!=t[i])  ans++;
	} 
	cout<<ans;
	re 0;
}


Measured memory_bytes: 3848
#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 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>
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 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);


const int MAX = 300000;
int a[MAX], dp[MAX][5];
signed main(){
  int L;
  cin >> L;
  for(int i = 1;i <= L;i++)cin >> a[i];
  rrep(i,L){
    int x[] = {a[i], max(2-a[i], a[i]%2), a[i]%2==0, max(2-a[i], a[i]%2), a[i]};
    x[0] = dp[i-1][0]+a[i];
    for(int j = 1;j < 5;j++)x[j] = min(x[j-1], dp[i-1][j]+x[j]);
    for(int j = 0;j < 5;j++)dp[i][j] = x[j];
  }
  cout << dp[L][4] << endl;
  return 0;
}








Measured memory_bytes: 11520
#include<stdio.h>
int main(void){
int a,b,i,j,k,l;

while(scanf("%d",&a)!= EOF){
    b=0;
for(i=0;i<10;i++){
    for(j=0;j<10;j++){
        for(k=0;k<10;k++){
            for(l=0;l<10;l++){
                if(i+j+k+l==a){
                    b++;
                }
            }
        }
    }
}
printf("%d\n",b);
}

return 0;
}

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    
    ll N;

    cin >> N;

    ll sum = 0;
    for(ll i = 1;i <= N; i++){
        if(i%3==0 || i%5 == 0){
            continue;
        }
        sum += i;
    }

     cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3636