akhauriyash/Code-Regression huggingface dataset:
// 00:49

#include <cmath>
#include <iostream>

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

int convert(std::string str) {
  int len = str.length();

  int index = -1;
  int mult = 1;
  rep(i, len) {
    char c = str[i];
    if (c == 'A')
      index += 1 * mult;
    else if (c == 'C')
      index += 2 * mult;
    else if (c == 'G')
      index += 3 * mult;
    else if (c == 'T')
      index += 4 * mult;

    mult *= 4;
  }

  return index;
}

int main() {
  int n;
  std::cin >> n;

  // const int size = 16777216;
  // bool dict[16777216];
  bool *dict = new bool[16777216];
  for (int i = 0; i < 16777216; i++) {
    dict[i] = 0;
  }

  std::string com;
  std::string str;

  rep(i, n) {
    std::cin >> com >> str;
    int index = convert(str);
    if (com == "insert") {
      dict[index] = 1;
    } else {
      bool isIncluded = dict[index];
      if (isIncluded)
        std::cout << "yes" << '\n';
      else
        std::cout << "no" << '\n';
    }
  }

  return 0;
}



Measured memory_bytes: 19584
class Node():
    def __init__(self, value):
        self.value = value
        self.deep = -1
        self.parent = None
        self.left = -1
        self.right = -1
        self.height = -1
        self.sib = -1

def setdeep(tree, i, deep):
    tree[i].deep = deep
    if tree[i].left != -1:
        setdeep(tree, tree[i].left, deep + 1)
    if tree[i].right != -1:
        setdeep(tree, tree[i].right, deep + 1)

def setheight(tree, i):
    if tree[i].height != -1:
        pass
    elif tree[i].left == -1 and tree[i].right == -1:
        tree[i].height = 0
    elif tree[i].left == -1:
        tree[i].height = setheight(tree, tree[i].right)
    elif tree[i].right == -1:
        tree[i].height = setheight(tree, tree[i].left)
    else:
        tree[i].height = max(setheight(tree, tree[i].right), setheight(tree, tree[i].left))
    return tree[i].height + 1

if __name__ == '__main__':
    n = int(input())
    tree = {}

    for _ in range(n):
        datas = [int(num) for num in input().split(' ')]
        nodeid = datas[0]
        if nodeid not in tree.keys():
            tree[nodeid] = Node(nodeid)
        tree[nodeid].left = left = int(datas[1])
        tree[nodeid].right = right = int(datas[2])
        if left != -1:
            if left not in tree.keys():
                tree[left] = Node(left)
            tree[left].parent = nodeid
            tree[left].sib = right
        if right != -1:
            if right not in tree.keys():
                tree[right] = Node(right)
            tree[right].parent = nodeid
            tree[right].sib = left

    for i in range(n):
        curnode = tree[i]
        if curnode.parent is None:
            # this is root
            setdeep(tree, i, 0)
            setheight(tree, i)
            break
            
    for i in range(n):
        curnode = tree[i]
        deg = 0
        if curnode.left == -1 and curnode.right == -1:
            nodetype = 'leaf'
            deg = 0
        else:
            if curnode.left != -1:
                deg += 1
            if curnode.right != -1:
                deg += 1
            nodetype = 'internal node'
        if curnode.parent == None:
            nodetype = 'root'
            parent = -1
        else:
            parent = curnode.parent
        print('node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s' \
            % (i, parent,curnode.sib, deg,  curnode.deep, curnode.height, nodetype) )


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

using namespace std;
#define PB push_back
#define LL long long
#define int LL
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define VI vector<int>
#define PII pair<int,int>
#define LD long double

template<class C> void mini(C& a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n;
  cin>>n;

  VI inp(n);
  REP(i, n)
    cin>>inp[i];
  int curValue = 0;
  int res = 0;
  if(inp[0] != 0){
    cout<<-1<<"\n";
    return 0;
  }
  FORD(i, n - 1, 0){
    curValue--;
    maxi(curValue, 0LL);
    debug(curValue, inp[i]);
    if(inp[i] < curValue){
      cout<<-1<<"\n";
      return 0;
    } else if(inp[i] == curValue){
      continue;
    }
    curValue = inp[i];
    res += curValue;
  }
  cout<<res<<"\n";
}

Measured memory_bytes: 1792
# At BC 042 C (300)

# find first digit (from the left)
# that needs to be changed.
# if that digit is incremented, then
#   decrement everything after it as much as possible
# if that digit has to be decremented, then increase (or insert) a digit
#   before that digit and then decrement everything after the incremented digit
#
def dec(i, D):
    for k in range(i - 1, -1, -1):
        if k not in D:
            return k
    return i

