akhauriyash/Code-Regression huggingface dataset:
n,c=map(int,input().split())
X=[]
for i in range(n):
  x,y=map(int,input().split())
  X.append((x,y))
SR,DR=[0]*(n+1),[0]*(n+1)
s,d=0,0
cur=0
for i in range(n):
  x,y=X[i]
  SR[i+1]=SR[i]+y-(x-cur)
  DR[i+1]=DR[i]+y-2*(x-cur)
  cur=x

SL,DL=[0]*(n+1),[0]*(n+1)
s,d=0,0
cur=c
for i in reversed(range(n)):
  x,y=X[i]
  SL[n-i]=SL[n-1-i]+y-(cur-x)
  DL[n-i]=DL[n-1-i]+y-2*(cur-x)
  cur=x

for i in range(n):
  SL[i+1]=max(SL[i+1],SL[i])
  SR[i+1]=max(SR[i+1],SR[i])
ans=0
for i in range(n+1):
  a=max(DR[i]+SL[n-i],DL[i]+SR[n-i])
  ans=max(ans,a)
print(ans)

Measured memory_bytes: 35024
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-9
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
vector<pii> g[N];
bool ans[N];

void dfs(int i, int p, int c){
    ans[i] = c;
    for(pii j : g[i]) if(j.f != p) dfs(j.f, i, (c + j.s) % 2);
}

int main(){
    readi(n);
    lp(i,1,n-1){
        int a,b,c;
        read3i(a,b,c);
        g[a].pb({b, c});
        g[b].pb({a, c});
    }
    dfs(1, 1, 0);
    lp(i,1,n) println(ans[i]);
}

