akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs



struct MaxFlow {
  struct Edge {
    i64 v, c, f;
  };

  i64 n, s, t;
  vector<vector<i64>> g;
  vector<Edge> es;

  MaxFlow(i64 n, i64 s, i64 t) : n(n), s(s), t(t), g(n + 1) {}
  void add_edge(i64 u, i64 v, i64 c);
  i64 relax();
  i64 max_flow();
};

void MaxFlow::add_edge(i64 u, i64 v, i64 c) {
  g[u].push_back(es.size());
  es.push_back({ v, c, 0 });
  g[v].push_back(es.size());
  es.push_back({ u, 0, 0 });
}

i64 MaxFlow::relax() {
  queue<i64> q;
  vector<i64> route(n + 1, -1);
  q.push(s);
  route[s] = -2;
  while (!q.empty()) {
    i64 u = q.front();
    q.pop();
    for (i64 ei : g[u]) {
      const Edge& e = es[ei];
      if (route[e.v] == -1 && e.c - e.f > 0) {
        q.push(e.v);
        route[e.v] = ei;
        if (e.v == t) goto found;
      }
    }
  }
  return 0;
found:
  i64 mf = 1ll << 62;
  for (i64 u = t; u != s; ) {
    i64 ei = route[u], rei = ei ^ 1;
    const Edge& e = es[ei], &re = es[rei];
    mf = min(mf, e.c - e.f);
    u = re.v;
  }
  for (i64 u = t; u != s; ) {
    i64 ei = route[u], rei = ei ^ 1;
    Edge& e = es[ei], &re = es[rei];
    e.f += mf;
    re.f -= mf;
    u = re.v;
  }
  return mf;
}

i64 MaxFlow::max_flow() {
  i64 f = 0;
  while (true) {
    i64 x = relax();
    if (x == 0) break;
    f += x;
  }
  return f;
}

void validate(const MaxFlow& mf) {
  i64 s = mf.s, t = mf.t;
  for (i64 i = 0; i < mf.es.size(); i += 2) {
    const auto& ef = mf.es[i], er = mf.es[i + 1];
    assert(ef.f + er.f == 0);
  }
  i64 sf = 0, tf = 0;
  for (i64 ei : mf.g[s]) sf += mf.es[ei].f;
}

int main() {
  i64 n, m;
  cin >> n >> m;
  MaxFlow mf(n, 0, n - 1);
  for (i64 i = 0; i < m; ++i) {
    i64 u, v, c;
    cin >> u >> v >> c;
    mf.add_edge(u, v, c); 
  }
  i64 ans = mf.max_flow();
  // validate(mf);
  cout << ans << endl;
  return 0;
}



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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a+b>c+d)	cout << "Left" << endl;
	else if(a+b==c+d) cout << "Balanced" << endl;
	else cout << "Right" << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        String result = s;
        while (result.contains("B")) {
            result = result.replaceAll("[01]B", "");
            result = result.replaceAll("^B", "");
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

int main()
{
  int N;
  cin >> N;
  int cnt = 0;
  for (int i = 1; i <= N; i++)
  {
    int a;
    cin >> a;
    if (i % 2 == 1)
    {
      if (a % 2 == 1)
      {
        cnt++;
      }
    }
  }
  cout << cnt << '\n';
}

Measured memory_bytes: 3636
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val X = Array.fill[Int](N)(sc.nextInt())
    val sorted = X.clone()
    Sorting.quickSort(sorted)
    val m1: Int = sorted(N / 2 - 1)
    val m2: Int = sorted(N / 2)

    rep(N) { i =>
      val m = if(X(i) <= m1)
        m2
      else
        m1
      out.println(m)
    }
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    (0 until n) foreach f
  }

  private def map[@specialized(Int, Long) A](n: Int)(f: Int => A): Seq[A] = {
    (0 until n) map f
  }
}


Measured memory_bytes: 56360
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
int p[25];
int n;