def inc(i, D):
    for k in range(i + 1, 10):
        if k not in D:
            return k
    return i

def max_dec_or_inc(A, start, D):
    for j in range(start, len(A)):
        d = dec(A[j], D)
        if d != A[j]:
            while d != A[j]:
                A[j] = d
                d = dec(A[j], D)
        elif A[j] in D: # must change
            u = inc(i, D)
            A[j] = u

def inc_one(A, end, D):
    for j in range(end - 1, -1, -1):
        up = inc(A[j], D)
        if up != A[j]:
            A[j] = up
            return j
    A.insert(0, inc(0, D))
    return 0

def f(n, D):
    out = list(map(int, str(n)))
    for j, i in enumerate(out):
        if i in D: # first from left that needs to be changed
            up = inc(i, D)
            if up != i: # possible to increment at j
                out[j] = up
                # decrement everything after j
                max_dec_or_inc(out, j + 1, D)
            else: # must decrement at index j
                out[j] = dec(i, D)
                # increment one before j
                idx = inc_one(out, j, D)
                # decrement everything after j
                max_dec_or_inc(out, idx + 1, D)
            break
    r = int("".join([str(x) for x in out]))
    return r

assert f(1000, [1, 3, 4, 5, 6, 7, 8, 9]) == 2000
assert f(9999, [0]) == 9999
assert f(6888, [8, 9]) == 7000
assert f(9999, [9]) == 10000
assert f(9999, [0, 9]) == 11111
assert f(9999, [0, 1, 9]) == 22222

n, k = map(int, input().split())
D = list(sorted(map(int, input().split())))
ans = f(n, D)
print(ans)


Measured memory_bytes: 38256
def num(m):
    return len(list(filter(lambda x: x>=m-1, e)))

n = int(input())
e = [0]*(n+1)
for i in range(2,n+1):
    t = i
    for j in range(2,i+1):
        while t%j == 0:
            e[j] += 1
            t //= j

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1)+ num(5) * (num(5) - 1) * (num(3) - 2) // 2)


Measured memory_bytes: 3060
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;
int main() {
    int n,ans;
    cin >> n;
    int a = n % 3;
    if(a == 0){
        cout << n/3 << endl;
    }
    else{
        ans = n/3;
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
  int64_t N,sum=0;
  cin >> N;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0){
      sum+=i;
    }
  }
  cout << sum << endl;
}

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

signed main(){
  
  string n;
  cin >> n;
  
  if(
     n[(int)n.size()-1] == '0' ||
     n[(int)n.size()-1] == '1' ||
     n[(int)n.size()-1] == '6' ||
     n[(int)n.size()-1] == '8'
     ) cout << "pon" << endl;
  else if(
	  n[(int)n.size()-1] == '3'
	  ) cout << "bon" << endl;
  else cout << "hon" << endl;
  
  return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
using namespace std;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	
	cout<<(n/(a+b))*a+min(n%(a+b),a);
return 0;
}

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

int a[10010];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  int cnt = 0;
  for(int i = 0; i < n; i++){
    int t = a[i];
    for(int j = sqrt(t); j >= 2; j--){
      while(t%j == 0) t /= j;
    }
    if(t == a[i]) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3120
N = gets.to_i
K = gets.to_i

min = 10000000000
(2**N).times do |i|
  r = 1
  sousa = sprintf("%0#{N}b", i)
  N.times do |j|
    if sousa[j]=="0" then
      r *= 2
    else
      r += K
    end
  end
  min = [min,r].min
end
puts min

Measured memory_bytes: 1788
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    int S,h,m,s;
    cin>>S;
    h=S/3600;
    S=S%3600;
    m=S/60;
    s=S%60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}


Measured memory_bytes: 3100
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

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 FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


