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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  set<pair<int, int>> s;
  vector<bool> ok(n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      ok[i] = true;
      cnt++;
    } else {
      s.insert(make_pair(b[i], i));
    }
  }
  constexpr int kInf = 2'000'000'000;
  int64_t ans = 0;
  while (cnt < n) {
    int x = s.rbegin()->second;
    s.erase(make_pair(b[x], x));
    int y = (x + n - 1) % n, z = (x + 1) % n;
    // cout << "y = " << y << " z = " << z << endl;
    if (b[y] + b[z] > b[x] - a[x]) {
      cout << -1 << "\n";
      return 0;
    }
    // cout << "x = " << x << " b[x] = " << b[x] << " b[y] = " << b[y] << " b[z] = " << b[z] << endl;
    int sum = b[y] + b[z];
    if (ok[y] && ok[z]) {
      if ((b[x] - a[x]) % sum != 0) {
        cout << -1 << "\n";
        return 0;
      }
      ans += (b[x] - a[x]) / sum;
      b[x] = a[x];
      ok[x] = true;
      cnt++;
    } else {
      int obj = b[x] - (max(ok[y] ? -kInf : b[y], ok[z] ? -kInf : b[z]) - 1);
      int k = (obj + sum - 1) / sum;
      // cout << "obj = " << obj << " k = " << k << endl;
      ans += k;
      b[x] -= sum * k;
      // cout << "become b[x] = " << b[x] << endl;
      if (b[x] < a[x]) {
        cout << -1 << "\n";
        return 0;
      }
      // assert(b[x] < (ok[y] ? kInf : b[y]) && b[x] < (ok[z] ? kInf : b[z]));
      if (b[x] == a[x]) {
        ok[x] = true;
        cnt++;
      } else {
        s.insert(make_pair(b[x], x));
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 13312
def check(startA, startB, S, T, a, b):
  pat1 = float("inf")
  if startA >= 0:
    pat1 = x - S[startA]
    if startB >= 0 and S[startA] > T[startB]:
      if startB != b - 1:
        pat1 += min(S[startA] - T[startB], T[startB + 1] - S[startA])
      else:
        pat1 += S[startA] - T[startB]
    elif startB == -1 and S[startA] < T[0]:
      pat1 += T[0] - S[startA]
  pat2 = float("inf")
  if startA != a - 1:
    pat2 = S[startA + 1] - x
    if startB != b - 1 and S[startA + 1] < T[startB + 1]:
      if startB != -1:
        pat2 += min(T[startB + 1] - S[startA + 1], S[startA + 1] - T[startB])
      else:
        pat2 += T[startB + 1] - S[startA + 1]
    elif startB == b - 1 and S[startA + 1] > T[b - 1]:
      pat2 +=  S[startA + 1] - T[b - 1]
  return min(pat1, pat2)
  
a, b, q = map(int, input().split())
S = [int(input()) for _ in range(a)]
T = [int(input()) for _ in range(b)]
X = [int(input()) for _ in range(q)]
import bisect
for x in X:
  startA = bisect.bisect_left(S,x) - 1
  startB = bisect.bisect_left(T,x) - 1
  
  print(min(check(startA, startB, S, T, a, b), check(startB, startA, T, S, b, a)))

Measured memory_bytes: 16156
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    auto S = readln.chomp.to!(wchar[]);
    auto T = readln.chomp.to!(wchar[]);

    auto lcm = N * M / gcd(N, M);
    auto n = lcm / N;
    auto m = lcm / M;

    long i, j;
    for (;;) {
        if (i >= N || j >= M) break;
        if (S[i] != T[j]) {
            writeln("-1");
            return;
        }
        i += m;
        j += n;
    }
    writeln(lcm);
}

Measured memory_bytes: 2684
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
INF = float("inf")
import sys

N = int(sys.stdin.readline())

if 30 <= N:
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 9144
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

ll l[51];
void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  ll ret = 0;
  sort(l, l+n);
  int d = 55;
  while(d > 0) {
    bool upd = false;
    for(int i = 0; i < n; i++) {
      ll dec = n * (1LL << d);
      if(l[i] - dec >= n) {
        upd = true;
        ret += (1LL << d);
        l[i] -= dec;
        for(int j = 0; j < n; j++) {
          if(i == j) continue;
          l[j] += (1LL << d);
        }
      }
      sort(l, l+n);
    }
    if(!upd) d--;
  }
  while(l[n-1] >= n) {
    ret++;
    l[n-1] -= n;
    for(int i = 0; i < n-1; i++) l[i]++;
    sort(l, l+n);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
s=input()
c=0
if 'keyence' in s:
  c=1
if s[:1]=='k' and s[-6:]=='eyence':
  c=1
if s[:2]=='ke' and s[-5:]=='yence':
  c=1
if s[:3]=='key' and s[-4:]=='ence':
  c=1
if s[:4]=='keye' and s[-3:]=='nce':
  c=1
if s[:5]=='keyen' and s[-2:]=='ce':
  c=1
if s[:6]=='keyenc' and s[-1:]=='e':
  c=1

print('YES' if c==1 else 'NO')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;

ll solve(ll a,ll b)
{
    ll temp = a%b;
    ll a1 = a,b1 = b;

    while(temp)
    {
        a = b;
        b = temp;

        temp = a%b;
    }
    return a1/b * b1;
}

int main()
{
    int n,i;
    ll ans;
    ll t;

    while(scanf("%d",&n) != EOF)
    {
        ans = 1;
        for(i = 0;i < n;i++)
        {
            scanf("%lld",&t);
            ans = solve(ans,t);
            //printf("ans%lld\n",ans);
        }
        printf("%lld\n",ans);
    }

    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
if n == 1:
    print("Yes")
    print(2)
    print("1 1")
    print("1 1")
    exit()

ok = False
for i in range(2, int(math.sqrt(n*2)+1)):
    if n*2 % i == 0 and n*2 // i == i+1:
        ok = True
        size = i
        break
if ok:
    ans = [[0] * size for _ in range(size+1)]
    val = 1
    for i in range(0, size+1):
        for j in range(i, size):
            ans[i][j] = val
            val += 1
    val = 1
    for i in range(0, size):
        for j in range(i, size):
            ans[1+j][i] = val
            val += 1
    print("Yes")
    print(size+1)
    for line in ans:
        print(str(size) + " " + " ".join([str(item) for item in line]))

else:
    print("No")

Measured memory_bytes: 12148
import java.util.*;

public class Main {
    static long INF = 1000000000000000L;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long tmp1 = b / c;
        long tmp2 = b / d;
        long tmp3 = b / lcm(c, d);
        
        long tmp4 = (a-1) / c;
        long tmp5 = (a-1) / d;
        long tmp6 = (a-1) / lcm(c, d);
        
        long ans = (b-a+1) - ((tmp1 + tmp2 - tmp3) - (tmp4 + tmp5 - tmp6));
        System.out.println(ans);
    }
    
    public static long lcm(long m, long n) {
        return m * (n / gcd(m, n));
    }
    
    public static long gcd(long a, long b) {
        if (b == 0) return a;
        
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 21972
// B - Shift only
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int minc = INT_MAX;
	for(int i=0; i<N; ++i){
		int a; cin>>a;
		int c = 0;
		while(a%2==0 && a){ c++; a>>=1; }
		minc = min(minc, c);
	}
	cout<< minc <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<time.h> 
#define loop(i,c,n) for(long long i=c;i<n;i++) 
#define iter(v) for(auto x : v)  // to iterate over entire vector/sets/map
using namespace std; 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii; 
typedef set<int> si; 
int max(int a,int b){if(a>b)return a;
return b;} 
//optimised school method
bool isPrime(ll a){ 
if(a<=1)return false ;
if(a<=3)return true ;
if(a%2==0 || a%3==0)return false;
for(ll i=5;i*i<=a;i=i+6){//Instead of checking till n, we can check till √n because a larger factor of n 
//must be a multiple of smaller factor that has been already checked.
if(a%i==0 || a%(i+2)==0)return false;}return true;}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);  
	cout.tie(0);
	//  to read input from local files  
	 #ifndef ONLINE_JUDGE 
	clock_t clocktime; 
	clocktime= clock(); 
	 freopen("input.txt", "r",stdin);
	 freopen("output.txt", "w",stdout);
	#endif
	// to read entire line with spaces 
	// string s;
	// getline(cin,s);
	
	// when amount of data is unknown
	// while(cin>>x){} 
	int x;    
	loop(i,0,5){cin>>x;if(x==0){cout<<i+1;break;}}
 
	
	#ifndef ONLINE_JUDGE
	clocktime = clock()-clocktime; 
	double runtime  = (((double)clocktime)/CLOCKS_PER_SEC); 
	cout<<"\n--------\nTimeUsed -- "<<runtime<<"s"; 
	#endif
	return 0;
}

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

int d, g;
int ans = 100100100;


void dfs(int i, int now, int count, vector<int> p, vector<int>& c) {
    if(i == d) {
        if(g <= now) {
            ans = min(ans, count);
        } else {
            for(int j = d-1; 0 <= j; j--) {
            if(g <= now + p.at(j) * (j+1) * 100) {
                int r = (g - now) / ((j+1) * 100);
                if(now + r * (j+1) * 100 < g) r++;
                ans = min(ans, count + r);
                }
            }
        }

        return;
    }

    int next = now;

    dfs(i + 1, next, count, p, c);

    next += p.at(i) * (i + 1) * 100 + c.at(i);
    count += p.at(i);
    p.at(i) = 0;
    dfs(i + 1, next, count, p, c);
}

int main() {
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) cin >> p.at(i) >> c.at(i);
    dfs(0, 0, 0, p, c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,k=0;
	char a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%c",&a[i]);
		if(a[i]=='Y')
		{
			k=1;
			printf("Four");
			break;
		}
	}
	if(k!=1)
	{
		printf("Three");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
//#include<Windows.h>
using namespace std;
#define ll long long int
#define LL ll
#define INF 0x3f3f3f3f
const int maxn = 1e2 + 10;
int a[maxn];
int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	LL ans = -1e9 - 10;
	int res[maxn];
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	if (m == 0) {
		puts("0"); return 0;
	}
	for (int i = 0; i <= n; i++) {//左端取出
		for (int j = 0; j <= n; j++) {//右端取出
			memset(res, 0, sizeof res);
			LL sum = -1e9 - 10;
			if (i + j > n || i + j > m) continue;//重复取值，操作次数超过m
			if (i + j == 0) continue;
			int k = m - i - j;//放回，与反复放回
			int p; int cs = 0;
			for (p = 1; p <= i; p++) {
				res[++cs] = a[p];
			}
			for (p = n; p > n - j; p--) {
				res[++cs] = a[p];
			}
			if (cs) sum = 0;
			sort(res + 1, res + 1 + cs);
			for (p = 1; p <= cs; p++) sum += res[p];
			//cout << res[1] << "    " << cs << endl;
			for (p = 1; p <= cs; p++) {
				if (k <= 0) break;
				if (res[p] <= 0 && k) {
					sum -= res[p]; k--;
				}
				if (res[p] > 0) break;
			}
			/*if (k % 2 == 1 && p <= cs && p >= 2) sum = max(sum - res[p], sum + res[p - 1]);
			else if (k % 2 == 1 && p > cs) sum += res[p - 1];
			else if (k % 2 == 1 && p == 1) sum -= res[p];*/
			ans = max(ans, sum);


			//if (sum == 4) cout << i << "    " << j << endl;
			//if (sum == -3) cout << i << "   " << j << "     " << k << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  sort(all(A));
  reverse(all(A));

  map<ll, int> m;
  rep(i, N) {
    ++m[A[i]];
  }

  ll ans = 0;
  rep(i, N) {
    if (m[A[i]] == 0) { continue; }  // already erased
    --m[A[i]];

    ll t = 1LL; // The summed value of A[i] + A[j] where j < i and A[i] + A[j] == 2 ** k.
    while (t <= A[i]) { t <<= 1; }

    if (m[t-A[i]] > 0) {
      ++ans;
      --m[t-A[i]];
    }
  }
  cout << ans << endl;
}


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

int main(){
  int a = 0;
  int b1 = 0;
  int b2 = 0;
  int b3 = 0;
  
  // input 
  cin >> a;
  
  // bit extract
  b1 = a % 10;
  b2 = ((a- b1) % 100)/10;
  b3 = a/100;
  
  
  // Output
  cout << b1 + b2 + b3 << endl;
}


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

using namespace std;

int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<bool> a(n+1, false);
	for (int i = 0; i < m; i++)
	{
		int tmp;
		cin >> tmp;
		a[tmp] = true;
	}

	int count1 = 0, count2 = 0;

	for (int i = 1; i < x; i++)
	{
		if (a[i])
		{
			count1++;
		}
	}

	for (int i = x + 1; i < n; i++)
	{
		if (a[i])
		{
			count2++;
		}
	}

	if (count1 > count2)
	{
		cout << count2 << endl;
	}
	else
	{
		cout << count1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


import sys
N = int(input())
ans = 0
if N == 1:
    print(0)
    sys.exit()
    
temp = make_divisors(N)
for i in temp:
    if i == 1:
        continue
    if N // (i-1) == N % (i-1):
        ans += i-1
        
print(ans)

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#include <iomanip>
//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;
#define MOD 1000000007
#define int long long

//long long int power(long long int a, long long int b){
//	long long int c=1;
//	while(b){
//		if(b & 1){
//		c=(c*a);
//	}
//		a=(a*a);
//		b/=2;
//		
//	}
//	return c;
//}
int fact(int n) 
{ 
   
    return (n==1 || n==0) ? 1: (n * fact(n - 1)%MOD)%MOD;  
} 
int is_prime(int a){
	int c=1;
	int w = sqrt(a);
	if(a==1)
		return 0;
	for(int i=2; i<=w; i++){
		if(a%i==0){
			c=0;
			break;
		}
	}
	return c;
}
 

#define pb push_back
#define rep(i,b) for ( int i = 0; i < b; i++)
#define rep1(i,b) for ( int i = 1; i <= b; i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pi  3.14159265358979323846
 
using namespace std;


signed main()
{
	int k;
	cin>>k;
	rep(i,k)
		cout<<"ACL";
		
}
	

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3030;
int can[maxn];
int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int wa = 100 * a, su = 0;
  auto upd = [&](int x, int y){	
    if(y * 100 > x * e) return;
  	if(100 * su * (x + y) < 100 * (wa + su) * y){
    	wa = x;
      	su = y;
    }
  };
  for(int i = 0; i <= 3000; i++) for(int j = 0; j <= 3000; j++)
    if(i * c + j * d <= f) can[i * c + j * d] = 1;
  for(int i = 0; i <= 3000; i++) for(int j = 0; j <= 3000; j++)
    if(i * a * 100 + j * b * 100 <= f){
    	int wa = i * a * 100 + j * b * 100;
		for(int k = 0; k <= 3000; k++) if(k + wa <= f && can[k]) upd(wa, k);
    }
  cout << wa+su << " " << su << endl;
  return 0;
}
    


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Map<Integer, Integer>> list = new ArrayList<>();
		for (int i = 1; i <= n; i++) {
			int a = sc.nextInt();
			Map<Integer, Integer> map = new HashMap<>();
			for (int j = 0; j < a; j++) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt();
				map.put(x, y);
			}
			list.add(map);
		}
		sc.close();

		int ans = 0;
		int end = 1 << n;
		label:
		for (int i = 0; i < end; i++) {
			int[] b = new int[n];
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					b[j] = 1;
				}
			}
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					Map<Integer, Integer> map = list.get(j);
					for (int k : map.keySet()) {
						int v = map.get(k);
						if (b[k] != v) {
							continue label;
						}
					}
				}
			}
			ans = Math.max(ans, Integer.bitCount(i));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 30148
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#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...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


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




ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

ll r,c;
ll dp[3009][3009][4];
ll v[3009][3009];
ll dfs(ll x,ll y,ll z)
{
	if(x<0||c<0||x>=r||y>=c) return 0;
	
	if(dp[x][y][z]!=-1) return dp[x][y][z];
	if(z==3) dp[x][y][z]=dfs(x+1,y,0);
	else if(v[x][y]>0) dp[x][y][z]=max(dfs(x,y+1,z),v[x][y]+max(dfs(x,y+1,z+1),dfs(x+1,y,0)));
	else dp[x][y][z]=max(dfs(x,y+1,z),dfs(x+1,y,0));
	return dp[x][y][z];
}


int main()
{
speed
cin>>r>>c;
ll k;
cin>>k;
rep(i,0,r+1) rep(j,0,c+1) rep(k,0,4) dp[i][j][k]=-1;
rep(i,0,k)
{
	ll x,y,z;
	cin>>x>>y>>z;
	v[x-1][y-1]=z;
	
}
cout<<dfs(0,0,0)<<endl;
}


Measured memory_bytes: 356464
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 200500;
int n;
char s[5];
ll f[N][3];
int op[N];
int main() {
	memset(f, -0x3f, sizeof(f));
	read(n); read(f[1][0]);
	for (int i = 2, x;i <= n; i++) {
		read(x);
		f[i][0] = max(f[i-1][1], f[i-1][0]) + x;
		f[i][1] = max(f[i-1][1], f[i-1][2]) - x;
		f[i][2] = f[i-1][2] + x;
		if (x < 0) Mx(f[i][2], f[i][1]), Mx(f[i][1], f[i][0]);
	}
	write(max(f[n][0], max(f[n][1], f[n][2])));
	return 0;
}

Measured memory_bytes: 7768
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    int max_index=-1;
    int max=0, value=0;
    int ans=0;
    string S;
    cin >> N;
    cin >> S;
    for(int i=0;i<N;i++){
        if(S[i]=='#'){
            value--;
        } else {
            value++;
            if(max<value){
                max=value;max_index=i;
            }
        }
    }
    if(max_index==-1){
        for(int i=0;i<N;i++){
            if(S[i]=='.'){
                ans++;
            }
        }
    } else {
        for(int i=0;i<=max_index;i++){
            if(S[i]=='#'){
                ans++;
            }
        }
        for(int i=max_index+1;i<N;i++){
            if(S[i]=='.'){
                ans++;
            }
        }
    }
    cout << ans;
    
    
    return 0;
}


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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  int K;
  cin >> K;
  sort(a.begin(), a.end(), [](int l, int r) { return l > r; });
  for (int i = 0; i < K; i++) {
    a.at(0) *= 2;
  }
  int ans = a.at(0) + a.at(1) + a.at(2);
  cout << ans << endl;
}

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