int main(void){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> p[i];
    
    int cnt = 0;
    for(int i = 1; i < n - 1; i++){
        if(((p[i-1] < p[i]) && (p[i+1] > p[i])) || ((p[i+1] < p[i]) && (p[i] < p[i-1]))) cnt += 1;
    }
    
    cout << cnt << endl;
}


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 = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(Math.min(a,b)+" "+ Math.max((a+b-n),0) );
    }

}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<long double> A( N );
	for( int i = 0;i < N; i++ ) {
		cin >> A[i];
	}

	vector<long double> a( N );
	for( int i = 0;i < N; i++ ) {
		a[i] = log10( A[i] );
	}
	vector<long double> acc( N + 1 );
	for( int i = 0;i < N; i++ ) {
		acc[i + 1] = acc[i] + a[i];
	}

	for( int i = K + 1;i <= N; i++ ) {
		string ans = "No";
		if( acc[i] - acc[i - K] > acc[i - 1] - acc[i - 1 - K] ) ans = "Yes";
		cout << ans << endl;
	}
}


Measured memory_bytes: 12948
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var X = input[0];
            var Y = input[1];
            var A = input[2];
            var B = input[3];
            var C = input[4];
            var p = ReadArrayInt().OrderByDescending(i => i).Take(X < A ? X : A).ToArray();
            var q = ReadArrayInt().OrderByDescending(i => i).Take(Y < B ? Y : B).ToArray();
            var r = ReadArrayInt().OrderByDescending(i => i).Take(X + Y < C ? X + Y : C).ToArray();
            var pCnt = 0;
            var qCnt = 0;
            var rCnt = 0;
            var ans = 0L;
            var rem = X + Y;
            while (rem > 0)
            {
                var pChk = pCnt < p.Count() ? p[pCnt] : -1;
                var qChk = qCnt < q.Count() ? q[qCnt] : -1;
                var rChk = rCnt < r.Count() ? r[rCnt] : -1;
                if (pChk >= qChk && pChk > rChk)
                {
                    ans += pChk;
                    pCnt++;
                }
                else if (qChk > rChk)
                {
                    ans += qChk;
                    qCnt++;
                }
                else
                {
                    ans += rChk;
                    rCnt++;
                }
                rem--;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


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

int main() {
    string s, t; cin >> s >> t;
    int ss = s.size();
    int ts = t.size();
    vector<vector<int> > dp(ss + 1, vector<int> (ts + 1, 0));
    for (int i = 1; i <= ss; i++) {
        for (int j = 1; j <= ts; j++) {
            if (s.at(i-1) == t.at(j-1)) {
                dp.at(i).at(j) = dp.at(i-1).at(j-1) + 1;
            } else {
                dp.at(i).at(j) = max(dp.at(i-1).at(j), dp.at(i).at(j-1));
            }
        }
    }
    string ans;
    int i = ss;
    int j = ts;
    while (i > 0 && j > 0) {
        if (s.at(i-1) == t.at(j-1)) {
            ans = s.at(i-1) + ans;
            i--; j--;
        } else if (dp.at(i).at(j) > dp.at(i).at(j-1)) {
            i--;
        } else {
            j--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef pair<int,int> pii;
int main(){
  int n; scanf("%d", &n);
  int x[500000];
  vector<pii> xyz;
  for(int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    xyz.push_back(make_pair(x[i], i));
  }
  sort(xyz.begin(), xyz.end());
  int mid1 = xyz[n/2-1].first;
  int mid2 = xyz[n/2].first;
  //int flag[500000];
  /*if(mid1 == mid2){
    for(int i = 0; i < n; i++) printf("%d\n", mid1);
  }*/
  for(int i = 0; i < n; i++){
    if(x[i] < mid2) printf("%d\n", mid2);
    else printf("%d\n", mid1);
  }
  return 0;
}
  

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  int m;
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++) {
    cin >> t.at(i);
  } 
  vector<string> st(n + m);
  for (int i = 0; i < n; i++) {
    st.at(i) = s.at(i);
  }
  for (int i = n; i < n + m; i++ ) {
    st.at(i) = t.at(i - n);
  }
  int max = 0;
  int count = 0;
  for (int i = 0; i < n + m; i++) {
    for (int j = 0; j < n; j++) {
      if (st.at(i) == s.at(j))  {
        count++;
      }
    }
    for (int j = 0; j < m; j++) {
      if (st.at(i) == t.at(j)) {
        count--;
      }
    }
    if (max < count) {
      max = count;
    }
    count = 0;
  }
  cout << max << endl;  
}
      

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;
int A[2*N];
int B[2*N];
vector<int> V[2*N];
void dfs(int v, int p, int c){
    c += A[v];
    B[v] = c;
    for(int i = 0; i < V[v].size(); i++){
        if(V[v][i] != p) dfs(V[v][i], v, c);
    }
}

void solve(){
    int q, n;
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n-1; i++){
        int p, q;
        scanf("%d%d", &p, &q);
        V[p].push_back(q);
        V[q].push_back(p);
    }
    for(int i = 0; i < q; i++){
        int p, r;
        scanf("%d%d", &p, &r);
        A[p] += r;
    }
    dfs(1, -1, 0);
    for(int i = 1; i <= n; i++){
        if(i > 1) printf(" ");
        printf("%d", B[i]);
    }
}

int main(){
    int test_cases_number = 1;
//    scanf("%d", &test_cases_number);
//    ios_base::sync_with_stdio(0);
//    cin.tie(0); cout.tie(0);
//    cin >> test_cases_number;
    for(int i = 0; i < test_cases_number; i++)
        solve();
}



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

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    rep(i,1000){
        ostringstream sout;
        sout<<setfill('0')<<setw(3)<<i;
        string psw = sout.str();

        int t=0;
        int cnt =0;
        while(cnt<n){
            if(s[cnt]==psw[t]){
                if(t==2){
                    ans++;
                    break;
                }
                t++;
            }
            cnt++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char A, B;
    cin >> A >> B;
    if (A > B) {
        cout << '>';
    } else if (B > A) {
        cout << '<';
    } else {
        cout << '=';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, K;
vector<ll> A;
vector<ll> F;

bool f(ll mid) {
    ll now = 0;
    for(int i = 0; i < N; i++) {
        ll B = mid / F[i];
        now += max(0LL, A[i] - B);
    }
    return now <= K;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>());
    ll ok = 1e12;
    ll ng = -1;
    while(ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define set multiset
#define null NULL
#define ort (b+s)/2

using namespace std;

typedef long long Lint;
typedef long double db;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<db,db> dd;
typedef pair<int,string> is;

const int maxn = 600020;
const int K = 320;
const int MOd = 1e9 + 7;

int ar[maxn];

void solve() {
	scanf("%d %d %d",&ar[1],&ar[2],&ar[3]);
	sort( ar+1, ar+1+3 );
	if( ar[1] == ar[2] && ar[2] != ar[3] ) {
		printf("Yes\n");
		return;
	}
	if( ar[1] != ar[2] && ar[2] == ar[3] ) {
		printf("Yes\n");
		return;
	}
	printf("No\n");
}

int main(  ) {


    int n = 1;
    //scanf("%d",&n);
    while( n-- ) solve();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	
	if(A+B >= C){
		printf("%d\n",B+C);
	}else{
		printf("%d\n",A+2*B+1);
	}
	return 0;
}

int Mymin(int a,int b){
	int r;
	if(a < b){
		r = a;
	}else{
		r = b;
	}
	return r;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){

  int x, y, z, n, i, j;

  scanf("%d%d", &x, &y);

  if(x == y){
    printf("%d\n", x);
    return 0;
  }

  n = y;
  z = x % y;
  if(y >= x){
    n = x;
    z = y % x;
  }

  for(i = 1; i <= z; i++){
    if(z%i == 0 && n%i == 0)
      j = i;
  }

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

  return 0;
}

Measured memory_bytes: 592
fun main(args: Array<String>) {

    val s = readLine()!!
    val t = readLine()!!

    println(method139A(s,t))
}

fun method139A(s: String, t: String): Any? {

    var count = 0
    for (index in 0 until 3) {

        if (s[index] == t[index]) {
            count++
        }
    }

    return count
}


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



int main(int argc, char const *argv[])
{
	int n;
	cin>>n;int cnt[100005]={},cnt1[100005]={},cnt2[100005]={},v;
	for (int i = 0; i < n; ++i)
	{
		cin>>v;
		if (i%2==0)
		{
			++cnt[v];
			++cnt1[v];
		}
		else
		{
			++cnt[v];
			++cnt2[v]; 
		}
	}
	sort(cnt,cnt+100005);
	sort(cnt1,cnt1+100005);
	sort(cnt2,cnt2+100005);
	reverse(cnt,cnt+100005);
	reverse(cnt1,cnt1+100005);
	reverse(cnt2,cnt2+100005);
	if (cnt1[0]+cnt2[0]==cnt[0])
	{
		cout<<n-max(cnt1[0]+cnt2[1],cnt1[1]+cnt2[0])<<endl;
	}
	else
	{
		cout<<n-cnt1[0]-cnt2[0]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1408
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn sub(a: u64, b: u64) -> u64 {
    if a > b {
        a - b
    } else {
        0
    }
}

use std::cmp::max;

fn main() {
    let nc: Vec<u64> = read_vec();
    let n = nc[0] as usize;
    let c = nc[1];
    let xv: Vec<Vec<u64>> = read_vec2(n);

    let mut v: Vec<u64> = vec![0; n];
    let mut l: Vec<u64> = vec![0; n];
    let mut r: Vec<u64> = vec![0; n];
    for i in 0..n {
        v[i] = xv[i][1];
        r[i] = xv[i][0];
        l[i] = c - xv[i][0];
    }

    let mut rmax: Vec<u64> = vec![0; n];
    let mut rmax2: Vec<u64> = vec![0; n];
    let mut vsum = v[0];
    rmax[0] = sub(vsum, r[0]);
    rmax2[0] = sub(vsum, 2 * r[0]);
    for i in 1..n {
        vsum += v[i];
        let t = sub(vsum, r[i]);
        rmax[i] = max(t, rmax[i - 1]);
        let t2 = sub(vsum, 2 * r[i]);
        rmax2[i] = max(t2, rmax2[i - 1]);
    }

    let mut lmax: Vec<u64> = vec![0; n];
    let mut lmax2: Vec<u64> = vec![0; n];
    let mut vsum = v[n - 1];
    lmax[n - 1] = sub(vsum, l[n - 1]);
    lmax2[n - 1] = sub(vsum, 2 * l[n - 1]);
    for i in (0..n - 1).rev() {
        vsum += v[i];
        let t = sub(vsum, l[i]);
        lmax[i] = max(t, lmax[i + 1]);
        let t2 = sub(vsum, 2 * l[i]);
        lmax2[i] = max(t2, lmax2[i + 1]);
    }

    let mut rl = 0;
    for i in 0..n - 1 {
        let t = rmax2[i] + lmax[i + 1];
        if t > rl {
            rl = t;
        }
    }

    let mut lr = 0;
    for i in (1..n).rev() {
        let t = lmax2[i] + rmax[i - 1];
        if t > lr {
            lr = t;
        }
    }

    let t1 = max(lr, rl);
    let t2 = max(rmax[n - 1], lmax[0]);
    let ans = max(t1, t2);
    println!("{}", ans);
}


Measured memory_bytes: 16636
from itertools import tee


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


N, M, *X = map(int, open(0).read().split())
if N >= M:
    print(0)
    exit()

X.sort()
diffs = [cur - prev for prev, cur in pairwise(X)]
diffs.sort()
print(sum(diffs[: M - N]))


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1000100;
int MOD,g,z;
int u[MAXN],v[MAXN],c[MAXN];
int s,t,r;
int n,m,Q,fa[MAXN],Get[2][MAXN];
inline int id(register int A,register int B,register int C)
{
	return (A-1)*6+B*3+C;
}
inline int find(register int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void add(register int U,register int V)
{
	U=find(U),V=find(V);
	if(U!=V) fa[U]=V;
	return;
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m>>Q>>MOD;
	for(register int i=1;i<=m;i++) cin>>u[i]>>v[i]>>c[i],g=__gcd(g,abs(c[i]-c[1]));
	if(!g) g=MOD;
	MOD=__gcd(MOD,g*3),z=c[1]%g;
	for(register int i=0;i<=n*6;i++) fa[i]=i;
	for(register int i=1;i<=m;i++)
	{
		register int w=(c[i]-z)/g;
		add(id(u[i],0,0),id(v[i],1,(w+0)%3)),add(id(v[i],0,0),id(u[i],1,(w+0)%3));
		add(id(u[i],0,1),id(v[i],1,(w+2)%3)),add(id(v[i],0,1),id(u[i],1,(w+2)%3));
		add(id(u[i],0,2),id(v[i],1,(w+4)%3)),add(id(v[i],0,2),id(u[i],1,(w+4)%3));
		add(id(u[i],1,0),id(v[i],0,(w+0)%3)),add(id(v[i],1,0),id(u[i],0,(w+0)%3));
		add(id(u[i],1,1),id(v[i],0,(w+2)%3)),add(id(v[i],1,1),id(u[i],0,(w+2)%3));
		add(id(u[i],1,2),id(v[i],0,(w+4)%3)),add(id(v[i],1,2),id(u[i],0,(w+4)%3));
	}
	for(register int i=0,j=z;i<(MOD<<1);i++,j=(j<<1)%MOD) Get[i&1][j]=1;
	while(Q--)
	{
		cin>>s>>t>>r;
		register int ret=0;
		if(find(id(t,0,0))==find(id(s,0,0))) ret|=Get[0][(r+z+3*g)%MOD];
		if(find(id(t,0,0))==find(id(s,0,1))) ret|=Get[0][(r+z+2*g)%MOD];
		if(find(id(t,0,0))==find(id(s,0,2))) ret|=Get[0][(r+z+1*g)%MOD];
		if(find(id(t,0,0))==find(id(s,1,0))) ret|=Get[1][(r+z+3*g)%MOD];
		if(find(id(t,0,0))==find(id(s,1,1))) ret|=Get[1][(r+z+2*g)%MOD];
		if(find(id(t,0,0))==find(id(s,1,2))) ret|=Get[1][(r+z+1*g)%MOD];
		cout<<(ret?"YES":"NO")<<"\n";
	}
	return 0;
}

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

int main(){
	//input
	int n;
	long long k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	std::vector<int> check(n,0);
	std:: vector<int> myturn(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
		a[i]--;
	}

	//algorithm
	//1に戻る周期が知りたい
	int now_posi = 0, next;
	int begin = 0, end = 0, cycle = 0;
	int count = 0;
	check[0]++;
	for(int i=1; i<n; i++){
		next = a[now_posi];
		check[next]++;
		if(check[next]>1){
			begin = next;
			end = now_posi;
			cycle = i - myturn[begin];
			break;
		}
		myturn[next] = i;
		now_posi = next;
	}

	now_posi = 0;
	int counter;
	for(int i=0; i<k; i++){
		next = a[now_posi];
		now_posi = next;
		if(next == begin){
			counter = (k-i-1)%cycle;
			if(counter != 0){
				for(int j=0; j<counter; j++){
					next = a[now_posi];
					now_posi = next;
				}
			}
			break;
		}
	}

	std::cout << next+1 << std::endl;
	
	return 0;


}

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

int main() {
	int i, j;
	string news;
	while (getline(cin, news)){
		for (i = 0; i <= 25; i++) {
			for (j = 0; j < news.size(); j++){
				if (news[j]>'a' && news[j] <= 'z')news[j] -= 1;
				else if (news[j] == 'a') news[j] = 'z';
			}
			for (j = 0; j < news.size() - 4; j++) {
				if ((news[j] == 't'&&news[j + 1] == 'h') && (news[j + 2] == 'e' || (news[j + 2] == 'i'&&news[j + 3] == 's') || (news[j + 2] == 'a'&&news[j + 3] == 't'))) {
					goto end;
				}
			}
		}
	end:
		cout << news << endl;
	}
}

Measured memory_bytes: 1172
import numpy as np

K=int(input())
AB=np.array(input().split(" "),dtype=np.int32)
A=AB[0]
B=AB[1]

flag=False

for i in range(A,B+1):
    if(i%K==0):
        flag=True

if(flag):
    print("OK")
else:
    print("NG")

Measured memory_bytes: 27172
#include <bits/stdc++.h>
using namespace std;
int main(){ 
  int N=0;
  cin>>N;
  vector<string> test(N);
  int ac=0;
  int wa=0;
  int tle=0;
  int  re=0;
  for(int i; i<N; i++){
    cin>>test.at(i);
    if(test.at(i)=="AC"){
      ac++;
    }
    if(test.at(i)=="WA"){
      wa++;
    }
    if(test.at(i)=="TLE"){
      tle++;
    }
    if(test.at(i)=="RE"){
      re++;
    }
  }
  cout<<"AC x "<<ac<<endl;
   cout<<"WA x "<<wa<<endl;
   cout<<"TLE x "<<tle<<endl;
   cout<<"RE x "<<re<<endl;
}
    
    

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

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

	//string s;
	int n,a,b;

	cin >> n >> a >> b;
	
	int ans=min(a*n,b);
	
	//if(ans<0) ans=0;
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, W; cin >> N >> W;
    int w[N], v[N];
    REP(i, 0, N) cin >> w[i] >> v[i];

    int maxV = 100 * 1000;
    ll dp[N + 1][maxV + 1] = {};
    REP(i, 0, N + 1) REP(j, 0, maxV + 1) dp[i][j] = 1LL << 60;
    dp[0][0] = 0;
    REP(i, 0, N) {
        REP(j, 0, maxV + 1) {
            if (j >= v[i]) {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    int ans;
    REP(i, 0, maxV + 1) if (dp[N][i] <= W) ans = i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  Vec(P,lli,M,0);
  Vec(Q,lli,M,0);
  rep(i,0,M) cin >> P[i] >> Q[i];
  Sort(P);
  Sort(Q);
  Out(max(0LL,Q[0]-P[M-1]+1));
}


Measured memory_bytes: 1792
#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;
  cin >> N;
  string S, T;
  cin >> S >> T;

  string ans;
  rep(i,N) {
    ans += S[i];
    ans += T[i];
  }
  
  cout << ans << endl;

  return 0;
}


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

int main(void){
    string s;
    string check = "Yes";
    
    cin >> s;
    
    rep(i, s.size()){
        if(i%2 == 0){
            if(s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D' ){
                check = "No";
                break;    
            }
        } else {
            if(s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D' ){
                check = "No";
                break;
            }
        }
    }

    cout << check << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int a[100010];
ll ans;

ll f(int d,ll R){
	if(R<a[d]){
		puts("-1");
		exit(0);
	}
	if(d==n){
		ans+=a[d];
		return a[n];
	}
	
	
	ll nex=f(d+1,min((R-a[d])*2,1000000000000000000));
	ll crr=min(R-a[d],nex)+a[d];
	ans+=crr;
	return crr;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n+1)scanf("%d",a+i);
	
	f(0,1);
	printf("%lld",ans);
}

Measured memory_bytes: 5240
while True:
	s = raw_input().split()
	if '?' == s[1]:
		break
	if '+' == s[1]:
		print int(s[0])+int(s[2])
	if '-' == s[1]:
		print int(s[0])-int(s[2])
	if '*' == s[1]:
		print int(s[0])*int(s[2])
	if '/' == s[1]:
		print int(s[0])/int(s[2])

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int mul(int a, int b) {
    return (long long) a * b % MOD;
}

int cnt[60][2], power[60];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    power[0] = 1;
    for (int i=1; i<60; i++)
        power[i] = mul(power[i-1], 2);

    int ret = 0;
    for (int i=0; i<n; i++) {
        long long a;
        cin >> a;
        for (int j=0; j<60; j++) {
            add(ret, mul(cnt[j][!(a & (1LL << j))], power[j]));
            cnt[j][!!(a & (1LL << j))]++;
        }
    }
    cout << ret << "\n";

    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    char c; cin >> c;
    cout << char(c+1) << endl;

	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a;i < n; i++)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define MAXN 100005
vi adj[MAXN];
int dp[MAXN],used[MAXN];

int dfs(int u){
	if(used[u]) return dp[u];
	int ans = 0;
	used[u] = 1;
	for(int v : adj[u]){
		ans = max(ans, dfs(v) +1);
	}
	return dp[u] = ans;
}
int main(){__
	int n,m;
	cin >> n >> m;
	for(int i =0; i < m; i++){
		int u,v;
		cin >>u >> v;
		adj[u].pb(v);
	}
	int ans = 0;
	for(int i = 1; i <=n; i++){
		if(!used[i]){
			ans = max(ans, dfs(i));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8576
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string X; cin >> X;
    stack<char> s;
    rep(i, X.length()) {
        if (s.empty()) s.push(X[i]);
        else if (s.top() == 'S' && X[i] == 'T') s.pop();
        else s.push(X[i]);
    }
    cout << s.size() << endl;

    return 0;
}


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

long N;
long B[110];
long A[110];

int main()
{
  cin >> N;
  for (int i=1;i<=N;i++)
    cin >> B[i];
  int isdeleted;
  for (int i=N;i>=1;i--){
    isdeleted=0;
    for (int j=i;j>=1;j--){
      if (B[j]==j){
        A[i]=j;
        for (int k=j;k<=i-1;k++)
          B[k]=B[k+1];
        isdeleted=1;
        break;
      }
      if (B[j]>j){
        cout << -1 << endl;
        return 0;
      }
    }
    if (isdeleted==0){
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i=1;i<=N;i++)
    cout << A[i] << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    ll n, a;
    unordered_map<ll, ll> m;
    cin >> n;
    for (ll i=0;i<n;i++) {
        cin >> a;
        m[a]++;
    }
    ll sum = 0;
    for (const auto& e : m) {
        if (e.first > e.second) {
            sum += e.second;
        } else {
            sum += e.second - e.first;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 4260
def GCD(a,b):
  if a<b:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B // C)
upperD = int(B // D)
lowerC = int(A // C)
lowerD = int(A // D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D // gcd
upperL = int(B // lcm)
lowerL = int(A // lcm)
numL = upperL - lowerL

print(str(B - A - (numC + numD - numL)))

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

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

	cin >> N >> K;
	vector<pair<int, int>>v(N);
	for (int i = 0; i < N; i++) {
		cin >> M;
		v[i] = { M,i + 1 };
	}
	sort(v.begin(), v.end(), greater<pair<int, int>>());
	vector<int>ans;
	vector<int>used(N + 1, 0);
	int cnt = 0;
	int turn = 0;
	while (v[0].first) {
		bool flag = false;
		for (int i = 0; i < N; i++) {
			if (used[v[i].second])continue;
			if (v[i].first) {
				ans.push_back(v[i].second);
				v[i].first--;
				used[v[i].second]++;
				if (used[v[i].second] == 1)cnt++;
				if (cnt == N) {
					flag = true;
					turn++;
					for (auto &j : used)j = 0;
					used[v[i].second] = 1;
					cnt = 1;
					sort(v.begin(), v.end(),greater<pair<int,int>>());
					break;
				}
			}
		}
		if (!flag)break;
	}
	//cout << turn << endl;
	if (turn > K) {
		cout << ans.size() << endl;
		for (auto i : ans)cout << i << " ";
		cout << endl;
		return 0;
	}
	if (turn <= K) {
		cout << -1 << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main(){
	
	int x,y;
	cin >> x >> y;

	if (x%y == 0) {
		cout << -1 << endl;
	}
	else {
		while (1) {
			int a = x;
			if (a%x == 0 && x%y != 0) {
				cout << a << endl;
				return 0;
			}
			a++;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7

min_sum = sum(range(K))
max_sum = sum(range(N + 1 - K, N + 1))
ans = 0
for i in range(K, N + 2):
    ans += max_sum - min_sum + 1
    ans %= MOD
    min_sum += i
    max_sum += (N - i)
print(ans)

Measured memory_bytes: 67888
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
bool flag=false,flag2=false;
char s[10];
int main(void)
{	
	scanf("%s",s);
	if(strlen(s)!=3)
	{
		printf("No\n");
		return 0;
	}
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')
			flag=true;
		if(s[i]=='B')
			flag2=true;
	}
	if(flag==true&&flag2==true)
	{
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, **abc, **dp, i, j, k, pts, m;
  cin >> n;
  abc = new int*[n];
  dp = new int*[n];
  for(i = 0; i < n; i++)
  {
    abc[i] = new int[3];
    dp[i] = new int[3];
  }
  for(i = 0; i < n; i++)
  {
    for(j = 0; j < 3; j++)
    {
      cin >> abc[i][j];
      if(i == n - 1)
      {
        dp[i][j] = abc[i][j];
      }
    }
  }
  for(i = n - 2; i >= 0; i--)
  {
    for(j = 0; j < 3; j++)
    {
      m = INT_MIN;
      for(k = 0; k < 3; k++)
      {
        if(j != k)
        {
          m = max(m, dp[i + 1][k]);
        }
      }
      dp[i][j] = abc[i][j] + m;
    }
  }
  m = INT_MIN;
  for(i = 0; i < 3; i++)
  {
    m = max(m, dp[0][i]);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 8064
/*input
5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
#define version 20190814
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int tmp=32-__builtin_clz(i^j);
			cout<<tmp<<' ';
		}
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
string sA,sB,sC;
  cin>>sA>>sB>>sC;
  sA+='A'; sB+='B'; sC+='C';
  int i=0;
  int j=-1;
  int k=-1;
  char ans=sA.at(0);
  for(int l=0; ;l++){
  if(ans=='a'){
  i++; ans=sA.at(i);
  }else if(ans=='b'){
    j++; ans=sB.at(j);
  
  }else{
   k++; ans=sC.at(k);
  }if(ans=='A'|| ans=='B' || ans=='C'){
     break;
  }
    
    }cout<<ans<<endl;
  
   return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    qs = sorted(list(zip(a, b)), reverse=True)
    
    ret = 0
    d = float('inf')
    for ai, bi in qs:
        if bi < d:
            ret += 1
            d = ai + 1
    return ret


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
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    result = solve(N, M, a, b)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21436
#include <iostream>
#include <vector>
 
using namespace std;
 
int N;
vector<int> h;
vector<int> a;
vector<size_t> dp;
 
void update_max(int i, size_t val)
{ 
  for (; i < N; i = (i | (i+1)))
    dp[i] = max(dp[i], val);
}
 
size_t get_max(int r)
{ 
  size_t res = 0;
  for (; r >= 0; r = (r & (r+1)) - 1)
    res = max(res, dp[r]);
  return res;
}
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
 
  cin >> N;
 
  h.resize(N);
  a.resize(N);
 
  dp = vector<size_t>(N+1, 0);
 
  for (int i = 0; i < N; ++i)
  { 
    cin >> h[i];
  }
  for (int i = 0; i < N; ++i)
  { 
    cin >> a[i];
  }
  size_t res = 0;
 
  for (int i = 0; i < N; ++i)
  {
    const size_t cur_max = get_max(h[i]-1) + a[i];
    update_max(h[i], cur_max);
    res = max(res, cur_max);
  }
  cout << res << endl;
 
  return 0;
}

Measured memory_bytes: 6052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105,mod=1e9+7;
ll a[N];

int main(){
	ll n,s=1000;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
		
	int k=1,i=1;
	while(i<=n && k<=n){
		while(k<n && a[k]>=a[k+1]) k++;
		i=k;
		while(i<n && a[i]<=a[i+1]) i++;
		s+=1ll*(a[i]-a[k])*(s/a[k]);
		//cout<<a[k]<<" "<<a[i]<<endl;
		k=i+1;
	}
	
	printf("%lld\n",s);
    return 0;
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");


int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    float n,d;
    cin>>n>>d;
    d=(2*d)+1;
    cout<<ceil(n/d)<<"\n";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,m;
int x[100001],y[100001];
const ll MOD=(ll)1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
    freopen("out","w",stdout);
#endif
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<m;i++){
    cin>>y[i];
  }
  ll xsum=0,ysum=0;
  ll now=n-1;
  for(int i=n-1;i>=0;i--){
    xsum+=now*x[i];
    now-=2;
  }
  now=m-1;
  for(int i=m-1;i>=0;i--){
    ysum+=now*y[i];
    now-=2;
  }
  cout<<((xsum%MOD)*(ysum%MOD))%MOD<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 1024
str = gets.chomp
q = gets.to_i
q.times do
  o,a,b,p = gets.split
  case o
  when 'print'
    puts str[a.to_i..b.to_i]
  when 'reverse'
    str[a.to_i..b.to_i] = str[a.to_i..b.to_i].reverse
  when 'replace'
    str[a.to_i..b.to_i] = p
  end
end

Measured memory_bytes: 8676
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int M = Integer.parseInt(st.nextToken());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         long sum = 0L;
         for(int x: arr)
            sum += x;
         if(sum > M)
            System.out.println(-1);
         else
            System.out.println(M-sum);
      }
   }

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

int main(){
	int N;
	string S;
	cin >> N;
	cin >> S;
	int x;
	
	rep(i, S.size()){
		x = S[i] - 'A';
		x = (x+N)%26;
		S[i] = 'A' + x;
		cout << S[i];
	}
    return 0;
}



Measured memory_bytes: 256