/*
uniform_int_distribution<type>(l, r)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/


Measured memory_bytes: 8064
# coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	a = 0
	b = 0
	for i in range(n):
		cards = map(int, raw_input().split())
		if cards[0] > cards[1]:
			a += cards[0] + cards[1]
		elif cards[0] < cards[1]:
			b += cards[0] + cards[1]
		else: #cards[0] == cards[1]
			a += cards[0]
			b += cards[1]
	print("{:} {:}".format(a,b))

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

int main()
{
  string s;
  cin >> s;
  
  int tail = s.size();
  
  while (tail > 0)
  {
    if (tail >= 7 && s.substr(tail - 7, 7) == "dreamer")
    {
      tail -= 7;
    }
    else if (tail >= 6 && s.substr(tail - 6, 6) == "eraser")
    {
      tail -= 6;
    }
    else if (tail >= 5 && s.substr(tail - 5, 5) == "dream")
    {
      tail -= 5;
    }
    else if (tail >= 5 && s.substr(tail - 5, 5) == "erase")
    {
      tail -= 5;
    }
    else
    {
      cout << "NO";
      return 0;
    }
  }
  
  cout << "YES";
  return 0;
}


Measured memory_bytes: 512
import numpy as np
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, m, k = geta(int)
    a = np.array([0] + list(geta(int)))
    b = np.array([0] + list(geta(int)))

    ca = np.cumsum(a)
    cb = np.cumsum(b)

    ans = 0
    for i, ai in enumerate(ca):
        if k < ai:
            break

        j = np.searchsorted(cb, k-ai, side="right") - 1

        if ans < i + j:
            ans = i + j

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50168
#include <bits/stdc++.h>
using namespace std;
int n;
const long long D=1e9+7;
long long gcd(long long x,long long y){
    if(y==0)return x;
    return gcd(y,x%y);
}
long long pow2(long long x,long long y){
    if(y%2==0)return 1;
    long long ret=pow2(x,y/2);
    return ret*ret%D*(y%2==0 ? 1: x)%D;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin>>s;
    if(s[0]!=s[1] || s[1]!=s[2]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
h,w = gets.split.map(&:to_i)
dp = Array.new(h+1){[0]*(w+1)}
(h+1).times do |i|
  dp[i][0] = 0
end
dp[0][1] = 1

1.upto(h) do |i|
  l = gets.chomp
  1.upto(w) do |j|
    s = l[j-1]
    dp[i][j] = s == "." ? (dp[i][j-1] + dp[i-1][j]) % MOD : 0
  end
end
p dp[h][w] % MOD

Measured memory_bytes: 12028
#include <iostream>
#include<math.h>

using namespace std;


int main() {
    int A, B;
    cin >> A >> B;

    if (A == B) {
        cout << 2 * A;
    } else if (A > B) {
        cout << 2 * A - 1;
    } else {
        cout << 2 * B - 1;
    }
}


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

using namespace std;

int main(){

	int n, m, ans=0;
	vector<int> v, d;

	cin>> n >> m;
	v.resize(m);
	d.resize(m-1);
  
	for(int i=0;i<m;i++) cin>> v[i];
	sort(v.begin(), v.end());
  
	for(int i=0;i<m-1;i++) d[i]=v[i+1]-v[i];
	sort(d.begin(), d.end());
  
  	for(int i=0;i<m-n;i++) ans+=d[i];

	cout<< ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 107;
const int M = 1e9 + 7;
const int V = int(sqrt(1e9)) + 7;

int n;
int k;
int root;
int inv;
int dp[N][V][2];
int su[N][V][2];
int cnt[V];
// 0 real
// 1 add

void prepare(int i) {
	for (int j = 1; j <= root; ++j) {
		su[i][j][0] = (dp[i][j][0] + su[i][j - 1][0]) % M;
	}
	for (int j = inv; j >= 0; --j) {
		su[i][j][1] = (dp[i][j][1] + su[i][j + 1][1]) % M;
	}
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for (int i = 1; i < V; ++i) {
		cnt[i] = (n / i) - (n / (i + 1));
	}
	for (int i = 1; i * i <= n; ++i) {
		root = i;
		dp[1][i][0] = 1;
		if (i * i < n) {
			dp[1][i][1] = cnt[i];
		}
	}
	assert(root);
	inv = n / root - 1;
	prepare(1);
	for (int i = 2; i <= k; ++i) {
		for (int j = 1; j <= root; ++j) {
			dp[i][j][0] = (su[i - 1][root][0] + su[i - 1][j][1]) % M;
		}
		for (int j = 1; j <= inv; ++j) {
			dp[i][j][1] = (su[i - 1][j][0] * cnt[j]) % M;
		}
		prepare(i);
	}
	int ans = (su[k][root][0] + su[k][0][1]) % M;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 102144
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut n: i64 = sc.read();

    let mut ans = vec![];
    loop {
        ans.push(n.rem_euclid(-2));
        n = n.div_euclid(-2);
        if n == 0 {
            break;
        }
    }
    println!(
        "{}",
        ans.into_iter()
            .rev()
            .map(|x| ('0' as u8 + x as u8) as char)
            .collect::<String>()
    );
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2224
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		    Scanner sc = new Scanner(System.in);

		    String a = sc.next();
		    String b = sc.next();
		    int ai = Integer.parseInt(a.toLowerCase(),16);
		    int bi = Integer.parseInt(b.toLowerCase(),16);		    
		    if(ai > bi) {
		    	System.out.println(">");
		    }
		    else if(ai < bi){
		    	System.out.println("<");
		    }
		    else {
		    	System.out.println("=");
		    }
		    
		    sc.close(); }
}


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

#define f(x, y, z) for (int x = (y), __ = (z); x < __; ++x)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define mst(x, a) memset(x, a, sizeof(x))

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9 + 7;

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

const int MAXN = 1e5 + 10;
vector<vector<int>> g(MAXN);
ll down[MAXN], up[MAXN];

int N, M;

ll mul(ll a, ll b) { return a * b % M; }

ll add(ll a, ll b) { return (a + b) % M; }

ll blackRoot(int x, int par) {
  ll rb = 1;
  for (int child : g[x]) {
    if (child != par) {
      rb = mul(rb, 1 + blackRoot(child, x));
    }
  }
  return down[x] = rb;
}

void calcUp(int x, int par) {
  int size = g[x].size();
  if (size == 0) return;
  vector<ll> suffix(size);
  suffix[size - 1] = 1;
  for (int i = size - 1; i > 0; i--) {
    int child = g[x][i];
    if (child != par) {
      suffix[i - 1] = mul(suffix[i], 1 + down[child]);
    } else {
      suffix[i - 1] = suffix[i];
    }
  }

  ll prefix = 1;
  for (int i = 0; i < size; i++) {
    int child = g[x][i];
    if (child != par) {
      up[child] = mul(mul(prefix, suffix[i]), 1 + up[x]);
      prefix = mul(prefix, 1 + down[child]);
    }
  }
  for (int child : g[x]) {
    if (child != par) {
      calcUp(child, x);
    }
  }
}

int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i < N; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }

  blackRoot(1, 0);
  up[1] = 0;
  calcUp(1, 0);
  for (int i = 1; i <= N; i++) {
    printf("%lld\n", mul(down[i], (1 + up[i])));
  }
}


Measured memory_bytes: 17280
import java.util.Scanner
import scala.collection.mutable.PriorityQueue

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val a = new Array[Int](3*n + 1)

  for(i <- 1 to 3*n)
    a(i) = sc.nextInt()

  val left = new Array[Long](n+1)
  val right = new Array[Long](n+1)


  // left
  left(0) = a.map(_.toLong).slice(1, n+1).sum
  val pqd = new PriorityQueue[Int]()(Ordering.Int.reverse)
  for(i <- 1 to n)
    pqd.enqueue(a(i))
  for(i <- n+1 to 2*n){
    pqd.enqueue(a(i))
    left(i-n) = left(i-n-1) + a(i) - pqd.dequeue
  }


  // right
  val tmp: Array[Long] = a.map(_.toLong).slice(2*n+1, 3*n+1)
  right(n) = tmp.sum
  val pqa = new PriorityQueue[Int]
  for(i <- (2*n+1 to 3*n).reverse)
    pqa.enqueue(a(i))
  for(i <- (n to 2*n-1).reverse){
    pqa.enqueue(a(i+1))
    right(i-n) = right(i-n+1) + a(i+1) - pqa.dequeue
  }


  var ans: Long = -1e18.toLong
  for(i <- 0 to n){
    ans = Math.max(ans, left(i) - right(i))
  }

  println(ans)
  // right.foreach(println(_))
}


Measured memory_bytes: 123848
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  for(ll i=0;i<N;i++) {
 if(i==K-1) {
if(S[i]=='A') {
  cout<<"a";
}
   else if(S[i]=='B') {
cout<<"b";
   }
else {
  cout<<"c";
}
 }
    
    else {
      cout<<S[i];
    }
  }
  
  cout<<endl;
}
  


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-

def DFS_stack(adj, start):
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n # 0:????¨????, 1:?¨??????????, 2:?¨??????????
    S = []
    time = 1

    S.append(start)
    flag[start] = 1
    d[start] = time
    time = time + 1
    
    while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§
        if len(S) != 0:
            u = S.pop()
            v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] 
            # v := ??£??\???????????????????????¢?´¢??????????????????
            if len(v) != 0:
                S.append(u)
                S.append(v[0])
                flag[v[0]] = 1
                d[v[0]] = time
                time = time + 1
            else:
            #??£??\??????????????¨????¨??????????
                flag[u] = 2
                f[u] = time
                time = time + 1

        else:
        	#??????????????????????????£?????´????????¢?´¢??????????????????????????¢?´¢????§?
            u = flag.index(0)
            S.append(u)
            flag[u] = 1
            d[u] = time
            time = time + 1            

    return d, f    

def DFS(adj, start):
    
    n = len(adj)
    d = [0] * n
    f = [0] * n
    flag = [0] * n
    time = 1
    
    def DFS_recursive(u, time):
        #print(u, flag)
        flag[u] = 1
        d[u] = time
        time = time + 1
        v = [i for i, x in enumerate(adj[u]) if x == 1]
        for i in v:
            if flag[i] == 0:
                time = DFS_recursive(i, time)
        flag[u] = 2
        f[u] = time
        time = time + 1
        return time
        
    time = DFS_recursive(start, time)
    for i in range(n):
        if flag[i] == 0:
           time =  DFS_recursive(i, time)
    
    return d, f



def main():
    
    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1
            
    #d, f = DFS_stack(adj, 0)
    d, f = DFS(adj, 0)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == "__main__":
    main()    

Measured memory_bytes: 7936
#import <Foundation/Foundation.h>

int main() {
  NSInteger A, B, C, D;
  scanf("%ld %ld %ld %ld", &A, &B, &C, &D);
  while (A > 0 && C > 0) {
    C -= B;
    if (C <= 0) {
      break;
    }
    A -= D;
  }
  printf("%s", A <= 0 ? "No" : "Yes");
  return 0;
}

Measured memory_bytes: 12536
n= str(input())
n = list((n))
p = n[-1]
p = int(p)
if p == 2 or p == 4 or p ==5 or p == 7 or p == 9:
    print("hon")
elif p == 0 or p == 1 or p == 6 or p == 8:
    print("pon")
elif p == 3:
    print("bon")

Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
   	int x;
   	cin >> x;
   	fi(x, INF) {
   		int d = 2;
   		bool pr = true;
   		while (d * d <= i) {
   			if (i % d == 0)
   				pr = false;
   			++d;
   		}
   		if (pr) {
   			cout << i << '\n';
   			return 0;
   		}
   	}
}

Measured memory_bytes: 256
#include<stdio.h>

int n, y;
int main() {
	scanf("%d %d", &n, &y);
	if (y % 1000 != 0) { printf("-1 -1 -1"); return 0; }
	y /= 1000;
	/*
	a+b+c=n
	10a+5b+c=Y/1000
	->
	9a+4b=Y/1000-n
	a+b<n
	10a+5b<Y/1000
	*/
	int a, b;
	for (a = 0; a <= n; ++a) {
		for (b = 0; b <= (n - a)&&((10*a+5*b)<=y); ++b) {
			if ((9 * a + 4 * b) == y - n)
			{
				printf("%d %d %d", a, b, n - a - b); return 0;
			}
		}
	}
	printf("-1 -1 -1");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};


