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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 998244353, nn = 3003;
int n, s;
int a[nn];
int dp[nn][nn];

// dp[i][j] -> fixing R = i, no. of left position that can be taken to get sum j

void solve(){
    cin >> n >> s;
    for(int i = 1; i <= n; ++i) cin >> a[i];

    for(int i = 1; i <= n; i++) {
        dp[i][a[i]] = i;

        for(int j = 0; j <= s; j++) {
            dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
            if(j >= a[i]) dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]]) % mod;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = (ans + dp[i][s]) % mod;         // fix L = i, ignoring all elements previous to i 
    }
    cout << ans << '\n';
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 10000;

int main(){
  int N, K;
  while(cin>>N>>K){
    int limit[101];
    memset(limit,-1,sizeof(limit));
    REP(i,K){
      int day, spa;
      cin>>day>>spa;
      day--; spa--;
      limit[day] = spa;
    }
    int dp[9] = {};
    REP(i,3)if(limit[0]==-1||limit[0]==i){
      REP(j,3)if(limit[1]==-1||limit[1]==j){
        dp[i*3+j] = 1;
      }
    }
    for(int d = 2; d < N; d++){
      int nextdp[9] = {};
      REP(next, 3)if(limit[d]==-1 || limit[d]==next){
        REP(i,3)REP(j,3)if(!(i == j && j == next)){
          nextdp[j*3+next] += dp[i*3+j];
          nextdp[j*3+next] %= MOD;
        }
      }
      memcpy(dp, nextdp, sizeof(dp));
    }
    int ans = 0;
    REP(i,9)ans += dp[i];
    cout<<ans%MOD<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#coding:utf-8
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
X.append(x)
Y = list(map(int, input().split()))
Y.append(y)
X_max = max(X)
Y_min = min(Y)

if X_max < Y_min:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
S = raw_input()

ans = 0
for i in range(2**(len(S)-1)):
    b = bin(i)[2:]
    while len(b) < len(S)-1:
        b = "0"+b
    
    cal = S[0]
    for v, w in zip(S[1:], b):
        if w == "1":
            cal += "+"
        cal += v
    
    ans += eval(cal)
    
print ans

Measured memory_bytes: 2692
#include <stdio.h>
#include <string.h>

// min
int main(void){
  char s[101];
  int ans = 0;
  scanf("%s", s);

  for(int i = 0; i < strlen(s) / 2;  i++){
    if(s[i] != s[strlen(s) - 1 - i]){
      ans++;
    }
  }

  printf("%d\n", ans);

  return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

const int Z = 1e9+7;

int fp(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return 1ll * a * fp(a, x - 1) % Z;
    }
    int t = fp(a, x / 2);
    return 1ll * t * t % Z;
}

int inv(int a) {
    return fp(a, Z - 2);
}

int main() {
    int n, k;
    cin >> n >> k;
    int d[n];
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        d[--a]++;
        d[--b]++;
    }

    int fac[k+1];
    fac[0] = 1;
    for (int i = 1; i <= k; i++) {
        fac[i] = 1ll * fac[i-1] * i % Z;
    }

    int ans;
    if (k == 1) {
        ans = n == 1 ? 1 : 0;
    } else {
        ans = 1ll * fac[k] * fp(fac[k-2], n - 1) % Z;
        for (int i = 0; i < n; i++) {
            ans = 1ll * ans * (d[i] + 1 <= k ? inv(fac[k-1-d[i]]) : 0) % Z;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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 MAX_N = 1000000; 

vector<int> prime(MAX_N);
vector<bool> is_prime(MAX_N+1);

// n以下の素数を返す
int sieve(int n){
    int p = 0;
    rep(i, n+1) is_prime.at(i) = true;
    is_prime.at(0) = is_prime.at(1) = false;
    rep2(i, 2, n+1){
        if(is_prime.at(i)){
            prime.at(++p) = i;
            for (int j = 2*i; j <= n; j+= i) is_prime.at(j) = false;
        }
    }
    return p;
}

int main(){
    int n;
    while(cin >> n){
        cout << sieve(n) << endl;
    }
}


Measured memory_bytes: 6596
class UnionFind():
    # コンストラクタ
    def __init__(self, n):
        # 要素数
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n

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

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, 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

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

##############################################################
N,M = map(int, input().split())
pos = [0] * N
for idx, p in enumerate(map(int,input().split())):
    pos[p - 1] = idx

UF = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    UF.union(x - 1, y - 1)

ans = 0
for n in range(N):
    if UF.same(pos[n], n):
        ans += 1

print(ans)

Measured memory_bytes: 14452
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int d;
	cin >> d;
	if (d == 25)cout << "Christmas" << endl;
	if (d == 24)cout << "Christmas Eve" << endl;
	if (d == 23)cout << "Christmas Eve Eve" << endl;
	if (d == 22)cout << "Christmas Eve Eve Eve" << endl;

}

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

using namespace std;

int main() {
    int m, d, past;
    int day[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    string week[] = { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" };
    while (cin >> m >> d, m != 0) {
        past = 0;
        for (int i = 0; i < m - 1; i++) {
            past += day[i];
        }
        past += d - 1;
        cout << week[past % 7] << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     int n;cin>>n;LL sum=0;
     int v[n+1];
     for(int i=1;i<=n;i++)
     {
         if(i%3==0 || i%5==0)
         {
             v[i] = 0;
         }
         else
         {
             v[i] = i;
         }
     }
     for(int i=1;i<=n;i++)
     {
         sum = sum + v[i];
     }
     cout<<sum<<endl;
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 7468
#include<stdio.h>
#include<stdlib.h>
int main(){
  int h,n,a[2000000],total;
  scanf("%d %d",&h,&n);
  total=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    total=total+a[i];
  }
  if(total>=h){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


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

int main(void){
   int n,a[100];
   cin >> n;
   for(int i = 1; i <= n; i++){
       cin >> a[i];
   }

   cout << a[n];
   for(int i = n-1; i >= 1; i--){
       cout << " " << a[i];
   }
   cout << endl;
   return 0;
}


Measured memory_bytes: 3080
//:D

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;

    cin>>k;
    cout<<arr[k-1]<<"\n";     //:D

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		String problem = sc.nextLine();

		if(problem.contains("a")&&problem.contains("b")&&problem.contains("c")){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define nax (ll)1e6+2
#define INF 1e9+5
typedef long long ll;
typedef unsigned long long ull;
class solution{
public: 
	void solve(){
		int h,w;
		cin>>h>>w;
		int n;
		cin>>n;
		int a[h+1][w+1];
		/*for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin>>a[i][j];
			}
		}*/
		int ma = max(h,w);
		int ans = 0;
		int val =0;
		while(val <n)
		{
			ans++;
			val += ma;
			
		}
		cout<<ans;
	}
};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n,count = 0,i = 0;
		int result[] = new int[1000];
		while(sc.hasNext()){
			n = sc.nextInt();
			for(int a = 0; a <10; a++){
				for(int b = 0; b < 10; b++){
					for(int c = 0; c < 10; c++){
						for(int d = 0; d < 10; d++){
							if(a+b+c+d == n) count++;
						}
					}
				}
			}
			result[i] = count;
			i++;
			count = 0;
		}
		for(int j = 0; j < i; j++){
			System.out.println(result[j]);
		}
	}
}

Measured memory_bytes: 26768
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

bool check(int n) {
    string s = to_string(n);
    int l = 0, r = s.size()-1;
    while (l <= r) {
        if (s[l++] != s[r--])
            return false;
    }
    return true;
}
int main() {
    int a, b, ans = 0;
    cin >> a >> b;
    for(int i = a; i <= b; i++) {
        if (check(i))
            ans += 1;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			Map<Integer, Integer> am = new HashMap<>();
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				int v = 0;
				if (am.containsKey(x)) {
					v = am.get(x);
				}
				am.put(x, v + 1);
			}
			long max1 = -1;
			long max2 = -1;
			long max3 = -1;
			for (Map.Entry<Integer, Integer> e : am.entrySet()) {
				int x = e.getKey();
				if (e.getValue() >= 4) {
					max3 = Math.max(max3, x);
				}
				if (e.getValue() >= 2) {
					if (x >= max1) {
						max2 = max1;
						max1 = x;
					} else if (x >= max2) {
						max2 = x;
					}
				}
			}
			long ans = 0;
			if (max1 >= 0 && max2 >= 0) {
				ans = Math.max(ans, max1 * max2);
			}
			if (max3 >= 0) {
				ans = Math.max(ans, max3 * max3);
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

using namespace std;

int main(){
    char c, d;
    while(~(c = getchar())){
	if(c == '@'){
	    c = getchar();
	    d = getchar();
	    for(int i = 0;i < c - '0';i++){
		putchar(d);
	    }
	}
	else{
	    putchar(c);
	}
    }
    return 0;
}

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

using namespace std;

class UnionFind {
public:
  vector<int> parent;

  UnionFind(int n) : parent(n, -1) {
  }

  int root(int x) {
    if (parent[x] < 0) {
      return x;
    } else {
      return parent[x] = root(parent[x]);
    }
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -parent[root(x)];
  }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N + M);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int l;
      cin >> l;
      uf.unite(l - 1, M + i);
    }
  }
  for (int i = 0; i < N - 1; i++) {
    if (!uf.issame(M + i, M + i + 1)) {
      cout << "NO" << '\n';
      return 0;
    }
  }
  cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,cnt=0;
    cin >> n;
    vector<ll> l(n);
    rep(i,n) cin >> l[i];
    sort(all(l));
    rep(i,n)for(int j=i+1; j<n; j++)for(int k=j+1; k<n; k++){
        if(l[i]+l[j]>l[k] && l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll N;
    string S;
    cin >> N;
    vector<ll> A(N+2,0);
    map<ll,ll>mp;
    rep(i,N-1){
        cin >> A[i+2];
        mp[A[i+2]]++;
    }
    rep(i,N){
        cout << mp[i+1] <<endl;
    }
}

Measured memory_bytes: 17248
#include<stdio.h>
int main(void)
{
	int w,h,x,y,r,a;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	a=0;
	if(x-r<0){
		a+=1;
	}
	if(y-r<0){
		a+=1;
	}
	if(y+r>h){
		a+=1;
	}
	if(x+r>w){
		a+=1;
	}
	if(a==0){
		printf("Yes\n");
	}
	if(a>0){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string O = Console.ReadLine();
        string E = Console.ReadLine();
        int length = O.Length + E.Length;
        for(int i = 0; i < length; i++)
        {
            Console.Write(
                (i + 1) % 2 == 0 ?
                E[(i - 1)/ 2].ToString() :
                O[i / 2].ToString()
                );
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int k; scanf("%d", &k);
    char s[101]; scanf("%s", s);
    int len = strlen(s);

    if (len > k) {
        int i;
        for (i = 0; i < k; ++i) printf("%c", s[i]);
        puts("...");
    } else {
        printf("%s\n", s);
    }
    return 0;
}

Measured memory_bytes: 1652
#include <iostream>
#include <stdlib.h>
#define llint long long

using namespace std;

int n;
llint a[100005], b[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n+1;i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		llint x = min(a[i], b[i]);
		ans += x;
		b[i] -= x;
		x = min(a[i+1], b[i]);
		ans += x;
		a[i+1] -= x;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

const int  MAX_R=3010;
ll dp[MAX_R][MAX_R][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R,C,K; cin >> R >> C >> K;
    vector<vector<int>> V(R,vector<int>(C,0));
    for (int i=0;i<K;++i){
        int r,c,v; cin >> r >> c >> v;
        V[--r][--c]+=v;
    }
    dp[0][0][0]=0;
    for (int i=0;i<R;++i){
        for (int j=0;j<C;++j){
            for (int k=2;k>=0;--k){
                chmax(dp[i][j][k+1],dp[i][j][k]+V[i][j]);
            }
            for (int k=0;k<4;++k){
                if (i+1<R) chmax(dp[i+1][j][0],dp[i][j][k]);
                if (j+1<C) chmax(dp[i][j+1][k],dp[i][j][k]);
            }
        }
    }
    ll ans=max({dp[R-1][C-1][0],dp[R-1][C-1][1],dp[R-1][C-1][2],dp[R-1][C-1][3]});
    cout << ans << '\n';
}

Measured memory_bytes: 320644
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(int a)
{
    if (a != 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    int a, b;

    cin >> a >> b;
    if (b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * String Search - Naive String Search
 */
public class Main {

	static final int B = 37;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		char[] T, P;
		T = br.readLine().toCharArray();
		P = br.readLine().toCharArray();

		if (T.length < P.length) return;

		int t = 0, p = 0, BN = power(B, P.length);

		for (int i = 0; i < P.length; i++) {
			t = t * B + T[i];
			p = p * B + P[i];
		}

		//solve
		StringBuilder sb = new StringBuilder();

		if (t == p) sb.append("0\n");
		for (int i = 1; i < T.length - P.length + 1; i++) {
			t = t * B + T[i + P.length - 1] - T[i - 1] * BN;
			if (t == p) sb.append(i + "\n");
		}

		System.out.print(sb.toString());

	}

	static int power(int x, int n) {
		if (n == 0) return 1;
		int ret = power(x * x, n / 2);
		if ((n & 1) == 1) ret *= x;
		return ret;
	}

}

Measured memory_bytes: 80336
#include<cstdio>
#include<list>
using namespace std;

int main(){
	int N;
	scanf("%d", &N);
	list<int> b;
	for (int i = 0; i < N; ++i){
		int tmp;
		scanf("%d", &tmp);
		b.push_front(tmp);
	}
	int a[N];
	for (int i = N - 1; i >= 0; --i){
		list<int>::iterator it = b.begin();
		int j = i + 1;
		while(*it < j){
			j--;
			it++;
		}
		if(*it > j){
			printf("-1\n");
			return 0;
		}else{
			a[i] = *it;
			b.erase(it);
		}
	}
	for (int i = 0; i < N; ++i) printf("%d\n", a[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


ll cnt[100010];

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

    int n, a;
    cin >> n;
    rep(i, n){
        cin >> a;
        cnt[a]++;
        cnt[a+1]++;
        if(a-1 > 0) cnt[a-1]++;
    }

    ll res = 0;
    reps(i, 1, 100001){
        res = max(res, cnt[i]);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

//auto mod int

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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++() {
      if ((x++) >= mod) x-= mod;
      return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator--() {
      if ((x += mod-1) >= 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;
  }
};

int main(){
    ll n,k;
    cin >> n >> k;
    mint ans = 0;
    vector<mint> s(n+1);
    s[0] = 0;
    for(ll i=1; i<=n; i++) s[i] = s[i-1] + i;
    for(ll i=k; i<=n+1; i++){
        mint mn = s[i-1];
        int ni = max((ll)0,n-i);
        mint mx = s[n] - s[ni];
        mint now = mx - mn + 1;
        //cout << mn.x << " "<< mx.x << " " <<  now.x << endl;
        ans += now;
    }
    cout << ans.x << endl;

    return 0;
}

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

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

using namespace std;
typedef long long ll;
const int INF = 1001001001;

const int di[4] = {-1, 0 , 1, 0};
const int dj[4] = {0, -1 , 0, 1 };
typedef pair<int, int> P;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }
    int white = 0;
    rep(i, h)rep(j, w){
        if(s[i][j] == '.') white++;
    }
    white -= 2;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x){
        if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));
    };
    update(0, 0, 0);
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        rep(dir, 4){
            int ni = i + di[dir];
            int nj = j + dj[dir];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(s[ni][nj] == '#') continue;
            update(ni, nj, dist[i][j] + 1);
        }
    }
    int distance = dist[h-1][w-1];
//    cout << white << " " << distance << endl;
    int ans = white - (distance - 1) ;
    if(dist[h-1][w-1] == INF){
        cout << "-1" << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

n = int(input())
A = list(map(int,input().split()))
k = A[-1]
q = partition(A,0,n-1)
s = list(map(str,A))
print(" ".join(s[:q])+" [{}] ".format(s[q])+" ".join(s[q+1:]))


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

int main(){
    int H,W;
    cin>>H>>W;
    int a[510][510];
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>a[i][j];
        }
    }
    vector<int>ans;
    for(int i=1;i<=H;i++){
        if(i%2==1){
            for(int j=1;j<=W;j++){
                if(a[i][j]%2==1){
                    ans.push_back(i);
                    ans.push_back(j);
                    if(j!=W){
                        ans.push_back(i);
                        ans.push_back(j+1);
                        a[i][j+1]++;
                    }else if(i!=H){
                        ans.push_back(i+1);
                        ans.push_back(j);
                        a[i+1][j]++;
                    }
                }
            }
        }else{
            for(int j=W;j>=1;j--){
                if(a[i][j]%2==1){
                    ans.push_back(i);
                    ans.push_back(j);
                    if(j!=1){
                        ans.push_back(i);
                        ans.push_back(j-1);
                        a[i][j-1]++;
                    }else if(i!=H){
                        ans.push_back(i+1);
                        ans.push_back(j);
                        a[i+1][j]++;
                    }
                }
            }
        }
    }
    cout<<ans.size()/4<<endl;
    for(int i=0;i<ans.size()/4;i++){
        cout<<ans[i*4]<<" ";
        cout<<ans[i*4+1]<<" ";
        cout<<ans[i*4+2]<<" ";
        cout<<ans[i*4+3]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
const int Mod = 1e9 + 7;
LL n, k, ans;

int main() {
	cin >> n >> k;
	for(LL i = k; i <= n + 1; i++) {
		ans += (2 * n - i + 1) * i / 2;
		ans -= (i - 1) * i / 2 - 1;
	}
	cout << ans % (LL)Mod << endl;
	return 0;
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int
#define endl '\n'

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

//#define int int64_t

/*global*/



signed main()
{
	int n; cin >> n;
	vector<int> b(n-1);
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i) cin >> b[i];

	vector<int> a(n, INF);
	
	for(int i{}; i < n-1; ++i)
	{
		a[i] = min(a[i], b[i]);
		if(i+1 != n-1)
		{
			a[i+1] = min(b[i], b[i+1]);
		}
		else a[i+1] = b[i];
	}

	int ans{};
	for(auto const &v: a)
	{
		ans += v;
	}

	cout << ans << '\n';


}

Measured memory_bytes: 256
def abc():
    n = int(input().rstrip())
    stores = []
    for i in range(1, n + 1):
        name, score = input().rstrip().split()
        stores.append((i, name, int(score)))
    stores.sort(key=lambda x:(x[1], -x[2]))
    for x in stores:
        print(x[0])


abc()


Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(){
  string a,b;
  cin >> a >> b;
  int c=stoi(a+b);
  
   for(int i=0;i*i<=c;i++){
    if(c==i*i){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
grid = []
all = 0
for i in range(3):
    c1,c2,c3 = map(int,input().split(" "))
    all += c1
    all += c2
    all += c3
    grid.append([c1,c2,c3])
if (all//3 > 600)or(all < 0):
    print("No")
    exit()
else:
    for i in range(101):
        a1=i
        b1 = grid[0][0] - a1
        b2 = grid[0][1] - a1
        b3 = grid[0][2] - a1
        a2 = grid[1][0] - b1
        a3 = grid[2][0] - b1
        if (a2+b2==grid[1][1])and(a2+b3==grid[1][2])and(a3+b2==grid[2][1])and(a3+b3==grid[2][2]):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

int main(){
	float x1,x2,x3,x4,y1,y2,y3,y4;
	float a1=0.0,a2=0.0;
	int n,i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
			a1=(y2-y1)/(x2-x1);
			a2=(y4-y3)/(x4-x3);
		
			if( a1==a2 )printf("YES\n");
			else printf("NO\n");
	}
return 0;
}

Measured memory_bytes: 616
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 998244353  # type: int

def get_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD

def make_facts(n):
    '''
        make factorials
        0!(=1), 1!, 2!, 3! .... n!
    '''
    fact = [1]
    for i in range(n):
        fact.append((fact[i] * (i + 1)) % MOD)
    return fact

def make_combs_(n, k):
    '''
        make [C(0, k), C(1, k), C(2, k) ..... C(n, k)]
    '''
    fact = [1] * (n + 1)
    for i in range(2, n + 1):
        fact[i] = (fact[i - 1] * i) % MOD

    ret = [0] * (n + 1)
    for i in range(k, n + 1):
        a = fact[i]
        b = (fact[k] * fact[i - k]) % MOD
        ret[i] = get_fraction_mod(a, b)
    return ret

def make_combs(n, k):
    '''
        make [C(n, 0), C(n, 1), C(n, 2) ..... C(n, k)]
        n! / (n - k)! k!
    '''
    facts = make_facts(n)
    invs = [] # inverted for fraction
    for fact in facts:
        invs.append(pow(fact, MOD - 2, MOD))

    ret = []
    for i in range(0, n + 1):
        a = facts[n]
        #b = facts[i]
        #c = facts[n - i]
        ret.append(a * invs[i] * invs[n - i] % MOD)
    return ret

def solve(N: int, M: int, K: int):
    pows = []
    for i in range(N + 1):
        t = pow(M - 1, i, MOD)
        pows.append(t)
    s = pow(M, N, MOD)
    #s = pows[N]
    coms = make_combs(N - 1, N - 1)
    #print(s, coms)
    for i in range(K + 1, N):
        c = coms[i]
        ss = M * pows[N - i - 1]
        #print(i, c, ss, c * ss)
        s -= c * ss
        s %= MOD
    print(s)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 99476
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, r, t;
int main(){
    cin>>n>>l>>r;
    n--;
    k=l;t=r;
    while(n--){
        cin>>l>>r;
        if(k<=l&&t<=r){k=l;t=r;}
        else if(k<=l&&t>r){t=(t+r-1)/r;t*=r;k=t/r*l;}
        else if(t<=r&&k>l){k=(k+l-1)/l;k*=l;t=k/l*r;}
        else{
            i=(t+r-1)/r;
            j=(k+l-1)/l;
            //cout<<i<<" | "<<j<<endl;
            i=max(i,j);
            k=i*l;
            t=i*r;
        }
        //cout<<k<<" "<<t<<endl;
    }
    cout<<k+t<<endl;
}


Measured memory_bytes: 256
//#define GBN_USE_C
#ifdef GBN_USE_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#else
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#endif

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

typedef char str255[256];
int  StrLen(char *s       ) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除
void StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; }

#define BIG_PRIME 1'000'000'007
#define BP_remainder(x) ((x) % BIG_PRIME)

const int INF = 1 << 30;
const int INF_NEG = INF * -1;
const ll INF_LONG = 1LL << 62;
const ll INF_LONG_NEG = INF_LONG * -1;

int main()
{
    int N; cin >> N;
    vector<string> s(N);
    char tmpStr[20]; tmpStr[10] = '\0';
    vector<int> tmpInt(10);
    rep(i, N){
        string inStr; cin >> inStr;
        rep(j, 10) tmpInt[j] = inStr[j];
        sort(tmpInt.begin(), tmpInt.end());
        rep(j, 10) tmpStr[j] = (char)tmpInt[j];
        s[i] = tmpStr;
    }

    sort(s.begin(), s.end());
    ll same = 1;
    ll ans = 0;
    string prev = s[0];
    for (int i = 1; i < N; ++i){
        if (prev == s[i]){
            ++same;
        } else {
            ans += same * (same - 1) / 2;
            prev = s[i];
            same = 1;
        }
    }
    ans += same * (same - 1) / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
def main():
    N, T = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    A = [a[0] for a in AB]
    B = [b[1] for b in AB]

    dp1 = [[0]*T for _ in range(N)]
    dp2 = [[0]*T for _ in range(N+2)]

    for i in range(N-1):
        for j in range(T):
            dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j])
            if 0 <= j - A[i]:
                dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j - A[i]] + B[i])

    for i in range(2, N+1)[::-1]:
        for j in range(T):
            dp2[i][j] = max(dp2[i][j], dp2[i+1][j])
            if 0 <= j - A[i-1]:
                dp2[i][j] = max(dp2[i][j], dp2[i+1][j - A[i-1]] + B[i-1])

    ans = 0
    for i in range(N):
        for j in range(T-1):
            ans = max(ans, dp1[i][j] + dp2[i+2][T - 1 - j] + B[i])
    print(ans)


if __name__ == '__main__':
    main()


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

struct data
{
    long long prop,sum;
}  tree[524924]   ;

long long ara[200002];

/*void build(long long nd,long long l,long long r)
{
    if(l==r)
    {
        tree[nd]=ara[l];
    }
    else
    {
        long long lt,rt,md; lt=nd<<1; rt=lt+1;  md=(l+r)>>1;

        build(lt,l,md); build(rt,md+1,r);

        tree[nd]=max(tree[lt],tree[rt]);


    }

}*/

long long query(long long nd,long long l,long long r,long long x,long long y,long long car)
{

     if(l>y || r<x)return 0;
     else if(l>=x && r<=y)
     {
         return tree[nd].sum+(r-l+1)*car;
     }
     else
     {

         long long lt,rt,md,fq,sq; lt=nd<<1; rt=lt+1; md=(l+r)>>1;

         fq=query(lt,l,md,x,y,car+tree[nd].prop); sq=query(rt,md+1,r,x,y,car+tree[nd].prop);

         return fq+sq;

     }


}

void update(long long nd,long long l,long long r,long long x,long long y,long long val)
{

     if(l>y || r<x)return;
     else if(l>=x && r<=y)
     {
         tree[nd].sum+=(r-l+1)*val;
         tree[nd].prop+=val;
         return;

     }
     else
     {

         long long lt,rt,md; lt=nd<<1; rt=lt+1; md=(l+r)>>1;

         update(lt,l,md,x,y,val); update(rt,md+1,r,x,y,val);

         tree[nd].sum=tree[lt].sum+tree[rt].sum+(r-l+1)*tree[nd].prop;


     }


}

int main()
{


        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x,y,z,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld %lld",&n,&d,&a); m=d*2;

        for(i=0;i<n;i++)
        {

            scanf("%lld %lld",&p,&r); q=r/a; if(r%a!=0)q++;
            vct.push_back(make_pair(p,q));
            v.push_back(p);

        }

        sort(vct.begin(),vct.end());  sort(v.begin(),v.end());

        /*for(i=0;i<n;i++)
        {
            q=vct[i].second; ara[i+1]=q;

        }

        build(1,1,n);*/

        vector<long long>::iterator it;

        for(i=0;i<n;i++)
        {
            p=vct[i].first; q=vct[i].second;

            z=query(1,1,n,i+1,i+1,0); //cout<<i+1<<" "<<q<<"      "<<z<<endl;

            h=max(0LL,q-z); ans=ans+h;  if(i==n-1)break;

            e=p+m;  it=upper_bound(v.begin(),v.end(),e); g=it-v.begin(); g--;

            if(g!=i)
            {
                //cout<<i+2<<" "<<g+1<<"    "<<h<<endl;

                update(1,1,n,i+2,g+1,h);

            }



        }


        printf("%lld\n",ans);







    return 0;
}





Measured memory_bytes: 18224
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}
 
int main(){
	ll n;
	cin>>n;
	ll a=0;
	ll sum=0;
	rep(i,0,n){
		ll b;
		cin>>b;
		a=max(a,b);
		sum+=b;
	}
	if((sum-a)>a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int w,h;
	char room[101][101];
	while(cin>>h>>w,h){
		for(int i=0;i<h;i++)	cin>>room[i];
		int x=0,y=0,cnt=0;
		while(1){
			if     (room[y][x]=='>')	x++;
			else if(room[y][x]=='<')	x--;
			else if(room[y][x]=='^')	y--;
			else if(room[y][x]=='v')	y++;
			else{
				cout<<x<<" "<<y<<endl;
				break;
			}

			if(cnt>w*h){
				cout<<"LOOP"<<endl;
				break;
			}
			cnt++;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream> 
#include <vector> 

using namespace std; 

int main() { 
  int n, v;
  cin>>n>>v;
  int w = 110000;
  int ans = 0;
  long int a[n][2];
  vector<vector<long int>> dp(2, vector<long int>(w, 0));
  for (int i=0;i<n;i++) { 
    cin>>a[i][0]>>a[i][1]; 
  } 
  for(int i=1;i<w;i++)
    dp[0][i] = 1e+10;
  //cout<<dp.size()<<" "<<dp[0].size()<<endl;
  for (int i=1;i<=n;i++) { 
    int t = i%2;
    //cout<<t<<" "<<i<<endl;
    for (int j=0;j<w;j++)
      dp[t][j] = 1e+10;
    for (int j=0;j<w;j++) {
      dp[t][j] = min(dp[t][j], dp[!t][j]);
      if (j >= a[i-1][1]) {
        dp[t][j] = min(dp[t][j], dp[!t][j-a[i-1][1]] + a[i-1][0]);
        //cout<<dp[t][j]<<" ";
      }
  	}
  }
  //cout<<"asdfsfs";
  for (int j=0;j<w;j++) {
    if (dp[n%2][j] <= v)
      ans = j;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

bool memo[30][30][110];
pair<int, int> g[30][30];
int dist[30][30];
const int MAX = 10000;

int main(){
  int n, m;
  while(scanf("%d%d", &n, &m), n + m){
    int st, gl;
    int cm = 0;
    scanf("%d%d", &st, &gl); st--; gl--;

    REP(i,n) REP(j,n) g[i][j] = mp(MAX, MAX);

    REP(i,m){
      int a, b, d, c;
      scanf("%d%d%d%d", &a, &b, &d, &c);
      a--; b--;
      g[a][b] = g[b][a] = mp(d, c);
      cm = max(cm, c);
    }

    REP(i,n) REP(j,n) dist[i][j] = g[i][j].f;
    REP(i,n) dist[i][i] = 0;

    REP(k,n) REP(i,n) REP(j,n)
      dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    if(dist[st][gl] == MAX){
      puts("unreachable");
      continue;
    }

    REP(i,n) REP(j,n) REP(k,cm + 1)
      memo[i][j][k] = false;

    typedef pair<double, pair<int, pair<int, int> > > data;
    priority_queue<data, vector<data>, greater<data> > pq;
    pq.push(mp(0, mp(0, mp(st, st))));

    while(pq.size()){
      data d = pq.top(); pq.pop();
      double tm = d.f;
      int v     = d.s.f;
      int pos   = d.s.s.f;
      int prev  = d.s.s.s;
      //printf("%f %d %d\n", tm, pos, prev);

      if(memo[pos][prev][v]) continue;
      memo[pos][prev][v] = true;

      if(pos == gl && v == 1){
        printf("%.5f\n", tm);
        break;
      }

      REP(i,n) if(prev != i && g[pos][i].f != MAX){
        int pp = i;
        REP(j,3){
          int vv = v + (j - 1);
          if(vv <= 0 || vv > g[pos][i].s) continue;
          if(memo[pp][pos][vv]) continue;
          double tt = tm + (double)g[pos][i].f / vv;
          pq.push(mp(tt, mp(vv, mp(pp, pos))));
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007



string s;
ll a = 0,b = 0;

int main() {
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == '0')a++;
		else b++;
	}
	cout << s.size() - abs(a - b) << endl;
}


Measured memory_bytes: 512