int A[ 20 ];

int main()
{
int i;
int N;
int iMax;
int iCnt;
char S[ 100 ];
long long iNum;
long long a;

	long r = strtol("99yen", NULL, 10);
	
	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	N = strlen( S );
	iNum = strtol( S, NULL, 10 );

	N -= 2;
	a = 1;
	for( i = 0; i < N; i++ )
	{
		A[ i ] = abs( ( iNum % 1000 ) - 753 );
		iNum /= 10;
	}

	sort( A, A + N );
	cout << A[ 0 ] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nk = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] h = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int normal_attack = nk[0] - nk[1];
        Arrays.sort(h);

        long ans = 0;
        for(int i=0; i<normal_attack; i++) {
            ans += h[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 82384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;


//////////////////////////
ll A, B, C, D;
map<ll, ll> mp;

void ans(ll x) {
	if (x == 0) { mp[0] = 0; return; }
	if (x == 1) { mp[1] = A; return; }

	if (mp.count(x)) { return; }

	ll y = x / 2;
	ans(y);
	if(x>2)ans(y + 1);

	ll z = x / 3;
	ans(z);
	ans(z + 1);

	ll w = x / 5;
	ans(w);
	ans(w + 1);

	ll ret = INF;
	if (x <= INF / A) { ret = A * x; }
	ret = min(ret, mp[y] + B + A*(x%2));
	if(x>2)ret = min(ret, mp[y + 1] + B + A*(2-x%2));
	ret = min(ret, mp[z] + C + A * (x % 3));
	ret = min(ret, mp[z + 1] + C + A*(3-x%3));
	ret = min(ret, mp[w] + D + A * (x % 5));
	ret = min(ret, mp[w + 1] + D + A * (5 - x % 5));

	mp[x] = ret;
}



int main() {
	ll T;
	cin >> T;

	repn(t, T) {
		mp.clear();
		ll N;
		cin >> N;
		cin >> B >> C >> D >> A;

		ans(N);

		
		cout <<mp[N]<<endl;
	}
	
}


Measured memory_bytes: 4792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define NMAX 10

using namespace std;

int main(){
	char A[NMAX];
	cin >> A;
	int str = strlen(A);
	bool aaa[str];
	int pin=0;
	int max_a = 0;
	
	rep(i,0,str){
		if(A[i] == 'A' || A[i] == 'C' || A[i] == 'G' || A[i] == 'T'){
			aaa[i] = true;
		}else{
			aaa[i] = false;
		}
	}
	int count=0;
	rep(i,0,str){
		if(aaa[i]){
			count++;
		}else{
			if(max_a < count){
				max_a = count;
			}
			count = 0;
		}
	}
	if(max_a < count){
		max_a = count;
		pin= str;
	}
	cout << max_a << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
	int a,c;
	char b;
	while(scanf("%d %c %d",&a,&b,&c)!=EOF&&c!='?') {
		if(b=='+')
			cout<<a+c<<endl;
		else if(b=='-')
			cout<<a-c<<endl;
		else if(b=='*')
			cout<<a*c<<endl;
		else if(b=='/')
			cout<<a/c<<endl;
	}
	return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,i,j,t;
long long k;
char ch[10010];
int main(){
	scanf("%s",ch);n=strlen(ch);for (i=0;i<n;i++) if (ch[i]=='1') t++; else break;
	scanf("%lld",&k);if (k<=t) printf("%d\n",1); else printf("%c\n",ch[t]);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 pb push_back
#define all(v) (v).begin(), (v).end()

typedef long long ll;

template <class T = int>
T in() { T x; cin >> x; return x; }
#define output(e) cout << e << '\n'

#ifdef LOCAL
#define dr_elem(x) cout << #x << "->" << x << " "
#define dr_end() << "\n"
#else
#define dr_elem(x)
#define dr_end(x)
#endif


//
// Implementation
//

int main() {
  string s1 = in<string>();
  string s2 = in<string>();
  string s3 = in<string>();
  string s;
  s += s1[0] - 'a' + 'A';
  s += s2[0] - 'a' + 'A';
  s += s3[0] - 'a' + 'A';
  output(s);
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
}

Measured memory_bytes: 23252
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n  # 各要素の親要素の番号を格納するリスト

    def find(self, x):  # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):  # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):  # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # グループの数を返す
        return len(self.roots())

    def all_group_members(self):  # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M, K = map(int, input().split())
    graph_friends =[[] for _ in range(N)]
    uf_friends = UnionFind(N)
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        graph_friends[a].append(b)
        graph_friends[b].append(a)
        uf_friends.union(a, b)

    graph_block = [[] for _ in range(N)]
    for _ in range(K):
        c, d = [int(i) - 1 for i in input().split()]
        graph_block[c].append(d)
        graph_block[d].append(c)

    ans = [0] * N
    for i in range(N):
        size = uf_friends.size(i) - 1
        for f in graph_friends[i]:  # 「友達関係」の時は外す
            if uf_friends.same(i, f):  # 隣接して絵いるかつ親が同じ
                size -= 1
        for b in graph_block[i]:  # 「ブラック関係」の時は外す
            if uf_friends.same(i, b):  # 隣接してるかつ親が同じ
                size -= 1
        ans[i] = size
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 55836
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  ll a[n][n-1];
  fo(i,n)
  {
  	fo(j,n-1)
  	cin>>a[i][j];
  }
  vector <pair<ll,ll>> loc(n,{0,0});
  ll ans=0;
  while(1)
  {
  	ll f=0;
  	fo(i,n)
  	{
  		ll r=a[i][loc[i].fi]-1;
  		if(r<n&&a[r][loc[r].fi]-1==i&&loc[i].se!=-1&&loc[r].se!=-1)
  		{
  			loc[i].fi++;
  			loc[i].se=-1;
  			loc[r].fi++;
  			loc[r].se=-1;
  			f=1;
  		}
  	}
  	if(f)
  	{
  		ans++;ll g=0;
  		fo(i,n)
  		{
  			if(loc[i].fi<n-1)
  			{
  				g=1;
  				break;
  			}
  		}
  		if(!g)
  			break;
  		fo(i,n)
  		loc[i].se=0;
  	}
  	if(!f)
  	{
  		cout<<-1;
  		return 0;
  	}
  }
  cout<<ans;
  return 0;
}

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

int main(){

    map<int, pair<int, int> > m;
    int h, w, d; cin >> h >> w >> d;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            int a; cin >> a;
            m[a] = {i, j};
        }
    }

    vector<int> acc(h*w + 1, 0);

    for(int x = 1; x <= d; x++){

        for(int cur = x + d; cur <= h * w; cur += d){
            int pre = cur - d;
            pair<int, int> cur_pos = m[cur];
            pair<int, int> pre_pos = m[pre];
            int dis = (int)abs(cur_pos.first - pre_pos.first) + (int)abs(cur_pos.second - pre_pos.second);
            acc[cur] = dis;
            acc[cur] += acc[pre];

            //cout << cur << " " << pre << " " << acc[cur] << endl;
        }
    
    }

    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        cout << acc[r] - acc[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int L[200];

int main()
{
    cin >> N;
    int sum = 0;
    rep(i, 0, N)
    {
        cin >> L[i];
        sum += L[i];
    }
    string ans = "Yes";
    rep(i, 0, N)
    {
        int rest = sum - L[i];
        if (L[i] >= rest)
        {
            ans = "No";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cerr << #x << " is " << x << endl;
#define F(i,b) for(int i = 0 ; i < (int)(b) ; i++)
#define RF(j,b) for(int j = (int)(b)-1 ; j >= 0 ; j--)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s , t ;
vi a[26] ;
void solve(){
	cin >> s >> t ;
	for(int i = 0 ; i < sz(s) ; i++){
		a[s[i]-'a'].pb(i) ;
		a[s[i]-'a'].pb(i+sz(s)) ;
	}
	for(int i = 0 ; i < 26 ; i++){
		sort(all(a[i])) ;
	}
	int ans = 0 , n = sz(s) ; int p = 0 ;
	for(int i = 0 ; i < sz(t) ; i++){
		int c = t[i] - 'a' ;
		if(sz(a[c]) == 0) return cout << -1 , void() ;
		p = *lower_bound(all(a[c]), p) + 1 ;
		if(p >= n){
			p -= n ;
			ans += n ;
		}
	}
	cout << ans + p << endl ;
}

int32_t main(){_
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}

}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

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

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

    int K;
    std::cin >> K;

    int n = K / 2;
    int c = n * (K - n);

    std::cout << c << std::endl;
}


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

using namespace std ;

const int MAX = 3e5 + 10 ;

char arr[MAX] ;
int n , k , c ;

int dppref[MAX] , dpsuff[MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>k>>c ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i-1 >= 0)
			dppref[i] = dppref[i-1] ;
		int x = 0 ;
		if(i-c-1 >= 0)
			x = dppref[i-c-1] ;
		if(arr[i] == 'o')
			dppref[i] = max(dppref[i] , x+1) ;
	}
	for(int i = n-1 ; i >= 0 ; --i)
	{
		if(i+1 <= n-1)
			dpsuff[i] = dpsuff[i+1] ;
		int x = 0 ;
		if(i+c+1 <= n-1)
			x = dpsuff[i+c+1] ;
		if(arr[i] == 'o')
			dpsuff[i] = max(dpsuff[i] , x+1) ;
	}
	if(dppref[n-1] < k)
		return 0 ;
	int idx = c ;
	multiset< pair<int , int> >s ;
	multiset<int>Max ;
	for(int i = 0 ; i < n ; ++i)
	{
		while(s.size() > 0)
		{
			pair<int , int>p = *s.begin() ;
			if(p.first <= i)
			{
				s.erase(s.find(p)) ;
				Max.erase(Max.find(p.second)) ;
			}
			else
				break ;
		}
		int x = 0 ;
		if(i != n-1)
			x = max(x , dpsuff[i+1]) ;
		if(i != 0)
			x = max(x , dppref[i-1]) ;
		if(Max.size() > 0)
			x = max(x , *Max.rbegin()) ;
		int a = 0 ;
		if(i+c+1 <= n-1)
			a = dpsuff[i+c+1] ;
		int b = 0 ;
		if(i-c-1 >= 0)
			b = dppref[i-c-1] ;
		if(x < k && arr[i] == 'o' && 1 + a + b == k)
			cout<<i+1<<"\n" ;
		idx++ ;
		idx = min(idx , n-1) ;
		s.insert({idx , dppref[i] + dpsuff[idx]}) ;
		Max.insert(dppref[i] + dpsuff[idx]) ;
	}
	return 0 ;
}		

Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//sin(x* pi / 180)
//be careful from the multiplication while using this define 
//alot of memset may couse TLE
#define TC int t;cin>>t;while(t--)
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
//</DEFINE>
ll OO = 1e18;
ll dp[2][3000][3000];
int main() {
	Fast(), File();
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	for (int i = 0; i < n; i++)dp[1][i][i] = v[i], dp[0][i][i] = -v[i];
	for (int i = 1; i < n; i++) {
		int l = 0;
		for (int r = i; r < n; r++, l++) {
			dp[0][l][r] = OO, dp[1][l][r] = -OO;
			dp[0][l][r] = min(dp[1][l + 1][r] - v[l], dp[0][l][r]);
			dp[1][l][r] = max(dp[0][l + 1][r] + v[l], dp[1][l][r]);
			dp[0][l][r] = min(dp[1][l][r - 1] - v[r], dp[0][l][r]);
			dp[1][l][r] = max(dp[0][l][r - 1] + v[r], dp[1][l][r]);
		}
	}
	cout << dp[1][0][n - 1] << endl;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s;
ll prime[200];
// < ----------- func eh ---------------- ? //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	vll cnt(26,0);
	for(auto ch : s) {
		cnt[ch-'a'] ^=1;
	}
	ll sum = accumulate(all(cnt),0);
	if(sum) cout<<"No";
	else cout<<"Yes";
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3588
// https://atcoder.jp/contests/abc102/tasks/arc100_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, sum = 0;
    cin >> n;
    vector<int> v, w;

    for (int i = 0; i < n; i++) {
        cin >> m;
        v.push_back(m);
        w.push_back(m - i - 1);
    }
    sort(ALL(w));

    int mid = w[n / 2];
    for (int i = 0; i < n; i++) {
        sum += abs(w[i] - mid);
    }
    cout << sum << endl;

    return 0;
}


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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans;
    rep(i,n) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	char x[200005]; scanf("%s", &x);
	
	int n = strlen(x);
	int a = 0, b = 0;
	
	rep(i, n){
		if(x[i] == 'S')	a--;
		else{
			a++;
			b = max(a, b);
		}
	}
	
	printf("%d\n", 2 * b);
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 2e5 + 5;
int n;
int a[N];
void solve() {  
    cin >> n;
    int x = 0;
    rep(i, 0, n)
        cin >> a[i], x ^= a[i];
    rep(i, 0, n) {
        a[i] ^= x;
        cout << a[i] << ' ';
    }
}       

Measured memory_bytes: 5156
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);
 
    $d = (int)$data[0] / (int)$data[1];
    $r = (int)$data[0] % (int)$data[1];
    $f = (int)$data[0] / (int)$data[1];
 
    printf("%d %d %f\n", $d, $r, $f);
}

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

typedef long long ll;
ll k, num, t1, t2, i, sz = 50;
int main()
{
	cin >> k;
	cout << sz << endl;
//	if (k % sz == 0) {
//			t1 = k / sz + 4;
//		cout <<t1 << " " << t1 << " " << t1 << " " << t1 << " " << t1 << endl;
//		return 0;
//	}
	t1 = k / sz;
	t1 += 49 - k % sz;
	t2 = t1 + 51;
	for (i =0; i < sz - k % sz; i++) {
		cout << t1 << " ";
	}
	for (i = 0; i < k % sz; i++) {
		cout << t2 << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
q = int(input())

# bc = [list(map(int,input().split())) for _ in range(q)]

c = Counter(a)

allsum = 0
for k,v in c.items():
    allsum += k*v
    
ans = []

for i in range(q):
    bi,ci = list(map(int,input().split()))
    allsum += ci*c[bi] - bi*c[bi]
    c[ci] = c[ci] + c[bi]
    c[bi] = 0
    ans.append(allsum)
    
for i in ans:
    print(i)

Measured memory_bytes: 27100