int main(){
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind road(N), rail(N);
  for(int i = 0; i < K; ++i){
    int p, q;
    cin >> p >> q;
    road.unite(p-1, q-1);
  }
  for(int i = 0; i < L; ++i){
    int r, s;
    cin >> r >> s;
    rail.unite(r-1, s-1);
  }
  map< pair<int, int> , int> M;
  for(int i = 0; i < N; ++i) ++M[make_pair(road.find(i), rail.find(i))];
  for(int i = 0; i < N-1; ++i) cout << M[make_pair(road.find(i), rail.find(i))] << " ";
  cout << M[make_pair(road.find(N-1), rail.find(N-1))] << endl;
  return 0;
}


Measured memory_bytes: 13568
n=int(input())
s=input()

def f(s,t):
    a=set(s)
    b=set(t)
    c=a&b
    return len(c)

x=0
for i in range(1,n-1):
    str1=s[0:i]
    str2=s[i:n]
    x=max(x,f(str1,str2))
print(x)

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

int main()
{
    int A, B;
    cin >> A >> B;
    if (abs(A - ((A + B) / 2)) == abs(B - ((A + B) / 2)))
    {
        cout << (A + B) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x -> left != NIL){
    x = x -> left;
  }

  return x;
}

Node treeMaximum(Node x){
  while(x -> right != NIL){
    x = x -> right;
  }

  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL && k == u -> key){
    return u;
  }

  else if(k < u -> key){
    return treeSearch(u -> left, k);
  }else{
    return treeSearch(u -> right, k);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z -> key < x -> key){
      x = x -> left;
    }else{
      x = x -> right;
    }
  }
  
  z -> parent = y;

  if(y == NIL){
    root = z;
  }else if(z -> key < y -> key){
    y -> left = z;
  }else{
    y -> right = z;
  }
}