char A[303][303];
int U[303];
int ans[303][303];
void solve() {
	int H, W, K; cin >> H >> W >> K;
	int L = 1000000;
	REP(i, 303)U[i] = 1e9;
	vector<P>v;
	REP(i, H) {
		REP(j, W) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				v.push_back({ j,i });
				L = min(L, j);
				U[j] = min(U[j], i);
			}
		}
	}
	VSORT(v);
	FOR(k, 1, K + 1) {
		int x = v[k - 1].second, y = v[k - 1].first;
		int u = x;
		if (U[y] == x)u = 0;
		int l = y;
		if (L == y)l = 0;
		int r = W;
		FOR(j, y+1, W)if (U[j] != 1e9) { r = j; break; }
		int d = H;
		FOR(i, x + 1, H)if (A[i][y] == '#') {
			d = i; break;
		}
		FOR(i, u, d) {
			FOR(j, l, r)ans[i][j] = k;
		}
	}
	REP(i, H) {
		REP(j, W)pe(ans[i][j]);
		cout << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 3184
#include <iostream>
using namespace std;
string str;
int a = -1, b = -1;
int main(void){
    // Your code here!
    cin >> str;
    if (str.length() == 2) cout << (str[0] == str[1] ? "1 2" : "-1 -1") << endl;
    else {
        for (int i = 2; i < str.length(); i++) {
            if (str[i - 2] == str[i - 1]) a = i - 1, b = i;
            if (str[i - 1] == str[i]) a = i, b = i + 1;
            if (str[i] == str[i - 2]) a = i - 1, b = i + 1;
        }
        cout << a << ' ' << b << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int a[5],f1,f2;
string str;
int main() {
    cin>>str;
    for (int i=1; i<=4; i++) a[i]=(int)(str[i-1])-48;
    if (a[3]>1) f1=1;
    else if (a[3]==1 and a[4]>2) f1=1;
    else if (a[3]==0 and a[4]==0) f1=1;
    if (a[1]>1) f2=1;
    else if (a[1]==1 and a[2]>2) f2=1;
    else if (a[1]==0 and a[2]==0) f2=1;
    if (f1 and f2) cout<<"NA\n";
    else if (f1) cout<<"MMYY\n";
    else if (f2) cout<<"YYMM\n";
    else cout<<"AMBIGUOUS\n";
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        char[] data = S.toCharArray();
        List<Integer>[] list = new List[10];
        for (int i = 0; i < 10; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 0; i < data.length; i++) {
            list[data[i]-'0'].add(i);
        }
        HashSet<String> counted = new HashSet<>();
        int ans = 0;
        for (int i = 0; i < 10; i++) {
            for (int k = 0; k < 10; k++) {
                for (int j = 0; j < 10; j++) {
                    if (list[i].size() == 0 || list[j].size() == 0 || list[k].size() == 0) {
                        continue;
                    }
                    int x = list[i].get(0);
                    int z = list[k].get(list[k].size()-1);
                    for (int y : list[j]) {
                        if (x < y && y < z) {
                            ans += 1;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24656
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    int dif = 'A' - 'a';
    for(int i = 0; i < n; i++){
        if(i == k-1){
            char tmp = s[i] - dif;
            cout << tmp;

        }else{
            cout << s[i];
        }
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc087/tasks/abc087_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(X, A, B):
    nokori = X - A
    return nokori % B


def main(args):
    X = int(input())
    A = int(input())
    B = int(input())
    ans = solve(X, A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
from typing import List
import sys


def solution(inp: List) -> int:
    inp.pop(0)
    ans: int = 0
    recent: int = 0
    for n in inp:
        if recent > int(n):
            ans += recent - int(n)
            continue
        recent = int(n)
    return ans


inp: List = []
for j in sys.stdin:
    inp += j.split()
print(solution(inp))


Measured memory_bytes: 28732
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

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

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    X = [x - A for x in X]

    base = 2500
    dp = [[0] * 5001 for _ in range(N + 1)]
    dp[0][base] = 1
    for i in range(N):
        for j in range(-2500, 2501):
            if -2500 <= j - X[i] <= 2500:
                dp[i + 1][j + base] = dp[i][j + base] + dp[i][j - X[i] + base]
            else:
                dp[i + 1][j + base] = dp[i][j + base]

    print(dp[N][base] - 1)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 11484
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
const int MXN = 2e5+5;
VI V[MXN];
LL sil[MXN];
LL inv[MXN];
int mod = 1e9+7;
int siz[MXN];
LL coeff[MXN];
LL dp[MXN];
LL pod[MXN];
LL par[MXN];
int n;

LL pot(LL a, LL n)
    {
    if(n == 0)return 1;
    if(n % 2)return pot(a, n-1) * a % mod;
    return pot(a * a % mod, n/2);
    }
LL invv(int x)
  {
  return pot(x, mod-2);
  }


LL npok(int n, int k)
  {
  return sil[n] * inv[n-k] % mod * inv[k] % mod;
  }

LL bez(int v, int i)
  {
  int act_siz = (i == par[v] ? n-siz[v] : siz[i]);
  return coeff[v] * invv(npok(n-1, act_siz)) % mod;
  }

LL dfs(int v, int pp)
  {
  par[v] = pp;
  siz[v] = 1;
  dp[v] = 1;
  for(auto i: V[v])
    if(i != pp)
      {
      dfs(i, v);
      siz[v] += siz[i];
      dp[v] *= dp[i];
      dp[v] %= mod;
      }

  coeff[v] = 1;
  int all_siz = n-1;
  for(auto i: V[v])
    {
    int act_siz = (i == pp ? n-siz[v] : siz[i]);
    coeff[v] *= npok(all_siz, act_siz);
    coeff[v] %= mod;
    all_siz -= act_siz;
    }

  pod[v] = dp[v];
  dp[v] *= bez(v, pp);
  dp[v] %= mod;


//  debug(v, coeff[v], dp[v]);
  return dp[v];
  }

LL ans[MXN];

void dfs2(int v, LL push, int pp)
  {
  ans[v] = push * pod[v] % mod * coeff[v] % mod;

  for(auto i: V[v])
    if(i != pp)
      {
      dfs2(i, push * pod[v] % mod * invv(dp[i]) % mod * bez(v, i) % mod, v);
      }
  }


int main()
{
  ios_base::sync_with_stdio(0);
  cin >> n;
  sil[0] = 1;
  FOR(i, 1, n)sil[i] = sil[i-1] * i % mod;
  inv[n] = pot(sil[n], mod-2);
  FORD(i, n-1, 0)inv[i] = inv[i+1] * (i+1) % mod;

  REP(i, n-1)
    {
    int a, b;
    cin >> a >> b;
    V[a].PB(b);
    V[b].PB(a);
    }

  dfs(1, 0);
  dfs2(1, 1, 0);
  FOR(i, 1, n)
    {
    cout << ans[i] << endl;
    }
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int r, D, x;
    cin >> r >> D >>x;
    int prev = x;
    for (int i = 0; i < 10; ++i) {
        prev =  r*prev-D;
        cout <<  prev<< endl;
    }

}

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


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			String s = sc.next();
			String s2 = s;
			String s3 = s;
			int q= sc.nextInt();
			for (int i=0; i<q; i++) {
				String command = sc.next();
				int a = sc.nextInt();
				int b = sc.nextInt();

				switch(command) {
				case "replace":
					String p = sc.next();
					s3 = s2.substring(0,a) + p + s2.substring(b+1);
					s2 = s3;
					break;
				case "reverse":
					s3 = s2.substring(a,b+1);
					StringBuffer sb = new StringBuffer(s3);
					String reverse = sb.reverse().toString();
					s3 = s2.substring(0,a) + reverse + s2.substring(b+1);
					s2 = s3;
					break;
				case "print":
					s3 = s2.substring(a, b+1);
					System.out.println(s3);  //結果表示
					break;

				}
			}
		}
	}
}


Measured memory_bytes: 29656
#include <iostream>

using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int S[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    
    for (int i = 0; i < n1; i++) {
        L[i] = S[left + i];
    }
    
    for (int i = 0; i < n2; i++) {
        R[i] = S[mid + i];
    }
    
    L[n1] = R[n2] = SENTINEL;
    
    int i = 0, j = 0;
    
    for (int k = left; k < right; k++) {
        cnt++;
        
        if (L[i] <= R[j]) {
            S[k] = L[i++];
        } else {
            S[k] = R[j++];
        }
    }
}

void mergeSort(int S[], int n, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(S, n, left, mid);
        mergeSort(S, n, mid, right);
        merge(S, n, left, mid, right);
    }
}

int main() {
    int n, S[MAX];
    int i;
    cnt = 0;
    
    cin >> n;
    
    for (i = 0; i < n; i++) {
        cin >> S[i];
    }
    
    mergeSort(S, n, 0, n);
    
    for (i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << S[i];
    }
    
    cout << endl;
    
    cout << cnt << endl;
    
    return 0;
}



Measured memory_bytes: 6992
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    na = 1
    nb = 1
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        r = max((na + t - 1) // t, (nb + a - 1) // a)
        na = r * t
        nb = r * a
    print(na + nb)


if __name__ == '__main__':
    slove()


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

int main()
{
    int n;
    cin >> n;
    vector<int> now(n, 0);
    vector<int> future(n);

    for (auto i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        future[i] = h;
    }

    int ans = 0;
    int update_num = 0;

    do
    {
        update_num = 0;
        int p = 0;
        while (p < n)
        {
            if (future[p] > now[p])
            {
                update_num += 1;
                while (p < n && future[p] > now[p])
                {
                    now[p] += 1;
                    p += 1;
                }
            }else{
                p += 1;
            }
        }

        ans += update_num;

    } while (update_num != 0);

    cout << ans << endl;
}

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

signed main(){
  string S;
  cin>>S;
  int SS=S.size();
  int ans=1000;
  rep(i,SS-2){
    int check=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
    ans=min(ans,abs(753-check));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
  int n;
  string str;
  int c=0;
  int cmax=0;
  cin>>n>>str;
  for(int i=0;i<n;i++)
  {
    if(str[i]=='D')
        c--;
    else
        c++;
    cmax=max(cmax,c);
  }
  cout<<cmax;

    return 0;
}








Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    int N;
    cin>>N;
    string s,t;
    cin>>s>>t;
    string s1="";
    F0R(i,N){
        s1+=s[i];
        s1+=t[i];
    }
    out(s1);

    return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int a, b; cin >> a >> b;

	if(a <= 0 and b >= 0) cout << "Zero" << endl;
	else if(a > 0) cout << "Positive" << endl;
	else if(b < 0){
		if((b-a)%2 == 1) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define hetu int t;cin >> t;while(t--) 


void solve()
{
	string s;
	cin >> s;
	if(s=="RRR")
	{
		cout << 3 << endl;
	}
	else if(s=="RRS")
	cout << 2 << endl;
	else if(s=="RSR")
	cout << 1 << endl;
	else if(s=="RSS")
	cout << 1 << endl;
	else if(s=="SRR")
	cout << 2 << endl;
	else if(s=="SRS")
	cout << 1 << endl;
	else if(s=="SSR")
	cout << 1 << endl;
	else if(s=="SSS")
	cout << 0 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//hetu
	solve();
	return 0;
}

Measured memory_bytes: 3648
import sys
b = input()
if not ( b == 'A' or b == 'T' or b == 'G' or b == 'C' ): sys.exit()

if b == 'T': print('A')
if b == 'A': print('T')
if b == 'C': print('G')
if b == 'G': print('C')

Measured memory_bytes: 9060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int A = sc.nextInt();
	    int B = sc.nextInt();
	    
	    double doubleK = (double)(A + B) / 2;
	    int intK = (A + B) / 2;
	    
	    if (doubleK == intK) {
	    	System.out.println(intK);
	    } else {
	    	System.out.println("IMPOSSIBLE");
	    }
	}	
}	

Measured memory_bytes: 20820
import math
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
def lcm(a,b):
  if a >= b:
    return a*b//gcd(a,b)
  else:
    return a*b//gcd(b,a)
 
 
A, B, C, D = map(int, input().split())
A -= 1

k1 = A // C
k2 = B // C
k3 = A // D
k4 = B // D
 
k5 = k2 - k1 + 1
k6 = k4 - k3 + 1
 
lcm_num = lcm(C, D)
k7 = A // lcm_num
k8 = B // lcm_num
 
k9 = k8 - k7 + 1
 
print(B - A + 1 - k5 - k6 + k9)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  vector<bitset<10>> shop(n);
  rep(i,n){
    bitset<10> tmp;
    rep(j,10){
      bool f;
      cin >> f;
      tmp.set(j,f);
    }
    shop.at(i) = tmp;
  }
  vector<vector<int>> p(n,vi(11));
  rep(i,n){
    rep(j,11) cin >> p.at(i).at(j);
  }
  
  int ans = -1e9;
  for(int i=1;i<(1 << 10);i++){
    bitset<10> joi(i);
    int ben = 0;
    rep(j,n){
      bitset<10> mult = (joi & shop.at(j));
      int sum = 0;
      rep(k,10){
        if(mult.test(k)) sum++;
      }
      ben += p.at(j).at(sum);
    }
    ans = max(ans,ben);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter, defaultdict


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: 0)

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        res = table[i]
        pre = D[ci]
        res += pre
        table[i + 1] = res % V

        D[ci] = D[ci] + table[i] % V

    print(table[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 31336
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> al = new ArrayList<>();

		int x = 999;
		int y = 999;
		int cnt = 0;
		
		while(x != 0 || y != 0) {
			x = sc.nextInt();
			y = sc.nextInt();
			if(x == 0 && y == 0) {
				break;
			} else if(x < y) {
				cnt = cnt + 2;
				al.add(x);
				al.add(y);
			} else if(x > y) {
				cnt = cnt + 2;
				al.add(y);
				al.add(x);
			} else {
				cnt = cnt + 2;
				al.add(x);
				al.add(y);
			}
		}
		
		int i = 0;
		while(i < cnt) {
			System.out.println(al.get(i) + " " + al.get(i+1));
			i = i + 2;
		}
	
	}
}

Measured memory_bytes: 37788
n,m=map(int,input().split())
claim=[0]*m
for i in range(m):
    claim[i]=list(map(int,input().split()))
claim=sorted(claim,key=lambda x:x[1])
right=claim[0][1]
count=1
for i in range(1,m):
    if claim[i][0]>=right:
        count+=1
        right=claim[i][1]
print(count)

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

int main(){

    int N;
    cin >> N;
    set<int> A;
    rep(i, N){
        int a = 0;
        cin >> a;
        A.insert(a);
    }

    int n = A.size();

    if(N == n) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}

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

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

    vector<int> vecFood(n);
    for(int i=0; i<n; i++)
        cin >> vecFood.at(i);
    
    vector<int> vecPoint(n);
    for(int i=0; i<n; i++)
        cin >> vecPoint.at(i);

    vector<int> vecAdd(n);
    for(int i=0; i<n-1; i++)
        cin >> vecAdd.at(i);

    // 結果計算
    int res = 0;
    for(int i=0; i<n; i++)
        res += vecPoint[i];

    for(int i=0; i<n-1; i++){
        if(vecFood[i] + 1 != vecFood[i+1])
            continue;
        
        res += vecAdd[vecFood[i]-1];
    }

    cout << res << endl;

    return 0;
}

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

int main(){
    ll N,K;
    cin >> N >> K;
    ll sum = 0;
    for(ll b=1;b<=N;b++){
        ll q = N/b;
        ll r = N%b;
        sum += max(ll(0),b-K)*q;
        if(K == 0)sum--;
        sum += max(ll(0),r-K+1);
        //sum -= 1;
    }
    cout << sum << endl;
    
    /*
    for(ll i=K;i<=N;i++){
        sum += N-i;
    }
    for(ll i=2*K+1; i<=N;i++){
        sum += i/(K+1);
    }

    cout << sum << endl;
    */
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		String w = scan.nextLine().toLowerCase();
		int count = 0;
		while (true) {
			String t = scan.next();
			if (t.equals("END_OF_TEXT")) break;
			else if (t.toLowerCase().equals(w)) count++;
		}
		scan.close();
		System.out.println(count);
	}
}

Measured memory_bytes: 26344
def difference(h1, m1, h2, m2, k): 
    t1 = h1 * 60 + m1 
    t2 = h2 * 60 + m2  
    diff = t2-t1
    print(diff - k)

L = input().split()
H1 = int(L[0])
M1 = int(L[1])
H2 = int(L[2])
M2 = int(L[3])
K = int(L[4])

difference(H1, M1, H2, M2, K)




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, t; cin>>n>>t;
    vector<pi> P(n);
    rep(i, n) cin>>P[i].fi>>P[i].se;
    sort(all(P));

    vector<vll> dp(n+1, vll(t+1, 0ll));
    for(int i=0; i<n; i++){
        for(int j=0; j<=t-1; j++){
            if (j < P[i].fi){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-P[i].fi] + P[i].se);
            }
        }
    }
    ll ans = 0;
    rep(i, n){
        ans = max(ans, dp[i][t-1] + P[i].se);
    }

    cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 70784
N, K = gets.split.map(&:to_i)

h = N.times.map { gets.to_i }.sort

min = 10 ** 9 + 1

0.upto(h.size - K) do |i|
  d = h[i + K - 1] - h[i]
  min = d if d < min
end

puts min


Measured memory_bytes: 16656
sankouNum, argoNum, rikaido = map(int, input().split())

sankouCosts = []
sankouEffects = []

for _ in range(sankouNum):
    cost, *effect = map(int, input().split())

    sankouCosts.append(cost)
    sankouEffects.append(effect)


ans = float('inf')

# 買う/買わないの全組み合わせの生成
import itertools
for params in itertools.product([0,1], repeat=sankouNum):

    currentCost = 0
    currentRikaidos = [0] * argoNum
    # 一つの組み合わせごとのループ
    for si, param in enumerate(params):
        if param == 0:
            # si番目の参考書は買わない
            pass
        elif param == 1:
            # si番目の参考書を買う
            currentCost += sankouCosts[si]
            for ri in range(argoNum):
                currentRikaidos[ri] += sankouEffects[si][ri]
    # 理解度を満たすか判定
    if min(currentRikaidos) >= rikaido:
        # 満たす場合、ansより小さければ現時点での最小コストとなる
        ans = min(ans, currentCost)

if ans == float('inf'):
    print(-1)
else:
    print(ans)
        

Measured memory_bytes: 9180
N,K = map(int,input().split())
ans = 0
cnt_seq = [0]*(K+1) # cnt_seq[i] 最大公約数がiであるような数列の個数
MOD = 10**9 + 7
ans = 0
for i in range(K,0,-1):
    cnt_seq[i] = pow(K//i,N,MOD)
    for j in range(2*i,K+1,i):
        cnt_seq[i] -= cnt_seq[j]%MOD
    ans += i*cnt_seq[i]%MOD
print(ans%MOD)

Measured memory_bytes: 69968
def BubbleSort(l):
  countSwap = 0
  for i in range(len(l)-1):
    for j in reversed(range(i+1, len(l))):
      if l[j] < l[j-1]:
        temp = l[j]
        l[j] = l[j-1]
        l[j-1] = temp
        countSwap += 1
  print(" ".join(map(str, l)))
  print(countSwap)

N = input()
l = list(map(int, input().split()))
BubbleSort(l)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 305
#define mod 1000000007
#define inf 999999999999999

int n, m;
ll l, dist[maxn][maxn];
ll ans[maxn][maxn];

int main()
{
    cin >> n >> m >> l;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            dist[i][j] = (i == j) ? 0 : inf;
            ans[i][j] = (i == j) ? 0 : inf;
        }

    for (int i = 0; i < m; i++)
    {
        int x, y;
        ll w;
        scanf("%d%d%lld", &x, &y, &w);
        dist[x][y] = dist[y][x] = w;
    }

    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (dist[i][j] <= l)
                ans[i][j] = 1;

    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);

    int q;
    cin >> q;
    while (q--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        if (ans[x][y] == inf)
            printf("-1\n");
        else
            printf("%d\n", ans[x][y] - 1);
    }
    return 0;
}

Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#define SF scanf
#define PF printf
#define MAXN 200010
#define INF 10000000000000000ll
using namespace std;
int n,k;
typedef long long ll;
ll tree[MAXN*4],f[MAXN],sum;
int a[MAXN],b[MAXN],l[MAXN],r[MAXN];
vector<int> val;
ll min1(ll x,ll y){
	if(x==0)
		return y;
	if(y==0)
		return x;
	return min(x,y);	
}
ll que(int l,int r,int id,int pos){
	if(l==r)
		return tree[id];
	int mid=(l+r)>>1;
	if(pos<=mid)
		return min1(tree[id],que(l,mid,id*2,pos));
	else
		return min1(tree[id],que(mid+1,r,id*2+1,pos));
}
void change(int l,int r,int id,int pl,int pr,int v){
	if(pl>pr)
		return ;
	if(l>=pl&&r<=pr){
		tree[id]=min1(tree[id],v);	
		return ;
	}
	int mid=(l+r)>>1;
	if(pl<=mid)
		change(l,mid,id*2,pl,pr,v);
	if(pr>mid)
		change(mid+1,r,id*2+1,pl,pr,v);
}
int main(){
	SF("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		SF("%d",&a[i]);
		SF("%d",&b[i]);
		if(b[i]==1&&2*a[i]>k){
			PF("-1");
			return 0;
		}
		sum+=a[i];
		a[i]=(a[i]+a[i-1])%k;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			l[i]=2*(k-a[i-1])%k;
			r[i]=2*(k-a[i])%k;
		}
		else{
			l[i]=0;
			r[i]=k-1;	
		}
		val.push_back(l[i]);
		val.push_back(r[i]);
	}
	sort(val.begin(),val.end());
	int len=unique(val.begin(),val.end())-val.begin()-1;
	for(int i=1;i<=n;i++){
		//PF("{%d %d}\n",l[i],r[i]);
		r[i]=lower_bound(val.begin(),val.begin()+len,r[i])-val.begin();
		l[i]=lower_bound(val.begin(),val.begin()+len,l[i])-val.begin();	
		//PF("<%d %d>\n",l[i],r[i]);
	}
	for(int i=n;i>=1;i--){
		int res=que(0,len,1,l[i]);
		if(res==0)
			f[i]=0;	
		else
			f[i]=f[res]+(val[l[res]]-val[l[i]]+k)%k;
		if(l[i]<=r[i]){
			change(0,len,1,0,l[i]-1,i);
			change(0,len,1,r[i]+1,len,i);
		}
		else
			change(0,len,1,r[i]+1,l[i]-1,i);
	}
	ll ans=INF;
	for(int i=0;i<=len;i++){
		ll res=que(0,len,1,i);
		if(res)
			res=f[res]+(val[l[res]]-val[i]+k)%k;
		ans=min(ans,res);
	}
	PF("%lld",ans+2ll*sum);
}

Measured memory_bytes: 8564
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2000 + 20;
int n, m, q;
int sum[N][N], sumR[N][N], sumD[N][N];
string s[N];

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

	cin >> n >> m >> q;

	for (int i = 0; i < n; i++) cin >> s[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			sum[i + 1][j + 1] += sum[i][j + 1];
			sum[i + 1][j + 1] += sum[i + 1][j];
			sum[i + 1][j + 1] -= sum[i][j];

			if (s[i][j] == '1')
				sum[i + 1][j + 1]++;
	
			sumR[i + 1][j + 1] += sumR[i][j + 1];
			sumR[i + 1][j + 1] += sumR[i + 1][j];
			sumR[i + 1][j + 1] -= sumR[i][j];

			if (j + 1 < m && s[i][j] == '1' && s[i][j + 1] == '1')
				sumR[i + 1][j + 1]++;

			sumD[i + 1][j + 1] += sumD[i][j + 1];
			sumD[i + 1][j + 1] += sumD[i + 1][j];
			sumD[i + 1][j + 1] -= sumD[i][j];

			if (i + 1 < n && s[i][j] == '1' && s[i + 1][j] == '1')
				sumD[i + 1][j + 1]++;
		}


	while (q--)
	{
		int a1, b1, a2, b2;
		cin >> a1 >> b1 >> a2 >> b2;
		a1--, b1--;

		int ans = sum[a2][b2] - sum[a1][b2] - sum[a2][b1] + sum[a1][b1];
		ans -= sumR[a2][b2 - 1] - sumR[a1][b2 - 1] - sumR[a2][b1] + sumR[a1][b1];
		ans -= sumD[a2 - 1][b2] - sumD[a1][b2] - sumD[a2 - 1][b1] + sumD[a1][b1];

		cout << ans << '\n';
	}
}


Measured memory_bytes: 53760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	int A,B;
	cin>>A>>B;
	int ans;
	if(B%A==0)ans=A+B;
	else ans=B-A;
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power( (num*num)%mod,g/2,mod);
}


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

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

