akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int P, Q, R;

    cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, R + P)) << endl;

    return 0;
}


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

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

def f(n):
    a = set()
    
    for i in range(1, n + 1):
        if n % i == 0:
            a.add(n // i)
            a.add(i)
            
    return len(a)
    
print(len([v for v in range(1, N + 1) if v % 2 == 1 and f(v) == 8]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}


signed main(){
    cout << fixed << setprecision(10);
    intl q;
    cin >> q;
    intl l[q],r[q];
    rep(i,q)cin >> l[i] >> r[i];
    intl x[100001];
    bool y[100001];
    x[0] = 0;
    x[1] = 0;
    m0(x);
    m1(y);
    repi(i,2,100001){
        bool f = true;
        for(intl j = 2; j * j <= i; j++){
            if(!(i % j)){
                y[i] = false;
                f = false;
                break;
            }
        }
        x[i] = x[i - 1];
        if(f)if(i % 2)if(y[(i + 1) / 2])x[i]++;
    }
    /*rep(i,15){
        cout << i << ":" << x[i] << endl;
    }*/
    rep(i,q){
        cout << (x[r[i]] - x[l[i] - 1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //
        Scanner sc = new Scanner(System.in);
        //int n = sc.nextInt();
        long h = sc.nextLong();
        long w = sc.nextLong();

        if (h==1 || w == 1) System.out.println(1);
        else if (h*w%2 == 0) System.out.println(h*w/2);
        else System.out.println(h*w/2+1);
        sc.close();
    }
}

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

ll gcd(ll a, ll b) {
    if (a < b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    
    ll r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main(void){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << B-A+1 - (B/C-(A-1)/C + B/D-(A-1)/D -(B/lcm(C, D)-(A-1)/lcm(C, D))) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]

toN = list(filter(lambda x: N in x, AB))
toN = set([flatten for inner in toN for flatten in inner])
frm_first = list(filter(lambda x: 1 in x, AB))
frm_first = set([flatten for inner in frm_first for flatten in inner])

if toN & frm_first:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 61816
a,b,c,d = map(lambda x: int(x), list(input()))

def get_str(i):
    if i >= 0:
        s = "+{}".format(i)
    else:
        s = "{}".format(i)
    return s

for i in range(1 << 3):
    ai, bi, ci, di = a, b, c, d
    if (i >> 2) % 2:
        bi = -b
    if (i >> 1) % 2:
        ci = -c
    if (i >> 0) % 2:
        di = -d

    if ai+bi+ci+di == 7:
        s = ""
        s += get_str(ai)
        s += get_str(bi)
        s += get_str(ci)
        s += get_str(di)
        s += "=7"
        print(s[1::])
        break

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N;
int X[200010];
int A[200010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> X[i], A[i] = X[i];

    sort(RNG(A, 0, N));

    rep(i, 0, N)
        if(X[i] <= (A[N/2]+A[N/2-1])/2) cout << A[N/2] << endl;
        else cout << A[N/2-1] << endl;

    return 0;
}

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

using namespace std;

unsigned int a[101];

int main()
{
	unsigned int n, ans = 0;

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

	for (unsigned int i = 0; i < n; ++i) {
		ans += a[i];
		unsigned int min = a[i];
        // cerr << a[i] << ": ";
		for (unsigned j = i; j < n; ++j) {
			if (min > a[j]) {
                min = a[j];
				a[j] = 0;

			} else {
				a[j] -= min;
			}
          // cerr << a[j] << " ";
		}
         // cerr << endl;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    int X,Y;
    cin>>X>>Y;
    rep(i,100){
        rep(j,100){
            if(i+j==X && 2*i+4*j==Y){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout << fixed; cout << setprecision(x); cout << y;
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
// int dx2[] = { -1 , -1 , -1, 0 , 0 , 1 , 1 , 1};
// int dy2[] = { -1 , 0 , 1 , -1, 1 , -1, 0, 1};
int dx2[8] = {2, 2, -2, -2, 1, 1, -1, -1};
int dy2[8] = { -1, 1, 1, -1, 2, -2, 2, -2};

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
int32_t main()
{
	g_b();
	int p = 1;
	int ans = 0;
	mk(a, n);
	int sum = accumulate(a.begin(), a.end(), 0LL);

	for (int i = 0; i  < n - 1; i++)
	{
		sum = sum - a[i];
		ans += (sum % mod * a[i] % mod) % mod;
	}
	cout << ans % mod ;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

ll popcount(ll x) {
    ll res = 0;
    while (x > 0) {
        res += x%2;
        x /= 2;
    }
    return res;
}

vl exe_counts;
void init(ll N=200020) {
    exe_counts.assign(N,0);
    rng(i,1,N+1) {
        ll p = popcount(i);
        exe_counts[i] = 1 + exe_counts[i%p];
    }
}

int main() {
    ll n; cin >> n;
    string x; cin >> x;
    reverse(all(x));
    init();

    ll p = 0;
    rep(i,n) if (x[i] == '1') p++;

    vl xm(n), xp(n);
    ll bm = 1, bp = 1;
    rep(i,n) {
        if (p > 1) {
            xm[i] = bm;
            bm = (bm*2) % (p-1);
        }
        xp[i] = bp;
        bp = (bp*2) % (p+1);
    }

    ll ansm = 0, ansp = 0;
    rep(i,n) {
        if (x[i] == '1') {
            ansm += xm[i];
            ansp += xp[i];
        }
    }
    vl ans(n);
    rep(i,n) {
        if (x[i] == '0') {
            ll idx = (ansp + xp[i]) % (p + 1);
            if (idx < 0) idx += p + 1;
            ans[n-i-1] = 1 + exe_counts[idx];
        } else {
            if (p <= 1) {
                ans[n-i-1] = 0;
                continue;
            }
            ll idx = (ansm - xm[i]) % (p - 1);
            if (idx < 0) idx += p - 1;
            else ans[n-i-1] = 1 + exe_counts[idx];
        }
    }
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9712
void main(){
	string s = readln().chomp();
	int ans;	
	foreach(elm; s){
		ans += (elm=='+')?1:-1;
	}
	ans.writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2580
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    A = tuple(map(int, f_i.readline().split()))
    """
    def fact2(num):
        cnt = 0
        while num % 2 == 0:
            num //= 2
            cnt += 1
    
    f = fact2(A[0])
    for a in A[1:]:
        if f != fact2(a):
            return 0
    """
    from fractions import gcd
    def lcm(a, b):
        return a * b // gcd(a, b)
    
    import functools
    def mul_lcm(nums):
        return functools.reduce(lcm, nums)
    
    half_A = tuple((a // 2 for a in A))
    l = mul_lcm(half_A)
    
    for a in half_A:
        if (l // a) % 2 == 0:
            return 0
    
    return (M // l + 1) // 2

print(solve())

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  ll n, k, l, r, a[45];
  cin >> n >> k >> l >> r;
  REP(i, n) cin >> a[i];
  ll n2 = n / 2;
  VVL ps1(n2 + 1), ps2(n - n2 + 1);

  REP(i, 1 << n2) {
    ll vl = 0, cnt = 0;
    REP(j, n2) if (i >> j & 1) {vl += a[j]; ++cnt;}
    ps1[cnt].push_back(vl);
  }
  REP(i, 1 << (n - n2)) {
    ll vl = 0, cnt = 0;
    REP(j, n - n2) if (i >> j & 1) {vl += a[n2 + j]; ++cnt;}
    ps2[cnt].push_back(vl);
  }
  REP(i, n2) sort(ALL(ps1[i]));
  
  ll ret = 0;
  FOR(i, max((ll)0, k - n2), min(k, n - n2) + 1) {
    REP(j, ps2[i].size()) {
      ret += (ll)(upper_bound(ALL(ps1[k - i]), r - ps2[i][j]) -
                  lower_bound(ALL(ps1[k - i]), l - ps2[i][j]));
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 23376
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;

int main(){
  int ac=0,wa=0,tle=0,re=0;
  int n;
  string temp;
  cin >> n;

  REP(i,n){
    cin >> temp;
    if(temp=="AC")ac++;
    else if(temp=="WA")wa++;
    else if(temp=="TLE")tle++;
    else if(temp=="RE")re++;
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

int main(){
	int a;
  	cin >> a;
  	
  	if(a >= 64){
      cout << 64 << endl;
    }
 	else if(a >= 32){
      cout << 32 << endl;
    }
  	else if(a >= 16){
      cout << 16 << endl;
    } 
  	else if(a >= 8){
      cout << 8 << endl;
    }
  	else if(a >= 4){
      cout << 4 << endl;
    }
  	else if(a >= 2){
		cout << 2 << endl;
    } 
  	else{
	cout << 1 << endl;
    }
}
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXV = 1e5+2;
int N, W, dp[MAXV];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N >> W;
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for(int i = 1, w, v;i<=N;i++){
		cin >> w >> v;
		for(int j = MAXV-1;j>=v;j--){
			dp[j] = min(dp[j], dp[j-v]+w);
		}
	}
	for(int i = MAXV-1;i>=0;i--){
		if(dp[i]<=W){cout << i << '\n'; return 0;}
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  int c_cnt = 2;
  if (S[0] != S[1] && S[0] != S[2] && S[1] != S[2]) c_cnt = 3;
  if (S[0] != S[2] && S[0] != S[3] && S[2] != S[3]) c_cnt = 3;
  if (S[1] != S[2] && S[1] != S[3] && S[2] != S[3]) c_cnt = 3;
  
  if (c_cnt != 2) {
    cout << "No" << endl;
    return 0;
  }
  
  for (int i = 0; i < 4; i++) {
    int cnt = 0;
    for (int j = 0; j < 4; j++) {
      if(S[i] == S[j]) {
        cnt++;
      }
    }
    if (cnt != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
ll int x[100001]={'\0'};
ll int y[100001]={'\0'};
ll int z[100001]={'\0'};
int n;
int solve(int arr[100001][3],int n,int j)
{
	if(n==0)
	{
		if(j==1)
		{
			return max(arr[0][2],arr[0][0]);
		}
		else if(j==2)
		{
			return max(arr[0][1],arr[0][0]);
		}
		return max(arr[0][2],arr[0][1]);
	}
	else if(j==0)
	{
		if(y[n]!=0&&z[n]!=0)
		{
			return max(arr[n][1]+y[n],arr[n][2]+z[n]);
		}
		else
		{
			if(y[n]==0)
			y[n]=solve(arr,n-1,1);
			if(z[n]==0)
			z[n]=solve(arr,n-1,2);
			return max(arr[n][1]+y[n],arr[n][2]+z[n]);
		}
	}
	else if (j==1)
	{
		if(x[n]!=0&&z[n]!=0)
		{
			return max(arr[n][0]+x[n],arr[n][2]+z[n]);
		}
		else
		{
			if(x[n]==0)
			x[n]=solve(arr,n-1,0);
			if(z[n]==0)
			z[n]=solve(arr,n-1,2);
			return max(arr[n][0]+x[n],arr[n][2]+z[n]);
		}
	}
	else 
	{
			if(x[n]!=0&&y[n]!=0)
			{
			return max(arr[n][0]+x[n],arr[n][1]+y[n]);
			}
		else
		{
			if(x[n]==0)
			x[n]=solve(arr,n-1,0);
			if(y[n]==0)
			y[n]=solve(arr,n-1,1);
			return max(arr[n][0]+x[n],arr[n][1]+y[n]);
		}
	}
	
}
int main()
{
	cin>>n;
	if(n>1){
	int arr[100001][3];
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	ll a = arr[n-1][0]+solve(arr,n-2,0);
	ll b = arr[n-1][1]+solve(arr,n-2,1);
	ll c = arr[n-1][2]+solve(arr,n-2,2);
	cout<<max(max(a,b),c)<<"\n";	
	}
	else
	{
		ll a , b , c ;
		cin>>a>>b>>c;
		cout<<max(max(a,b),c)<<"\n";
	}
}

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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    while((st=sc.readLine())!=null){
		String[] sp = st.split(" ");
		System.out.println(Integer.valueOf(sp[0])+Integer.valueOf(sp[1]));
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 16996
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool result= true;

    for(int i=0;i<s.size();i++)
    {
        if(i%2==0 and s[i]=='L')
            result=false;

        if(i%2==1 and s[i]=='R')
            result=false;
    }

    if(result)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    exit(0);
}


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

int main() {
    int number = 0;
    cin >> number;
    long prepre = 2L;
    long pre = 1L;
    long result = 0;
    if (number == 0) {
        result = prepre;
    }
    else if (number == 1) {
        result = pre;
    }
    else {
        for (int i = 2; i <= number; i++) {
            result = prepre + pre;
            if (i % 2 == 0) {
                prepre = result;
            } else {
                pre = result;
            }
        }
    }
    
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N,K = map(int,input().split())
A = sorted(Counter(map(int, input().split())).items(), key=lambda x:x[1], reverse=False)
s = len(A) - K
c = 0
if s > 0:
    for i in range(s):
        c += A[i][1]
print(c)


Measured memory_bytes: 41504
#include<iostream>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  int i,n,t;
  cin >> n;
  multiset<int, std::greater<int>>a;
  for(i=0;i<n;i++){
    int t;
    cin>>t;
    a.insert(t);
  }
  int ans=0;
  while(!a.empty()){
    int x=*a.begin();
    a.erase(a.begin());
    int y=pow(2,(int)log2(x)+1)-x;
    auto it=a.find(y);
    if(it!=a.end()){
      a.erase(it);
      ans+=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std; int main(){int n,m,d[11][10010],r,t,a;while(cin>>n>>m&&n&&m){rep(i,n)rep(j,m)cin>>d[i][j];r=0;rep(i,1<<n){t=0;rep(j,m){a=0;rep(k,n)a+=(d[k][j]+!!(i&(1<<k)))%2;t+=max(a,n-a);}r=max(r,t);}cout<<r<<endl;}}

Measured memory_bytes: 1556
function Main(input) {
  var x = input;
  if(x == 2){
  	x = 2;
  } else if(x >= 2 && x < 4) {
 	x = 2 
  } else if(x >= 4 && x < 8) {
 	x = 4 
  } else if(x >= 8 && x < 16) {
 	x = 8 
  } else if(x >= 16 && x < 32) {
 	x = 16 
  } else if(x >= 32 && x < 64) {
 	x = 32 
  } else if(x >= 64  && x < 128) {
 	x = 64 
  }
  
  console.log(x);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555;
const double PI = acos(-1.0);
int prime[N], res[N];
void sieve()
{
	int N = 1e5 + 1;
	prime[0] = prime[1] = 1;
	for(int i = 2; i <= N; ++i){
		if(!prime[i]){
			for(int j = i + i; j <= N; j += i){
				prime[j] = 1;
			}
		}
	}
	for(int i = 2; i <= N; ++i){
		if(!prime[i] && !prime[(i + 1) / 2]){
			res[i] = 1;
		}
	}
	for(int i = 1; i <= N; ++i){
		res[i] += res[i - 1];
	}
}
void solve()
{
	int n;
	cin >> n;
	sieve();
	while(n--){
		int l, r;
		cin >> l >> r;
		cout << res[r] - res[l - 1] << endl;
	}

}
 
int main()
{
    Red;
    solve();
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	bool key1=false,key2=false;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')key1=true;
		if(s[i]=='B')key2=true;
	}
	if(key1&&key2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF)
  {
    bool good[n]; memset(good, false, sizeof(good));
    int h[n]; for (int i = 0; i < n; i++) scanf("%d", &h[i]);
    vector<int> graph[n];
    for (int i = 0; i < m; i++)
    {
      int u, v; scanf("%d %d", &u, &v); u--, v--;
      graph[u].push_back(v), graph[v].push_back(u);
    }

    for (int i = 0; i < n; i++)
    {
      good[i] = true;
      for (int j: graph[i])
        if (h[j] >= h[i])
          good[i] = false;
    }

    int ans = 0; for (int i = 0; i < n; i++) ans += good[i];
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 9392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

int main(void){
	int n,k; cin >> n >> k;
	int ans = n;
	vector<bool> sunuke(n, false);
	int d,a;
	Rep(k){
		cin >> d;
		Rep(d){
			cin >> a;
			if(!sunuke[--a]){
				sunuke[a] = true;
				ans--;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

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

    int ans1 = 0;
    for(int i = 1; i <= n; i++){
        ans1 += a[i] / 2;
        a[i] %= 2;
        if(i < n && a[i] > 0 && a[i+1] > 0){
            ans1++;
            a[i]--;
            a[i+1]--;
        }
    }

    int ans2 = 0;
    for(int i = n; i >= 1; i--){
        ans2 += a[i] / 2;
        a[i] %= 2;
        if(i > 1 && a[i] > 0 && a[i-1] > 0){
            ans2++;
            a[i]--;
            a[i-1]--;
        }
    }
    cout << max(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 1792
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;

constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

LL n, k, a, b;
int main() {
	cin >> n >> k;
	vector<pair<LL,LL>>v;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		v.emplace_back(mp(a, b));
	}
	sort(ALL(v));
	LL count = 0;
	for (int i = 0; i < v.size(); i++) {
		count += v[i].second;
		if (count >= k) {
			cout << v[i].first << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
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 fi first
#define se second
#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;
    cin >> n;
    Vi c(n+1),d(n+1);
    Vi a(n),b(n);
    rp(i,n) cin >> a[i];
    rp(i,n) cin >> b[i];
    Vi af(n+1,0),bf(n+1,0);
    rp(i,n){
        af[a[i]]++;
        bf[b[i]]++;
        //print("a");
    }
    rp(i,n+1){
        if(af[i]+bf[i]>n){
            print("No");
            return;
        }
    }
    rp(i,n+1){
        c[i]=upper_bound(all(a),i)-a.begin();
        d[i]=upper_bound(all(b),i)-b.begin();
    }
    ll m=-1000000;
    // for(auto cc:c){
    //     princ(cc);
    // }
    // print("");
    // for(auto dd:d){
    //     princ(dd);
    // }
    // print("");
    repi(i,1,n+1){
        chmax(m,c[i]-d[i-1]);
    }
    if(m==n) m=0;
    print("Yes");
    rp(i,n){
        princ(b[(i-m)<0?(i-m)%n+n:(i-m)%n]);
    }
    cout << endl;
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 12656
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define PII pair<int ,int>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	while (n--) {
		string x; cin >> x;
		cout << x << endl << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	char op;
	while(1) {
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		if(op == '+') printf("%d\n",a+b);
		else if(op == '-') printf("%d\n",a-b);
		else if(op == '*') printf("%d\n",a*b);
		else if(op == '/') printf("%d\n",a/b);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string a, b;
	cin >> a >> b;
	int s1 = a.size(), s2 = b.size();
	if (s1 > s2) {
		cout << "GREATER";
		return 0;
	}
	else if (s1 < s2) {
		cout << "LESS";
		return 0;
	}
	else if (a > b) {
		cout << "GREATER";
		return 0;
	}
	else if (a < b) {
		cout << "LESS";
		return 0;
	}
	else {
		cout << "EQUAL";
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=sorted([input().split()+[i] for i in range(n)])+[['',0,0]]

b_n=l[0][0]
t_list=[]

for name, p, inx in l:
 if name!=b_n:
  t_list.sort(reverse=True)
  for i,j in t_list:
   print(j+1)
  t_list=[]
  b_n=name

 t_list.append([int(p),inx])

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a,b,c,d,e;
	int ans = 0;
	int A[100], B[100], C[100][100];
	cin >> a>> b>> c;
	for(int i = 0; i < a; i++){
		cin >> A[i];
		for(int j = 1; j <= b; j+= A[i]){
			ans++;
		}
	}
	cout << ans + c << endl;

	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll x;cin >>x;
    vector<bool>ch(x+1,false);
    ch[1]=true;
    for (int i = 2; i <=x; ++i) {
        ll c=i;
        ll now=i;
        now*=c;
        while(now<=x){
            ch[now]=true;
            now*=c;
        }
    }
    for (int i = 0; i < x + 1; ++i) {
        if(ch[x-i]){
            cout <<x-i<<endl;
            return 0;
        }
    }
    return 0;
}

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

typedef complex<int> point;
typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define lasB(b) (b&(-b))
#define pld pair<ld,ld>
#define mod 1000000007
#define PI acos(-1.0)
#define PB push_back
#define N   1000006
#define EPS (1e-8)
#define ss substr
#define S second
#define IM image
#define F first
#define RE real
#define B begin
#define E end

int n,m,sol=1;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i*i<=m;i++)
    {
        if(m%i==0)
        {
            if(m/i>=n)
            {
                sol=max(sol,i);
            }
            if(m/(m/i)>=n)
            {
                sol=max(sol,m/i);
            }
        }
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> p2;

void init() {
    int n = 1000001;
    int i = 1;
    while (i < n) {
        i*=2;
        p2.push_back(i);
    }
}

int main() {
    init();
    int n, i;
    scanf("%d", &n);
    i = int(upper_bound(p2.begin(), p2.end(), n) - p2.begin() -1);
    printf("%d\n", p2[i]);
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 2e5+10;

ll N, D, A;
vii XH;
int first_effect_bomb[MAX];

ll solve() {
    sort(ALL(XH));
    ll ans = 0;
    first_effect_bomb[0] = 0;
    int bomb_idx = 0;
    int farthest_idx = 0;
    REP (i, N) {
        ll x = XH[i].first + 2*D;
        while (farthest_idx < N && XH[farthest_idx+1].first <= x) {
            farthest_idx++;
            first_effect_bomb[farthest_idx] = bomb_idx;
        }
        XH[i].second -= bomb_idx - first_effect_bomb[i];
        if (XH[i].second > 0) {
            ans += XH[i].second;
            bomb_idx += XH[i].second;
        }
    }
    return ans;
}

int main() {
    cin >> N >> D >> A;
    XH = vii(N);
    REP (i, N) {
        int h;
        cin >> XH[i].first >> h;
        XH[i].second = (h + A - 1) / A;
    }
    cout << solve() << endl;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  for(int i=0; i<1300; i++){
    int c = int(floor(double(i)*0.08));
    int d = int(floor(double(i)*0.1));
    if(a==c&&b==d){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    bool denied = false;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) denied = true;
        }
    }
    cout << (denied ? "DENIED" : "APPROVED") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)
#define tot(i,n) for(int i=1;i<=n;i++)
using namespace std;
string s;
int main () {
    cin >> s ;
    int a,b,k;
    a=b=0;
  k=s.length();
   lol(i,k){
        if(s[i]=='0')a++;
        if(s[i]=='1')b++;
    }
    cout << min(a,b)*2<< endl;
}

Measured memory_bytes: 512
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const n = parseInt(content, 10);
  const nums = [];
  for (let i = 1; i <= n; i++) {
    let x = i;
    if (x % 3 == 0){
      nums.push(i);
      continue;
    }

    while(true) {
      if (x % 10 === 3){
        nums.push(i);
        break;
      }

      x = Math.floor(x / 10);
      if (x !== 0) {
        continue;
      } else {
        break;
      }
    }
  }

  console.log('', nums.join(' '))
});


Measured memory_bytes: 16900
N, M = map(int, input().split())

par = [i for i in range(N)]
rank = [0 for i in range(N)]


def get_root(A):
    if par[A] == A:
        return A
    par[A] = get_root(par[A])
    return par[A]


def connect(A, B):
    A = get_root(A)
    B = get_root(B)
    if rank[A] < rank[B]:
        par[A] = B
    else:
        par[B] = A
        if rank[A] == rank[B]:
            rank[A] += 1


def verify_connect(A, B):
    if get_root(A) == get_root(B):
        return True
    else:
        return False


for i in range(M):
    x, y, z = map(int, input().split())
    connect(x-1, y-1)
ans = 0
for i in range(N):
    if i == get_root(i):
        ans += 1

print(ans)


Measured memory_bytes: 7860
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int D, N;

int T[205], A[205], B[205], C[205];

int dp[205][205];

signed main()
{
    cin >> D >> N;

    rep(i, D) {
        cin >> T[i];
    }

    rep(i, N) {
        cin >> A[i] >> B[i] >> C[i];
    }

    for (int i = 1; i < D; ++i) {
        rep(j, N) {
            if (A[j] <= T[i] && T[i] <= B[j]) {
                rep(k, N) {
                    if (A[k] <= T[i - 1] && T[i - 1] <= B[k]) {
                        chmax(dp[i][j], dp[i - 1][k] + abs(C[j] - C[k]));
                    }
                }
            }
        }
    }

    int ma = 0;

    rep(i, N) {
        chmax(ma, dp[D - 1][i]);
    }

    cout << ma << endl;
}

Measured memory_bytes: 3176
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main()
{
  int N;
  cin >> N;
  typedef long long ll;
  vector<ll> A(N), c(N + 1);
  for (auto & a : A)
  {
    cin >> a;
    ++c[a];
  }
  vector<ll> c0(N + 1), c1(N + 1);
  for (int i = 1; i <= N; ++i)
  {
    c0[i] = c[i]*(c[i] - 1)/2;
    if (0 < c[i])
      c1[i] = (c[i] - 1)*(c[i] - 2)/2;
  }
  ll sum = accumulate(c0.begin(), c0.end(), static_cast<ll>(0));
  for (const auto & a : A)
    cout << sum - c0[a] + c1[a] << endl;
  return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    //y /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll k,s,ans=0;
    cin >> k >> s;
    rep(i,k+1){
        rep(j,k+1){
            ll l=s-i-j;
            if(l <= k && l >= 0){
                ans++;
                //cout << i << j << l <<endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,ans[100],i;
  while(cin>>n){
    if(n==-1) break;
    i=0;
    while(n>=4){
      ans[i] = n % 4;
      n /= 4;
      i++;
    }
    ans[i] = n;
    for(int j=i;j>=0;j--) cout << ans[j];
    cout << endl;
  }
  return 0;
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define PI 3.141592653589793

#define MOD 1000000007L
#define INF 100000000000

int comp(string a, string b) {
	if (a == b) {
		return 0;
	}
	int sdiff = a.size() - b.size();
	if (sdiff != 0) {
		return sdiff > 0 ? 1 : -1;
	}
	for (size_t i = 0; i < a.size(); i++) {
		int ai = a[i] - '0';
		int bi = b[i] - '0';
		if (ai != bi) {
			return ai > bi ? 1 : -1;
		}
	}
	return 0;
}

signed main() {
	string a, b;
	cin >> a >> b;
	vector<string> res ={ "LESS", "EQUAL", "GREATER" };
	cout << (res[comp(a, b) + 1]) << endl;
}


Measured memory_bytes: 256
int main() {

	int n, l, sum;

	scanf("%d%d",&n,&l);

	sum = n*(n+1)/2;

	if (l>0)
		sum -= 1;
	else if (n>= 1-l)
		sum -= 1-l;
	else
		sum -= n;

	int flav = (n-1)*l - (n-1) + sum;
	printf("%d",flav);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
using namespace std;
const int INF = 1e18;
const int MOD = 1000000007;

using Graph = vector<vector<int>>;
Graph G;
int wage[100];

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int A[n + 1], B[n];
    rep(i, n + 1) cin >> A[i];
    rep(i, n) cin >> B[i];

    int before = 0;
    rep(i, n + 1) before += A[i];

    for (int i = 0; i < n; i++)
    {
        int left = min(A[i], B[i]);
        A[i] -= left;
        B[i] -= left;
        int right = min(A[i + 1], B[i]);
        A[i + 1] -= right;
        B[i] -= right;
    }

    int after = 0;
    rep(i, n + 1) after += A[i];

    cout << before - after << endl;
}

signed main()
{
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

const int bit[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072};

void recursion(int n, int flag[], int a, int b, int ans[])
{
	if (n == 1) {
		ans[0] = a;
		ans[bit[n]-1] = b;
		return;
	}
	
	int i, j, k, l;
	for (i = a, j = b, k = 0; flag[k] != 0 || (i & 1) == (j & 1); i >>= 1, j >>= 1, k++);
	flag[k] = 1;
	for (l = 0; flag[l] != 0; l++);
	recursion(n - 1, flag, a, a ^ bit[l], ans);
	recursion(n - 1, flag, a ^ bit[l] ^ bit[k], b, &(ans[bit[n-1]]));
	flag[k] = 0;
}

int main()
{
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	
	int i, j , count = 0;
	for (i = A, j = B; i > 0 || j > 0; i >>= 1, j >>= 1) if ((i & 1) != (j & 1)) count++;
	if (count % 2 == 0) {
		printf("NO\n");
		fflush(stdout);
		return 0;
	}
	
	int ans[131072], flag[18] = {};
	recursion(N, flag, A, B, ans);
	printf("YES\n");
	for (i = 0; i < bit[N] - 1; i++) printf("%d ", ans[i]);
	printf("%d\n", ans[bit[N]-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2204
#include <bits/stdc++.h>
using namespace std;
/*
recursive
--------------------------------------------------
string LCS(char* s1,char* s2)
{
  if(s1[0]=='\0' || s2[0]=='\0') return "";
  if(s1[0] == s2[0])
  {
    return s1[0]+LCS(s1+1,s2+1);
  }
  string str1 = LCS(s1+1,s2);
  string str2 = LCS(s1,s2+1);
  return str1.size()>str2.size()?str1:str2;
}
*/
int main() {
  string s1,s2;
  cin>>s1>>s2;
  /*
  char str1[s1.size()+1],str2[s2.size()+1];
  memcpy(str1, s1.c_str(),s1.size());
  str1[s1.size()] = '\0';
  memcpy(str2,s2.c_str(),s2.size());
  str2[s2.size()] = '\0';

  cout<<LCS(str1,str2)<<endl;  
  */
  string ans = "";
  int n1=s1.size(),n2=s2.size();
  int dp[n1+1][n2+1];
  for(int i=0;i<=n1;i++)
    dp[i][n2] = 0;
  for(int i=0;i<=n2;i++)
    dp[n1][i] = 0;
  for(int i=n1-1;i>=0;i--)
  {
    for(int j =n2-1;j>=0;j--)
    {
      if(s1[i] == s2[j] )
      {
        dp[i][j] = 1+dp[i+1][j+1];
      }
      else
      {
        dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  int i=0,j=0;
  while(i<n1 && j<n2)
  {
    if(s1[i] == s2[j])
    {
      ans = ans+s1[i];
      i++;
      j++;
    }
      
    else if(dp[i][j] >dp[i][j+1] )
      i=i+1;
    else
      j=j+1;
  }
  cout<<ans<<endl;
  return 0;
}

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

bool grid[80][80][6400];
int z[80][80];

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &z[i][j]);
    int x;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &x), z[i][j] = abs(z[i][j] - x);
    grid[0][0][z[0][0]] = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (i + 1 < h){
                for (int k = 0; k < 6400; k++){
                    if (!grid[i][j][k]) continue;
                    if (k + z[i + 1][j] < 6400) grid[i + 1][j][k + z[i + 1][j]] = true;
                    if (abs(k - z[i + 1][j]) < 6400) grid[i + 1][j][abs(k - z[i + 1][j])] = true;
                }
            }
            if (j + 1 < w){
                for (int k = 0; k < 6400; k++){
                    if (!grid[i][j][k]) continue;
                    if (k + z[i][j + 1] < 6400) grid[i][j + 1][k + z[i][j + 1]] = true;
                    if (abs(k - z[i][j + 1]) < 6400) grid[i][j + 1][abs(k - z[i][j + 1])] = true;
                }
            }
        }
    }
    for (int i = 0; i < 6400; i++){
        if (grid[h - 1][w - 1][i]){
            printf("%d\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 40192