void inorder(Node u){
  if(u == NIL){
    return;
  }
  inorder(u -> left);
  printf(" %d", u -> key);
  inorder(u -> right);
}

void preorder(Node u){
  if(u == NIL){
    return;
  }
    printf(" %d", u -> key);
    preorder(u -> left);
    preorder(u -> right);
}

int main(){
  
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  

  return 0;
}




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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;

    cin >> n;
    if (n / 10 == 9 || n % 10 == 9) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
x = []
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

def Search(data, value):
    for i in range(len(data)):
           if data[i] == value:
               return i
    return -1
    
for j in range(q):
    if Search(S, T[j])  > -1:
        x.append(Search(S, T[j]))
print(len(x))


Measured memory_bytes: 6552
N=int(input())
S=input()
st=""
n2=0
for i in range(len(S)):
  c1=S[i]
  n1=ord(c1)
  if n1+N>26:
    n2=(((n1-65)+N)%26)+65
  else:
    n2=n1
  st=st+chr(n2)
print(st)

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    vector<int> a(m+10,-1);
    rep(i,m){
        cin>>a[i];
    }
    vector<int> b(n+10);
    int c=0;
    for(int i=0;i<=n;i++){
        if(i==0){
            b[0]=1;
        }
        else if(i==1){
            b[1]=1;
        }
        else{
            b[i]=b[i-1]+b[i-2];
        }
        if(a[c]==i){
            b[i]=0;
            c++;
        }
        //cout<<b[i]<<endl;
        b[i]%=MOD;
        //cout<<i<<" "<<b[i]<<endl;
    }
    cout<<b[n]<<endl;

    
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int s;
  cin >> s;
  vector<int> a;
  int x = s;
  int cnt = 1;
  while(true) {
    a.push_back(x);
    rep(i, a.size()-1) {
      if (a.at(i) == x) {
        cout << cnt << endl;
        return 0;
      }
    }
    if (x%2 == 0) x /= 2;
    else x = 3*x + 1;
    cnt++;
  }
}

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

int n, m, k[20], s[20][20], p[20];