int main(){
  int n, x;
  cin >> n >> x;
  int ans = 0, mini = INT_MAX;
  for(int i=0;i<n;i++){
    int m;
    cin >> m;
    mini = min(mini, m);
    x -= m;
    ans++;
  }
  ans += x / mini;
  
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

int main()
{
    ll flag = 1 ;
    string s ;
    cin >> s ;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'h' and s[i + 1] == 'i')    i++ ;
        else {
            flag = 0 ;
        }
    }
    if (flag)   cout << "Yes" ;
    else    cout << "No" ;

    return 0 ;
}


Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()


t = [0] * (N+1)

for i in range(N):
    if S[i : i+2] == "AC":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for j in range(Q):
    l,r = map(int,input().split())
    print(t[r-1] - t[l-1])


Measured memory_bytes: 77428
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n, k, q;
	cin >> n >> k >> q;
	int* a;
	a = new int[n];
	memset(a, 0, sizeof(int)*n);
	rep(i, q) {
		int t;
		cin >> t;
		++a[t - 1];
	}

	rep(i, n) {
		if (k-q+a[i] > 0) {
			cout << "Yes" << "\n";
		}
		else {
			cout << "No" << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1024
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

let numComp = 0;
process.stdin.on('end', () => {
  const depth = +content.trim();
  const points = kochCurve([0, 0], [100, 0], depth);
  const precision = 6;
  console.log(
    points
      .map(point => point.map(n => n.toFixed(precision)).join(' '))
      .join('\n')
  );
});

const rotate = ([x1, y1], [x2, y2], degree) => {
  const rad = degree / 180 * Math.PI;
  const cos = Math.cos(rad);
  const sin = Math.sin(rad);
  return [
    (x1 - x2) * cos - (y1 - y2) * sin + x2,
    (x1 - x2) * sin + (y1 - y2) * cos + y2,
  ]
};

const kochCurve = (start, end, depth) => {
  if (depth === 0) {
    return [start, end];
  }

  const [x1, y1] = start;
  const [x2, y2] = end;
  const s = [(2 * x1 + x2) / 3, (2 * y1 + y2) / 3];
  const t = [(x1 + 2 * x2) / 3, (y1 + 2 * y2) / 3];
  const u = rotate(t, s, 60);

  const points = [start, s, u, t, end];
  if (depth === 1) {
    return points;
  } else {
    const result = [];
    for (let i = 0; i < points.length - 1; i++) {
      let p = kochCurve(points[i], points[i + 1], depth - 1);
      if (i !== points.length - 2) {
        p = p.slice(0, -1);
      }

      result.push(...p);
    }

    return result;
  }
};


Measured memory_bytes: 20264
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
 int a, b;
cin >> a >> b;
cout << a * b << " " << (a * 2) + (b * 2) << endl;
  return 0;
}



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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{	
	string s; cin >> s;
	int n = s.length();
	int res = 0;
	for (int i = 0; i < n / 2; ++i)
	{
		for (int j = 0; j < n / 2; ++j)
		{
			string p = s.substr(i, j);
			string t = s.substr(i + j, j);
			//cout << " p = " << p << " t = " << t << endl;
			if (p == t && len(p) == len(t)) 
			{
				res = max(res, 2 * j);
			}
		}
	}
	cout << res;
	
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3644