int main() {
  cin >> n >> m;
  rep(i, m){
    cin >> k[i];
    rep(j, k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m){
    cin >> p[i];
  }
  int res = 0;
  for(int S = 0; S < (1 << n); S++){
    bool lightAll = true;
    rep(i, m){
      int cnt = 0;
      rep(j, k[i]){
        if(S & (1 << s[i][j]))
          cnt++;
      }
      if(cnt % 2 != p[i]){
        lightAll = false;
      }
    }
    if(lightAll){
      //cerr << bitset<10>(S) << endl;
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
X,K,D = map(int, input().split())
X=abs(X)
if X>=K*D:
  print(X-K*D)
else:
  y=X//D
  z=K-y
  j=y*D
  if z%2==0:
    print(abs(X-j))
  else:
    print(abs(X-j-D))

Measured memory_bytes: 9092
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi T = {1};
    for(int k : {6, 9}){
        int x = k;
        while(x <= n){
            T.emplace_back(x);
            x *= k;
        }
    }
    sort(_all(T));

    vi dp(n+1, inf);
    dp[0] = 0;

    rep(i, n){
        int cur = dp[i];

        for(int k : T){
            int ni = i + k;
            if(ni > n) break;
            chmin(dp[ni], cur + 1);
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,Q = inpl()

lines = defaultdict(set)
for _ in range(N-1):
    a,b = inpl()
    a,b = a-1,b-1
    lines[a].add(b)

adds = [0]*N
for _ in range(Q):
    p,x = inpl()
    adds[p-1] += x

visited = [False]*N
ans = [0]*N

q = queue.LifoQueue()
q.put([0,0])

while not q.empty():
    x,cnt = q.get()
    cnt += adds[x]
    ans[x] += cnt
    for t in lines[x]:
        q.put([t,cnt])

print(' '.join(map(str,ans)))


Measured memory_bytes: 141308
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+9;
int main()
{
	int n;
	scanf("%d",&n);
	char str[maxn];
	set<string>s;
	for(int i=1;i<=n;i++)scanf("%s",str),s.insert(str);
	printf("%d\n",s.size());
}


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    string w[n];
    int i, j;
    REP(i, n){
        w[i] = "";
    }
    REP(i, n){
        cin>>w[i];
    }
    for(i=1; i<n; i++){
        if(w[i-1][w[i-1].length()-1]==w[i][0]){

        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
        
        for(j=0; j<i; j++){
            if(w[i]==w[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}

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

int main(void)
{
	int n;
	string s1,s2;
	string kurai = "mcxi";
	vector<int> v1(4),v2(4);
	vector<int> sum(4);
	int temp;
	char c;

	int i,i1,i2;

	cin >> n;

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

		cin >> s1 >> s2;

	//	cout << s1 << " " << s2;

		/* syoki */
		for(i1=0; i1<4; i1++){
			v1[i1] = 0;
			v2[i1] = 0;
			sum[i1] = 0;
		}


		/* v1 */
		temp = 1;
		for(i1=0; i1<s1.length(); i1++){

			if ('2' <= s1[i1] && s1[i1] <= '9'){
				temp = s1[i1] - 48;
				continue;
			}
	//		cout << temp << endl;
			for(i2=0; i2<4; i2++){

				if (s1[i1] == kurai[i2]){
					v1[i2] = temp;
					temp = 1;
					break;
				}

			}
		}

		
		/* v2 */
		temp = 1;
		for(i1=0; i1<s2.length(); i1++){

			if ('2' <= s2[i1] && s2[i1] <= '9'){



				temp = s2[i1] - 48;
				
				continue;
			}


			for(i2=0; i2<4; i2++){

				if (s2[i1] == kurai[i2]){
					v2[i2] = temp;
					temp = 1;
					break;
				}

			}
		}



		/* plus */
		for(i1=3; i1>=0; i1--){
			sum[i1] = sum[i1] + v1[i1] + v2[i1];

			if (sum[i1]>=10){
				sum[i1] = sum[i1] % 10;
				sum[i1-1]++;
			}

		}



		/* print */
		for(i1=0; i1<4; i1++){

			if (sum[i1] == 0) continue;
			else if (sum[i1] == 1){
				cout << kurai[i1];
			}
			else {
				c = sum[i1] + 48; 
				cout << c << kurai[i1];
			}
		}

		cout << endl;
	}

/*	for(i1=0; i1<4; i1++){
		cout << sum[i1] << " ";
	}
*/
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

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 (a>b) { a=b; return 1; } return 0; }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(ALL(v));
    int half = N / 2;
    if (v[half-1] == v[half]) {
        cout << 0 <<endl;
    } else {
        cout << v[half] - v[half-1] << endl;
    }


    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int A, B;
    cin >> A >> B;

    if(A == 1) A += 13;
    if(B == 1) B += 13;

    if(A < B) cout << "Bob" << endl;
    else if(B < A) cout << "Alice" << endl;
    else cout << "Draw" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

#define ALL(obj) (obj).begin(), (obj).end() 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)

/*
233333332

466666664
466666664

466...664
69....996
699...996
46....664
*/

void swap(ll* a, ll* b){
    ll t = *a;
    *a = *b;
    *b = t;
}

int main(){
    ll n,m,ans=0;
    cin >> n >> m;
    if(n<m) swap(&m,&n);
    if(n==1&&m==1){ ans=1;
    }else if(m==1){ ans=n-2;
    }else{ ans = (m-2)*(n-2);}

    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 256
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return Math.ceil(this/2 - 1); };
    Number.prototype.leftIdx = function() { return this * 2 + 1; };
    Number.prototype.rightIdx = function() { return this * 2 + 2; };
  }

  insert(key) {
    this.heapIncrease(this.keys.push(key) - 1);
  }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const keys = this.keys;
    const res = keys[0];
    keys[0] = keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys;
    const n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && Number(keys[left]) > Number(keys[largest])) largest = left;
      if (right < n && Number(keys[right]) > Number(keys[largest])) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }

  print() {
    console.log(this.keys);
    console.log(this.keys.reduce((s, e, i)=>s += e.toString() + (([0,2,6,18].indexOf(i) + 1) ? '\n' : ' '), ''));
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.pop();
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()}\n`; break;
    }
  });
  process.stdout.write(str);
})();



Measured memory_bytes: 203972
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    if (S.size() == 2){
        cout << S << endl;
    }
    else {
        reverse(ALL(S));
        cout << S << endl;
    }
}



Measured memory_bytes: 256
a=int(input())
b=[]
b=list(map(int,input().split()))
for i in range(a):
    if (sum(b[0:i])-sum(b[i:]))**2<(sum(b[0:i+1])-sum(b[i+1:]))**2:
        print(abs(sum(b[0:i])-sum(b[i:])))
        break

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println(br.readLine().contains("7") ? "Yes" : "No");
	}
}

Measured memory_bytes: 25372
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  int n;
  cin>>n;
  vector<int> s(n);
  int ans=0;
  for(int i=0; i<n; i++) {
    cin>>s[i];
    ans+=s[i];
  }
  sort(s.begin(), s.end());
  if(ans%10!=0) {
    cout<<ans<<endl;
    return 0;
  }
  for(int i=0; i<n; i++) {
    if((ans-s[i])%10!=0) {
      cout<<ans-s[i]<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    Cout(n*n*n);
    return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	string s, t;
	cin >> s >> t;

	int ans = 0;

	for(int i = 0; i < s.length(); i++) {
		if(s[i] != t[i]) ans++;
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3884
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc087_a.cpp
 * time   : Thu Apr 30 16:48:02 2020
 * quest  : A - Buying Sweets
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, a, b;
  cin >> x >> a >> b;
  if (a >= x)
    cout << "0\n";
  else
    cout << (x - a) % b << "\n";
  return 0;
}


Measured memory_bytes: 256
class SegmentTreeLazy():
    def __init__(self, arr, ti, ei, func, op, merge):
        self.h = (len(arr) - 1).bit_length()
        self.n = 2**self.h
        self.func = func
        self.op = op
        self.merge = merge
        self.ti = ti
        self.ei = ei
        self.val = [ti for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.val[self.n + i] = arr[i]
        for i in range(1, self.n)[::-1]:
            self.val[i] = self.func(self.val[2 * i], self.val[2 * i + 1])
        self.laz = [ei for _ in range(2 * self.n)]

    def reflect(self, k):
        if self.laz[k] == self.ei:
            return self.val[k]
        return self.op(self.val[k], self.laz[k])

    def propagate(self, k):
        if self.laz[k] == self.ei: return
        self.laz[2 * k] = self.merge(self.laz[2 * k], self.laz[k])
        self.laz[2 * k + 1] = self.merge(self.laz[2 * k + 1], self.laz[k])
        self.val[k] = self.reflect(k)
        self.laz[k] = self.ei

    def thrust(self, k):
        for i in range(1, self.h + 1)[::-1]:
            self.propagate(k >> i)

    def recalc(self, k):
        while k:
            k >>= 1
            self.val[k] = self.func(self.reflect(2 * k), self.reflect(2 * k + 1))

    def update(self, lt, rt, x):
        lt += self.n
        rt += self.n
        vl = lt
        vr = rt
        self.thrust(lt)
        self.thrust(rt - 1)
        while rt - lt > 0:
            if lt & 1:
                self.laz[lt] = self.merge(self.laz[lt], x)
                lt += 1
            if rt & 1:
                rt -= 1
                self.laz[rt] = self.merge(self.laz[rt], x)
            lt >>= 1
            rt >>= 1
        self.recalc(vl)
        self.recalc(vr - 1)

    def query(self, lt, rt):
        lt += self.n
        rt += self.n
        self.thrust(lt)
        self.thrust(rt - 1)
        vl = vr = self.ti
        while rt - lt > 0:
            if lt & 1:
                vl = self.func(vl, self.reflect(lt))
                lt += 1
            if rt & 1:
                rt -= 1
                vr = self.func(self.reflect(rt), vr)
            lt >>= 1
            rt >>= 1
        return self.func(vl, vr)

import sys
input = sys.stdin.buffer.readline

MOD = 998244353

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

arr = [a * MOD + 1 for a in map(int, input().split())]
ti = 0
ei = MOD

def func(a, b):
    a1, a2 = divmod(a, MOD)
    b1, b2 = divmod(b, MOD)
    c1 = (a1 + b1) % MOD
    c2 = (a2 + b2) % MOD
    return c1 * MOD + c2

def op(a, x):
    a1, a2 = divmod(a, MOD)
    x1, x2 = divmod(x, MOD)
    c1 = (a1 * x1 + a2 * x2) % MOD
    c2 = a2
    return c1 * MOD + c2

def merge(x, y):
    x1, x2 = divmod(x, MOD)
    y1, y2 = divmod(y, MOD)
    z1 = (x1 * y1) % MOD
    z2 = (x2 * y1 + y2) % MOD
    return z1 * MOD + z2

st = SegmentTreeLazy(arr, ti, ei, func, op, merge)

res = list()

for _ in range(Q):
    q, *p = map(int, input().split())
    if q == 0:
        l, r, b, c = p
        st.update(l, r, (b * MOD + c))
    else:
        l, r = p
        res.append(st.query(l, r) // MOD)

print('\n'.join(map(str, res)))

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

int main(){

	int w, val[50], cnt[6], v;

	map<char, int> fix, dsc, weight;
	
	weight.insert(make_pair('A', 200));
	weight.insert(make_pair('B', 300));
	weight.insert(make_pair('C', 500));
	
	fix.insert(make_pair('A', 380));
	fix.insert(make_pair('B', 550));
	fix.insert(make_pair('C', 850));
	
	dsc.insert(make_pair('A', 1520));
	dsc.insert(make_pair('B', 1870));
	dsc.insert(make_pair('C', 2244));
	
	fill(val, val+50, 9500);
	fill(cnt, cnt+6, 0);

	for(int cnt_fA=0; cnt_fA<=25; cnt_fA++){
		for(int cnt_fB=0; cnt_fB<=16; cnt_fB++){
			for(int cnt_fC=0; cnt_fC<=10; cnt_fC++){
				for(int cnt_dA=0; cnt_dA<=5; cnt_dA++){
					for(int cnt_dB=0; cnt_dB<=4; cnt_dB++){
						for(int cnt_dC=0; cnt_dC<=3; cnt_dC++){
							w = weight['A']*(cnt_fA + 5*cnt_dA) + weight['B']*(cnt_fB + 4*cnt_dB) + weight['C']*(cnt_fC + 3*cnt_dC);
							if(w <= 5000){
								v = fix['A']*cnt_fA + fix['B']*cnt_fB + fix['C']*cnt_fC + dsc['A']*cnt_dA + dsc['B']*cnt_dB + dsc['C']*cnt_dC;
								val[w/100] = min(val[w/100], v);
							}
						}
					}
				}
			}
		}
	}
	
	while(cin >> w){
		if(w == 0) break;
		cout << val[w / 100] << endl;
	}

	return 0;

}

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

int main() {
  int a,b,n,h,hh;
  string s;
  cin>>s;
  n=s.size();
  h=(n-1)/2;
  hh=h/2;
  int ans=1;
  for(int i=0;i<h;i++){
    if(s.at(i)!=s.at(n-1-i)){
      ans*=0;
    }
  }
  for(int i=0;i<hh;i++){
    if(s.at(i)!=s.at(h-1-i)){
      ans*=0;
    }
  }
  if(ans==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;  
  }
}

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

using namespace std;
pair<int,int> f[100005];
int find(int x)
{
	if(f[x].first==x&&f[x].second==0)
	{
		return x;
	}
	int t=find(f[x].first);
	f[x]=make_pair(t,f[f[x].first].second+f[x].second);
	         //f[x]父亲到其祖先的距离
	f[x].first=t;
	return t; 
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) f[i]=make_pair(i,0);
	for(int i=1;i<=m;i++)
	{
		int l,r,d;
		cin>>l>>r>>d;
		int x=find(l);
		int y=find(r);
		if(x==y)
		{
			if(f[r].second-f[l].second!=d)
			{
				cout<<"No"<<endl;
				return 0;
			} 
		}
		else
		{
			if(x>y) f[x]=make_pair(y,-(f[l].second-f[r].second+d));
			else f[y]=make_pair(x,f[l].second-f[r].second+d);
		}
	}	
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1024
def gcd(a,b):
    if(a%b!=0):
        return gcd(b,a%b)
    else:
        return b
def lcm(a,b):
    return (a*b//(gcd(a,b)))
def main3():
    n,m=map(int, input().split())
    s=input()
    t=input()
    if(n>m):
        s1 = t
        t1 = s
    else:
        s1 = s
        t1 = t
    l = (lcm(n,m))
    l_n = l//n
    l_m = l//m
    i = 0
    ind_min = []
    ind_max = []
    while(i<min(n,m)):
        ind_min.append(i*max(l_n,l_m)+1)
        i+=1
    i = 0
    while(i<max(n,m)):
        ind_max.append(i*min(l_n,l_m)+1)
        i+=1

    ind_max_d = {k:i for i,k in enumerate(ind_max)}

    for i in range(len(ind_min)):
        if(ind_min[i] in ind_max_d):
            if(s1[i] != t1[ind_max_d[ind_min[i]]]):
                print(-1)
                exit()
    print(l)



if __name__ == '__main__':
    main3()


Measured memory_bytes: 28372
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int n;
  while(~scanf("%d",&n)){
    int dismiss_tile;
    scanf("%d",&dismiss_tile);
    for(int i=0;i<dismiss_tile;i++){
      int col,row;
      scanf("%d %d",&col,&row);
      int pos = min(
	min(col-1,n-col),
	min(row-1,n-row)
      );

      printf("%d\n",pos % 3 + 1);
    }
  }
}

Measured memory_bytes: 1188
<?php
fscanf(STDIN, "%d %d %d %d",$n,$a,$b,$c);
//得たい竹リスト
$abc=[$a,$b,$c];

//持っている竹リスト
for ($i=0;$i<$n;$i++){
	fscanf(STDIN, "%d",$L);
	$l[]=$L;
}
//最小コスト初期値
$minCost = INF;
//a、b、c、未使用の4パターンの全探索
for ($i=0;$i<pow(4, $n);$i++){
	$arrayA = array();
	$arrayB = array();
	$arrayC = array();
	$arrayD = array();
	//n個の手持ちの竹を得たいどの竹で使用するか
	for ($j=0;$j<$n;$j++){
		//aの竹
		if ((($i>>($j*2))&3)==3){
			$arrayA[]=$l[$j];
		//bの竹	
		}else if ((($i>>($j*2))&3)==2){
			$arrayB[]=$l[$j];
		//cの竹	
		}else if ((($i>>($j*2))&3)==1){
			$arrayC[]=$l[$j];
		//使用しない	
		}else if ((($i>>($j*2))&3)==0){
			$arrayD[]=$l[$j];
		}
	}
	if (count($arrayA)==0 || count($arrayB)==0 || count($arrayC)==0) {
		continue;
	} else {
		//コスト計算
		$cost = abs((array_sum($arrayA)-$a)) + ((count($arrayA)-1)*10) + abs((array_sum($arrayB)-$b)) + ((count($arrayB)-1)*10) + abs((array_sum($arrayC)-$c)) + ((count($arrayC)-1)*10);
		//最小コスト
		if ($cost < $minCost) {
			$minCost = $cost;
		}
	}
}
echo $minCost;

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n;
cin>>n;
long long int i;
int c;
for(i=n;i<n+1000;i++){
    if(i%1000==0){
        c=i;
    }
}
  cout<<c-n;  
    
    
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
char s[50];
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>s+1;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(s[i]==s[i-1])
		{
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";
	return 0;
}

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

int main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int x, y;
  x = max(a, c);
  y = min(b, d);
  
  int t = 0;
  if (x < y){
    t = y - x;
  }
  
  cout << t << endl;
  
  return 0;
}

Measured memory_bytes: 256